project_form.php 15 KB

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