template.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. class Template extends Model {
  3. protected static $table = "template";
  4. protected static $id_field = "id";
  5. protected static $fillable_fields = ["customer_id", "name", "json", "practice", "pass_stage"];
  6. private $overrides = [];
  7. // Object methods
  8. public function getCustomer() {
  9. return Customer::get($this->customer_id);
  10. }
  11. public function getProcessingFilePath($file) {
  12. if(!$this->folder) throw new Exception("Template processing folder not set.");
  13. $folder_path = ROOT_DIR . "/template_processing/" . $this->folder;
  14. if(!file_exists($folder_path)) throw new Exception("Template processing folder does not exist.");
  15. $file_path = $folder_path . "/" . $file;
  16. if(!file_exists($file_path)) throw new Exception("Template processing file \"$file\" does not exist.");
  17. return $file_path;
  18. }
  19. public function getURL() {
  20. return "/account/templates/" . $this->id;
  21. }
  22. public function getFields() {
  23. $fields = [];
  24. $json = json_decode($this->json);
  25. $before_fields = $json->beforeTest;
  26. $during_fields = $json->duringTest;
  27. $all_fields = array_merge($before_fields, $during_fields);
  28. foreach($all_fields as $field) {
  29. if(empty($field->name)) continue;
  30. $fields[$field->name] = $field;
  31. }
  32. return $fields;
  33. }
  34. public function getTesterInvoiceFields() {
  35. $json = json_decode($this->json);
  36. if(!$json) throw new Exception("Failed to decode template JSON.");
  37. return $json->testerInvoiceFields ?? [];
  38. }
  39. public function getCustomerInvoiceFields() {
  40. $json = json_decode($this->json);
  41. if(!$json) throw new Exception("Failed to decode template JSON.");
  42. return $json->customerInvoiceFields ?? [];
  43. }
  44. public function setOverrides($overrides) {
  45. $this->overrides = $overrides;
  46. }
  47. public function applyOverridesToField($field) {
  48. foreach($this->overrides as $override) {
  49. if(empty($field->name)) continue;
  50. if($override->field == $field->name) {
  51. switch($override->element) {
  52. case "label":
  53. $field->label = $override->value;
  54. break;
  55. }
  56. }
  57. }
  58. return $field;
  59. }
  60. public function renderBeforeTestForm() {
  61. $json = json_decode($this->json);
  62. $fields = $json->beforeTest;
  63. ?>
  64. <form method="post" enctype="multipart/form-data" id="before-test-form">
  65. <div class="alert alert-info">
  66. <i class="fal fa-fw fa-info-circle"></i>
  67. Answer as clearly and accurately as you can otherwise you may be contacted after the test for clarification and/or verification purposes.
  68. </div>
  69. <?php
  70. foreach($fields as $field) {
  71. $field = $this->applyOverridesToField($field);
  72. Form::renderField($field);
  73. }
  74. ?>
  75. <input type="hidden" name="submit" value="<?=$_SESSION["csrf_token"]?>" />
  76. <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 />
  77. <button class="btn btn-primary mt-3" type="submit">
  78. Submit Info &amp; Photos
  79. </button>
  80. </form>
  81. <?php
  82. }
  83. public function renderDuringTestForm() {
  84. $json = json_decode($this->json);
  85. $fields = $json->duringTest;
  86. ?>
  87. <form method="post" id="test-form">
  88. <div id="test-main-form-container">
  89. <div class="alert alert-info">
  90. <i class="fal fa-fw fa-info-circle"></i>
  91. Answer as clearly and accurately as you can otherwise you may be contacted after the test for clarification and/or verification purposes.
  92. </div>
  93. <?php
  94. foreach($fields as $field) {
  95. $field = $this->applyOverridesToField($field);
  96. Form::renderField($field);
  97. }
  98. ?>
  99. <h3>Entry/Exit Times</h3>
  100. <p>Please confirm your entry and exit times below. Please try to be as accurate as possible.</p>
  101. <div class="row mb-1">
  102. <label class="col-sm-4 col-form-label" for="start-override-hour">Entry Time <span class="badge badge-danger">Required</span></label>
  103. <div class="col-sm">
  104. <div class="row">
  105. <div class="col-lg">
  106. <select class="form-control w-auto d-inline-block" name="start_override_hour" id="start-override-hour">
  107. <option value="">HH</option>
  108. <?php
  109. Form::renderHourOptions();
  110. ?>
  111. </select>
  112. <select class="form-control w-auto d-inline-block" name="start_override_minute" id="start-override-minute">
  113. <option value="">MM</option>
  114. <?php
  115. Form::renderMinuteOptions();
  116. ?>
  117. </select>
  118. <select class="form-control w-auto d-inline-block" name="start_override_second" id="start-override-second">
  119. <option value="">SS</option>
  120. <?php
  121. Form::renderSecondOptions(0);
  122. ?>
  123. </select>
  124. </div>
  125. <div class="col-lg">
  126. <select class="form-control w-auto d-inline-block" name="start_override_day" id="start-override-day">
  127. <option value="">Day</option>
  128. <?php
  129. Form::renderDayOptions(date("j"));
  130. ?>
  131. </select>
  132. <select class="form-control w-auto d-inline-block" name="start_override_month" id="start-override-month">
  133. <option value="">Month</option>
  134. <?php
  135. Form::renderMonthOptions(date("n"));
  136. ?>
  137. </select>
  138. <select class="form-control w-auto d-inline-block" name="start_override_year" id="start-override-year">
  139. <option value="">Year</option>
  140. <?php
  141. Form::renderYearOptionsDescending(2017, date("Y"), date("Y"));
  142. ?>
  143. </select>
  144. </div>
  145. </div>
  146. </div>
  147. </div>
  148. <div class="row mb-1">
  149. <label class="col-sm-4 col-form-label" for="end-override-hour">Exit Time <span class="badge badge-danger">Required</span></label>
  150. <div class="col-sm">
  151. <div class="row">
  152. <div class="col-lg">
  153. <select class="form-control w-auto d-inline-block" name="end_override_hour" id="end-override-hour">
  154. <option value="">HH</option>
  155. <?php
  156. Form::renderHourOptions();
  157. ?>
  158. </select>
  159. <select class="form-control w-auto d-inline-block" name="end_override_minute" id="end-override-minute">
  160. <option value="">MM</option>
  161. <?php
  162. Form::renderMinuteOptions();
  163. ?>
  164. </select>
  165. <select class="form-control w-auto d-inline-block" name="end_override_second" id="end-override-second">
  166. <option value="">SS</option>
  167. <?php
  168. Form::renderSecondOptions(0);
  169. ?>
  170. </select>
  171. </div>
  172. <div class="col-lg">
  173. <select class="form-control w-auto d-inline-block" name="end_override_day" id="end-override-day">
  174. <option value="">Day</option>
  175. <?php
  176. Form::renderDayOptions(date("j"));
  177. ?>
  178. </select>
  179. <select class="form-control w-auto d-inline-block" name="end_override_month" id="end-override-month">
  180. <option value="">Month</option>
  181. <?php
  182. Form::renderMonthOptions(date("n"));
  183. ?>
  184. </select>
  185. <select class="form-control w-auto d-inline-block" name="end_override_year" id="end-override-year">
  186. <option value="">Year</option>
  187. <?php
  188. Form::renderYearOptionsDescending(2017, date("Y"), date("Y"));
  189. ?>
  190. </select>
  191. </div>
  192. </div>
  193. </div>
  194. </div>
  195. <div class="bg-light text-center p-3 mt-3">
  196. <input type="hidden" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
  197. <button class="btn btn-block btn-primary" type="submit" id="test-submit-button">Submit Test Results</button>
  198. <small class="form-text text-muted d-none" id="test-no-internet-text">
  199. <span class="text-danger">No Internet Connectivity</span><br />
  200. Please check your Internet connectivity and try again.
  201. </small>
  202. <small id="test-submit-status">
  203. </small>
  204. </div>
  205. </div>
  206. </form>
  207. <?php
  208. }
  209. }
  210. ?>