<?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, [
  'fd_formAction' => (string)FILTER_SANITIZE_STRING,
  'fd_siteId' => (int)FILTER_VALIDATE_INT,
  'fd_isVendor' => (int)FILTER_VALIDATE_INT,
  'fd_firstName' => (string)FILTER_SANITIZE_STRING,
  'fd_lastName' => (string)FILTER_SANITIZE_STRING,
  'fd_carNum' => (string)FILTER_SANITIZE_STRING,
  'fd_ssaNum' => (string)FILTER_SANITIZE_STRING,
  'fd_visitorCompany' => (string)FILTER_SANITIZE_STRING,
  'fd_vendorContact1' => (string)FILTER_SANITIZE_STRING,
  'fd_vendorContact2' => (string)FILTER_SANITIZE_STRING,
  'fd_workStartTime' => (string)FILTER_SANITIZE_STRING,
  'fd_workEndTime' => (string)FILTER_SANITIZE_STRING,
  'fd_clientImpacted' => (string)FILTER_SANITIZE_STRING,
  'fd_visitType' => (int)FILTER_VALIDATE_INT,
  'fd_escortRequired' => (int)FILTER_VALIDATE_INT,
  'fd_visitorSignature' => (string)FILTER_SANITIZE_STRING,
  'fd_escortSignature' => (string)FILTER_SANITIZE_STRING,
  'fd_escortName' => (string)FILTER_SANITIZE_STRING
]);
if(empty($form_data['fd_formAction'])){                                         // SET INITIAL STAGE
  $form_data['fd_formAction'] = 'covidack';
}
?>

<!-- CONTENT -->

<?php if($form_data['fd_formAction'] === "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> <?=$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><?=$transLang['STR_COVID_Q1-TITLE']?></b><br><?=$transLang['STR_COVID_Q1-DESC']?></label>
          <div class="invalid-feedback"><?=$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><?=$transLang['STR_COVID_Q2-TITLE']?></b><br><?=$transLang['STR_COVID_Q2-DESC']?></label>
          <div class="invalid-feedback"><?=$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><?=$transLang['STR_COVID_Q3-TITLE']?></b><br><?=$transLang['STR_COVID_Q3-DESC']?></label>
          <div class="invalid-feedback"><?=$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><?=$transLang['STR_COVID_Q4-TITLE']?></b><br><?=$transLang['STR_COVID_Q4-DESC']?></label>
          <div class="invalid-feedback"><?=$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><?=$transLang['STR_COVID_Q5-TITLE']?></b><br><?=$transLang['STR_COVID_Q5-DESC']?></label>
          <div class="invalid-feedback"><?=$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><?=$transLang['STR_COVID_Q6-TITLE']?></b><br><?=$transLang['STR_COVID_Q6-DESC']?></label>
          <div class="invalid-feedback"><?=$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="fd_siteId" id="fd_siteId" value="<?php echo $siteid; ?>" />
          <input type="hidden" name="fd_formAction" id="fd_formAction" value="customerorvendor" />
          <button type="submit" id="saveBtn" class="btn btn-lg btn-success" name="saveBtn"><?=$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['fd_formAction'] === "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> <?=$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">
          <?=$transLang['STR_VENDORINFO_CUSTOMERORVENDOR_DESC']?>
        </div>
      </div>
      <div class="row row-cols-2 mb-4">
        <div class="col d-grid gap-2">
          <input type="hidden" name="fd_formAction" id="fd_formAction" value="nameandcompany" />
          <input type="hidden" name="fd_siteId" id="fd_siteId" value="<?=$form_data['fd_siteId']?>" />
          <button type="submit" id="fd_isVendor" class="btn btn-lg btn-outline-primary" name="fd_isVendor" value="0">&nbsp;<br><?=$transLang['CUSTOMER']?><br>&nbsp;</button>
        </div>
        <div class="col d-grid gap-2">
          <button type="submit" id="fd_isVendor" class="btn btn-lg btn-outline-primary" name="fd_isVendor" value="1">&nbsp;<br><?=$transLang['STR_VENDORINFO_VENDOR_TITLE']?><br>&nbsp;</button>
        </div>
      </div>
    </form>
  </div>
<!-- END CUSTOMERORVENDOR STAGE CONTENT -->

<?php }elseif($form_data['fd_formAction'] === "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> <?=$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"><?=$transLang['NAME']?></span>
            <input type="text" id="fd_firstName" name="fd_firstName" class="form-control" placeholder="<?=$transLang['FIRST']?>" required autofocus>
            <input type="text" id="fd_lastName" name="fd_lastName" class="form-control" placeholder="<?=$transLang['LAST']?>" required autofocus>
          </div>
        </div>
      </div>
      <?php if($SiteInfo->getSite($form_data['fd_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"><?=$transLang['CARNUM']?></span>
            <input type="text" id="fd_carNum" name="fd_carNum" class="form-control" placeholder="<?=$transLang['CARNUM']?>" required autofocus>
          </div>
        </div>
        <div class="col d-grid gap-2">
          <div class="input-group mb-3">
            <span class="input-group-text"><?=$transLang['SSANUM']?></span>
            <input type="text" id="fd_ssaNum" name="fd_ssaNum" class="form-control" placeholder="<?=$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"><?=$transLang['COMPANY']?></span>
            <input type="text" id="fd_visitorCompany" name="fd_visitorCompany" class="form-control" placeholder="<?=$transLang['COMPANY']?>" required autofocus>
          </div>
        </div>
      </div>
      <?php if($form_data['fd_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"><?=$transLang['STR_VENDORINFO_CONTACT1_TITLE']?></span>
            <input type="text" id="fd_vendorContact1" name="fd_vendorContact1" 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"><?=$transLang['STR_VENDORINFO_CONTACT2_TITLE']?></span>
            <input type="text" id="fd_vendorContact2" name="fd_vendorContact2" 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-fd_workStartTime"><?=$transLang['STR_VENDORINFO_WORKSTART_TITLE']?>&nbsp;<i class="fas fa-clock"></i></span>
            <input name="fd_workStartTime" type="text" class="form-control form-control-sm bg-white datetimepicker-input datetimepicker-fd_workStartTime" id="datetimepicker-fd_workStartTime" data-toggle="datetimepicker" data-target=".datetimepicker-fd_workStartTime"/>
          </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-fd_workEndTime"><?=$transLang['STR_VENDORINFO_WORKEND_TITLE']?>&nbsp;<i class="fas fa-clock"></i></span>
            <input name="fd_workEndTime" type="text" class="form-control form-control-sm bg-white datetimepicker-input datetimepicker-fd_workEndTime" id="datetimepicker-fd_workEndTime" data-toggle="datetimepicker" data-target=".datetimepicker-fd_workEndTime"/>
            <script type="text/javascript">
              $(function () {
                $('.datetimepicker-fd_workStartTime').datetimepicker({'timeZone': '<?php echo $timezone; ?>', 'sideBySide':true, 'format':'YYYY-MM-DD HH:mm:ss', 'allowInputToggle': true, 'defaultDate':'<?php echo $timenow; ?>' });
                $('.datetimepicker-fd_workEndTime').datetimepicker({'timeZone': '<?php echo $timezone; ?>', 'sideBySide':true, 'format':'YYYY-MM-DD HH:mm:ss', 'allowInputToggle': true, 'defaultDate':'<?php echo date('Y-m-d H:i:s', time()+43200); ?>' });
              });
            </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"><?=$transLang['STR_VENDORINFO_CUSTOMERIMPACTED_TITLE']?></span>
            <input type="text" id="fd_clientImpacted" name="fd_clientImpacted" 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="fd_formAction" id="fd_formAction" value="reasonforvisit" />
          <input type="hidden" name="fd_siteId" id="fd_siteId" value="<?=$form_data['fd_siteId']?>" />
          <input type="hidden" name="fd_isVendor" id="fd_isVendor" value="<?=$form_data['fd_isVendor']?>" />
          <button type="submit" id="saveBtn" class="btn btn-lg btn-success" name="saveBtn"><?=$transLang['NEXT']?></button>
        </div>
      </div>
    </form>
  </div>
<!-- END NAMEANDCOMPANY STAGE CONTENT -->

<?php }elseif($form_data['fd_formAction'] === "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> <?=$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"><?=$transLang['REASON']?></span>
            <select class="form-select" id="fd_visitType" name="fd_visitType" required>
              <option value="" selected><?=$transLang['SELECTREASON']?></option><?php foreach($VisitTypeInfo->getInfoVisitType($form_data['fd_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="fd_formAction" id="fd_formAction" value="visitorsignature" />
          <input type="hidden" name="fd_siteId" id="fd_siteId" value="<?=$form_data['fd_siteId']?>" />
          <input type="hidden" name="fd_isVendor" id="fd_isVendor" value="<?=$form_data['fd_isVendor']?>" />
          <input type="hidden" name="fd_firstName" id="fd_firstName" value="<?=$form_data['fd_firstName']?>" />
          <input type="hidden" name="fd_lastName" id="fd_lastName" value="<?=$form_data['fd_lastName']?>" />
          <input type="hidden" name="fd_carNum" id="fd_carNum" value="<?=$form_data['fd_carNum']?>" />
          <input type="hidden" name="fd_ssaNum" id="fd_ssaNum" value="<?=$form_data['fd_ssaNum']?>" />
          <input type="hidden" name="fd_visitorCompany" id="fd_visitorCompany" value="<?=$form_data['fd_visitorCompany']?>" />
          <input type="hidden" name="fd_vendorContact1" id="fd_vendorContact1" value="<?=$form_data['fd_vendorContact1']?>" />
          <input type="hidden" name="fd_vendorContact2" id="fd_vendorContact2" value="<?=$form_data['fd_vendorContact2']?>" />
          <input type="hidden" name="fd_workStartTime" id="fd_workStartTime" value="<?=$form_data['fd_workStartTime']?>" />
          <input type="hidden" name="fd_workEndTime" id="fd_workEndTime" value="<?=$form_data['fd_workEndTime']?>" />
          <input type="hidden" name="fd_clientImpacted" id="fd_clientImpacted" value="<?=$form_data['fd_clientImpacted']?>" />
          <button type="submit" id="saveBtn" class="btn btn-lg btn-success" name="saveBtn"><?=$transLang['NEXT']?></button>
        </div>
      </div>
    </form>
  </div>
<!-- END REASONFORVISIT STAGE CONTENT -->

<?php }elseif($form_data['fd_formAction'] === "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> <?=$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><?=$transLang['STR_COMMON_VSIGNATURE']?>:</h4>
          <div id="vsignature-parent sigs">
            <div id="vsignature"></div>
          </div>
        </div>
      </div>
      <?php if($form_data['fd_isVendor'] === (int)"0") { ?>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <h4><?=$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="fd_escortRequired" id="no-outlined" autocomplete="off" value="0" required>
            <label class="btn btn-outline-primary btn-lg" for="no-outlined"><?=$transLang['STR_COMMON_NO']?></label>
            <input type="radio" class="btn-check btn-lg" name="fd_escortRequired" id="yes-outlined" autocomplete="off" value="1" required>
            <label class="btn btn-outline-primary btn-lg" for="yes-outlined"><?=$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');
            $('#fd_visitorSignature').val(data);
          });
        });
        $("form").submit(function() {
          if($('#fd_visitorSignature').val() === '') {
            alert("<?=$transLang['STR_COMMON_SIGNATURE']?> <?=$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="fd_formAction" id="fd_formAction" value="escortorterms" />
          <input type="hidden" name="fd_siteId" id="fd_siteId" value="<?=$form_data['fd_siteId']?>" />
          <input type="hidden" name="fd_isVendor" id="fd_isVendor" value="<?=$form_data['fd_isVendor']?>" />
          <input type="hidden" name="fd_firstName" id="fd_firstName" value="<?=$form_data['fd_firstName']?>" />
          <input type="hidden" name="fd_lastName" id="fd_lastName" value="<?=$form_data['fd_lastName']?>" />
          <input type="hidden" name="fd_carNum" id="fd_carNum" value="<?=$form_data['fd_carNum']?>" />
          <input type="hidden" name="fd_ssaNum" id="fd_ssaNum" value="<?=$form_data['fd_ssaNum']?>" />
          <input type="hidden" name="fd_visitorCompany" id="fd_visitorCompany" value="<?=$form_data['fd_visitorCompany']?>" />
          <input type="hidden" name="fd_vendorContact1" id="fd_vendorContact1" value="<?=$form_data['fd_vendorContact1']?>" />
          <input type="hidden" name="fd_vendorContact2" id="fd_vendorContact2" value="<?=$form_data['fd_vendorContact2']?>" />
          <input type="hidden" name="fd_workStartTime" id="fd_workStartTime" value="<?=$form_data['fd_workStartTime']?>" />
          <input type="hidden" name="fd_workEndTime" id="fd_workEndTime" value="<?=$form_data['fd_workEndTime']?>" />
          <input type="hidden" name="fd_clientImpacted" id="fd_clientImpacted" value="<?=$form_data['fd_clientImpacted']?>" />
          <input type="hidden" name="fd_visitType" id="fd_visitType" value="<?=$form_data['fd_visitType']?>" />
          <input type="hidden" name="fd_visitorSignature" id="fd_visitorSignature" />
          <button type="submit" id="saveBtn" class="btn btn-lg btn-success" name="saveBtn"><?=$transLang['NEXT']?></button>
        </div>
      </div>
    </form>
  </div>
<!-- END VISITORSIGNATURE STAGE CONTENT -->

<?php }elseif($form_data['fd_formAction'] === (string)"escortorterms" && $form_data['fd_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> <?=$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"><?=$transLang['ENAME']?></span>
            <input type="text" id="fd_escortName" name="fd_escortName" class="form-control" placeholder="<?=$transLang['ETAG']?>" autofocus>
          </div>
        </div>
      </div>
      <div class="row row-cols-1 mb-4">
        <div class="col d-grid gap-2">
          <h4><?=$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');
            $('#fd_escortSignature').val(data);
          });
        });
        $("form").submit(function() {
          if($('#fd_escortSignature').val() === '') {
            alert("<?=$transLang['STR_COMMON_SIGNATURE']?> <?=$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="fd_formAction" id="fd_formAction" value="terms" />
          <input type="hidden" name="fd_siteId" id="fd_siteId" value="<?=$form_data['fd_siteId']?>" />
          <input type="hidden" name="fd_isVendor" id="fd_isVendor" value="<?=$form_data['fd_isVendor']?>" />
          <input type="hidden" name="fd_firstName" id="fd_firstName" value="<?=$form_data['fd_firstName']?>" />
          <input type="hidden" name="fd_lastName" id="fd_lastName" value="<?=$form_data['fd_lastName']?>" />
          <input type="hidden" name="fd_carNum" id="fd_carNum" value="<?=$form_data['fd_carNum']?>" />
          <input type="hidden" name="fd_ssaNum" id="fd_ssaNum" value="<?=$form_data['fd_ssaNum']?>" />
          <input type="hidden" name="fd_visitorCompany" id="fd_visitorCompany" value="<?=$form_data['fd_visitorCompany']?>" />
          <input type="hidden" name="fd_vendorContact1" id="fd_vendorContact1" value="<?=$form_data['fd_vendorContact1']?>" />
          <input type="hidden" name="fd_vendorContact2" id="fd_vendorContact2" value="<?=$form_data['fd_vendorContact2']?>" />
          <input type="hidden" name="fd_workStartTime" id="fd_workStartTime" value="<?=$form_data['fd_workStartTime']?>" />
          <input type="hidden" name="fd_workEndTime" id="fd_workEndTime" value="<?=$form_data['fd_workEndTime']?>" />
          <input type="hidden" name="fd_clientImpacted" id="fd_clientImpacted" value="<?=$form_data['fd_clientImpacted']?>" />
          <input type="hidden" name="fd_visitType" id="fd_visitType" value="<?=$form_data['fd_visitType']?>" />
          <input type="hidden" name="fd_visitorSignature" id="fd_visitorSignature" value="<?=$form_data['fd_visitorSignature']?>" />
          <input type="hidden" name="fd_escortRequired" id="fd_escortRequired" value="<?=$form_data['fd_escortRequired']?>" />
          <input type="hidden" name="fd_escortSignature" id="fd_escortSignature" />
          <button type="submit" id="saveBtn" class="btn btn-lg btn-success" name="saveBtn"><?=$transLang['NEXT']?></button>
        </div>
      </div>
    </form>
  </div>
<!-- END ESCORTSIGNATURE STAGE CONTENT -->

<?php }elseif(($form_data['fd_formAction'] === (string)"escortorterms" && $form_data['fd_escortRequired'] === (int)"0") || ($form_data['fd_formAction'] === (string)"escortorterms" && $form_data['fd_isVendor'] === (int)"1") || $form_data['fd_formAction'] === (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> <?=$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['fd_siteId'], $uid, "0", "0")[0]["sites_region"] == "US") { ?>
          <p><?=$transLang['ACKNOWLEDGEMENT']?></p>
          <?php } ?>
          <p><?=$transLang['STR_COVID_ACKNOWLEDGEMENT']?><p>
          <p><?=$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(); ?>"><?=$transLang['REFERENCE']?>:&nbsp;(<?=$transLang['ACKNOWLEDGEMENT_DOC_NAME']?>)</a>
          <?php if($form_data['fd_isVendor'] === (int)"1") { ?>
          <a class="btn btn-outline-secondary btn-block" data-bs-toggle="modal" data-bs-target="#termsVendorModalLong" href="<?php echo $StaticFunctions->getVendorRules(); ?>"><?=$transLang['REFERENCE']?>:&nbsp;(<?=$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="fd_formAction" id="fd_formAction" value="terms" />
          <input type="hidden" name="fd_siteId" id="fd_siteId" value="<?=$form_data['fd_siteId']?>" />
          <input type="hidden" name="fd_isVendor" id="fd_isVendor" value="<?=$form_data['fd_isVendor']?>" />
          <input type="hidden" name="fd_firstName" id="fd_firstName" value="<?=$form_data['fd_firstName']?>" />
          <input type="hidden" name="fd_lastName" id="fd_lastName" value="<?=$form_data['fd_lastName']?>" />
          <input type="hidden" name="fd_carNum" id="fd_carNum" value="<?=$form_data['fd_carNum']?>" />
          <input type="hidden" name="fd_ssaNum" id="fd_ssaNum" value="<?=$form_data['fd_ssaNum']?>" />
          <input type="hidden" name="fd_visitorCompany" id="fd_visitorCompany" value="<?=$form_data['fd_visitorCompany']?>" />
          <input type="hidden" name="fd_vendorContact1" id="fd_vendorContact1" value="<?=$form_data['fd_vendorContact1']?>" />
          <input type="hidden" name="fd_vendorContact2" id="fd_vendorContact2" value="<?=$form_data['fd_vendorContact2']?>" />
          <input type="hidden" name="fd_workStartTime" id="fd_workStartTime" value="<?=$form_data['fd_workStartTime']?>" />
          <input type="hidden" name="fd_workEndTime" id="fd_workEndTime" value="<?=$form_data['fd_workEndTime']?>" />
          <input type="hidden" name="fd_clientImpacted" id="fd_clientImpacted" value="<?=$form_data['fd_clientImpacted']?>" />
          <input type="hidden" name="fd_visitType" id="fd_visitType" value="<?=$form_data['fd_visitType']?>" />
          <input type="hidden" name="fd_visitorSignature" id="fd_visitorSignature" value="<?=$form_data['fd_visitorSignature']?>" />
          <input type="hidden" name="fd_escortRequired" id="fd_escortRequired" value="<?=$form_data['fd_escortRequired']?>" />
          <input type="hidden" name="fd_escortSignature" id="fd_escortSignature" value="<?=$form_data['fd_escortSignature']?>" />
          <input type="hidden" name="fd_escortName" id="fd_escortName" value="<?=$form_data['fd_escortName']?>" />
          <a class="btn btn-lg btn-danger" href="index.php"><i class="fas fa-ban"></i>&nbsp;<?=$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;<?=$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"><?=$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"><?=$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");
