deleteuser.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. $id = $db->escape_string($_GET['id']);
  3. //Load user data from DB
  4. $sql = "SELECT `".DBC_USERS_USERNAME."`, `".DBC_USERS_DOMAIN."` FROM `".DBT_USERS."` WHERE `".DBC_USERS_ID."` = '$id' LIMIT 1;";
  5. if(!$result = $db->query($sql)){
  6. die('There was an error running the query [' . $db->error . ']');
  7. }
  8. while($row = $result->fetch_assoc()){
  9. $username = $row[DBC_USERS_USERNAME];
  10. $domain = $row[DBC_USERS_DOMAIN];
  11. }
  12. $mailaddress = $username."@".$domain;
  13. // Delete user
  14. if(isset($_POST['confirm'])){
  15. $confirm = $_POST['confirm'];
  16. if($confirm === "yes"){
  17. // Check if admin is affected
  18. if (!in_array($mailaddress, $admins)) {
  19. $sql = "DELETE FROM `".DBT_USERS."` WHERE `".DBC_USERS_ID."` = '$id'";
  20. if(!$result = $db->query($sql)){
  21. die('There was an error running the query [' . $db->error . ']');
  22. }
  23. else{
  24. header("Location: ".FRONTEND_BASE_PATH."admin/listusers/?deleted=1");
  25. }
  26. }
  27. else{
  28. // Admin tries to delete himself. WTH.
  29. header("Location: ".FRONTEND_BASE_PATH."admin/listusers/?adm_del=1");
  30. }
  31. }
  32. else{
  33. header("Location: ".FRONTEND_BASE_PATH."admin/listusers/");
  34. }
  35. }
  36. ?>
  37. <h1>Delete user "<?php echo $mailaddress ?>"?</h1>
  38. <p>
  39. <strong>The user's mailbox will be deleted from the database!</strong><br>
  40. The mailbox in the filesystem won't be affected.
  41. </p>
  42. <form action="" method="post">
  43. <select name="confirm" autofocus>
  44. <option value="no">No!</option>
  45. <option value="yes">Yes!</option>
  46. </select>
  47. <input type="submit" class="button button-small" value="Okay"/>
  48. </form>