Beehive PHP Cross Reference Discussion Forums

Source: /admin_user_groups.php - 364 lines - 18387 bytes - Summary - Text - Print

   1  <?php
   2  
   3  /*======================================================================
   4  Copyright Project Beehive Forum 2002
   5  
   6  This file is part of Beehive Forum.
   7  
   8  Beehive Forum is free software; you can redistribute it and/or modify
   9  it under the terms of the GNU General Public License as published by
  10  the Free Software Foundation; either version 3 of the License, or
  11  (at your option) any later version.
  12  
  13  Beehive Forum is distributed in the hope that it will be useful,
  14  but WITHOUT ANY WARRANTY; without even the implied warranty of
  15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16  GNU General Public License for more details.
  17  
  18  You should have received a copy of the GNU General Public License
  19  along with Beehive; if not, write to the Free Software
  20  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
  21  USA
  22  ======================================================================*/
  23  
  24  // Bootstrap
  25  require_once  'boot.php';
  26  
  27  // Required includes
  28  require_once  BH_INCLUDE_PATH . 'admin.inc.php';
  29  require_once  BH_INCLUDE_PATH . 'constants.inc.php';
  30  require_once  BH_INCLUDE_PATH . 'form.inc.php';
  31  require_once  BH_INCLUDE_PATH . 'format.inc.php';
  32  require_once  BH_INCLUDE_PATH . 'forum.inc.php';
  33  require_once  BH_INCLUDE_PATH . 'header.inc.php';
  34  require_once  BH_INCLUDE_PATH . 'html.inc.php';
  35  require_once  BH_INCLUDE_PATH . 'perm.inc.php';
  36  require_once  BH_INCLUDE_PATH . 'session.inc.php';
  37  require_once  BH_INCLUDE_PATH . 'word_filter.inc.php';
  38  // End Required includes
  39  
  40  // Check we're logged in correctly
  41  if (!session::logged_in()) {
  42      html_guest_error();
  43  }
  44  
  45  // Check we have Admin / Moderator access
  46  if (!(session::check_perm(USER_PERM_ADMIN_TOOLS, 0))) {
  47      html_draw_error(gettext("You do not have permission to use this section."));
  48  }
  49  
  50  // Perform additional admin login.
  51  admin_check_credentials();
  52  
  53  // Redirect to Add Group page if requested.
  54  if (isset($_POST['add_new'])) {
  55      header_redirect("admin_user_groups_add.php?webtag=$webtag");
  56  }
  57  
  58  // Column sorting stuff
  59  if (isset($_GET['sort_by'])) {
  60      if ($_GET['sort_by'] == "GROUP_NAME") {
  61          $sort_by = "GROUP_NAME";
  62      } else if ($_GET['sort_by'] == "GROUP_DESC") {
  63          $sort_by = "GROUP_DESC";
  64      } else if ($_GET['sort_by'] == "USER_COUNT") {
  65          $sort_by = "USER_COUNT";
  66      } else if ($_GET['sort_by'] == "DEFAULT_GROUP") {
  67          $sort_by = "DEFAULT_GROUP";
  68      } else if ($_GET['sort_by'] == "PERMS") {
  69          $sort_by = "PERMS";
  70      } else {
  71          $sort_by = "GROUP_NAME";
  72      }
  73  } else {
  74      $sort_by = "GROUP_NAME";
  75  }
  76  
  77  if (isset($_GET['sort_dir'])) {
  78      if ($_GET['sort_dir'] == "DESC") {
  79          $sort_dir = "DESC";
  80      } else {
  81          $sort_dir = "ASC";
  82      }
  83  } else {
  84      $sort_dir = "ASC";
  85  }
  86  
  87  if (isset($_GET['page']) && is_numeric($_GET['page'])) {
  88      $page = ($_GET['page'] > 0) ? $_GET['page'] : 1;
  89  } else {
  90      $page = 1;
  91  }
  92  
  93  $default_user_group = forum_get_setting('default_user_group');
  94  
  95  $user_groups_array = perm_get_user_groups($page, $sort_by, $sort_dir);
  96  
  97  $user_group_name_array = perm_get_user_group_names();
  98  
  99  if (isset($_POST['delete'])) {
 100  
 101      $valid = true;
 102  
 103      if (isset($_POST['delete_group']) && is_array($_POST['delete_group'])) {
 104  
 105          foreach ($_POST['delete_group'] as $gid) {
 106  
 107              if (($group_name = perm_get_group_name($gid)) !== false) {
 108  
 109                  if (perm_remove_group($gid)) {
 110  
 111                      admin_add_log_entry(DELETE_USER_GROUP, array($group_name));
 112  
 113                  } else {
 114  
 115                      $error_msg_array[] = sprintf(gettext("Failed to delete group %s"), $group_name);
 116                      $valid = false;
 117                  }
 118              }
 119          }
 120  
 121          if ($valid) {
 122  
 123              header_redirect("admin_user_groups.php?webtag=$webtag&page=$page&sort_by=$sort_by&sort_dir=$sort_dir&deleted=true");
 124              exit;
 125          }
 126      }
 127  
 128  } else if (isset($_GET['set_default']) && is_numeric($_GET['set_default'])) {
 129  
 130      $forum_settings['default_user_group'] = $_GET['set_default'];
 131  
 132      if ((isset($user_group_name_array[$_GET['set_default']]) || $_GET['set_default'] == 0) && forum_save_settings($forum_settings)) {
 133          header_redirect("admin_user_groups.php?webtag=$webtag&page=$page&sort_by=$sort_by&sort_dir=$sort_dir&default={$_GET['set_default']}");
 134      }
 135  }
 136  
 137  html_draw_top(sprintf('title=%s', gettext("Admin - User Groups")), 'class=window_title', 'main_css=admin.css');
 138  
 139  echo "<h1>", gettext("Admin"), "<img src=\"", html_style_image('separator.png'), "\" alt=\"\" border=\"0\" />", gettext("User Groups"), "</h1>\n";
 140  
 141  if (isset($_GET['added'])) {
 142  
 143      html_display_success_msg(gettext("Successfully added group"), '86%', 'center');
 144  
 145  } else if (isset($_GET['edited'])) {
 146  
 147      html_display_success_msg(gettext("Successfully edited group"), '86%', 'center');
 148  
 149  } else if (isset($_GET['deleted'])) {
 150  
 151      html_display_success_msg(gettext("Successfully deleted selected groups"), '86%', 'center');
 152  
 153  } else if (isset($_GET['default'])) {
 154  
 155      if (isset($user_group_name_array[$_GET['default']])) {
 156  
 157          html_display_success_msg(sprintf(gettext('Successfully set default group to "%s".'), $user_group_name_array[$_GET['default']]), '86%', 'center');
 158  
 159      } else if ($_GET['default'] == 0) {
 160  
 161          html_display_success_msg(gettext('Successfully cleared default group'), '86%', 'center');
 162      }
 163  
 164  } else if (sizeof($user_groups_array['user_groups_array']) < 1) {
 165  
 166      html_display_warning_msg(gettext("No User Groups have been set up. To add a group click the 'Add New' button below."), '86%', 'center');
 167  
 168  } else {
 169  
 170      html_display_warning_msg(gettext("To change the default group, click the tick in the right-hand column. Note: The default group will be applied the first time a user visits your forum. It will not be applied retrospectively."), '86%', 'center');
 171  }
 172  
 173  echo "<br />\n";
 174  echo "<div align=\"center\">\n";
 175  echo "<form accept-charset=\"utf-8\" name=\"f_folders\" action=\"admin_user_groups.php\" method=\"post\">\n";
 176  echo "  ", form_input_hidden('webtag', htmlentities_array($webtag)), "\n";
 177  echo "  <table cellpadding=\"0\" cellspacing=\"0\" width=\"86%\">\n";
 178  echo "    <tr>\n";
 179  echo "      <td align=\"left\">\n";
 180  echo "        <table class=\"box\" width=\"100%\">\n";
 181  echo "          <tr>\n";
 182  echo "            <td align=\"left\" class=\"posthead\">\n";
 183  echo "              <table class=\"posthead\" width=\"100%\">\n";
 184  echo "                <tr>\n";
 185  echo "                  <td align=\"left\" class=\"subhead\" width=\"20\">&nbsp;</td>\n";
 186  
 187  if ($sort_by == 'GROUP_NAME' && $sort_dir == 'ASC') {
 188      echo "                   <td class=\"subhead_sort_asc\" align=\"left\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=GROUP_NAME&amp;sort_dir=DESC&amp;page=$page\">", gettext("Groups"), "</a></td>\n";
 189  } else if ($sort_by == 'GROUP_NAME' && $sort_dir == 'DESC') {
 190      echo "                   <td class=\"subhead_sort_desc\" align=\"left\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=GROUP_NAME&amp;sort_dir=ASC&amp;page=$page\">", gettext("Groups"), "</a></td>\n";
 191  } else if ($sort_dir == 'ASC') {
 192      echo "                   <td class=\"subhead\" align=\"left\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=GROUP_NAME&amp;sort_dir=ASC&amp;page=$page\">", gettext("Groups"), "</a></td>\n";
 193  } else {
 194      echo "                   <td class=\"subhead\" align=\"left\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=GROUP_NAME&amp;sort_dir=DESC&amp;page=$page\">", gettext("Groups"), "</a></td>\n";
 195  }
 196  
 197  if ($sort_by == 'GROUP_DESC' && $sort_dir == 'ASC') {
 198      echo "                   <td class=\"subhead_sort_asc\" align=\"left\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=GROUP_DESC&amp;sort_dir=DESC&amp;page=$page\">", gettext("Description"), "</a></td>\n";
 199  } else if ($sort_by == 'GROUP_DESC' && $sort_dir == 'DESC') {
 200      echo "                   <td class=\"subhead_sort_desc\" align=\"left\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=GROUP_DESC&amp;sort_dir=ASC&amp;page=$page\">", gettext("Description"), "</a></td>\n";
 201  } else if ($sort_dir == 'ASC') {
 202      echo "                   <td class=\"subhead\" align=\"left\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=GROUP_DESC&amp;sort_dir=ASC&amp;page=$page\">", gettext("Description"), "</a></td>\n";
 203  } else {
 204      echo "                   <td class=\"subhead\" align=\"left\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=GROUP_DESC&amp;sort_dir=DESC&amp;page=$page\">", gettext("Description"), "</a></td>\n";
 205  }
 206  
 207  if ($sort_by == 'PERMS' && $sort_dir == 'ASC') {
 208      echo "                   <td class=\"subhead_sort_asc\" align=\"center\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=PERMS&amp;sort_dir=DESC&amp;page=$page\">", gettext("Group Status"), "</a></td>\n";
 209  } else if ($sort_by == 'PERMS' && $sort_dir == 'DESC') {
 210      echo "                   <td class=\"subhead_sort_desc\" align=\"center\" class=\"header_sort_desc\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=PERMS&amp;sort_dir=ASC&amp;page=$page\">", gettext("Group Status"), "</a></td>\n";
 211  } else if ($sort_dir == 'ASC') {
 212      echo "                   <td class=\"subhead\" align=\"center\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=PERMS&amp;sort_dir=ASC&amp;page=$page\">", gettext("Group Status"), "</a></td>\n";
 213  } else {
 214      echo "                   <td class=\"subhead\" align=\"center\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=PERMS&amp;sort_dir=DESC&amp;page=$page\">", gettext("Group Status"), "</a></td>\n";
 215  }
 216  
 217  if ($sort_by == 'USER_COUNT' && $sort_dir == 'ASC') {
 218      echo "                   <td class=\"subhead_sort_asc\" align=\"center\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=USER_COUNT&amp;sort_dir=DESC&amp;page=$page\">", gettext("Users"), "</a></td>\n";
 219  } else if ($sort_by == 'USER_COUNT' && $sort_dir == 'DESC') {
 220      echo "                   <td class=\"subhead_sort_desc\" align=\"center\" class=\"header_sort_desc\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=USER_COUNT&amp;sort_dir=ASC&amp;page=$page\">", gettext("Users"), "</a></td>\n";
 221  } else if ($sort_dir == 'ASC') {
 222      echo "                   <td class=\"subhead\" align=\"center\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=USER_COUNT&amp;sort_dir=ASC&amp;page=$page\">", gettext("Users"), "</a></td>\n";
 223  } else {
 224      echo "                   <td class=\"subhead\" align=\"center\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=USER_COUNT&amp;sort_dir=DESC&amp;page=$page\">", gettext("Users"), "</a></td>\n";
 225  }
 226  
 227  if ($sort_by == 'DEFAULT_GROUP' && $sort_dir == 'ASC') {
 228      echo "                   <td class=\"subhead_sort_asc\" align=\"center\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=DEFAULT_GROUP&amp;sort_dir=DESC&amp;page=$page\">", gettext("Default"), "</a></td>\n";
 229  } else if ($sort_by == 'DEFAULT_GROUP' && $sort_dir == 'DESC') {
 230      echo "                   <td class=\"subhead_sort_desc\" align=\"center\" class=\"header_sort_desc\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=DEFAULT_GROUP&amp;sort_dir=ASC&amp;page=$page\">", gettext("Default"), "</a></td>\n";
 231  } else if ($sort_dir == 'ASC') {
 232      echo "                   <td class=\"subhead\" align=\"center\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=DEFAULT_GROUP&amp;sort_dir=ASC&amp;page=$page\">", gettext("Default"), "</a></td>\n";
 233  } else {
 234      echo "                   <td class=\"subhead\" align=\"center\"><a href=\"admin_user_groups.php?webtag=$webtag&amp;sort_by=DEFAULT_GROUP&amp;sort_dir=DESC&amp;page=$page\">", gettext("Default"), "</a></td>\n";
 235  }
 236  
 237  echo "                </tr>\n";
 238  
 239  if (sizeof($user_groups_array['user_groups_array']) > 0) {
 240  
 241      foreach ($user_groups_array['user_groups_array'] as $user_group) {
 242  
 243          echo "                <tr>\n";
 244          echo "                  <td align=\"left\" style=\"white-space: nowrap\" valign=\"top\">", form_checkbox("delete_group[]", $user_group['GID']), "</td>\n";
 245          echo "                  <td align=\"left\" style=\"white-space: nowrap\" valign=\"top\"><a href=\"admin_user_groups_edit.php?webtag=$webtag&amp;gid={$user_group['GID']}\" target=\"_self\">{$user_group['GROUP_NAME']}</a></td>\n";
 246  
 247          if (isset($user_group['GROUP_DESC']) && strlen(trim($user_group['GROUP_DESC'])) > 0) {
 248  
 249              $group_desc_short = (mb_strlen(trim($user_group['GROUP_DESC'])) > 50) ? mb_substr($user_group['GROUP_DESC'], 0, 47) . "&hellip;" : $user_group['GROUP_DESC'];
 250  
 251              echo "                  <td align=\"left\" valign=\"top\" style=\"white-space: nowrap\"><div title=\"", word_filter_add_ob_tags($user_group['GROUP_DESC'], true), "\">", word_filter_add_ob_tags($group_desc_short), "</div></td>\n";
 252  
 253          } else {
 254  
 255              echo "                  <td align=\"left\" valign=\"top\">&nbsp;</td>\n";
 256          }
 257  
 258          if (isset($user_group['PERMS']) && $user_group['PERMS'] > 0) {
 259              echo "                  <td align=\"center\" valign=\"top\" width=\"15%\">", perm_display_list($user_group['PERMS']), "</td>\n";
 260          } else {
 261              echo "                  <td align=\"center\" valign=\"top\" width=\"15%\">", gettext("none"), "</td>\n";
 262          }
 263  
 264          echo "                  <td align=\"center\" width=\"10%\" valign=\"top\"><a href=\"admin_user_groups_edit_users.php?webtag=$webtag&amp;gid={$user_group['GID']}\">{$user_group['USER_COUNT']}</a></td>\n";
 265          echo "                  <td align=\"center\" style=\"white-space: nowrap\">";
 266  
 267          if (isset($default_user_group) && ($default_user_group == $user_group['GID'])) {
 268              echo "<a href=\"admin_user_groups.php?webtag=$webtag&amp;page=$page&amp;sort_dir=$sort_dir&amp;sort_by=$sort_by&amp;set_default=0\"><img src=\"", html_style_image('default_group.png'), "\" border=\"0\" alt=\"", gettext("Unset Default"), "\" title=\"", gettext("Unset Default"), "\" /></a>\n";
 269          } else {
 270              echo "<a href=\"admin_user_groups.php?webtag=$webtag&amp;page=$page&amp;sort_dir=$sort_dir&amp;sort_by=$sort_by&amp;set_default={$user_group['GID']}\"><img src=\"", html_style_image('set_default_group.png'), "\" border=\"0\" alt=\"", gettext("Make Default"), "\" title=\"", gettext("Make Default"), "\" /></a>\n";
 271          }
 272  
 273          echo "                  </td>\n";
 274          echo "                </tr>\n";
 275      }
 276  }
 277  
 278  echo "                <tr>\n";
 279  echo "                  <td align=\"left\" colspan=\"6\">&nbsp;</td>\n";
 280  echo "                </tr>\n";
 281  echo "              </table>\n";
 282  echo "            </td>\n";
 283  echo "          </tr>\n";
 284  echo "        </table>\n";
 285  echo "      </td>\n";
 286  echo "    </tr>\n";
 287  echo "    <tr>\n";
 288  echo "      <td align=\"left\">&nbsp;</td>\n";
 289  echo "    </tr>\n";
 290  echo "    <tr>\n";
 291  echo "      <td class=\"postbody\" align=\"center\">";
 292  
 293  html_page_links("admin_user_groups.php?webtag=$webtag&sort_dir=$sort_dir&sort_by=$sort_by", $page, $user_groups_array['user_groups_count'], 10);
 294  
 295  echo "      </td>\n";
 296  echo "    </tr>\n";
 297  echo "    <tr>\n";
 298  echo "      <td align=\"left\">&nbsp;</td>\n";
 299  echo "    </tr>\n";
 300  echo "    <tr>\n";
 301  echo "      <td align=\"center\">", form_submit("add_new", gettext("Add New")), "&nbsp;", form_submit("delete", gettext("Delete Selected")), "</td>\n";
 302  echo "    </tr>\n";
 303  echo "  </table>\n";
 304  echo "</form>\n";
 305  echo "<br />\n";
 306  echo "<table cellpadding=\"0\" cellspacing=\"0\" width=\"86%\">\n";
 307  echo "  <tr>\n";
 308  echo "    <td align=\"left\">\n";
 309  echo "      <table class=\"box\" width=\"100%\">\n";
 310  echo "        <tr>\n";
 311  echo "          <td align=\"left\" class=\"posthead\">\n";
 312  echo "            <table class=\"posthead\" width=\"100%\">\n";
 313  echo "              <tr>\n";
 314  echo "                <td colspan=\"4\" class=\"subhead\" align=\"left\" style=\"white-space: nowrap\">", gettext("Permissions Key"), "</td>\n";
 315  echo "              </tr>\n";
 316  echo "              <tr>\n";
 317  echo "                <td align=\"center\">\n";
 318  echo "                  <table width=\"95%\">\n";
 319  echo "                    <tr>\n";
 320  echo "                      <td align=\"left\" valign=\"top\" width=\"50%\">\n";
 321  echo "                        <table width=\"100%\">\n";
 322  echo "                          <tr>\n";
 323  echo "                            <td align=\"left\" class=\"postbody\"><b>AT</b></td>\n";
 324  echo "                            <td align=\"left\" class=\"postbody\">", gettext("Group can access admin tools"), "</td>\n";
 325  echo "                          </tr>\n";
 326  echo "                          <tr>\n";
 327  echo "                            <td align=\"left\" class=\"postbody\"><b>LM</b></td>\n";
 328  echo "                            <td align=\"left\" class=\"postbody\">", gettext("Group can moderate Links sections"), "</td>\n";
 329  echo "                          </tr>\n";
 330  echo "                          <tr>\n";
 331  echo "                            <td align=\"left\" class=\"postbody\"><b>UW</b></td>\n";
 332  echo "                            <td align=\"left\" class=\"postbody\">", gettext("Group is wormed"), "</td>\n";
 333  echo "                          </tr>\n";
 334  echo "                        </table>\n";
 335  echo "                      </td>\n";
 336  echo "                      <td align=\"left\" valign=\"top\" width=\"50%\">\n";
 337  echo "                        <table width=\"100%\">\n";
 338  echo "                          <tr>\n";
 339  echo "                            <td align=\"left\" class=\"postbody\"><b>FM</b></td>\n";
 340  echo "                            <td align=\"left\" class=\"postbody\">", gettext("Group can moderate all folders"), "</td>\n";
 341  echo "                          </tr>\n";
 342  echo "                          <tr>\n";
 343  echo "                            <td align=\"left\" class=\"postbody\"><b>UB</b></td>\n";
 344  echo "                            <td align=\"left\" class=\"postbody\">", gettext("Group is banned"), "</td>\n";
 345  echo "                          </tr>\n";
 346  echo "                        </table>\n";
 347  echo "                      </td>\n";
 348  echo "                    </tr>\n";
 349  echo "                  </table>\n";
 350  echo "                </td>\n";
 351  echo "              </tr>\n";
 352  echo "              <tr>\n";
 353  echo "                <td align=\"left\" colspan=\"8\">&nbsp;</td>\n";
 354  echo "              </tr>\n";
 355  echo "            </table>\n";
 356  echo "          </td>\n";
 357  echo "        </tr>\n";
 358  echo "      </table>\n";
 359  echo "    </td>\n";
 360  echo "  </tr>\n";
 361  echo "</table>\n";
 362  echo "</div>\n";
 363  
 364  html_draw_bottom();

title

Description

title

Description

title

Description

title

title

Body