user_edit_form.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <?php
  2. $date_of_birth_parts = explode("-", $user->date_of_birth);
  3. $activated_checked = ($user->activated) ? "checked" : "";
  4. $can_claim_checked = ($user->can_claim) ? "checked" : "";
  5. ?>
  6. <script>
  7. var userId = <?=$user->id?>;
  8. </script>
  9. <div class="container mt-3 py-4">
  10. <h2>Edit User</h2>
  11. <form method="post">
  12. <div class="row">
  13. <div class="col-lg-6 mb-3">
  14. <h3>Details</h3>
  15. <div class="row mb-1">
  16. <label class="col-sm-4 col-form-label" for="level">Level</label>
  17. <div class="col-sm">
  18. <select class="form-control" name="level" id="level" required />
  19. <?php
  20. foreach(User::LEVELS as $value => $display) {
  21. if($value > Core::$user->level) continue;
  22. $selected = ($user->level == $value) ? "selected" : "";
  23. ?>
  24. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  25. <?php
  26. }
  27. ?>
  28. </select>
  29. </div>
  30. </div>
  31. <?php
  32. if($user->isCustomer()) {
  33. ?>
  34. <div class="row mb-1">
  35. <label class="col-sm-4 col-form-label" for="customer-id">Customer</label>
  36. <div class="col-sm">
  37. <select class="form-control" name="customer_id" id="customer-id" />
  38. <option value="">Unassigned</option>
  39. <?php
  40. foreach($customers as $customer) {
  41. $selected = ($customer->id == $user_customer_link->customer_id) ? "selected" : "";
  42. ?>
  43. <option value="<?=htmlspecialchars($customer->id)?>" <?=$selected?>><?=htmlspecialchars($customer->name)?></option>
  44. <?php
  45. }
  46. ?>
  47. </select>
  48. </div>
  49. </div>
  50. <?php
  51. }
  52. ?>
  53. <div class="row mb-1">
  54. <div class="col-sm offset-sm-4">
  55. <div class="form-check">
  56. <input class="form-check-input" type="checkbox" name="activated" id="activated" value="1" <?=$activated_checked?> />
  57. <label class="form-check-label" for="activated">Email Verified</label>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="row mb-1">
  62. <label class="col-sm-4 col-form-label" for="title">Title</label>
  63. <div class="col-sm">
  64. <select class="form-control" name="title" id="title" required>
  65. <option value="">Select title</option>
  66. <?php
  67. foreach(User::TITLES as $title) {
  68. $selected = ($user->title == $title) ? "selected" : "";
  69. ?>
  70. <option value="<?=htmlspecialchars($title)?>" <?=$selected?>><?=htmlspecialchars($title)?></option>
  71. <?php
  72. }
  73. ?>
  74. </select>
  75. </div>
  76. </div>
  77. <div class="row mb-1">
  78. <label class="col-sm-4 col-form-label" for="first-name">First Name</label>
  79. <div class="col-sm">
  80. <input class="form-control" type="text" name="first_name" id="first-name" placeholder="Enter first name" value="<?=htmlspecialchars($user->first_name)?>" required />
  81. </div>
  82. </div>
  83. <div class="row mb-1">
  84. <label class="col-sm-4 col-form-label" for="last-name">Last Name</label>
  85. <div class="col-sm">
  86. <input class="form-control" type="text" name="last_name" id="last-name" placeholder="Enter last name" value="<?=htmlspecialchars($user->last_name)?>" required />
  87. </div>
  88. </div>
  89. <div class="row mb-1">
  90. <label class="col-sm-4 col-form-label" for="gender">Gender</label>
  91. <div class="col-sm">
  92. <select class="form-control" name="gender" id="gender" required>
  93. <option value="">Select gender</option>
  94. <?php
  95. foreach(User::GENDERS as $gender) {
  96. $display = $gender;
  97. $value = substr($gender, 0, 1);
  98. $selected = ($user->gender == $value) ? "selected" : "";
  99. ?>
  100. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  101. <?php
  102. }
  103. ?>
  104. </select>
  105. </div>
  106. </div>
  107. <div class="row mb-1">
  108. <label class="col-sm-4 col-form-label" for="email">Email Address</label>
  109. <div class="col-sm">
  110. <input class="form-control" type="email" name="email" id="email" placeholder="Enter email address" value="<?=htmlspecialchars($user->email)?>" required />
  111. </div>
  112. </div>
  113. <div class="row mb-1">
  114. <label class="col-sm-4 col-form-label" for="phone">Mobile Number</label>
  115. <div class="col-sm">
  116. <input class="form-control" type="phone" name="phone" id="phone" placeholder="Enter mobile number" value="<?=htmlspecialchars($user->phone)?>" required />
  117. </div>
  118. </div>
  119. <div class="row mb-1">
  120. <label class="col-sm-4 col-form-label" for="password">Password (if changing)</label>
  121. <div class="col-sm">
  122. <input class="form-control" type="password" name="password" id="password" placeholder="Enter password" />
  123. <small class="text-muted form-text">At least <span data-length-requirement>6 characters</span>. Must contain at least one <span data-lowercase-requirement>lowercase</span>, <span data-uppercase-requirement>uppercase</span>, <span data-number-requirement>number</span> and <span data-special-requirement>special</span> character.</small>
  124. </div>
  125. </div>
  126. <div class="row mb-1">
  127. <label class="col-sm-4 col-form-label" for="password-confirm">Confirm Password</label>
  128. <div class="col-sm">
  129. <input class="form-control" type="password" name="password_confirm" id="password-confirm" placeholder="Confirm password" />
  130. </div>
  131. </div>
  132. <div class="row mb-1">
  133. <label class="col-sm-4 col-form-label" for="date-of-birth">Date of Birth</label>
  134. <div class="col-sm">
  135. <select class="form-control w-auto d-inline-block" name="date_of_birth_day" id="date-of-birth-day">
  136. <option value="">Day</option>
  137. <?php
  138. Form::renderDayOptions($date_of_birth_parts[2]);
  139. ?>
  140. </select>
  141. <select class="form-control w-auto d-inline-block" name="date_of_birth_month" id="date-of-birth-month">
  142. <option value="">Month</option>
  143. <?php
  144. Form::renderMonthOptions($date_of_birth_parts[1]);
  145. ?>
  146. </select>
  147. <select class="form-control w-auto d-inline-block" name="date_of_birth_year" id="date-of-birth-year">
  148. <option value="">Year</option>
  149. <?php
  150. Form::renderYearOptionsDescending(null, null, $date_of_birth_parts[0]);
  151. ?>
  152. </select>
  153. </div>
  154. </div>
  155. <div class="row mb-1">
  156. <label class="col-sm-4 col-form-label" for="reported">Reported</label>
  157. <div class="col-sm">
  158. <select class="form-control" name="reported" id="reported" />
  159. <?php
  160. foreach(Form::BOOLEAN_OPTIONS as $value => $display) {
  161. $selected = ($user->reported == $value) ? "selected" : "";
  162. ?>
  163. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  164. <?php
  165. }
  166. ?>
  167. </select>
  168. </div>
  169. </div>
  170. <div class="row mb-1">
  171. <label class="col-sm-4 col-form-label" for="reported-comment">Reported Notes</label>
  172. <div class="col-sm">
  173. <textarea class="form-control" name="reported_comment" id="reported-comment" placeholder="Enter reported notes" rows="4"><?=htmlspecialchars($user->reported_comment)?></textarea>
  174. </div>
  175. </div>
  176. <div class="row mb-1">
  177. <label class="col-sm-4 col-form-label" for="can-claim">Enable "Find Tests"</label>
  178. <div class="col-sm">
  179. <select class="form-control" name="can_claim" id="can-claim" />
  180. <?php
  181. foreach(Form::BOOLEAN_OPTIONS as $value => $display) {
  182. $selected = ($user->can_claim == $value) ? "selected" : "";
  183. ?>
  184. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  185. <?php
  186. }
  187. ?>
  188. </select>
  189. </div>
  190. </div>
  191. </div>
  192. <div class="col-lg-6 mb-3">
  193. <h3>Addresses</h3>
  194. <?php
  195. $addresses = $user->getAddresses();
  196. if(empty($addresses)) {
  197. ?>
  198. <div class="alert alert-info">This user does not have any addresses.</div>
  199. <?php
  200. }
  201. else {
  202. ?>
  203. <div class="mb-1" id="map" style="height: 248px;" data-maps data-lat="0" data-lng="0" data-zoom="5" data-callback="initialiseAddresses">
  204. </div>
  205. <div class="list-group">
  206. <?php
  207. foreach($addresses as $address) {
  208. ?>
  209. <div class="list-group-item">
  210. <strong><?=htmlspecialchars($address->name)?></strong><br />
  211. <small><?=htmlspecialchars($address->getDisplayAddress())?></small>
  212. </div>
  213. <?php
  214. }
  215. ?>
  216. </div>
  217. <?php
  218. }
  219. ?>
  220. </div>
  221. </div>
  222. <button class="btn btn-primary" type="submit" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">Submit</button>
  223. <a class="btn btn-secondary" href="<?=htmlspecialchars($_SERVER["HTTP_REFERER"] ?? "/account/users/$user->id")?>">Cancel</a>
  224. </form>
  225. </div>