user_edit_form.php 8.1 KB

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