<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  $libraryPath = 'cmsb/lib/viewer_functions.php';
  $dirsToCheck = ['','../','../../','../../../','../../../../']; // add if needed: '/home/xanitoshqadmin/public_html/x/w-xr/'
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load record from 'section_intro'
  list($section_introRecords, $section_introMetaData) = getRecords(array(
    'tableName'   => 'section_intro',
    'where'       => "`sn` = 'cv'",
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $section_introRecord = @$section_introRecords[0]; // get first record
  if (!$section_introRecord) { dieWith404("Record not found!"); } // show error message if no record found

//set for upload form
    $tableName = 'cvax';
	$recordNum = "";
    $preSaveTempId   = @$_REQUEST['preSaveTempId'] ? $_REQUEST['preSaveTempId'] : uniqid('x');
  	$errorsAndAlerts = '';

  // submit form
  if (@$_POST['submitForm']) {

    // error checking
    $errorsAndAlerts = "";

 //   if (!@$_REQUEST['phone'])   { $errorsAndAlerts .= "You must enter a phone number!<br/>\n"; }
  //  if (!@$_REQUEST['name'])   	{ $errorsAndAlerts .= "Please enter your name!<br/>\n"; }
  //  if (!@$_REQUEST['email'])   { $errorsAndAlerts .= "Please enter your email address!<br/>\n"; }

   // turn off strict mysql error checking for: STRICT_ALL_TABLES
    mysqlStrictMode(false); // disable Mysql strict errors for when a field isn't defined below (can be caused when fields are added later)
    error_reporting (E_ALL ^ E_NOTICE);

    // add record
    if (!@$errorsAndAlerts) {
    
    $tablename   = 'cvax';
       $colsToValues = array();
       $colsToValues['createdDate=']     = 'NOW()';
       $colsToValues['updatedDate=']     = 'NOW()';
       $colsToValues['createdByUserNum'] = 0;
       $colsToValues['updatedByUserNum'] = 0;
       $colsToValues['first_name']       = $_REQUEST['first_name'];
       $colsToValues['last_name']        = $_REQUEST['last_name'];
       $colsToValues['v_status']       	 = $_REQUEST['v_status'];
       $colsToValues['vaccine']          = $_REQUEST['vaccine'];
       $colsToValues['date_shot_1']      = $_REQUEST['date_shot_1'];
       $colsToValues['date_shot_2']      = $_REQUEST['date_shot_2'];
       $colsToValues['date_booster']   	 = $_REQUEST['date_booster'];
       $colsToValues['req_exemption']    = $_REQUEST['req_exemption'];
  //     $colsToValues['[photo']         	 = $_REQUEST['photo'];
       $hideMissingFieldErrors = true;
       $newRecordNum = mysql_insert($tablename, $colsToValues, $hideMissingFieldErrors);

// send email to applicant    
//$to='chodges@xanitos.com';
//$subject = 'New Headlines Online Story Submitted';
//$headers = "From: $signup_email" . "\r\n";
////$headers .= "Reply-To: $signup_email" . "\r\n";
//$headers .= "MIME-Version: 1.0\r\n";
//$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
//$message = '<html><body>';
//$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
//$message .= "<tr><td><p>A new headlines online story has been submitted</p></td></tr>";
//$message .= "</table>";
//$message .= "</body></html>";

// Send
//if (mail($to,$subject,$message, $headers))
//{
// $errorsAndAlerts = "Thank You! Your vaccination status was submitted successfully!";
//} else
//{
// $errorsAndAlerts = "Error! Your vaccination status was not submitted.";
//};
  }
// clear form
 $_REQUEST = array();

}
?>

<!doctype html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" >
	<title>Xanitos - Pre-hire Covid Vaccination Record</title>
	<meta name="description" content="...">
	<?php include("core-head.php") ?>
	<?php include("core-analytics.php") ?>
	<style>
	label {
    margin-bottom: .25em;
    margin-top: 1em;
	}
	</style>

</head>

<body class="header-sticky">
	<div id="wrapper">
		<!-- HEADER -->
		<header id="header" class="shadow-xs">
		<div class="container position-relative">
		<!-- NAVBAR -->
		<nav class="navbar navbar-expand-lg navbar-light justify-content-lg-between justify-content-md-inherit">
			<div class="align-items-start">
				<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarMainNav" aria-controls="navbarMainNav" aria-expanded="false" aria-label="Toggle navigation">
					<svg width="25" viewBox="0 0 20 20">
						<path d="M 19.9876 1.998 L -0.0108 1.998 L -0.0108 -0.0019 L 19.9876 -0.0019 L 19.9876 1.998 Z"></path>
						<path d="M 19.9876 7.9979 L -0.0108 7.9979 L -0.0108 5.9979 L 19.9876 5.9979 L 19.9876 7.9979 Z"></path>
						<path d="M 19.9876 13.9977 L -0.0108 13.9977 L -0.0108 11.9978 L 19.9876 11.9978 L 19.9876 13.9977 Z"></path>
						<path d="M 19.9876 19.9976 L -0.0108 19.9976 L -0.0108 17.9976 L 19.9876 17.9976 L 19.9876 19.9976 Z"></path>
					</svg>
				</button>
				<a class="navbar-brand" href="index.php">
					<img src="images/xanitos-logo-143x80.jpg" width="143" height="80" alt="Xanitos, Inc. logo">
				</a>
			</div>
		
			<!-- Menu -->
			<div class="collapse navbar-collapse navbar-animate-fadein" id="navbarMainNav">
				<div class="navbar-xs d-none">
					<button class="navbar-toggler pt-0" type="button" data-toggle="collapse" data-target="#navbarMainNav" aria-controls="navbarMainNav" aria-expanded="false" aria-label="Toggle navigation">
						<svg width="20" viewBox="0 0 20 20">
							<path d="M 20.7895 0.977 L 19.3752 -0.4364 L 10.081 8.8522 L 0.7869 -0.4364 L -0.6274 0.977 L 8.6668 10.2656 L -0.6274 19.5542 L 0.7869 20.9676 L 10.081 11.679 L 19.3752 20.9676 L 20.7895 19.5542 L 11.4953 10.2656 L 20.7895 0.977 Z"></path>
						</svg>
					</button>
					<a class="navbar-brand" href="index.php">
						<img src="images/xanitos-logo-143-80.jpg" width="172" height="70" alt="Xanitos, Inc. logo">
					</a>
				</div>
			</div>
		</nav>			
		<!-- /NAVBAR -->
		</div>
		</header>
		<!-- /HEADER -->
<section>
<div class="container"> 
	<div class="row">
		<div class="col-12 col-lg-8">
		<div class="mb-4">
            <h1 class="h3 h4-xs font-weight-medium mb-0"><?php echo htmlencode($section_introRecord['title']) ?></h1>
		</div>
            <?php echo $section_introRecord['content'] ?>
            <?php echo $preSaveTempId; ?> <br>
          <div id="contact_form"class="mb-4">
			<div class="panel-body">
		  		<?php if (@$errorsAndAlerts): ?>
			    <div class="alert alert-success">
			      	<?php echo $errorsAndAlerts; ?><br/>
			    </div>
		  		<?php endif ?>
		  	</div>
		<!-- contact form -->
		<form method="post" action="<?php echo $_SERVER['SCRIPT_NAME']; ?>">
		<input type="hidden" name="submitForm" value="1">
		<input type="hidden" name="num" value="<?php echo $recordNum ?>" />
		<input type="hidden" name="preSaveTempId" value="<?php echo htmlencode($preSaveTempId) ?>" />

			<fieldset>
				<div class="form-label-group">
					<label for="first_name">First Name</label><input class="form-control" type="text" name="first_name" value="<?php echo htmlspecialchars(@$_REQUEST['first_name']); ?>">
				</div>
				<div class="form-label-group">
					<label for="last_name">Last Name</label><input class="form-control" type="text" name="last_name" value="<?php echo htmlspecialchars(@$_REQUEST['last_Name']); ?>">
				</div>
				<div class="form-label-group">
				    <label for="v_status">Vaccine Status</label>
				    <select class="form-control" id="v_status" name="v_status" value="<?php echo htmlspecialchars(@$_REQUEST['v_status']); ?>">
				      <option>Select One</option>
				      <option>Fully-Vaccinated</option>
				      <option>In Progress</option>
				      <option>Unvaccinated</option>
				    </select>
				  </div>
				<div class="form-label-group">
				    <label for="v_status">Vaccine</label>
				    <select class="form-control" id="vaccine" name="vaccine" value="<?php echo htmlspecialchars(@$_REQUEST['vaccine']); ?>">
				      <option>Select One</option>
				      <option>PFizer</option>
				      <option>Moderna</option>
				      <option>Johnson &amp; Johnson</option>
				    </select>
				</div>
				<div class="form-label-group">
				 	<label for="date_shot_1">Date Shot 1</label>
				    <input class="form-control" type="date" id="date_shot_1" name="date_shot_1" value="<?php echo @$_REQUEST['date_shot_1']; ?>">
				</div>			
				<div class="form-label-group">
				 	<label for="date_shot_2">Date Shot 2</label>
				    <input class="form-control" type="date" id="date_shot_1" name="date_shot_2" value="<?php echo @$_REQUEST['date_shot_2']; ?>">
				</div>			
				<div class="form-label-group">
				 	<label for="date_booster">Date Booster</label>
				    <input class="form-control" type="date" id="date_booster" name="date_booster" value="<?php echo @$_REQUEST['date_booster']; ?>">
				</div>			
				<div class="form-label-group">
				    <label for="req_exemption">Request an Exemption</label>
				    <select class="form-control" id="req_exemption" name="req_exemption" value="<?php echo htmlspecialchars(@$_REQUEST['req_exemption']); ?>">
				      <option>Select One</option>
				      <option>Medical</option>
				      <option>Religious</option>
				    </select>
				</div>

		    <?php /* TODO: Add security check in uploadForm2_iframe.php to limit access to only allowed uploads */ ?>
		    <iframe src='https://xanitos.com/w-xr/uploadForm3_add.php?table=<?php echo $tableName ?>&amp;field=photos&amp;num=<?php echo $recordNum ?>&amp;preSaveTempId=<?php echo htmlencode($preSaveTempId) ?>'
		            height='350' width='100%' frameborder='0' scrolling='yes'>
		    </iframe><br>
		    <br>
			<div class="form-group">
				<label for="submit">&nbsp;</label><input class="btn btn-sm btn-primary btn-soft opacity-8" type="submit" name="submit" value="Submit Form">
			</div>
			</fieldset>
		</form>
		</div> <!-- close contact form-->

   </div>
  </div><!--/span-->
</section>

<!-- Footer -->
<?php include("core-footer.php") ?>
<!-- /Footer -->
</div> 
<!--/wrapper-->
<!-- Footer -->
	<?php include("core-bootstrap-script.php") ?>
<!-- /Footer -->
</body>
</html>