project_form.php 15 KB

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