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.

127 lines
5.1 KiB

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