template.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 setOverrides($overrides) {
  40. $this->overrides = $overrides;
  41. }
  42. public function applyOverridesToField($field) {
  43. foreach($this->overrides as $override) {
  44. if(empty($field->name)) continue;
  45. if($override->field == $field->name) {
  46. switch($override->element) {
  47. case "label":
  48. $field->label = $override->value;
  49. break;
  50. }
  51. }
  52. }
  53. return $field;
  54. }
  55. public function renderBeforeTestForm() {
  56. $json = json_decode($this->json);
  57. $fields = $json->beforeTest;
  58. ?>
  59. <form method="post" enctype="multipart/form-data" id="before-test-form">
  60. <div class="alert alert-info">
  61. <i class="fal fa-fw fa-info-circle"></i>
  62. Answer as clearly and accurately as you can otherwise you may be contacted after the test for clarification and/or verification purposes.
  63. </div>
  64. <?php
  65. foreach($fields as $field) {
  66. $field = $this->applyOverridesToField($field);
  67. Form::renderField($field);
  68. }
  69. ?>
  70. <input type="hidden" name="submit" value="<?=$_SESSION["csrf_token"]?>" />
  71. <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 />
  72. <button class="btn btn-primary mt-3" type="submit">
  73. Submit Info &amp; Photos
  74. </button>
  75. </form>
  76. <?php
  77. }
  78. public function renderDuringTestForm() {
  79. $json = json_decode($this->json);
  80. $fields = $json->duringTest;
  81. ?>
  82. <form method="post" id="test-form">
  83. <div id="test-main-form-container">
  84. <div class="alert alert-info">
  85. <i class="fal fa-fw fa-info-circle"></i>
  86. Answer as clearly and accurately as you can otherwise you may be contacted after the test for clarification and/or verification purposes.
  87. </div>
  88. <?php
  89. foreach($fields as $field) {
  90. $field = $this->applyOverridesToField($field);
  91. Form::renderField($field);
  92. }
  93. ?>
  94. <h3>Entry/Exit Times</h3>
  95. <p>Please confirm your entry and exit times below. Please try to be as accurate as possible.</p>
  96. <div class="row mb-1">
  97. <label class="col-sm-4 col-form-label" for="start-override-hour">Entry Time <span class="badge badge-danger">Required</span></label>
  98. <div class="col-sm">
  99. <div class="row">
  100. <div class="col-lg">
  101. <select class="form-control w-auto d-inline-block" name="start_override_hour" id="start-override-hour">
  102. <option value="">HH</option>
  103. <?php
  104. Form::renderHourOptions();
  105. ?>
  106. </select>
  107. <select class="form-control w-auto d-inline-block" name="start_override_minute" id="start-override-minute">
  108. <option value="">MM</option>
  109. <?php
  110. Form::renderMinuteOptions();
  111. ?>
  112. </select>
  113. <select class="form-control w-auto d-inline-block" name="start_override_second" id="start-override-second">
  114. <option value="">SS</option>
  115. <?php
  116. Form::renderSecondOptions(0);
  117. ?>
  118. </select>
  119. </div>
  120. <div class="col-lg">
  121. <select class="form-control w-auto d-inline-block" name="start_override_day" id="start-override-day">
  122. <option value="">Day</option>
  123. <?php
  124. Form::renderDayOptions(date("j"));
  125. ?>
  126. </select>
  127. <select class="form-control w-auto d-inline-block" name="start_override_month" id="start-override-month">
  128. <option value="">Month</option>
  129. <?php
  130. Form::renderMonthOptions(date("n"));
  131. ?>
  132. </select>
  133. <select class="form-control w-auto d-inline-block" name="start_override_year" id="start-override-year">
  134. <option value="">Year</option>
  135. <?php
  136. Form::renderYearOptionsDescending(2017, date("Y"), date("Y"));
  137. ?>
  138. </select>
  139. </div>
  140. </div>
  141. </div>
  142. </div>
  143. <div class="row mb-1">
  144. <label class="col-sm-4 col-form-label" for="end-override-hour">Exit Time <span class="badge badge-danger">Required</span></label>
  145. <div class="col-sm">
  146. <div class="row">
  147. <div class="col-lg">
  148. <select class="form-control w-auto d-inline-block" name="end_override_hour" id="end-override-hour">
  149. <option value="">HH</option>
  150. <?php
  151. Form::renderHourOptions();
  152. ?>
  153. </select>
  154. <select class="form-control w-auto d-inline-block" name="end_override_minute" id="end-override-minute">
  155. <option value="">MM</option>
  156. <?php
  157. Form::renderMinuteOptions();
  158. ?>
  159. </select>
  160. <select class="form-control w-auto d-inline-block" name="end_override_second" id="end-override-second">
  161. <option value="">SS</option>
  162. <?php
  163. Form::renderSecondOptions(0);
  164. ?>
  165. </select>
  166. </div>
  167. <div class="col-lg">
  168. <select class="form-control w-auto d-inline-block" name="end_override_day" id="end-override-day">
  169. <option value="">Day</option>
  170. <?php
  171. Form::renderDayOptions(date("j"));
  172. ?>
  173. </select>
  174. <select class="form-control w-auto d-inline-block" name="end_override_month" id="end-override-month">
  175. <option value="">Month</option>
  176. <?php
  177. Form::renderMonthOptions(date("n"));
  178. ?>
  179. </select>
  180. <select class="form-control w-auto d-inline-block" name="end_override_year" id="end-override-year">
  181. <option value="">Year</option>
  182. <?php
  183. Form::renderYearOptionsDescending(2017, date("Y"), date("Y"));
  184. ?>
  185. </select>
  186. </div>
  187. </div>
  188. </div>
  189. </div>
  190. <div class="bg-light text-center p-3 mt-3">
  191. <input type="hidden" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>" />
  192. <button class="btn btn-block btn-primary" type="submit" id="test-submit-button">Submit Test Results</button>
  193. <small class="form-text text-muted d-none" id="test-no-internet-text">
  194. <span class="text-danger">No Internet Connectivity</span><br />
  195. Please check your Internet connectivity and try again.
  196. </small>
  197. <small id="test-submit-status">
  198. </small>
  199. </div>
  200. </div>
  201. </form>
  202. <?php
  203. }
  204. }
  205. ?>