<?php
/**
 * Support Page
 *
 * @package     Wow_Pluign
 * @author      Dmytro Lobov <ad@wpcalc.com>
 * @copyright   2019 WpCalc
 * @since       1.0
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>

	<div class="about-wrap wow-support">
		<div class="feature-section one-col">
			<div class="col">

				<p><?php printf ( esc_attr__('To get your support related question answered in the fastest timing, please send a message via the form below or write to us on email %1$s', 'side-menu' ), '<a href="mailto:support@wow-company.com">support@wow-company.com</a>'); ?> .</p>

				<p><?php esc_attr_e( 'Also, you can send us your ideas and suggestions for improving the plugin.', 'side-menu' ) ; ?></p>
		  <?php $error = array();
		  if ( ! empty( $_POST['action'] ) && ! empty( $_POST['wow_support_field'] ) ) {
			  if ( wp_verify_nonce( $_POST['wow_support_field'], 'wow_support_action' )
			       && current_user_can( 'manage_options' )
			  ) {

				  $fname   = ! empty( $_POST['wow-fname'] ) ? sanitize_text_field( $_POST['wow-fname'] ) : '';
				  $lname   = ! empty( $_POST['wow-lname'] ) ? sanitize_text_field( $_POST['wow-lname'] ) : '';
				  $message = ! empty( $_POST['wow-message'] ) ? sanitize_text_field( $_POST['wow-message'] ) : '';
				  $email   = ! empty( $_POST['wow-email'] ) ? sanitize_email( $_POST['wow-email'] ) : '';
				  $type    = ! empty( $_POST['wow-message-type'] ) ? sanitize_text_field( $_POST['wow-message-type'] )
					  : '';

				  if ( empty( $fname ) ) {
					  $error[] = esc_attr__( 'Please, Enter your First Name.', 'side-menu' );
				  }
				  if ( empty( $lname ) ) {
					  $error[] = esc_attr__( 'Please, Enter your Last Name.', 'side-menu' );
				  }
				  if ( empty( $message ) ) {
					  $error[] = esc_attr__( 'Please, Enter your Message.', 'side-menu' );
				  }
				  if ( empty( $email ) ) {
					  $error[] = esc_attr__( 'Please, Enter your Email.', 'side-menu' );
				  }
				  if ( count( $error ) == 0 ) {


					  $headers = array(
			    'From: ' . esc_attr($fname) . ' ' . esc_attr($lname) . ' <' . sanitize_email($email) . '>',
						  'content-type: text/plain',
					  );
			  $message_mail = '
				<html>
				<head></head>
				<body>
				<table>
				<tr>
				</tr>
				<tr>
				<td><strong>Website:</strong></td>
				<td>' . esc_url($website) . '</td>
				</tr>
				</table>
				' . sanitize_textarea_field($message) . '
				</body>
				</html>';
					  wp_mail( 'support@wow-company.com', 'Support Ticket: ' . $type, $message_mail, $headers );
					  echo '<div class="wow-alert wow-alert-update "><p class="wow_error">'
					       . esc_attr__( 'Your Message sent to the Support.', 'side-menu' ) . '</p></div>';

				  }


			  } else {
				  echo '<div class="wow-alert wow-alert-error "><p class="wow_error">'
				       . esc_attr__( 'Sorry, but message did not send. Please, contact us ad@wpcalc.com',
						  'side-menu' ) . ' </p></div>';
			  }
		  }
		  ?>
		  <?php if ( count( $error ) > 0 ) {
			  echo '<div class="wow-alert wow-alert-error "><p class="wow_error">' . implode( "<br />", $error )
			       . '</p></div>';
		  } ?>


				<form method="post" action="" class="wow-plugin">
					<div class="container">
						<div class="element">
							<label><?php esc_html_e( 'First Name', 'side-menu' ); ?></label><br/>
							<input type="text" name="wow-fname" value=""
										 placeholder="<?php esc_html_e( 'Enter Your First Name', 'side-menu' ); ?>">
						</div>
						<div class="element">
							<label><?php esc_html_e( 'Last Name', 'side-menu' ); ?></label><br/>
							<input type="text" name="wow-lname" value=""
										 placeholder="<?php esc_html_e( 'Enter Your Last Name', 'side-menu' ); ?>">
						</div>
					</div>
					<div class="container">
						<div class="element">
							<label><?php esc_html_e( 'WebSite', 'side-menu' ); ?></label><br/>
							<input type="text" disabled name="wow-website" value="<?php echo get_option( 'home' ); ?>">
						</div>
						<div class="element">
							<label><?php esc_html_e( 'Contact email', 'side-menu' ); ?></label><br/>
							<input type="text" name="wow-email" value="<?php echo get_option( 'admin_email' ); ?>">
						</div>

					</div>
					<div class="container">
						<div class="element">
          <textarea name="wow-message" rows="10"
										placeholder="<?php esc_html_e( 'Enter Your Message', 'side-menu' ); ?>"></textarea>
						</div>
					</div>
					<div class="container">
						<div class="element">
							<input type="submit" class="add-item" name="action"
										 value="<?php esc_html_e( 'Send to Support', 'side-menu' ); ?>">
						</div>
					</div>
			<?php wp_nonce_field( 'wow_support_action', 'wow_support_field' ); ?>
				</form>
			</div>

		</div>
	</div>
<?php
