user_edit_form.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 $value => $display) {
  68. $selected = ($user->title == $value) ? "selected" : "";
  69. ?>
  70. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></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 $value => $display) {
  96. $value = substr($value, 0, 1);
  97. $selected = ($user->gender == $value) ? "selected" : "";
  98. ?>
  99. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  100. <?php
  101. }
  102. ?>
  103. </select>
  104. </div>
  105. </div>
  106. <div class="row mb-1">
  107. <label class="col-sm-4 col-form-label" for="email">Email Address</label>
  108. <div class="col-sm">
  109. <input class="form-control" type="email" name="email" id="email" placeholder="Enter email address" value="<?=htmlspecialchars($user->email)?>" required />
  110. </div>
  111. </div>
  112. <div class="row mb-1">
  113. <label class="col-sm-4 col-form-label" for="phone">Mobile Number</label>
  114. <div class="col-sm">
  115. <input class="form-control" type="phone" name="phone" id="phone" placeholder="Enter mobile number" value="<?=htmlspecialchars($user->phone)?>" required />
  116. </div>
  117. </div>
  118. <div class="row mb-1">
  119. <label class="col-sm-4 col-form-label" for="password">Password (if changing)</label>
  120. <div class="col-sm">
  121. <input class="form-control" type="password" name="password" id="password" placeholder="Enter password" />
  122. <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>
  123. </div>
  124. </div>
  125. <div class="row mb-1">
  126. <label class="col-sm-4 col-form-label" for="password-confirm">Confirm Password</label>
  127. <div class="col-sm">
  128. <input class="form-control" type="password" name="password_confirm" id="password-confirm" placeholder="Confirm password" />
  129. </div>
  130. </div>
  131. <div class="row mb-1">
  132. <label class="col-sm-4 col-form-label" for="date-of-birth">Date of Birth</label>
  133. <div class="col-sm">
  134. <select class="form-control w-auto d-inline-block" name="date_of_birth_day" id="date-of-birth-day">
  135. <option value="">Day</option>
  136. <?php
  137. Form::renderDayOptions($date_of_birth_parts[2]);
  138. ?>
  139. </select>
  140. <select class="form-control w-auto d-inline-block" name="date_of_birth_month" id="date-of-birth-month">
  141. <option value="">Month</option>
  142. <?php
  143. Form::renderMonthOptions($date_of_birth_parts[1]);
  144. ?>
  145. </select>
  146. <select class="form-control w-auto d-inline-block" name="date_of_birth_year" id="date-of-birth-year">
  147. <option value="">Year</option>
  148. <?php
  149. Form::renderYearOptionsDescending(null, null, $date_of_birth_parts[0]);
  150. ?>
  151. </select>
  152. </div>
  153. </div>
  154. <div class="row mb-1">
  155. <label class="col-sm-4 col-form-label" for="reported">Reported</label>
  156. <div class="col-sm">
  157. <select class="form-control" name="reported" id="reported" />
  158. <?php
  159. foreach(Form::BOOLEAN_OPTIONS as $value => $display) {
  160. $selected = ($user->reported == $value) ? "selected" : "";
  161. ?>
  162. <option value="<?=htmlspecialchars($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="reported-comment">Reported Notes</label>
  171. <div class="col-sm">
  172. <textarea class="form-control" name="reported_comment" id="reported-comment" placeholder="Enter reported notes" rows="4"><?=htmlspecialchars($user->reported_comment)?></textarea>
  173. </div>
  174. </div>
  175. <div class="row mb-1">
  176. <label class="col-sm-4 col-form-label" for="can-claim">Enable "Find Tests"</label>
  177. <div class="col-sm">
  178. <select class="form-control" name="can_claim" id="can-claim" />
  179. <?php
  180. foreach(Form::BOOLEAN_OPTIONS as $value => $display) {
  181. $selected = ($user->can_claim == $value) ? "selected" : "";
  182. ?>
  183. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  184. <?php
  185. }
  186. ?>
  187. </select>
  188. </div>
  189. </div>
  190. </div>
  191. <div class="col-lg-6 mb-3">
  192. <h3>Addresses</h3>
  193. <?php
  194. $addresses = $user->getAddresses();
  195. if(empty($addresses)) {
  196. ?>
  197. <div class="alert alert-info">This user does not have any addresses.</div>
  198. <?php
  199. }
  200. else {
  201. ?>
  202. <div class="mb-1" id="map" style="height: 248px;" data-maps data-lat="0" data-lng="0" data-zoom="5" data-callback="initialiseAddresses">
  203. </div>
  204. <div class="list-group">
  205. <?php
  206. foreach($addresses as $address) {
  207. ?>
  208. <div class="list-group-item">
  209. <strong><?=htmlspecialchars($address->name)?></strong><br />
  210. <small><?=htmlspecialchars($address->getDisplayAddress())?></small>
  211. </div>
  212. <?php
  213. }
  214. ?>
  215. </div>
  216. <?php
  217. }
  218. ?>
  219. </div>
  220. </div>
  221. <button class="btn btn-primary" type="submit" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">Submit</button>
  222. <a class="btn btn-secondary" href="<?=htmlspecialchars($_SERVER["HTTP_REFERER"] ?? "/account/users/$user->id")?>">Cancel</a>
  223. </form>
  224. </div>