| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248 |
- <?php
- class Template extends Model {
- protected static $table = "template";
- protected static $id_field = "id";
- protected static $fillable_fields = ["customer_id", "name", "json", "practice", "pass_stage"];
- private $overrides = [];
- // Object methods
- public function getCustomer() {
- return Customer::get($this->customer_id);
- }
- public function getProcessingFilePath($file) {
- if(!$this->folder) throw new Exception("Template processing folder not set.");
- $folder_path = ROOT_DIR . "/template_processing/" . $this->folder;
- if(!file_exists($folder_path)) throw new Exception("Template processing folder does not exist.");
- $file_path = $folder_path . "/" . $file;
- if(!file_exists($file_path)) throw new Exception("Template processing file \"$file\" does not exist.");
- return $file_path;
- }
- public function getURL() {
- return "/account/templates/" . $this->id;
- }
- public function getFields() {
- $fields = [];
- $json = json_decode($this->json);
- $before_fields = $json->beforeTest;
- $during_fields = $json->duringTest;
- $all_fields = array_merge($before_fields, $during_fields);
- foreach($all_fields as $field) {
- if(empty($field->name)) continue;
- $fields[$field->name] = $field;
- }
- return $fields;
- }
- public function getTesterInvoiceFields() {
- $json = json_decode($this->json);
- if(!$json) throw new Exception("Failed to decode template JSON.");
- return $json->testerInvoiceFields ?? [];
- }
- public function setOverrides($overrides) {
- $this->overrides = $overrides;
- }
- public function applyOverridesToField($field) {
- foreach($this->overrides as $override) {
- if(empty($field->name)) continue;
- if($override->field == $field->name) {
- switch($override->element) {
- case "label":
- $field->label = $override->value;
- break;
- }
- }
- }
- return $field;
- }
- public function renderBeforeTestForm() {
- $json = json_decode($this->json);
- $fields = $json->beforeTest;
- ?>
- <form method="post" enctype="multipart/form-data" id="before-test-form">
- <div class="alert alert-info">
- <i class="fal fa-fw fa-info-circle"></i>
- Answer as clearly and accurately as you can otherwise you may be contacted after the test for clarification and/or verification purposes.
- </div>
- <?php
- foreach($fields as $field) {
- $field = $this->applyOverridesToField($field);
- Form::renderField($field);
- }
- ?>
- <input type="hidden" name="submit" value="<?=$_SESSION["csrf_token"]?>" />
- <span class="text-danger">Please note that it may take a while for photos to upload. Please do not refresh the page when it is uploading.</span><br />
- <button class="btn btn-primary mt-3" type="submit">
- Submit Info & Photos
- </button>
- </form>
- <?php
- }
- public function renderDuringTestForm() {
- $json = json_decode($this->json);
- $fields = $json->duringTest;
- ?>
- <form method="post" id="test-form">
- <div id="test-main-form-container">
- <div class="alert alert-info">
- <i class="fal fa-fw fa-info-circle"></i>
- Answer as clearly and accurately as you can otherwise you may be contacted after the test for clarification and/or verification purposes.
- </div>
- <?php
- foreach($fields as $field) {
- $field = $this->applyOverridesToField($field);
- Form::renderField($field);
- }
- ?>
- <h3>Entry/Exit Times</h3>
- <p>Please confirm your entry and exit times below. Please try to be as accurate as possible.</p>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="start-override-hour">Entry Time <span class="badge badge-danger">Required</span></label>
- <div class="col-sm">
- <div class="row">
- <div class="col-lg">
- <select class="form-control w-auto d-inline-block" name="start_override_hour" id="start-override-hour">
- <option value="">HH</option>
- <?php
- Form::renderHourOptions();
- ?>
- </select>
- <select class="form-control w-auto d-inline-block" name="start_override_minute" id="start-override-minute">
- <option value="">MM</option>
- <?php
- Form::renderMinuteOptions();
- ?>
- </select>
- <select class="form-control w-auto d-inline-block" name="start_override_second" id="start-override-second">
- <option value="">SS</option>
- <?php
- Form::renderSecondOptions(0);
- ?>
- </select>
- </div>
- <div class="col-lg">
- <select class="form-control w-auto d-inline-block" name="start_override_day" id="start-override-day">
- <option value="">Day</option>
- <?php
- Form::renderDayOptions(date("j"));
- ?>
- </select>
- <select class="form-control w-auto d-inline-block" name="start_override_month" id="start-override-month">
- <option value="">Month</option>
- <?php
- Form::renderMonthOptions(date("n"));
- ?>
- </select>
- <select class="form-control w-auto d-inline-block" name="start_override_year" id="start-override-year">
- <option value="">Year</option>
- <?php
- Form::renderYearOptionsDescending(2017, date("Y"), date("Y"));
- ?>
- </select>
- </div>
- </div>
- </div>
- </div>
- <div class="row mb-1">
- <label class="col-sm-4 col-form-label" for="end-override-hour">Exit Time <span class="badge badge-danger">Required</span></label>
- <div class="col-sm">
- <div class="row">
- <div class="col-lg">
- <select class="form-control w-auto d-inline-block" name="end_override_hour" id="end-override-hour">
- <option value="">HH</option>
- <?php
- Form::renderHourOptions();
- ?>
- </select>
- <select class="form-control w-auto d-inline-block" name="end_override_minute" id="end-override-minute">
- <option value="">MM</option>
- <?php
- Form::renderMinuteOptions();
- ?>
- </select>
- <select class="form-control w-auto d-inline-block" name="end_override_second" id="end-override-second">
- <option value="">SS</option>
- <?php
- Form::renderSecondOptions(0);
- ?>
- </select>
- </div>
- <div class="col-lg">
- <select class="form-control w-auto d-inline-block" name="end_override_day" id="end-override-day">
- <option value="">Day</option>
- <?php
- Form::renderDayOptions(date("j"));
- ?>
- </select>
- <select class="form-control w-auto d-inline-block" name="end_override_month" id="end-override-month">
- <option value="">Month</option>
- <?php
- Form::renderMonthOptions(date("n"));
- ?>
- </select>
- <select class="form-control w-auto d-inline-block" name="end_override_year" id="end-override-year">
- <option value="">Year</option>
- <?php
- Form::renderYearOptionsDescending(2017, date("Y"), date("Y"));
- ?>
- </select>
- </div>
- </div>
- </div>
- </div>
- <div class="bg-light text-center p-3 mt-3">
- <input type="hidden" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
- <button class="btn btn-block btn-primary" type="submit" id="test-submit-button">Submit Test Results</button>
- <small class="form-text text-muted d-none" id="test-no-internet-text">
- <span class="text-danger">No Internet Connectivity</span><br />
- Please check your Internet connectivity and try again.
- </small>
- <small id="test-submit-status">
- </small>
- </div>
- </div>
- </form>
- <?php
- }
- }
- ?>
|