user_edit_form.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. $date_of_birth_parts = explode("-", $user->date_of_birth);
  3. $activated_checked = ($user->activated) ? "checked" : "";
  4. ?>
  5. <script>
  6. var userId = <?=$user->id?>;
  7. </script>
  8. <div class="container mt-3 py-4">
  9. <h2>Edit User</h2>
  10. <form method="post">
  11. <div class="row">
  12. <div class="col-lg-6 mb-3">
  13. <h3>Details</h3>
  14. <div class="row mb-1">
  15. <label class="col-sm-4 col-form-label" for="level">Level</label>
  16. <div class="col-sm">
  17. <select class="form-control" name="level" id="level" required />
  18. <?php
  19. foreach(User::LEVELS as $value => $display) {
  20. if($value > Core::$user->level) continue;
  21. $selected = ($user->level == $value) ? "selected" : "";
  22. ?>
  23. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  24. <?php
  25. }
  26. ?>
  27. </select>
  28. </div>
  29. </div>
  30. <div class="row mb-1">
  31. <div class="col-sm offset-sm-4">
  32. <div class="form-check">
  33. <input class="form-check-input" type="checkbox" name="activated" id="activated" value="1" <?=$activated_checked?> />
  34. <label class="form-check-label" for="activated">Email Verified</label>
  35. </div>
  36. </div>
  37. </div>
  38. <div class="row mb-1">
  39. <label class="col-sm-4 col-form-label" for="title">Title</label>
  40. <div class="col-sm">
  41. <select class="form-control" name="title" id="title" required>
  42. <option value="">Select title</option>
  43. <?php
  44. foreach(User::TITLES as $title) {
  45. $selected = ($user->title == $title) ? "selected" : "";
  46. ?>
  47. <option value="<?=htmlspecialchars($title)?>" <?=$selected?>><?=htmlspecialchars($title)?></option>
  48. <?php
  49. }
  50. ?>
  51. </select>
  52. </div>
  53. </div>
  54. <div class="row mb-1">
  55. <label class="col-sm-4 col-form-label" for="first-name">First Name</label>
  56. <div class="col-sm">
  57. <input class="form-control" type="text" name="first_name" id="first-name" placeholder="Enter first name" value="<?=htmlspecialchars($user->first_name)?>" required />
  58. </div>
  59. </div>
  60. <div class="row mb-1">
  61. <label class="col-sm-4 col-form-label" for="last-name">Last Name</label>
  62. <div class="col-sm">
  63. <input class="form-control" type="text" name="last_name" id="last-name" placeholder="Enter last name" value="<?=htmlspecialchars($user->last_name)?>" required />
  64. </div>
  65. </div>
  66. <div class="row mb-1">
  67. <label class="col-sm-4 col-form-label" for="gender">Gender</label>
  68. <div class="col-sm">
  69. <select class="form-control" name="gender" id="gender" required>
  70. <option value="">Select gender</option>
  71. <?php
  72. foreach(User::GENDERS as $gender) {
  73. $display = $gender;
  74. $value = substr($gender, 0, 1);
  75. $selected = ($user->gender == $value) ? "selected" : "";
  76. ?>
  77. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>><?=htmlspecialchars($display)?></option>
  78. <?php
  79. }
  80. ?>
  81. </select>
  82. </div>
  83. </div>
  84. <div class="row mb-1">
  85. <label class="col-sm-4 col-form-label" for="email">Email Address</label>
  86. <div class="col-sm">
  87. <input class="form-control" type="email" name="email" id="email" placeholder="Enter email address" value="<?=htmlspecialchars($user->email)?>" required />
  88. </div>
  89. </div>
  90. <div class="row mb-1">
  91. <label class="col-sm-4 col-form-label" for="phone">Mobile Number</label>
  92. <div class="col-sm">
  93. <input class="form-control" type="phone" name="phone" id="phone" placeholder="Enter mobile number" value="<?=htmlspecialchars($user->phone)?>" required />
  94. </div>
  95. </div>
  96. <div class="row mb-1">
  97. <label class="col-sm-4 col-form-label" for="password">Password (if changing)</label>
  98. <div class="col-sm">
  99. <input class="form-control" type="password" name="password" id="password" placeholder="Enter password" />
  100. <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>
  101. </div>
  102. </div>
  103. <div class="row mb-1">
  104. <label class="col-sm-4 col-form-label" for="password-confirm">Confirm Password</label>
  105. <div class="col-sm">
  106. <input class="form-control" type="password" name="password_confirm" id="password-confirm" placeholder="Confirm password" />
  107. </div>
  108. </div>
  109. <div class="row mb-1">
  110. <label class="col-sm-4 col-form-label" for="date-of-birth">Date of Birth</label>
  111. <div class="col-sm">
  112. <select class="form-control w-auto d-inline-block" name="date_of_birth_day" id="date-of-birth-day">
  113. <option value="">Day</option>
  114. <?php
  115. Form::renderDayOptions($date_of_birth_parts[2]);
  116. ?>
  117. </select>
  118. <select class="form-control w-auto d-inline-block" name="date_of_birth_month" id="date-of-birth-month">
  119. <option value="">Month</option>
  120. <?php
  121. Form::renderMonthOptions($date_of_birth_parts[1]);
  122. ?>
  123. </select>
  124. <select class="form-control w-auto d-inline-block" name="date_of_birth_year" id="date-of-birth-year">
  125. <option value="">Year</option>
  126. <?php
  127. Form::renderYearOptionsDescending(null, null, $date_of_birth_parts[0]);
  128. ?>
  129. </select>
  130. </div>
  131. </div>
  132. </div>
  133. <div class="col-lg-6 mb-3">
  134. <h3>Addresses</h3>
  135. <?php
  136. $addresses = $user->getAddresses();
  137. if(empty($addresses)) {
  138. ?>
  139. <div class="alert alert-info">This user does not have any addresses.</div>
  140. <?php
  141. }
  142. else {
  143. ?>
  144. <div class="mb-1" id="map" style="height: 248px;" data-maps data-lat="0" data-lng="0" data-zoom="5" data-callback="initialiseAddresses">
  145. </div>
  146. <div class="list-group">
  147. <?php
  148. foreach($addresses as $address) {
  149. ?>
  150. <div class="list-group-item">
  151. <strong><?=htmlspecialchars($address->name)?></strong><br />
  152. <small><?=htmlspecialchars($address->getDisplayAddress())?></small>
  153. </div>
  154. <?php
  155. }
  156. ?>
  157. </div>
  158. <?php
  159. }
  160. ?>
  161. </div>
  162. </div>
  163. <button class="btn btn-primary" type="submit" name="submit" value="<?=htmlspecialchars($_SESSION["csrf_token"])?>">Submit</button>
  164. <a class="btn btn-secondary" href="<?=htmlspecialchars($_SERVER["HTTP_REFERER"] ?? "/account/users/$user->id")?>">Cancel</a>
  165. </form>
  166. </div>