You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
5.0 KiB

  1. <?php
  2. // Project: Web Reference Database (refbase) <http://www.refbase.net>
  3. // Copyright: Matthias Steffens <mailto:refbase@extracts.de> and the file's
  4. // original author(s).
  5. //
  6. // This code is distributed in the hope that it will be useful,
  7. // but WITHOUT ANY WARRANTY. Please see the GNU General Public
  8. // License for more details.
  9. //
  10. // File: ./user_removal.php
  11. // Repository: $HeadURL: file:///svn/p/refbase/code/branches/bleeding-edge/user_removal.php $
  12. // Author(s): Matthias Steffens <mailto:refbase@extracts.de>
  13. //
  14. // Created: 16-Apr-02, 10:54
  15. // Modified: $Date: 2015-02-16 20:53:19 +0000 (Mon, 16 Feb 2015) $
  16. // $Author: karnesky $
  17. // $Revision: 1405 $
  18. // This script deletes a user from the 'users' and 'auth' tables.
  19. // The script can be only called by the admin. If the removal succeeds, it redirects to 'users.php'.
  20. // Note that there's no further verification! If you clicked 'Delete User' on 'user_receipt.php' the user will be killed immediately.
  21. // Incorporate some include files:
  22. include 'initialize/db.inc.php'; // 'db.inc.php' is included to hide username and password
  23. include 'includes/include.inc.php'; // include common functions
  24. include 'initialize/ini.inc.php'; // include common variables
  25. // --------------------------------------------------------------------
  26. // START A SESSION:
  27. // call the 'start_session()' function (from 'include.inc.php') which will also read out available session variables:
  28. start_session(true);
  29. // Extract the 'userID' parameter from the request:
  30. if (isset($_REQUEST['userID']))
  31. $userID = $_REQUEST['userID'];
  32. else
  33. $userID = "";
  34. // Check if the admin is logged in
  35. if (!(isset($_SESSION['loginEmail']) && ($loginEmail == $adminLoginEmail))) // ('$adminLoginEmail' is specified in 'ini.inc.php')
  36. {
  37. // save an error message:
  38. $HeaderString = "You must be logged in as admin to remove any users!";
  39. // save the URL of the currently displayed page:
  40. $referer = $_SERVER['HTTP_REFERER'];
  41. // Write back session variables:
  42. saveSessionVariable("HeaderString", $HeaderString); // function 'saveSessionVariable()' is defined in 'include.inc.php'
  43. saveSessionVariable("referer", $referer);
  44. header("Location: index.php");
  45. exit;
  46. }
  47. // Check the correct parameters have been passed
  48. if (empty($userID))
  49. {
  50. // save an error message:
  51. $HeaderString = "Incorrect parameters to script 'user_removal.php'!";
  52. // Write back session variables:
  53. saveSessionVariable("HeaderString", $HeaderString); // function 'saveSessionVariable()' is defined in 'include.inc.php'
  54. // Redirect the browser back to the calling page
  55. header("Location: " . $referer); // variable '$referer' is globally defined in function 'start_session()' in 'include.inc.php'
  56. exit;
  57. }
  58. // --------------------------------------------------------------------
  59. // CONSTRUCT SQL QUERY:
  60. // If the admin is logged in:
  61. if (isset($_SESSION['loginEmail']) && ($loginEmail == $adminLoginEmail)) // -> perform a delete action:
  62. {
  63. // DELETE - construct queries to delete the relevant record(s)
  64. // ... from the users table:
  65. $queryArray[] = "DELETE FROM $tableUsers WHERE user_id = " . quote_smart($userID);
  66. // ... from the auth table:
  67. $queryArray[] = "DELETE FROM $tableAuth WHERE user_id = " . quote_smart($userID);
  68. // ... from the user_permissions table:
  69. $queryArray[] = "DELETE FROM $tableUserPermissions WHERE user_id =" . quote_smart($userID);
  70. // ... from the user_formats table:
  71. $queryArray[] = "DELETE FROM $tableUserFormats WHERE user_id =" . quote_smart($userID);
  72. // ... from the user_styles table:
  73. $queryArray[] = "DELETE FROM $tableUserStyles WHERE user_id =" . quote_smart($userID);
  74. // ... from the user_types table:
  75. $queryArray[] = "DELETE FROM $tableUserTypes WHERE user_id =" . quote_smart($userID);
  76. // ... from the user_options table:
  77. $queryArray[] = "DELETE FROM $tableUserOptions WHERE user_id =" . quote_smart($userID);
  78. }
  79. // --------------------------------------------------------------------
  80. // (1) OPEN CONNECTION, (2) SELECT DATABASE
  81. connectToMySQLDatabase(); // function 'connectToMySQLDatabase()' is defined in 'include.inc.php'
  82. // (3) RUN the queries on the database through the connection:
  83. foreach($queryArray as $query)
  84. $result = queryMySQLDatabase($query); // function 'queryMySQLDatabase()' is defined in 'include.inc.php'
  85. // ----------------------------------------------
  86. // (4) File a message and go back to the list of users:
  87. // save an informative message:
  88. $HeaderString = "User was deleted successfully!";
  89. // Write back session variables:
  90. saveSessionVariable("HeaderString", $HeaderString); // function 'saveSessionVariable()' is defined in 'include.inc.php'
  91. header("Location: users.php"); // re-direct to the list of users
  92. // (5) CLOSE the database connection:
  93. disconnectFromMySQLDatabase(); // function 'disconnectFromMySQLDatabase()' is defined in 'include.inc.php'
  94. // --------------------------------------------------------------------
  95. ?>