project_form.php 13 KB

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