project_form.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <?php
  2. $date_start = explode(" ", date("Y-m-d H:i:s", strtotime($project->dts_start . " UTC")))[0];
  3. $date_start_parts = explode("-", $date_start);
  4. $date_deadline = explode(" ", date("Y-m-d H:i:s", strtotime($project->dts_deadline . " UTC")))[0];
  5. $date_deadline_parts = explode("-", $date_deadline);
  6. $date_report_parts = [0, 0, 0];
  7. if($project->dts_report) {
  8. $date_report = explode(" ", date("Y-m-d H:i:s", strtotime($project->dts_report . " UTC")))[0];
  9. $date_report_parts = explode("-", $date_report);
  10. }
  11. $time_of_day_options = [
  12. "A" => "Anytime",
  13. "D" => "Daytime",
  14. "N" => "Nighttime",
  15. ];
  16. ?>
  17. <div class="container mt-3 py-4">
  18. <h2>
  19. <?=($project->id ? "Edit" : "Add")?>
  20. Project
  21. </h2>
  22. <form method="post" id="project-form">
  23. <h3>Project Details</h3>
  24. <div class="row">
  25. <div class="col-lg">
  26. <div class="row mb-1">
  27. <label class="col-sm-4 col-form-label" for="name">Name</label>
  28. <div class="col-sm">
  29. <input class="form-control" type="text" name="name" id="name" placeholder="Enter name" value="<?=htmlspecialchars($project->name)?>" required />
  30. </div>
  31. </div>
  32. <div class="row mb-1">
  33. <label class="col-sm-4 col-form-label" for="template-id">Template</label>
  34. <div class="col-sm">
  35. <select class="form-control" name="template_id" id="template-id" required>
  36. <?php
  37. foreach($templates as $template) {
  38. $selected = ($template->id == $project->template_id) ? "selected" : "";
  39. ?>
  40. <option value="<?=$template->id?>" <?=$selected?>><?=htmlspecialchars($template->name)?></option>
  41. <?php
  42. }
  43. ?>
  44. </select>
  45. </div>
  46. </div>
  47. <div class="row mb-1">
  48. <label class="col-sm-4 col-form-label" for="test-count">Test Count</label>
  49. <div class="col-sm">
  50. <input class="form-control" type="number" name="test_count" id="test-count" placeholder="Enter test count" value="<?=htmlspecialchars($project->test_count)?>" required />
  51. </div>
  52. </div>
  53. <div class="row mb-1">
  54. <label class="col-sm-4 col-form-label" for="default-customer-fee">Default Customer Fee</label>
  55. <div class="col-sm">
  56. <div class="input-group">
  57. <div class="input-group-prepend">
  58. <span class="input-group-text">£</span>
  59. </div>
  60. <input class="form-control" type="number" name="default_customer_fee" min=0" step="0.01" id="default-customer-fee" placeholder="Enter default customer fee" value="<?=htmlspecialchars($project->default_customer_fee)?>" required />
  61. </div>
  62. </div>
  63. </div>
  64. <div class="row mb-1">
  65. <label class="col-sm-4 col-form-label" for="default-tester-fee">Default Tester Fee</label>
  66. <div class="col-sm">
  67. <div class="input-group">
  68. <div class="input-group-prepend">
  69. <span class="input-group-text">£</span>
  70. </div>
  71. <input class="form-control" type="number" name="default_tester_fee" min=0" step="0.01" id="default-tester-fee" placeholder="Enter default tester fee" value="<?=htmlspecialchars($project->default_tester_fee)?>" required />
  72. </div>
  73. </div>
  74. </div>
  75. <div class="row mb-1">
  76. <label class="col-sm-4 col-form-label" for="time-of-day">Time of Day</label>
  77. <div class="col-sm">
  78. <select class="form-control" name="time_of_day" id="time-of-day" required>
  79. <?php
  80. foreach($time_of_day_options as $value => $display) {
  81. $selected = ($value == $project->time_of_day) ? "selected" : "";
  82. ?>
  83. <option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  84. <?php
  85. }
  86. ?>
  87. </select>
  88. </div>
  89. </div>
  90. <div class="row mb-1">
  91. <label class="col-sm-4 col-form-label" for="tester-can-claim">Tester Can Claim</label>
  92. <div class="col-sm">
  93. <select class="form-control" name="tester_can_claim" id="tester-can-claim">
  94. <?php
  95. foreach(Form::BOOLEAN_OPTIONS as $value => $display) {
  96. $selected = ($value == $project->tester_can_claim) ? "selected" : "";
  97. ?>
  98. <option value="<?=$value?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  99. <?php
  100. }
  101. ?>
  102. </select>
  103. <small class="form-text text-muted">Tests will appear in "Find Tests" for testers.</small>
  104. </div>
  105. </div>
  106. </div>
  107. <div class="col-lg">
  108. <div class="row mb-1">
  109. <label class="col-sm-4 col-form-label" for="min-age">Min. Age</label>
  110. <div class="col-sm">
  111. <input class="form-control" type="number" name="min_age" id="min-age" placeholder="Enter minimum age" value="<?=htmlspecialchars($project->min_age)?>" required />
  112. </div>
  113. </div>
  114. <div class="row mb-1">
  115. <label class="col-sm-4 col-form-label" for="max-age">Max. Age</label>
  116. <div class="col-sm">
  117. <input class="form-control" type="number" name="max_age" id="max-age" placeholder="Enter maximum age" value="<?=htmlspecialchars($project->max_age)?>" required />
  118. </div>
  119. </div>
  120. <div class="row mb-1">
  121. <label class="col-sm-4 col-form-label" for="date-start-day">Start Date</label>
  122. <div class="col-sm">
  123. <label class="sr-only" for="date-start-day"></label>
  124. <select class="form-control w-auto d-inline-block" name="date_start_day" id="date-start-day">
  125. <option value="">Day</option>
  126. <?php
  127. Form::renderDayOptions($date_start_parts[2]);
  128. ?>
  129. </select>
  130. <label class="sr-only" for="date-start-month"></label>
  131. <select class="form-control w-auto d-inline-block" name="date_start_month" id="date-start-month">
  132. <option value="">Month</option>
  133. <?php
  134. Form::renderMonthOptions($date_start_parts[1]);
  135. ?>
  136. </select>
  137. <label class="sr-only" for="date-start-year"></label>
  138. <select class="form-control w-auto d-inline-block" name="date_start_year" id="date-start-year">
  139. <option value="">Year</option>
  140. <?php
  141. Form::renderYearOptions(2017, date("Y") + 1, $date_start_parts[0]);
  142. ?>
  143. </select>
  144. </div>
  145. </div>
  146. <div class="row mb-1">
  147. <label class="col-sm-4 col-form-label" for="date-deadline">Deadline</label>
  148. <div class="col-sm">
  149. <label for="date-deadline-day" class="sr-only">Day</label>
  150. <select class="form-control w-auto d-inline-block" name="date_deadline_day" id="date-deadline-day">
  151. <option value="">Day</option>
  152. <?php
  153. Form::renderDayOptions($date_deadline_parts[2]);
  154. ?>
  155. </select>
  156. <label for="date-deadline-month" class="sr-only">Month</label>
  157. <select class="form-control w-auto d-inline-block" name="date_deadline_month" id="date-deadline-month">
  158. <option value="">Month</option>
  159. <?php
  160. Form::renderMonthOptions($date_deadline_parts[1]);
  161. ?>
  162. </select>
  163. <label for="date-deadline-year" class="sr-only">Year</label>
  164. <select class="form-control w-auto d-inline-block" name="date_deadline_year" id="date-deadline-year">
  165. <option value="">Year</option>
  166. <?php
  167. Form::renderYearOptions(2017, date("Y") + 1, $date_deadline_parts[0]);
  168. ?>
  169. </select>
  170. </div>
  171. </div>
  172. <div class="row mb-1">
  173. <label class="col-sm-4 col-form-label" for="date-report">Report Month</label>
  174. <div class="col-sm">
  175. <input name="date_report_day" id="date-report-day" value="12" type="hidden" />
  176. <label for="date-report-month"></label>
  177. <select class="form-control w-auto d-inline-block" name="date_report_month" id="date-report-month">
  178. <option value="">Month</option>
  179. <?php
  180. Form::renderMonthOptions($date_report_parts[1]);
  181. ?>
  182. </select>
  183. <label for="date-report-year"></label>
  184. <select class="form-control w-auto d-inline-block" name="date_report_year" id="date-report-year">
  185. <option value="">Year</option>
  186. <?php
  187. Form::renderYearOptions(2017, date("Y") + 1, $date_report_parts[0]);
  188. ?>
  189. </select>
  190. </div>
  191. </div>
  192. </div>
  193. </div>
  194. <?php
  195. if($project->id) {
  196. ?>
  197. <hr />
  198. <div class="row">
  199. <div class="col">
  200. <h3>Template Overrides</h3>
  201. </div>
  202. <div class="col-auto">
  203. <a class="btn btn-outline-primary" href="/account/projects/<?=$project->id?>/edit/template-overrides">Edit</a>
  204. </div>
  205. </div>
  206. <?php
  207. $overrides = $project->getTemplateOverrides();
  208. if(empty($overrides)) {
  209. ?>
  210. <div class="alert alert-info">There are no template overrides configured for this project.</div>
  211. <?php
  212. }
  213. else {
  214. $fields = $template->getFields();
  215. ?>
  216. <table class="table table-bordered table-hover">
  217. <thead>
  218. <tr>
  219. <th>Field</th>
  220. <th>Element</th>
  221. <th>Value</th>
  222. </tr>
  223. </thead>
  224. <tbody>
  225. <?php
  226. foreach($overrides as $override) {
  227. ?>
  228. <tr>
  229. <td>
  230. <?=htmlspecialchars($fields[$override->field]->label)?>
  231. </td>
  232. <td>
  233. <?=ucfirst($override->element)?>
  234. </td>
  235. <td>
  236. <?=htmlspecialchars($override->value)?>
  237. </td>
  238. </tr>
  239. <?php
  240. }
  241. ?>
  242. </tbody>
  243. </table>
  244. <?php
  245. }
  246. }
  247. ?>
  248. <hr />
  249. <input type="hidden" name="location_ids" id="location-ids" value="<?=implode(", ", $location_ids)?>" />
  250. <h3>Project Locations</h3>
  251. <?php
  252. if($project->id) {
  253. ?>
  254. <div class="alert alert-warning">
  255. <div class="row">
  256. <div class="col-auto">
  257. <i class="fal fa-exclamation-triangle"></i>
  258. </div>
  259. <div class="col pl-0">
  260. Please be aware that deselecting a location will cancel the test for the project no matter its current status.<br />
  261. <strong>This action cannot be undone, you have been warned!</strong>
  262. </div>
  263. </div>
  264. </div>
  265. <?php
  266. }
  267. ?>
  268. <div class="row">
  269. <div class="col-md mb-3">
  270. <h4>Selected</h4>
  271. <div class="card">
  272. <div class="card-body">
  273. <div class="input-group">
  274. <div class="input-group-prepend">
  275. <label class="input-group-text" for="selected-filter">
  276. Filter
  277. </label>
  278. </div>
  279. <input class="form-control" id="selected-filter" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#selected-locations-list-group" />
  280. </div>
  281. <div class="alert alert-info mt-3 mb-0" id="selected-locations-alert">
  282. No locations selected for testing.
  283. </div>
  284. </div>
  285. <div class="list-group list-group-flush limit-height-2" id="selected-locations-list-group">
  286. <?php
  287. foreach($locations as $index => $location) {
  288. if(!in_array($location->id, $location_ids)) continue;
  289. $address = $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
  290. $filter_parts = array_filter([
  291. $address, $location->name
  292. ]);
  293. $filter = strtolower(implode("", $filter_parts));
  294. ?>
  295. <div class="list-group-item" data-location-id="<?=$location->id?>" data-internal-id="<?=htmlspecialchars($location->internal_id)?>" data-name="<?=htmlspecialchars($location->name)?>" data-filter-value="<?=htmlspecialchars($filter)?>">
  296. <div class="row no-gutters">
  297. <div class="col-2 text-right">
  298. <?=$location->id?>
  299. </div>
  300. <div class="col hover-container px-3">
  301. <a href="/account/locations/<?=$location->id?>" target="_blank"><?=htmlspecialchars($location->name)?></a>
  302. <a class="visible-on-hover float-right" href="/account/locations/<?=$location->id?>/edit" target="_blank"><i class="fal fa-pencil"></i> Edit</a>
  303. <?php
  304. if($location->internal_id) {
  305. ?>
  306. <br />
  307. <small class="text-primary">Internal ID: <?=htmlspecialchars($location->internal_id)?></small>
  308. <?php
  309. }
  310. ?><br />
  311. <small><?=htmlspecialchars($address)?></small>
  312. </div>
  313. <div class="col-auto align-self-center text-right">
  314. <button class="btn btn-outline-danger" type="button">
  315. <i class="fas fa-times"></i>
  316. <span class="sr-only">Deselect</span>
  317. </button>
  318. </div>
  319. </div>
  320. </div>
  321. <?php
  322. }
  323. ?>
  324. </div>
  325. </div>
  326. </div>
  327. <div class="col-md mb-3">
  328. <h4>Not Selected</h4>
  329. <div class="card">
  330. <div class="card-body">
  331. <div class="input-group">
  332. <div class="input-group-prepend">
  333. <label class="input-group-text" for="not-selected-filter">
  334. Filter
  335. </label>
  336. </div>
  337. <input id="not-selected-filter" class="form-control" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#not-selected-locations-list-group" />
  338. </div>
  339. <div class="alert alert-info mt-3 mb-0" id="not-selected-locations-alert">
  340. No additional locations are available for testing.
  341. </div>
  342. </div>
  343. <div class="list-group list-group-flush limit-height-2" id="not-selected-locations-list-group">
  344. <?php
  345. foreach($locations as $index => $location) {
  346. if(in_array($location->id, $location_ids)) continue;
  347. $address = $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
  348. $filter_parts = array_filter([
  349. $address, $location->name
  350. ]);
  351. $filter = strtolower(implode("", $filter_parts));
  352. ?>
  353. <div class="list-group-item" data-location-id="<?=$location->id?>" data-internal-id="<?=htmlspecialchars($location->internal_id)?>" data-name="<?=htmlspecialchars($location->name)?>" data-filter-value="<?=htmlspecialchars($filter)?>">
  354. <div class="row no-gutters">
  355. <div class="col-2 text-right">
  356. <?=$location->id?>
  357. </div>
  358. <div class="col hover-container px-3">
  359. <a href="/account/locations/<?=$location->id?>" target="_blank"><?=htmlspecialchars($location->name)?></a>
  360. <a class="visible-on-hover float-right" href="/account/locations/<?=$location->id?>/edit" target="_blank"><i class="fal fa-pencil"></i> Edit</a>
  361. <?php
  362. if($location->internal_id) {
  363. ?>
  364. <br />
  365. <small class="text-primary">Internal ID: <?=htmlspecialchars($location->internal_id)?></small>
  366. <?php
  367. }
  368. ?>
  369. <br />
  370. <small><?=htmlspecialchars($address)?></small>
  371. </div>
  372. <div class="col-auto align-self-center text-right">
  373. <button class="btn btn-outline-success" type="button">
  374. <i class="fas fa-check"></i>
  375. <span class="sr-only">Select</span>
  376. </button>
  377. </div>
  378. </div>
  379. </div>
  380. <?php
  381. }
  382. ?>
  383. </div>
  384. </div>
  385. </div>
  386. </div>
  387. <hr />
  388. <button class="btn btn-primary" type="submit">Submit</button>
  389. <input type="hidden" name="submit" value="<?=$_SESSION["csrf_token"]?>" />
  390. </form>
  391. </div>