<style>
	.tabel-buyer th, .tabel-buyer td {
		border:0;
		border-bottom:1px dotted #333333;
	}
	.tabel-buyer th p {
		color:#FFFFFF;
		margin:0; padding: 8px 10px;
	}
	.tabel-buyer td p {
		margin:0; padding: 8px 10px;
	}
</style>
<?php
	echo '
	<script src="https://www.google.com/recaptcha/api.js" async defer></script>
	<script type="text/javascript" src="'.$thisPage.'js/messages.js"></script>
	<link rel="stylesheet" type="text/css" href="'.$thisPage.'css/messages.css" />
	<link rel="stylesheet" type="text/css" href="'.$thisPage.'css/captcha.css" />';

	$postData = $statusMsg = ''; 
	$status   = 'warning'; 
	$recaptcha_site_key 	= '6LfLsq4UAAAAAJo0hnNyq5dzdpg-WAZXWpf8vQZ2';
	$recaptcha_site_secret 	= '6LfLsq4UAAAAAGXSwWU2pAp2JqZ0Us5uMV1oz6oC'; //Your_reCAPTCHA_Secret_Key 
	
	if(isset($_POST['submit2'])){ 
		$postData = $_POST; 
		if (!empty($postData)) {
			$name    	  = !empty($_POST['name'])		   ? $_POST['name']		    : ''; 
			$email   	  = !empty($_POST['email'])		   ? $_POST['email']		: ''; 
			$saluation    = !empty($_POST['saluation'])	   ? $_POST['saluation']	: ''; 
			$verify_token = !empty($_POST['verify_token']) ? $_POST['verify_token'] : ''; 
			
			$to = $email;
			$subject = 'Account Confirmation'; 
			$htmlContent = "
			<p><strong>Dear ".$saluation." ".$name."</strong></p>
			<p>Thank you for your registration on Trade Expo Indonesia Virtual Exhibition 2020.</p> 
			<p>Please <a style=\"border:1px solid #333333; background-color:#F00000; color:#ffffff; padding:5px\" href=\"http://veitei.tradexpoindonesia.com/verification/".$email."/".$verify_token."\" target=\"_blank\">click here to verify</a> your account.</p> 
			<p>Make sure you follow our social media on Facebook, Twitter, and Instagram @tradexpoid for any updates regarding the show.</p>
			<p>Use this email to get access to Trade Expo Indonesia Virtual Exhibition 2020 via <a href=\"http://www.tradexpoindonesia.com\" target=\"_blank\">www.tradexpoindonesia.com</a></p>
			<p>See you at Trade Expo Indonesia Virtual Exhibition 2020 on 10-16 November 2020</p>
			<p>Thank you.</p>
			<p>Regards.</p>
			<p>
				<a href=\"http://www.tradexpoindonesia.com\" target=\"_blank\">
					<img src=\"http://tei.tkb.id/icon.png\" width=\"200\" border=\"0\"/> <br>
				</a>
				<a href=\"https://www.facebook.com/tradexpoid\" target=\"_blank\">
					<img src=\"http://tei.tkb.id/images/facebook.png\" width=\"68\" border=\"0\"/>
				</a>
				<a href=\"https://www.youtube.com/channel/UCkNGfFmuNKL6kKvFB7Y3B8w\" target=\"_blank\">
					<img src=\"http://tei.tkb.id/images/youtube.png\" width=\"68\" border=\"0\"/>
				</a>
				<a href=\"https://www.instagram.com/tradexpoid\" target=\"_blank\">
					<img src=\"http://tei.tkb.id/images/instagram.png\" width=\"68\" border=\"0\"/>
				</a>
			</p>
			<p>
				Please do not reply to this message. Replies to this message are routed to an unmonitored mailbox. <br>
				If you have questions please go to http://www.tradexpoindonesia.com/contact-us/indonesian-office/. 
			</p>"; 
			//echo $htmlContent;
			
			$headers  = "MIME-Version: 1.0" . "\r\n"; 
			$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; 
			$headers .= 'From:Tradexpo Indonesia <visit@tradexpoindonesia.com>' . "\r\n"; 
			//$headers .= "BCc:chunkhu@gmail.com" . "\r\n";
			 
			if (@mail($to,$subject,$htmlContent,$headers)) {
				$status = 'success'; 
				$postData = '';
				$statusMsg = 'Email has been sent successfully.'; 
			} else {
				$statusMsg = 'Email has failed to sent.'; 
			}
		}
	} else if(isset($_POST['submit'])){ 
		$postData = $_POST; 
		if(!empty($_POST['email'])){ 
			if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])){ 
				if (isset($_POST) && !empty($_POST)) {
					$captcha_response = htmlspecialchars($_POST['g-recaptcha-response']);
					$curl = curl_init();
					$captcha_verify_url = "https://www.google.com/recaptcha/api/siteverify";
					
					curl_setopt($curl, CURLOPT_URL,$captcha_verify_url);
					curl_setopt($curl, CURLOPT_POST, true);
					curl_setopt($curl, CURLOPT_POSTFIELDS, "secret=".$recaptcha_site_secret."&response=".$captcha_response);
					curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
					
					$captcha_output = curl_exec ($curl);
					curl_close ($curl);
				
					$decoded_captcha = json_decode($captcha_output);
					$captcha_status  = $decoded_captcha->success; // store validation result to a variable.
					
					if($captcha_status === TRUE){
						$email = !empty($_POST['email'])?$_POST['email']:''; 
						$list_data = '';
						$sql = 
						" SELECT * FROM users ".
						" WHERE exhibitor_id is null ".
						" AND email = '".$email."' ";
						//echo $sql; 
						if ($hasil = mysql_query($sql, $conn2)) {
							if (mysql_num_rows($hasil) > 0) {
								while ($data = mysql_fetch_array($hasil)) {
									$saluation    = $data{"saluation"};
									$name 		  = $data["name"];
									$verify_token = $data["verify_token"];
									
									$list_data .= '
									<tr>
										<td><p>'.$data["name"].'</p></td>
										<td><p>'.$data["country"].'</p></td>
										<td><p>'.$data["email"].'</p></td>
									</tr>';
								}
							}
						}						
						echo '
						<form name="form" id="form" class="form" action="" method="post">
							<table class="tabel-buyer table table-bordered table-hover table-striped">
								<thead>
									<tr>
										<th width="35%" scope="col"><p><strong>Name</strong></p></th>
										<th width="25%" scope="col"><p><strong>County</strong></p></th>
										<th width="40%" scope="col"><p><strong>Email</strong></p></th>
									</tr>
								</thead>
								<tbody>';
									if ($list_data) {
										echo $list_data;
									} else {
										echo '
										<tr>
											<td colspan="3">
												<p>No data found.</p>
												<p>
													<a href="?" class="hvr-sweep-to-right">
														Enter another email
													</a>
												</p>
											</td>
										</tr>';
									}
									if ($list_data) {
										echo '
										<tr>
											<td colspan="3" align="center" style="text-align:center;background-color:#ffffff; ">
												<br>
												<input type="hidden" name="saluation" value="'.$saluation.'" />
												<input type="hidden" name="name" value="'.$name.'" />
												<input type="hidden" name="email" value="'.$email.'" />
												<input type="hidden" name="verify_token" value="'.$verify_token.'" />
												<input style="height:50px; width:120px" class="hvr-sweep-to-right" type="submit" name="submit2" value="Resend Email">
												<br>
											</td>
										</tr>';
									}
									echo '
								</tbody>
							</table>
						</form>';
					} else if($captcha_status === FALSE){
						$statusMsg = '
						Robot verification failed, please try again.'; 
					}
				}
			} else { 
				$statusMsg = 'Please check on the reCAPTCHA box.'; 
			}
		} else {
			$statusMsg = 'Please fill all the mandatory fields.'; 
		}
	}
?>

<?php
if(!isset($_POST['submit']) || $statusMsg){ 
	?>
	<style>
    .info-msg, .success-msg, .warning-msg, .error-msg {
      margin: 10px 0;
      padding: 10px;
      border-radius: 3px 3px 3px 3px;
    }
    .info-msg {
      color: #059;
      background-color: #BEF;
    }
    .success-msg {
      color: #270;
      background-color: #DFF2BF;
    }
    .warning-msg {
      color: #9F6000;
      background-color: #FEEFB3;
    }
    .error-msg {
      color: #D8000C;
      background-color: #FFBABA;
    }
    </style>
    
    <p>
        Please enter email:
    </p>
    
    <div class="box" style="font-size:16px; line-height:20px; ">
        <form name="form" id="form" class="form" action="" method="post">
            <section class="layout-centered" data-modul="M00613">
                <div class="rowInner spacerRow">
                    <div class="col l-col12 m-col12 s-col12" style="padding:0; margin:0">
                        <?php 
                        if(!empty($statusMsg)){ 
                            if ($status == "success") {
                                echo '
                                <div class="'.$status.'-msg">
                                    <i class="fa fa-check"></i>
                                    '.$statusMsg.'
                                </div>';
                            } else {
                                echo '
                                <div class="'.$status.'-msg">
                                    <i class="fa fa-warning"></i>
                                    '.$statusMsg.'
                                </div>';
                            }
                        }
                        ?>
                    </div>
                    <div class="col l-col12 m-col12 s-col12" style="border:1px solid #999999; padding:0; margin:0">
                        <div class="row" style="padding:18px 0px; background-color:#f8f8f8">
                            <div class="col l-col4 m-col12 s-col12">
                                <strong>Type Email Address</strong>
                                <div class="hide-for-medium-up" style="padding-bottom:8px"></div>
                            </div>
                            <div class="col l-col8 m-col12 s-col12">
                                <input size="45" type="email" name="email" value="<?php echo !empty($postData['email'])?$postData['email']:''; ?>" placeholder="Your email address" required="" />
                            </div>
                        </div>
                        <div class="row" style="padding:18px 0px; background-color:#f8f8f8">
                            <div align="center">
                                <div align="center" class="g-recaptcha" data-sitekey="<?php echo $recaptcha_site_key; ?>"></div>
                                <div align="center" style="padding:15px">
                                    <input style="height:50px; width:120px" class="hvr-sweep-to-right" type="submit" name="submit" value="SUBMIT">
                                </div>
                            </div>		
                        </div>
                    </div>
                </div>
            </section>
        </form>
    </div>	
	<?php
}
?>

