PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/bitsand/admin/root_oldlogins.php

http://bitsand.googlecode.com/
PHP | 151 lines | 110 code | 17 blank | 24 comment | 26 complexity | c3536e31edca4ecb570d70ee9c3cb136 MD5 | raw file
  1. <?php
  2. /*
  3. Bitsand - a web-based booking system for LRP events
  4. Copyright (C) 2006 - 2011 The Bitsand Project (http://bitsand.googlecode.com/)
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17. include ('../inc/inc_head_db.php');
  18. require ('../inc/inc_admin.php');
  19. require ('../inc/inc_root.php');
  20. //Initialise some useful variables
  21. $key = CRYPT_KEY;
  22. $db_prefix = DB_PREFIX;
  23. $sMsg = '';
  24. //Set age
  25. if (isset ($_POST ['btnUpdate']) && CheckReferrer ('root_oldlogins.php'))
  26. $iAge = (int) $_POST ['txtAge'];
  27. elseif (isset ($_POST ['hAge']) && CheckReferrer ('root_oldlogins.php'))
  28. $iAge = (int) $_POST ['hAge'];
  29. else
  30. $iAge = 18;
  31. $sDate = date ("Y-m-d", strtotime ("-$iAge months"));
  32. //Delete users
  33. if (isset ($_POST ['btnDelete']) && CheckReferrer ('root_oldlogins.php') && $_POST ['txtConfirm'] == 'CONFIRM') {
  34. foreach ($_POST as $key => $value) {
  35. if (substr ($key, 0, 7) == "hPlayer") {
  36. $pid = (int) $value;
  37. $delete = (int) $_POST ["chkPl{$value}"];
  38. if ($delete > 0) { $delete = 1; }
  39. else { $delete = 0; }
  40. //Run DELETE queries for this user
  41. if ($delete == 1)
  42. {
  43. if (ba_db_query ($link, "DELETE FROM {$db_prefix}access_log WHERE alPlayerID = $pid"))
  44. LogError ("There was a problem deleting inactive users.\nSQL:\n$sql\n");
  45. if (ba_db_query ($link, "DELETE FROM {$db_prefix}bookings WHERE bkPlayerID = $pid"))
  46. LogError ("There was a problem deleting inactive users.\nSQL:\n$sql\n");
  47. if (ba_db_query ($link, "DELETE FROM {$db_prefix}characters WHERE chPlayerID = $pid"))
  48. LogError ("There was a problem deleting inactive users.\nSQL:\n$sql\n");
  49. if (ba_db_query ($link, "DELETE FROM {$db_prefix}guildmembers WHERE gmPlayerID = $pid"))
  50. LogError ("There was a problem deleting inactive users.\nSQL:\n$sql\n");
  51. if (ba_db_query ($link, "DELETE FROM {$db_prefix}ospstaken WHERE otPlayerID = $pid"))
  52. LogError ("There was a problem deleting inactive users.\nSQL:\n$sql\n");
  53. if (ba_db_query ($link, "DELETE FROM {$db_prefix}sessions WHERE ssPlayerID = $pid"))
  54. LogError ("There was a problem deleting inactive users.\nSQL:\n$sql\n");
  55. if (ba_db_query ($link, "DELETE FROM {$db_prefix}skillstaken WHERE stPlayerID = $pid"))
  56. LogError ("There was a problem deleting inactive users.\nSQL:\n$sql\n");
  57. $sql = "DELETE FROM {$db_prefix}players WHERE plPlayerID = $pid";
  58. if (ba_db_query ($link, $sql) === False) {
  59. $sWarn = "There was a problem deleting the users";
  60. LogError ("There was a problem deleting inactive users.\nSQL:\n$sql\n");
  61. }
  62. }
  63. }
  64. }
  65. }
  66. include ('../inc/inc_head_html.php');
  67. ?>
  68. <script type="text/javascript">
  69. // <!--
  70. function selectAll (Selected) {
  71. var f = document.getElementById ("frmOldLogins");
  72. for (var i=0; i < f.length; i++)
  73. f.elements[i].checked = Selected;
  74. }
  75. // -->
  76. </script>
  77. <script src="../inc/sorttable.js" type="text/javascript"></script>
  78. <h1><?php echo TITLE?> - Inactive Users</h1>
  79. <?php
  80. if ($sMsg != '')
  81. echo "<p>$sMsg</p>";
  82. ?>
  83. <p>
  84. <a href = 'admin.php'>Admin</a>
  85. </p>
  86. <p>
  87. The following users have not logged in for at least <?php echo $iAge ?> months. You may wish to delete their details.</br>
  88. Click on a column header to sort by that column.
  89. </p>
  90. <p>
  91. <a href = "#" onclick = "selectAll (1)">Select All</a> <a href = "#" onclick = "selectAll (0)">Select None</a>
  92. </p>
  93. <form action = 'root_oldlogins.php' method = 'post' id = 'frmOldLogins'>
  94. <table border = 1 class="sortable">
  95. <tr><th>Select</th>
  96. <th>Player ID</th>
  97. <th>First Name</th>
  98. <th>Surname</th>
  99. <th>E-mail</th></tr>
  100. <?php
  101. $sql = "SELECT plPlayerID, plFirstName, plSurname, plEmail FROM {$db_prefix}players WHERE plLastLogin < '$sDate' or plLastLogin IS NULL";
  102. $result = ba_db_query ($link, $sql);
  103. while ($row = ba_db_fetch_assoc ($result)) {
  104. echo "<tr>";
  105. echo "<td><input type = 'hidden' name = 'hPlayer" . $row ['plPlayerID'] . "' value = '" . $row ['plPlayerID'] . "'>";
  106. echo "<input type = 'checkbox' name = 'chkPl{$row ['plPlayerID']}' value = '{$row ['plPlayerID']}'></td>\n";
  107. echo "<td>" . PID_PREFIX . sprintf ('%03s', $row ['plPlayerID']) . "</td>";
  108. echo "<td>{$row ['plFirstName']}</td>";
  109. echo "<td>{$row ['plSurname']}</td>";
  110. echo "<td>{$row ['plEmail']}</td>";
  111. echo "</tr>\n";
  112. }
  113. ?>
  114. </table>
  115. <p>
  116. <a href = "#" onclick = "selectAll (1)">Select All</a> <a href = "#" onclick = "selectAll (0)">Select None</a>
  117. </p>
  118. <p>
  119. Change period to <input class = 'text' name = 'txtAge' style = 'width: 3ex' value = '<?php echo $iAge ?>'> months
  120. <input type = 'submit' value = 'Update' name = 'btnUpdate'>
  121. </p>
  122. <p>
  123. <input type = 'hidden' name = 'hAge' value = '<?php echo $iAge; ?>'>
  124. To guard against mistakes, enter <b>confirm</b> (in capital letters) in the box below, then click "Delete these users"<br>
  125. <input name = 'txtConfirm'>&nbsp;
  126. <input type = 'submit' value = 'Delete these users' name = 'btnDelete'>
  127. </p>
  128. </form>
  129. <?php
  130. include ('../inc/inc_foot.php');
  131. ?>