<?php
include '../connect/main-config.php' ;
include '../connect/status.php' ;
include '../requires/function.php' ;

include '../languages/en.php' ;

require( '../extensions/sms.php' ) ;
require( '../extensions/otp.php' ) ;

$array            = resetRequest( $_GET ) ;
$visitor_id       = $array['visitor_id'] ;
$token            = $array['token'] ;

// select staff
$select_visitor   = $mysqli->query( "SELECT * FROM visitor
							         WHERE deleted_at IS NULL AND visitor_id = '".$visitor_id."' LIMIT 1" ) ;
if ( $select_visitor->num_rows == 0 || setSecret( $visitor_id ) != $token ){
    header('Location: index.php') ;
    exit ;
}

$row_visitor    = $select_visitor->fetch_assoc() ;

// get branch name
$branch_name     = '' ;
$mysqli_query    = "SELECT branch_id, branch_name FROM branch
				    WHERE branch_id = '".$row_visitor['branch']."' LIMIT 1" ;
$mysqli_branch   = $mysqli->query($mysqli_query) ;
if ( $mysqli_branch->num_rows > 0 ){
	$row_branch  = $mysqli_branch->fetch_assoc() ;
	$branch_name = $row_branch['branch_name'] ;
}

$qrcode  		 = 'VT|'.$visitor_id ;
$outputqrcode    = generateQrcode( '', $qrcode, $qrcode ) ;


include '../requires/page_header.php' ;
include 'requires.php' ;

$more_scripts   = showMessage( $_SESSION['error'], $message ) ;
?>

<div class="modal fade" id="myModal" data-backdrop="static" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-body">
				<div class="modal-top">

				</div>
				<div class="modal-center">
					
					<div class="logo-box">
						<img class="logo" src="../images/logo.png" />
					</div>

					<div class="title-box">
						<h3 class="title"><?= COMPANYSHORT ?> <?=$lang['Visitor Registration Form']?></h3>
						<div class="description">
							<h5>
								<?php 
								switch ( $row_visitor['status'] ){
									case 'pending' 		   :
									case 'approved' 	   :
									case 'rejected' 	   :
									case 'tested' 		   :
									case 'tested-rejected' :
										echo str_replace( 'XXXX', COMPANYSHORT, $lang['Welcome to XXXX Group!'] ) ;
									break ;
									case 'tested-approved' :
									case 'visited'         :
										echo $lang['Thank you for your submission. Your application form has been approved. Kindly present your QR code to us during the visitation date.'] ;
									break ;
								}
								?>
							</h5>
						</div>
					</div>

					<?php if ( $row_visitor['status'] == 'tested-approved' || $row_visitor['status'] == 'visited' ){ ?>
						<div class="qrcode-box">
							<img class="logo" src="<?= $outputqrcode['url'] ?>" />
						</div>
					<?php } ?>

					<div class="input-form" id="submit-register" >
						<div class="table-box">
							<table class="table-preview desktop-preview">
								<tr>
									<td width="130"><?=$lang['Appointment Date']?></td>
									<td><b><?= date( 'Y-m-d H:iA', strtotime( $row_visitor['visited_at'] ) ) ?> ~ <?= date( 'Y-m-d H:iA', strtotime( $row_visitor['visited_at_to'] ) ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Branch To Visit']?></td>
									<td><b><?= dataFilter( $branch_name ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Visitor Category']?></td>
									<td><b><?= ucwords( dataFilter( $row_visitor['category'] ) ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Visitor Name']?></td>
									<td><b><?= dataFilter( $row_visitor['name'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Contact Number']?></td>
									<td><b><?= dataFilter( $row_visitor['mobile'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Email']?></td>
									<td><b><?= dataFilter( $row_visitor['email'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['NRIC / Passport No']?></td>
									<td><b><?= dataFilter( $row_visitor['identity'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Nationality']?></td>
									<td><b><?= dataFilter( $row_visitor['nationality'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Visitor Company']?></td>
									<td><b><?= ucwords( $row_visitor['visitor_company'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Car Plate']?></td>
									<td><b><?= dataFilter( $row_visitor['car_plate'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Reason To Visit']?></td>
									<td><b><?= dataFilter( $row_visitor['reason'] ) ?></b></td>
								</tr>
								<tr>
									<td><?= COMPANYSHORT . ' ' . $lang['Contact Person'] ?></td>
									<td><b><?= dataFilter( $row_visitor['contact_person'] ) ?></b></td>
								</tr>
							</table>
							<table class="table-preview mobile-preview">
								<tr>
									<td><?=$lang['Appointment Date']?><br /><b><?= date( 'Y-m-d H:iA', strtotime( $row_visitor['visited_at'] ) ) ?> ~ <?= date( 'Y-m-d H:iA', strtotime( $row_visitor['visited_at_to'] ) ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Branch To Visit']?><br /><b><?= dataFilter( $branch_name ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Visitor Category']?><br /><b><?= ucwords( dataFilter( $row_visitor['category'] ) ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Visitor Name']?><br /><b><?= dataFilter( $row_visitor['name'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Contact Number']?><br /><b><?= dataFilter( $row_visitor['mobile'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Email']?><br /><b><?= dataFilter( $row_visitor['email'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['NRIC / Passport No']?><br /><b><?= dataFilter( $row_visitor['identity'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Nationality']?><br /><b><?= dataFilter( $row_visitor['nationality'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Visitor Company']?><br /><b><?= ucwords( $row_visitor['visitor_company'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Car Plate']?><br /><b><?= dataFilter( $row_visitor['car_plate'] ) ?></b></td>
								</tr>
								<tr>
									<td><?=$lang['Reason To Visit']?><br /><b><?= dataFilter( $row_visitor['reason'] ) ?></b></td>
								</tr>
								<tr>
									<td><?= COMPANYSHORT . ' ' . $lang['Contact Person'] ?><br /><b><?= dataFilter( $row_visitor['contact_person'] ) ?></b></td>
								</tr>
							</table>
						</div>
					</div>

					<div class="input-form" id="submit-register" >

						<div class="input-box" style="display: flex;justify-content: space-between;">
							<span class="input-title input-title-2">* <?=$lang['If any technical issue kindly contact us']?><br /><?= SUPPORTNAME ?> @ <a href="tel:<?= SUPPORTMOBILE ?>"><?= SUPPORTMOBILE ?></a></span>
						</div>

						<!-- <div class="input-box">
							<div class="language" style="display: flex;justify-content: space-between;">
					            <a href="language.php?lang=en&link=//<?= $_SERVER['HTTP_HOST'].urlencode($_SERVER['REQUEST_URI']) ?>" class="<?= $get_lang == 'en' ? 'active' :'' ?>">EN</a>
					            <a href="language.php?lang=cn&link=//<?= $_SERVER['HTTP_HOST'].urlencode($_SERVER['REQUEST_URI']) ?>" class="<?= $get_lang == 'cn' ? 'active' :'' ?>">CN</a>
					            <a href="language.php?lang=ma&link=//<?= $_SERVER['HTTP_HOST'].urlencode($_SERVER['REQUEST_URI']) ?>" class="<?= $get_lang == 'ma' ? 'active' :'' ?>">BM</a>
					        </div>
						</div> -->

					</div>	

				</div>
				<div class="modal-bottom">

				</div>
			</div>
		</div>
	</div>
</div>

<?php
include 'requires/page_footer.php' ;
?>