project_form.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. ?>
  12. <div class="container mt-3 py-4">
  13. <h2>
  14. <?=($project->id ? "Edit" : "Add")?>
  15. Project
  16. </h2>
  17. <form method="post">
  18. <h3>Project Details</h3>
  19. <div class="row">
  20. <div class="col-lg">
  21. <div class="row mb-1">
  22. <label class="col-sm-4 col-form-label" for="name">Name</label>
  23. <div class="col-sm">
  24. <input class="form-control" type="text" name="name" id="name" placeholder="Enter name" value="<?=htmlspecialchars($project->name)?>" required />
  25. </div>
  26. </div>
  27. <div class="row mb-1">
  28. <label class="col-sm-4 col-form-label" for="template-id">Template</label>
  29. <div class="col-sm">
  30. <select class="form-control" name="template_id" id="template-id" required>
  31. <?php
  32. foreach($templates as $template) {
  33. $selected = ($template->id == $project->template_id) ? "selected" : "";
  34. ?>
  35. <option value="<?=$template->id?>"><?=htmlspecialchars($template->name)?></option>
  36. <?php
  37. }
  38. ?>
  39. </select>
  40. </div>
  41. </div>
  42. <div class="row mb-1">
  43. <label class="col-sm-4 col-form-label" for="test-count">Test Count</label>
  44. <div class="col-sm">
  45. <input class="form-control" type="number" name="test_count" id="test-count" placeholder="Enter test count" value="<?=htmlspecialchars($project->test_count)?>" required />
  46. </div>
  47. </div>
  48. <div class="row mb-1">
  49. <label class="col-sm-4 col-form-label" for="default-tester-fee">Default Tester Fee</label>
  50. <div class="col-sm">
  51. <div class="input-group">
  52. <div class="input-group-prepend">
  53. <span class="input-group-text">£</span>
  54. </div>
  55. <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 />
  56. </div>
  57. </div>
  58. </div>
  59. </div>
  60. <div class="col-lg">
  61. <div class="row mb-1">
  62. <label class="col-sm-4 col-form-label" for="min-age">Min. Age</label>
  63. <div class="col-sm">
  64. <input class="form-control" type="number" name="min_age" id="min-age" placeholder="Enter minimum age" value="<?=htmlspecialchars($project->min_age)?>" required />
  65. </div>
  66. </div>
  67. <div class="row mb-1">
  68. <label class="col-sm-4 col-form-label" for="max-age">Max. Age</label>
  69. <div class="col-sm">
  70. <input class="form-control" type="number" name="max_age" id="max-age" placeholder="Enter maximum age" value="<?=htmlspecialchars($project->max_age)?>" required />
  71. </div>
  72. </div>
  73. <div class="row mb-1">
  74. <label class="col-sm-4 col-form-label" for="date-start-day">Start Date</label>
  75. <div class="col-sm">
  76. <select class="form-control w-auto d-inline-block" name="date_start_day" id="date-start-day">
  77. <option value="">Day</option>
  78. <?php
  79. Form::renderDayOptions($date_start_parts[2]);
  80. ?>
  81. </select>
  82. <select class="form-control w-auto d-inline-block" name="date_start_month" id="date-start-month">
  83. <option value="">Month</option>
  84. <?php
  85. Form::renderMonthOptions($date_start_parts[1]);
  86. ?>
  87. </select>
  88. <select class="form-control w-auto d-inline-block" name="date_start_year" id="date-start-year">
  89. <option value="">Year</option>
  90. <?php
  91. Form::renderYearOptions(2017, date("Y") + 1, $date_start_parts[0]);
  92. ?>
  93. </select>
  94. </div>
  95. </div>
  96. <div class="row mb-1">
  97. <label class="col-sm-4 col-form-label" for="date-deadline">Deadline</label>
  98. <div class="col-sm">
  99. <select class="form-control w-auto d-inline-block" name="date_deadline_day" id="date-deadline-day">
  100. <option value="">Day</option>
  101. <?php
  102. Form::renderDayOptions($date_deadline_parts[2]);
  103. ?>
  104. </select>
  105. <select class="form-control w-auto d-inline-block" name="date_deadline_month" id="date-deadline-month">
  106. <option value="">Month</option>
  107. <?php
  108. Form::renderMonthOptions($date_deadline_parts[1]);
  109. ?>
  110. </select>
  111. <select class="form-control w-auto d-inline-block" name="date_deadline_year" id="date-deadline-year">
  112. <option value="">Year</option>
  113. <?php
  114. Form::renderYearOptions(2017, date("Y") + 1, $date_deadline_parts[0]);
  115. ?>
  116. </select>
  117. </div>
  118. </div>
  119. <div class="row mb-1">
  120. <label class="col-sm-4 col-form-label" for="date-report">Report Month</label>
  121. <div class="col-sm">
  122. <input name="date_report_day" id="date-report-day" value="12" type="hidden" />
  123. <select class="form-control w-auto d-inline-block" name="date_report_month" id="date-report-month">
  124. <option value="">Month</option>
  125. <?php
  126. Form::renderMonthOptions($date_report_parts[1]);
  127. ?>
  128. </select>
  129. <select class="form-control w-auto d-inline-block" name="date_report_year" id="date-report-year">
  130. <option value="">Year</option>
  131. <?php
  132. Form::renderYearOptions(2017, date("Y") + 1, $date_report_parts[0]);
  133. ?>
  134. </select>
  135. </div>
  136. </div>
  137. </div>
  138. </div>
  139. <hr />
  140. <input type="hidden" name="location_ids" id="location-ids" value="<?=implode(", ", $location_ids)?>" />
  141. <h3>Project Locations</h3>
  142. <?php
  143. if($project->id) {
  144. ?>
  145. <div class="alert alert-warning">
  146. <div class="row">
  147. <div class="col-auto">
  148. <i class="fal fa-exclamation-triangle"></i>
  149. </div>
  150. <div class="col pl-0">
  151. Please be aware that deselecting a location will cancel the test for the project no matter its current status.<br />
  152. <strong>This action cannot be undone, you have been warned!</strong>
  153. </div>
  154. </div>
  155. </div>
  156. <?php
  157. }
  158. ?>
  159. <div class="row">
  160. <div class="col-md mb-3">
  161. <h4>Selected</h4>
  162. <div class="card">
  163. <div class="card-body">
  164. <div class="input-group">
  165. <div class="input-group-prepend">
  166. <span class="input-group-text">
  167. Filter
  168. </span>
  169. </div>
  170. <input class="form-control" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#selected-locations-list-group" />
  171. </div>
  172. <div class="alert alert-info mt-3 mb-0" id="selected-locations-alert">
  173. No locations selected for testing.
  174. </div>
  175. </div>
  176. <div class="list-group list-group-flush limit-height-2" id="selected-locations-list-group">
  177. <?php
  178. foreach($locations as $index => $location) {
  179. if(!in_array($location->id, $location_ids)) continue;
  180. $address = $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
  181. $filter_parts = array_filter([
  182. $address, $location->name
  183. ]);
  184. $filter = strtolower(implode("", $filter_parts));
  185. ?>
  186. <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)?>">
  187. <div class="row no-gutters">
  188. <div class="col-2 text-right pr-3">
  189. <?=$location->id?>
  190. </div>
  191. <div class="col">
  192. <?=htmlspecialchars($location->name)?>
  193. <?php
  194. if($location->internal_id) {
  195. ?>
  196. <br />
  197. <small class="text-primary">Customer Internal ID: <?=htmlspecialchars($location->internal_id)?></small>
  198. <?php
  199. }
  200. ?><br />
  201. <small><?=htmlspecialchars($address)?></small>
  202. </div>
  203. <div class="col-auto align-self-center text-right">
  204. <button class="btn btn-outline-danger" type="button">
  205. <i class="fas fa-times"></i>
  206. <span class="sr-only">Deselect</span>
  207. </button>
  208. </div>
  209. </div>
  210. </div>
  211. <?php
  212. }
  213. ?>
  214. </div>
  215. </div>
  216. </div>
  217. <div class="col-md mb-3">
  218. <h4>Not Selected</h4>
  219. <div class="card">
  220. <div class="card-body">
  221. <div class="input-group">
  222. <div class="input-group-prepend">
  223. <span class="input-group-text">
  224. Filter
  225. </span>
  226. </div>
  227. <input class="form-control" type="text" placeholder="Enter name, address, ID or internal ID" data-filter-target="#not-selected-locations-list-group" />
  228. </div>
  229. <div class="alert alert-info mt-3 mb-0" id="not-selected-locations-alert">
  230. No additional locations are available for testing.
  231. </div>
  232. </div>
  233. <div class="list-group list-group-flush limit-height-2" id="not-selected-locations-list-group">
  234. <?php
  235. foreach($locations as $index => $location) {
  236. if(in_array($location->id, $location_ids)) continue;
  237. $address = $location->getDisplayAddress(["address_1", "address_2", "city", "postal_code"]);
  238. $filter_parts = array_filter([
  239. $address, $location->name
  240. ]);
  241. $filter = strtolower(implode("", $filter_parts));
  242. ?>
  243. <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)?>">
  244. <div class="row no-gutters">
  245. <div class="col-2 text-right pr-3">
  246. <?=$location->id?>
  247. </div>
  248. <div class="col">
  249. <?=htmlspecialchars($location->name)?>
  250. <?php
  251. if($location->internal_id) {
  252. ?>
  253. <br />
  254. <small class="text-primary">Customer Internal ID: <?=htmlspecialchars($location->internal_id)?></small>
  255. <?php
  256. }
  257. ?>
  258. <br />
  259. <small><?=htmlspecialchars($address)?></small>
  260. </div>
  261. <div class="col-auto align-self-center text-right">
  262. <button class="btn btn-outline-success" type="button">
  263. <i class="fas fa-check"></i>
  264. <span class="sr-only">Select</span>
  265. </button>
  266. </div>
  267. </div>
  268. </div>
  269. <?php
  270. }
  271. ?>
  272. </div>
  273. </div>
  274. </div>
  275. </div>
  276. <hr />
  277. <button class="btn btn-primary" type="submit" name="submit" value="<?=$_SESSION["csrf_token"]?>">Submit</button>
  278. </form>
  279. </div>