del_subuser.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. //Open Game Panel Sub User Add On By
  25. // own3mall
  26. function exec_ogp_module() {
  27. require_once ("includes/functions.php");
  28. global $db;
  29. global $view;
  30. startSession();
  31. // Unset refer session used to redirect back to subusers page after editing account information
  32. if(isset($_SESSION['REFER'])){
  33. unset($_SESSION['REFER']);
  34. }
  35. if (isset($_SESSION['ERRMSG_ARR']) && is_array($_SESSION['ERRMSG_ARR']) && count($_SESSION['ERRMSG_ARR']) > 0) {
  36. $errmsg = '<table>';
  37. foreach ($_SESSION['ERRMSG_ARR'] as $msg) {
  38. $errmsg.= "<tr><td><img width='8px' src='images/offline.png'/></td><td style='text-align:left;color:red;'>" . $msg . '</td></tr>';
  39. }
  40. $errmsg.= '</table><br>';
  41. unset($_SESSION['ERRMSG_ARR']);
  42. }
  43. echo "<h2>" . get_lang('delete_sub_user') . "</h2>";
  44. if (isset($errmsg)) {
  45. echo $errmsg;
  46. }
  47. // Subuser Delete Check
  48. if(isset($_POST['editUser'])){
  49. $_SESSION['REFER']="?m=subusers&p=del";
  50. $userID = $_POST['user_id'];
  51. unset($_POST['editUser']);
  52. $view->refresh("?m=user_admin&p=edit_user&user_id=" . $userID,0);
  53. }else{
  54. if (isset($_POST['delUser'])) {
  55. // Does user have permissions to delete this user?
  56. $isAdmin = $db->isAdmin($_SESSION['user_id']);
  57. $mySubUsers = $db->getUsersSubUsersIds($_SESSION['user_id']);
  58. if ( $mySubUsers === false || (!$isAdmin && @!in_array($_POST['user_id'], $mySubUsers)) || $_POST['user_id'] == $_SESSION['user_id'] ){
  59. print_failure(get_lang('no_rights'));
  60. return;
  61. }
  62. if (!isset($_POST['del_check'])) {
  63. $user_info = $db->getUserById($_POST['user_id']);
  64. echo "<table class='center' style='width:100%;' ><tr>\n" . "<td>" . get_lang_f('del_subuser_conf') . " " . $user_info['users_login'] . "?</td>" . "</tr><tr><td>" . '<form method="post" >' . "\n" . '<input type="hidden" name="user_id" value="' . $_POST['user_id'] . '">' . "\n" . '<input type="hidden" name="delUser" value="' . $_POST['delUser'] . '">' . "\n" . '<button name="del_check" value="yes" >' . get_lang('yes') . "</button>\n" . '<button name="del_check" value="no" >' . get_lang('no') . "</button>\n" . "</form>\n" . "</td>\n" . "</tr>\n" . "</table><br>\n";
  65. } elseif($_POST['del_check'] == "yes") {
  66. $userID = $_POST['user_id'];
  67. $user_info = $db->getUserById($userID);
  68. $errflag = false;
  69. if (!$db->delUser($userID)) {
  70. $errmsg_arr[] = get_lang('err_parent_user');
  71. $errflag = true;
  72. }
  73. //If there are input validations, redirect back to the registration form
  74. if ($errflag) {
  75. $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
  76. } else {
  77. echo "<p>" . get_lang_f('subuser_deleted',$user_info['users_login']) . "</p>";
  78. }
  79. }
  80. }
  81. $results = listAllSubUsers();
  82. echo $results;
  83. }
  84. }
  85. function listAllSubUsers() {
  86. global $db;
  87. // echo $_SESSION['user_id'];
  88. $htmlCode = "";
  89. $subusers = $db->getUsersSubUsersIds($_SESSION['user_id']);
  90. if (is_array($subusers)) {
  91. $htmlCode.= "<table style=\"margin-left: 1em;\"><tr><th>" . get_lang('your_subusers') . "</th><th></th></tr>";
  92. if (count($subusers) > 0) {
  93. foreach ($subusers as $subuser) {
  94. $user_info = $db->getUserById($subuser);
  95. $htmlCode.= '<tr><td>' . $user_info['users_login'] . '</td><td><form method="post"><input type="hidden" name="user_id" value="' . $subuser . '" /><input type="submit" value="Edit" name="editUser" /><input type="submit" value="Delete" name="delUser" /></form></td></tr>';
  96. }
  97. } else {
  98. $htmlCode.= "<p>" . get_lang('no_subusers') . "</p>";
  99. }
  100. $htmlCode.= "</table>";
  101. } else {
  102. $htmlCode.= "<p>" . get_lang('no_subusers') . "</p>";
  103. }
  104. return $htmlCode;
  105. }
  106. ?>