<?php
/*
 * Copyright (C) 2018 josh.north@point808.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

    ini_set('session.gc_maxlifetime', 24*60*60);                                // MIN SESSION
    ini_set('session.gc_probability', 1);                                       // GC RATES
    ini_set('session.gc_divisor', 100);                                         // TIMES
    ini_set('session.use_cookies', '1');
    ini_set('session.use_only_cookies', '1');
    ini_set('session.cookie_secure', '0');
    ini_set('session.cookie_httponly', '0');
    ini_set('session.cookie_samesite', 'Lax');
    session_save_path('.tmp');                                                  // TEMP
    session_start();                                                            // START
    require_once __DIR__ . '/autoload.php';                                     // AUTOLOAD
    use App\LobbySIO\Misc\Csrf;                                        // ANTICSRF
    $StaticFunctions = new \App\LobbySIO\Misc\StaticFunctions();                // DEFAULT CLASSES
    $SiteInfo = new \App\LobbySIO\Database\SiteInfo();
    $Users = new \App\LobbySIO\Database\Users();
    if (isset($_SESSION['user_id'])) {                                          // LOGGED IN? GET USER OBJECT
        $session_user = $Users->getUserInfo($_SESSION['user_id'], "1", "0"); }
    if (isset($session_user)) {                                                 // GET UID OR SET TO KIOSK
        $uid = $session_user["0"]["users_id"];} else { $uid = "2"; }
    $app_disp_lang = filter_input(INPUT_COOKIE, 'app_disp_lang');               // SETUP LANGUAGE
    if(!isset($app_disp_lang)) {
        $app_disp_lang=$StaticFunctions->getDefaultLanguage(); }
    $siteidcookie = filter_input(INPUT_COOKIE, 'app_site');                     // SETUP SITE
    foreach($SiteInfo->getSite("0", $uid, "0", "0") as $arr) {
        $lookup_array[$arr['sites_id']]=1; }
        if(isset($lookup_array[$siteidcookie])) {
            $siteid = $siteidcookie; } else { $siteid = "1"; }
        if(!isset($siteid)) { $siteid="1"; }
    $Translate = new \App\LobbySIO\Language\Translate($app_disp_lang);          // SETUP TRANSLATOR
    $transLang =  $Translate->userLanguage();
    $VisitTypeInfo = new \App\LobbySIO\Database\VisitTypeInfo();
    $app_current_pagename = $transLang['SIGNIN'];                               // PAGE SETUP
    $app_current_pageicon = '<i class="fas fa-sign-in-alt"></i> ';
    require_once("inc/header.inc.php");
    if ($StaticFunctions->getSessionStatus() == true) {                         // CHECK STATUS
        header('Location: index.php');                                          // ELSE HOME
    } else {
      header("X-Frame-Options: SAMEORIGIN");
      header("X-Content-Type-Options: nosniff");
      //header("Content-Security-Policy: script-src 'self' 'unsafe-inline'; script-src-elem 'self'; script-src-attr 'self'; style-src 'self'; style-src-elem 'self'; style-src-attr 'self'; img-src 'self'; connect-src 'self'; frame-src 'self'; font-src 'self'; media-src 'self'; object-src 'self'; manifest-src 'self'; worker-src 'self'; prefetch-src 'self'; form-action 'self'; frame-ancestors 'self'; default-src 'self'", false);
      if (!empty($_GET['a'])) {
        echo '<pre>' . print_r($_POST, true) . '</pre>';
        echo 'Verification has been : ' . (Csrf::verifyToken('home') ? 'successful' : 'unsuccessful');
      }
    ?>



<?php
// FILTER POSTED DATA
$form_data = filter_input_array(INPUT_POST, [
    'form_data_stage' => (string)FILTER_SANITIZE_STRING,
    'form_data_siteid' => (int)FILTER_VALIDATE_INT,
    'form_data_isvendor' => (int)FILTER_VALIDATE_INT,
    'form_data_firstname' => (string)FILTER_SANITIZE_STRING,
    'form_data_lastname' => (string)FILTER_SANITIZE_STRING,
    'form_data_carnum' => (string)FILTER_SANITIZE_STRING,
    'form_data_ssanum' => (string)FILTER_SANITIZE_STRING,
    'form_data_company' => (string)FILTER_SANITIZE_STRING,
    'form_data_contact1' => (string)FILTER_SANITIZE_STRING,
    'form_data_contact2' => (string)FILTER_SANITIZE_STRING,
    'form_data_workstart' => (string)FILTER_SANITIZE_STRING,
    'form_data_workend' => (string)FILTER_SANITIZE_STRING,
    'form_data_customerimpacted' => (string)FILTER_SANITIZE_STRING,
    'form_data_visittype' => (int)FILTER_VALIDATE_INT,
    'form_data_escortrequired' => (int)FILTER_VALIDATE_INT,
    'form_data_v_signature' => (string)FILTER_SANITIZE_STRING,
    'form_data_e_signature' => (string)FILTER_SANITIZE_STRING,
    'form_data_escortname' => (string)FILTER_SANITIZE_STRING
]);
// SET INITIAL STAGE
if(empty($form_data['form_data_stage'])){
  $form_data['form_data_stage'] = 'covidack';
}
?>

<!-- CONTENT -->

<?php if($form_data['form_data_stage'] === "covidack"){ ?>

<!-- START INITIAL STAGE CONTENT -->
  <div class="container">
    <div class="row row-cols-1">
      <div class="col d-grid gap-2">
        <h2><i class="fas fa-sign-in-alt"></i> <?php echo $transLang['SIGNIN']; ?></h2>
      </div>
    </div>
    <form name="form-signin" class="needs-validation" method="post" novalidate>
      <?php echo Csrf::getInputToken('home') ?>
      <div class="form-group form-row">
        <div class="form-check">
          <input class="form-check-input" type="checkbox" value="" id="q1" required>
          <label class="form-check-label" for="q1"><b><?php echo $transLang['COVID-Q1-TITLE']; ?></b><br><?php echo $transLang['COVID-Q1-DESC']; ?></label>
          <div class="invalid-feedback"><?php echo $transLang['STR_COMMON_REQUIRED']; ?></div>
        </div>
      </div>
      <div class="form-group form-row">
        <div class="form-check">
          <input class="form-check-input" type="checkbox" value="" id="q2" required>
          <label class="form-check-label" for="q2"><b><?php echo $transLang['COVID-Q2-TITLE']; ?></b><br><?php echo $transLang['COVID-Q2-DESC']; ?></label>
          <div class="invalid-feedback"><?php echo $transLang['STR_COMMON_REQUIRED']; ?></div>
        </div>
      </div>
      <div class="form-group form-row">
        <div class="form-check">
          <input class="form-check-input" type="checkbox" value="" id="q3" required>
          <label class="form-check-label" for="q3"><b><?php echo $transLang['COVID-Q3-TITLE']; ?></b><br><?php echo $transLang['COVID-Q3-DESC']; ?></label>
          <div class="invalid-feedback"><?php echo $transLang['STR_COMMON_REQUIRED']; ?></div>
        </div>
      </div>
      <div class="form-group form-row">
        <div class="form-check">
          <input class="form-check-input" type="checkbox" value="" id="q4" required>
          <label class="form-check-label" for="q4"><b><?php echo $transLang['COVID-Q4-TITLE']; ?></b><br><?php echo $transLang['COVID-Q4-DESC']; ?></label>
          <div class="invalid-feedback"><?php echo $transLang['STR_COMMON_REQUIRED']; ?></div>
        </div>
      </div>
      <div class="form-group form-row">
        <div class="form-check">
          <input class="form-check-input" type="checkbox" value="" id="q5" required>
          <label class="form-check-label" for="q5"><b><?php echo $transLang['COVID-Q5-TITLE']; ?></b><br><?php echo $transLang['COVID-Q5-DESC']; ?></label>
          <div class="invalid-feedback"><?php echo $transLang['STR_COMMON_REQUIRED']; ?></div>
        </div>
      </div>
      <div class="form-group form-row">
        <div class="form-check">
          <input class="form-check-input" type="checkbox" value="" id="q6" required>
          <label class="form-check-label" for="q6"><b><?php echo $transLang['COVID-Q6-TITLE']; ?></b><br><?php echo $transLang['COVID-Q6-DESC']; ?></label>
          <div class="invalid-feedback"><?php echo $transLang['STR_COMMON_REQUIRED']; ?></div>
        </div>
      </div>
      <div class="row">&nbsp;</div>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <input type="hidden" name="form_data_siteid" id="form_data_siteid" value="<?php echo $siteid; ?>" />
          <input type="hidden" name="form_data_stage" id="form_data_stage" value="customerorvendor" />
          <button type="submit" id="saveBtn" class="btn btn-lg btn-success" name="saveBtn"><?php echo $transLang['NEXT']; ?></button>
        </div>
      </div>
    </form>
  </div>
  <script>
    // Example starter JavaScript for disabling form submissions if there are invalid fields
    (function() {
      'use strict';
      window.addEventListener('load', function() {
      // Fetch all the forms we want to apply custom Bootstrap validation styles to
        var forms = document.getElementsByClassName('needs-validation');
        // Loop over them and prevent submission
        var validation = Array.prototype.filter.call(forms, function(form) {
          form.addEventListener('submit', function(event) {
            if (form.checkValidity() === false) {
              event.preventDefault();
              event.stopPropagation();
            }
            form.classList.add('was-validated');
          }, false);
        });
      }, false);
    })();
  </script>
<!-- END INITIAL STAGE CONTENT -->

<?php }elseif($form_data['form_data_stage'] === "customerorvendor"){ ?>

<!-- START CUSTOMERORVENDOR STAGE CONTENT -->
  <div class="container">
    <div class="row row-cols-1">
      <div class="col d-grid gap-2">
        <h2><i class="fas fa-sign-in-alt"></i> <?php echo $transLang['SIGNIN']; ?></h2>
      </div>
    </div>
    <form name="form-signin" class="form-signin" method="post">
      <?php echo Csrf::getInputToken('home') ?>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <?php echo $transLang['STR_VENDORINFO_CUSTOMERORVENDOR_DESC']; ?>
        </div>
      </div>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <div class="btn-group">
            <input type="radio" class="btn-check btn-lg" name="form_data_isvendor" id="customer-outlined" autocomplete="off" value="0" required>
            <label class="btn btn-outline-primary btn-lg" for="customer-outlined"><?php echo $transLang['CUSTOMER']; ?></label>
            <input type="radio" class="btn-check btn-lg" name="form_data_isvendor" id="vendor-outlined" autocomplete="off" value="1" required>
            <label class="btn btn-outline-primary btn-lg" for="vendor-outlined"><?php echo $transLang['STR_VENDORINFO_VENDOR_TITLE']; ?></label>
          </div>
        </div>
      </div>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <input type="hidden" name="form_data_stage" id="form_data_stage" value="nameandcompany" />
          <input type="hidden" name="form_data_siteid" id="form_data_siteid" value="<?php echo $form_data['form_data_siteid']; ?>" />
          <button type="submit" id="saveBtn" class="btn btn-lg btn-success" name="saveBtn"><?php echo $transLang['NEXT']; ?></button>
        </div>
      </div>
    </form>
  </div>
<!-- END CUSTOMERORVENDOR STAGE CONTENT -->

<?php }elseif($form_data['form_data_stage'] === "nameandcompany"){ ?>

<!-- START NAMEANDCOMPANY STAGE CONTENT -->
  <div class="container">
    <div class="row row-cols-1">
      <div class="col d-grid gap-2">
        <h2><i class="fas fa-sign-in-alt"></i> <?php echo $transLang['SIGNIN']; ?></h2>
      </div>
    </div>
    <form name="form-signin" class="form-signin" method="post">
      <?php echo Csrf::getInputToken('home') ?>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <div class="input-group mb-3">
            <span class="input-group-text"><?php echo $transLang['NAME']; ?></span>
            <input type="text" id="form_data_firstname" name="form_data_firstname" class="form-control" placeholder="<?php echo $transLang['FIRST']; ?>" required autofocus>
            <input type="text" id="form_data_lastname" name="form_data_lastname" class="form-control" placeholder="<?php echo $transLang['LAST']; ?>" required autofocus>
          </div>
        </div>
      </div>
      <?php if($SiteInfo->getSite($form_data['form_data_siteid'], $uid, "0", "0")[0]["sites_region"] == "EMEA") { ?>
      <div class="row row-cols-2 mb-4">
        <div class="col d-grid gap-2">
          <div class="input-group mb-3">
            <span class="input-group-text"><?php echo $transLang['CARNUM']; ?></span>
            <input type="text" id="form_data_carnum" name="form_data_carnum" class="form-control" placeholder="<?php echo $transLang['CARNUM']; ?>" required autofocus>
          </div>
        </div>
        <div class="col d-grid gap-2">
          <div class="input-group mb-3">
            <span class="input-group-text"><?php echo $transLang['SSANUM']; ?></span>
            <input type="text" id="form_data_ssanum" name="form_data_ssanum" class="form-control" placeholder="<?php echo $transLang['SSANUM']; ?>" required autofocus>
          </div>
        </div>
      </div>
      <?php } ?>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <div class="input-group mb-3">
            <span class="input-group-text"><?php echo $transLang['COMPANY']; ?></span>
            <input type="text" id="form_data_company" name="form_data_company" class="form-control" placeholder="<?php echo $transLang['COMPANY']; ?>" required autofocus>
          </div>
        </div>
      </div>
      <?php if($form_data['form_data_isvendor']===1) { ?>
      <div class="row row-cols-2 mb-4">
        <div class="col d-grid gap-2">
          <div class="input-group mb-3">
            <span class="input-group-text"><?php echo $transLang['STR_VENDORINFO_CONTACT1_TITLE']; ?></span>
            <input type="text" id="form_data_contact1" name="form_data_contact1" class="form-control" required autofocus>
          </div>
        </div>
        <div class="col d-grid gap-2">
          <div class="input-group mb-3">
            <span class="input-group-text"><?php echo $transLang['STR_VENDORINFO_CONTACT2_TITLE']; ?></span>
            <input type="text" id="form_data_contact2" name="form_data_contact2" class="form-control" required autofocus>
          </div>
        </div>
      </div>
      <div class="row row-cols-2 mb-4">
        <div class="col d-grid gap-2">
          <div class="input-group mb-3">
            <span class="input-group-text" data-bs-toggle="datetimepicker" data-target=".datetimepicker-form_data_workstart"><?php echo $transLang['STR_VENDORINFO_WORKSTART_TITLE']; ?>&nbsp;<i class="fas fa-clock"></i></span>
            <input placeholder="" name="form_data_workstart" type="text" class="form-control form-control-sm bg-white datetimepicker-input datetimepicker-form_data_workstart" id="datetimepicker-form_data_workstart" data-toggle="datetimepicker" data-target=".datetimepicker-form_data_workstart"/>
            <script type="text/javascript">
              $(function () {
                $('.datetimepicker-form_data_workstart').datetimepicker({'timeZone': '<?php echo $timezone; ?>', 'sideBySide':true, 'format':'YYYY-MM-DD HH:mm:ss', 'allowInputToggle': true });
              });
            </script>
          </div>
        </div>
        <div class="col d-grid gap-2">
          <div class="input-group mb-3">
            <span class="input-group-text" data-bs-toggle="datetimepicker" data-target=".datetimepicker-form_data_workend"><?php echo $transLang['STR_VENDORINFO_WORKEND_TITLE']; ?>&nbsp;<i class="fas fa-clock"></i></span>
            <input placeholder="" name="form_data_workend" type="text" class="form-control form-control-sm bg-white datetimepicker-input datetimepicker-form_data_workend" id="datetimepicker-form_data_workend" data-toggle="datetimepicker" data-target=".datetimepicker-form_data_workend"/>
            <script type="text/javascript">
              $(function () {
                $('.datetimepicker-form_data_workend').datetimepicker({'timeZone': '<?php echo $timezone; ?>', 'sideBySide':true, 'format':'YYYY-MM-DD HH:mm:ss', 'allowInputToggle': true });
              });
            </script>
          </div>
        </div>
      </div>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <div class="input-group mb-3">
            <span class="input-group-text"><?php echo $transLang['STR_VENDORINFO_CUSTOMERIMPACTED_TITLE']; ?></span>
            <input type="text" id="form_data_customerimpacted" name="form_data_customerimpacted" class="form-control" required autofocus>
          </div>
        </div>
      </div>
      <?php } ?>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <input type="hidden" name="form_data_stage" id="form_data_stage" value="reasonforvisit" />
          <input type="hidden" name="form_data_siteid" id="form_data_siteid" value="<?php echo $form_data['form_data_siteid']; ?>" />
          <input type="hidden" name="form_data_isvendor" id="form_data_isvendor" value="<?php echo $form_data['form_data_isvendor']; ?>" />
          <button type="submit" id="saveBtn" class="btn btn-lg btn-success" name="saveBtn"><?php echo $transLang['NEXT']; ?></button>
        </div>
      </div>
    </form>
  </div>
<!-- END NAMEANDCOMPANY STAGE CONTENT -->

<?php }elseif($form_data['form_data_stage'] === "reasonforvisit"){ ?>

<!-- START REASONFORVISIT STAGE CONTENT -->
  <div class="container">
    <div class="row row-cols-1">
      <div class="col d-grid gap-2">
        <h2><i class="fas fa-sign-in-alt"></i> <?php echo $transLang['SIGNIN']; ?></h2>
      </div>
    </div>
    <form name="form-signin" class="form-signin" method="post">
      <?php echo Csrf::getInputToken('home') ?>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <div class="input-group mb-3">
            <span class="input-group-text"><?php echo $transLang['REASON']; ?></span>
            <select class="form-select" id="form_data_visittype" name="form_data_visittype" required>
              <option value="" selected><?php echo $transLang['SELECTREASON']; ?></option><?php foreach($VisitTypeInfo->getInfoVisitType($form_data['form_data_isvendor'],"%") as $row): ?>
              <option value="<?php echo $row['visittypes_id']; ?>"><?php echo $transLang[$row['visittypes_name']]; ?></option><?php endforeach; ?>
            </select>
          </div>
        </div>
      </div>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <input type="hidden" name="form_data_stage" id="form_data_stage" value="visitorsignature" />
          <input type="hidden" name="form_data_siteid" id="form_data_siteid" value="<?php echo $form_data['form_data_siteid']; ?>" />
          <input type="hidden" name="form_data_isvendor" id="form_data_isvendor" value="<?php echo $form_data['form_data_isvendor']; ?>" />
          <input type="hidden" name="form_data_firstname" id="form_data_firstname" value="<?php echo $form_data['form_data_firstname']; ?>" />
          <input type="hidden" name="form_data_lastname" id="form_data_lastname" value="<?php echo $form_data['form_data_lastname']; ?>" />
          <input type="hidden" name="form_data_carnum" id="form_data_carnum" value="<?php echo $form_data['form_data_carnum']; ?>" />
          <input type="hidden" name="form_data_ssanum" id="form_data_ssanum" value="<?php echo $form_data['form_data_ssanum']; ?>" />
          <input type="hidden" name="form_data_company" id="form_data_company" value="<?php echo $form_data['form_data_company']; ?>" />
          <input type="hidden" name="form_data_contact1" id="form_data_contact1" value="<?php echo $form_data['form_data_contact1']; ?>" />
          <input type="hidden" name="form_data_contact2" id="form_data_contact2" value="<?php echo $form_data['form_data_contact2']; ?>" />
          <input type="hidden" name="form_data_workstart" id="form_data_workstart" value="<?php echo $form_data['form_data_workstart']; ?>" />
          <input type="hidden" name="form_data_workend" id="form_data_workend" value="<?php echo $form_data['form_data_workend']; ?>" />
          <input type="hidden" name="form_data_customerimpacted" id="form_data_customerimpacted" value="<?php echo $form_data['form_data_customerimpacted']; ?>" />
          <button type="submit" id="saveBtn" class="btn btn-lg btn-success" name="saveBtn"><?php echo $transLang['NEXT']; ?></button>
        </div>
      </div>
    </form>
  </div>
<!-- END REASONFORVISIT STAGE CONTENT -->

<?php }elseif($form_data['form_data_stage'] === "visitorsignature"){ ?>

<!-- START VISITORSIGNATURE STAGE CONTENT -->
  <div class="container">
    <div class="row row-cols-1">
      <div class="col d-grid gap-2">
        <h2><i class="fas fa-sign-in-alt"></i> <?php echo $transLang['SIGNIN']; ?></h2>
      </div>
    </div>
    <form name="form-signin" class="form-signin" method="post">
      <?php echo Csrf::getInputToken('home') ?>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <h4><?php echo $transLang['STR_COMMON_VSIGNATURE']; ?>:</h4>
          <div id="vsignature-parent sigs">
            <div id="vsignature"></div>
          </div>
        </div>
      </div>
      <?php if($form_data['form_data_isvendor'] === (int)"0") { ?>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <h4><?php echo $transLang['ESECTION']; ?>?</h4>
        </div>
      </div>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <div class="btn-group">
            <input type="radio" class="btn-check btn-lg" name="form_data_escortrequired" id="no-outlined" autocomplete="off" value="0" required>
            <label class="btn btn-outline-primary btn-lg" for="no-outlined"><?php echo $transLang['STR_COMMON_NO']; ?></label>
            <input type="radio" class="btn-check btn-lg" name="form_data_escortrequired" id="yes-outlined" autocomplete="off" value="1" required>
            <label class="btn btn-outline-primary btn-lg" for="yes-outlined"><?php echo $transLang['STR_COMMON_YES']; ?></label>
          </div>
        </div>
      </div>
      <?php } ?>
      <script>
        $(document).ready(function() {
          // Init jSignature for Visitor field, onchange store in text field
          var $vsignature = $("#vsignature").jSignature({ width:"100%", height: 200 });
          true;
          $('#vsignature').change(function() {
            var data = $vsignature.jSignature('getData');
            $('#form_data_v_signature').val(data);
          });
        });
        $("form").submit(function() {
          if($('#form_data_v_signature').val() === '') {
            alert("<?php echo $transLang['STR_COMMON_SIGNATURE']; ?> <?php echo $transLang['STR_COMMON_REQUIRED']; ?>");
            return false;
          }
          return true;
          });
      </script>
  <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <input type="hidden" name="form_data_stage" id="form_data_stage" value="escortorterms" />
          <input type="hidden" name="form_data_siteid" id="form_data_siteid" value="<?php echo $form_data['form_data_siteid']; ?>" />
          <input type="hidden" name="form_data_isvendor" id="form_data_isvendor" value="<?php echo $form_data['form_data_isvendor']; ?>" />
          <input type="hidden" name="form_data_firstname" id="form_data_firstname" value="<?php echo $form_data['form_data_firstname']; ?>" />
          <input type="hidden" name="form_data_lastname" id="form_data_lastname" value="<?php echo $form_data['form_data_lastname']; ?>" />
          <input type="hidden" name="form_data_carnum" id="form_data_carnum" value="<?php echo $form_data['form_data_carnum']; ?>" />
          <input type="hidden" name="form_data_ssanum" id="form_data_ssanum" value="<?php echo $form_data['form_data_ssanum']; ?>" />
          <input type="hidden" name="form_data_company" id="form_data_company" value="<?php echo $form_data['form_data_company']; ?>" />
          <input type="hidden" name="form_data_contact1" id="form_data_contact1" value="<?php echo $form_data['form_data_contact1']; ?>" />
          <input type="hidden" name="form_data_contact2" id="form_data_contact2" value="<?php echo $form_data['form_data_contact2']; ?>" />
          <input type="hidden" name="form_data_workstart" id="form_data_workstart" value="<?php echo $form_data['form_data_workstart']; ?>" />
          <input type="hidden" name="form_data_workend" id="form_data_workend" value="<?php echo $form_data['form_data_workend']; ?>" />
          <input type="hidden" name="form_data_customerimpacted" id="form_data_customerimpacted" value="<?php echo $form_data['form_data_customerimpacted']; ?>" />
          <input type="hidden" name="form_data_visittype" id="form_data_visittype" value="<?php echo $form_data['form_data_visittype']; ?>" />
          <input type="hidden" name="form_data_v_signature" id="form_data_v_signature" />
          <button type="submit" id="saveBtn" class="btn btn-lg btn-success" name="saveBtn"><?php echo $transLang['NEXT']; ?></button>
        </div>
      </div>
    </form>
  </div>
<!-- END VISITORSIGNATURE STAGE CONTENT -->

<?php }elseif($form_data['form_data_stage'] === (string)"escortorterms" && $form_data['form_data_escortrequired'] === (int)"1"){ ?>

<!-- START ESCORTSIGNATURE STAGE CONTENT -->
  <div class="container">
    <div class="row row-cols-1">
      <div class="col d-grid gap-2">
        <h2><i class="fas fa-sign-in-alt"></i> <?php echo $transLang['SIGNIN']; ?></h2>
      </div>
    </div>
    <form name="form-signin" class="form-signin" method="post">
      <?php echo Csrf::getInputToken('home') ?>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <div class="input-group mb-3">
            <span class="input-group-text"><?php echo $transLang['ENAME']; ?></span>
            <input type="text" id="form_data_escortname" name="form_data_escortname" class="form-control" placeholder="<?php echo $transLang['ETAG']; ?>" autofocus>
          </div>
        </div>
      </div>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <h4><?php echo $transLang['STR_COMMON_ESIGNATURE']; ?>:</h4>
          <div id="esignature-parent sigs">
            <div id="esignature"></div>
          </div>
        </div>
      </div>
      <script>
        $(document).ready(function() {
          // Init jSignature for Escort field, onchange store in text field
          var $esignature = $("#esignature").jSignature({ width:"100%", height: 200 });
          true;
          $('#esignature').change(function() {
            var data = $esignature.jSignature('getData');
            $('#form_data_e_signature').val(data);
          });
        });
        $("form").submit(function() {
          if($('#form_data_e_signature').val() === '') {
            alert("<?php echo $transLang['STR_COMMON_SIGNATURE']; ?> <?php echo $transLang['STR_COMMON_REQUIRED']; ?>");
            return false;
          }
          return true;
          });
      </script>
  <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <input type="hidden" name="form_data_stage" id="form_data_stage" value="terms" />
          <input type="hidden" name="form_data_siteid" id="form_data_siteid" value="<?php echo $form_data['form_data_siteid']; ?>" />
          <input type="hidden" name="form_data_isvendor" id="form_data_isvendor" value="<?php echo $form_data['form_data_isvendor']; ?>" />
          <input type="hidden" name="form_data_firstname" id="form_data_firstname" value="<?php echo $form_data['form_data_firstname']; ?>" />
          <input type="hidden" name="form_data_lastname" id="form_data_lastname" value="<?php echo $form_data['form_data_lastname']; ?>" />
          <input type="hidden" name="form_data_carnum" id="form_data_carnum" value="<?php echo $form_data['form_data_carnum']; ?>" />
          <input type="hidden" name="form_data_ssanum" id="form_data_ssanum" value="<?php echo $form_data['form_data_ssanum']; ?>" />
          <input type="hidden" name="form_data_company" id="form_data_company" value="<?php echo $form_data['form_data_company']; ?>" />
          <input type="hidden" name="form_data_contact1" id="form_data_contact1" value="<?php echo $form_data['form_data_contact1']; ?>" />
          <input type="hidden" name="form_data_contact2" id="form_data_contact2" value="<?php echo $form_data['form_data_contact2']; ?>" />
          <input type="hidden" name="form_data_workstart" id="form_data_workstart" value="<?php echo $form_data['form_data_workstart']; ?>" />
          <input type="hidden" name="form_data_workend" id="form_data_workend" value="<?php echo $form_data['form_data_workend']; ?>" />
          <input type="hidden" name="form_data_customerimpacted" id="form_data_customerimpacted" value="<?php echo $form_data['form_data_customerimpacted']; ?>" />
          <input type="hidden" name="form_data_visittype" id="form_data_visittype" value="<?php echo $form_data['form_data_visittype']; ?>" />
          <input type="hidden" name="form_data_v_signature" id="form_data_v_signature" value="<?php echo $form_data['form_data_v_signature']; ?>" />
          <input type="hidden" name="form_data_escortrequired" id="form_data_escortrequired" value="<?php echo $form_data['form_data_escortrequired']; ?>" />
          <input type="hidden" name="form_data_e_signature" id="form_data_e_signature" />
          <button type="submit" id="saveBtn" class="btn btn-lg btn-success" name="saveBtn"><?php echo $transLang['NEXT']; ?></button>
        </div>
      </div>
    </form>
  </div>
<!-- END ESCORTSIGNATURE STAGE CONTENT -->

<?php }elseif(($form_data['form_data_stage'] === (string)"escortorterms" && $form_data['form_data_escortrequired'] === (int)"0") || ($form_data['form_data_stage'] === (string)"escortorterms" && $form_data['form_data_isvendor'] === (int)"1") || $form_data['form_data_stage'] === (string)"terms"){ ?>

<!-- START TERMS STAGE CONTENT -->
  <div class="container">
    <div class="row row-cols-1 mb-2">
      <div class="col d-grid gap-2">
        <h2><i class="fas fa-sign-in-alt"></i> <?php echo $transLang['SIGNIN']; ?></h2>
      </div>
    </div>
    <form name="form-signin" class="form-signin" method="post" action="signin_display.php">
      <?php echo Csrf::getInputToken('home') ?>
      <div class="row row-cols-1 mb-2">
        <div class="col d-grid gap-2">
          <?php if($SiteInfo->getSite($form_data['form_data_siteid'], $uid, "0", "0")[0]["sites_region"] == "US") { ?>
          <p><?php echo $transLang['ACKNOWLEDGEMENT']; ?></p>
          <?php } ?>
          <p><?php echo $transLang['COVID_ACKNOWLEDGEMENT']; ?><p>
          <p><?php echo $transLang['GDPR_TEXT']; ?><p>
        </div>
      </div>
      <div class="row row-cols-1 mb-2">
        <div class="col d-grid gap-2">
          <a class="btn btn-outline-secondary btn-block" data-bs-toggle="modal" data-bs-target="#termsModalLong" href="<?php echo $StaticFunctions->getRules(); ?>"><?php echo $transLang['REFERENCE']; ?>:&nbsp;(<?php echo $transLang['ACKNOWLEDGEMENT_DOC_NAME']; ?>)</a>
          <?php if($form_data['form_data_isvendor'] === (int)"1") { ?>
          <a class="btn btn-outline-secondary btn-block" data-bs-toggle="modal" data-bs-target="#termsVendorModalLong" href="<?php echo $StaticFunctions->getVendorRules(); ?>"><?php echo $transLang['REFERENCE']; ?>:&nbsp;(<?php echo $transLang['ACKNOWLEDGEMENT_VENDOR_DOC_NAME']; ?>)</a>
          <?php } ?>
        </div>
      </div>
      <div class="row row-cols-2 mb-4">
        <div class="col d-grid gap-2">
          <input type="hidden" name="form_data_stage" id="form_data_stage" value="terms" />
          <input type="hidden" name="form_data_siteid" id="form_data_siteid" value="<?php echo $form_data['form_data_siteid']; ?>" />
          <input type="hidden" name="form_data_isvendor" id="form_data_isvendor" value="<?php echo $form_data['form_data_isvendor']; ?>" />
          <input type="hidden" name="form_data_firstname" id="form_data_firstname" value="<?php echo $form_data['form_data_firstname']; ?>" />
          <input type="hidden" name="form_data_lastname" id="form_data_lastname" value="<?php echo $form_data['form_data_lastname']; ?>" />
          <input type="hidden" name="form_data_carnum" id="form_data_carnum" value="<?php echo $form_data['form_data_carnum']; ?>" />
          <input type="hidden" name="form_data_ssanum" id="form_data_ssanum" value="<?php echo $form_data['form_data_ssanum']; ?>" />
          <input type="hidden" name="form_data_company" id="form_data_company" value="<?php echo $form_data['form_data_company']; ?>" />
          <input type="hidden" name="form_data_contact1" id="form_data_contact1" value="<?php echo $form_data['form_data_contact1']; ?>" />
          <input type="hidden" name="form_data_contact2" id="form_data_contact2" value="<?php echo $form_data['form_data_contact2']; ?>" />
          <input type="hidden" name="form_data_workstart" id="form_data_workstart" value="<?php echo $form_data['form_data_workstart']; ?>" />
          <input type="hidden" name="form_data_workend" id="form_data_workend" value="<?php echo $form_data['form_data_workend']; ?>" />
          <input type="hidden" name="form_data_customerimpacted" id="form_data_customerimpacted" value="<?php echo $form_data['form_data_customerimpacted']; ?>" />
          <input type="hidden" name="form_data_visittype" id="form_data_visittype" value="<?php echo $form_data['form_data_visittype']; ?>" />
          <input type="hidden" name="form_data_v_signature" id="form_data_v_signature" value="<?php echo $form_data['form_data_v_signature']; ?>" />
          <input type="hidden" name="form_data_escortrequired" id="form_data_escortrequired" value="<?php echo $form_data['form_data_escortrequired']; ?>" />
          <input type="hidden" name="form_data_e_signature" id="form_data_e_signature" value="<?php echo $form_data['form_data_e_signature']; ?>" />
          <input type="hidden" name="form_data_escortname" id="form_data_escortname" value="<?php echo $form_data['form_data_escortname']; ?>" />
          <a class="btn btn-lg btn-danger" href="index.php"><i class="fas fa-ban"></i>&nbsp;<?php echo $transLang['STR_COMMON_CANCEL']; ?></a>
        </div>
        <div class="col d-grid gap-2">
          <button type="submit" id="saveBtn" class="btn btn-lg btn-success" name="saveBtn"><i class="fas fa-save"></i>&nbsp;<?php echo $transLang['SIGNIN']; ?></button>
        </div>
      </div>
    </form>
  </div>
<!-- START TERMS MODAL -->
  <div class="modal fade" id="termsModalLong" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="termsModalLongTitle"><?php echo $transLang['TERMSTITLE']; ?></h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
        </div>
        <div class="modal-body">
          <object type="application/pdf" data="<?php echo $StaticFunctions->getRules(); ?>" width="700" height="600">_</object>
        </div>
      </div>
    </div>
  </div>
<!-- END TERMS MODAL -->
<!-- START TERMS MODAL -->
  <div class="modal fade" id="termsVendorModalLong" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-lg" role="document">
      <div class="modal-content">
        <div class="modal-header">
          <h5 class="modal-title" id="termsVendorModalLongTitle"><?php echo $transLang['TERMSTITLE']; ?></h5>
          <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
        </div>
        <div class="modal-body">
          <object type="application/pdf" data="<?php echo $StaticFunctions->getVendorRules(); ?>" width="700" height="600">_</object>
        </div>
      </div>
    </div>
  </div>
<!-- END TERMS MODAL -->
<!-- END TERMS STAGE CONTENT -->

<?php }else{ ?>
<!-- INVALID STAGE -->
<?php } ?>

<?php } require_once("inc/footer.inc.php");
