[ Index ]

PHP Cross Reference of MyBB

title

Body

[close]

/ -> managegroup.php (source)

   1  <?php
   2  /**
   3   * MyBB 1.6
   4   * Copyright 2010 MyBB Group, All Rights Reserved
   5   *
   6   * Website: http://mybb.com
   7   * License: http://mybb.com/about/license
   8   *
   9   * $Id$
  10   */
  11  
  12  define("IN_MYBB", 1);
  13  define('THIS_SCRIPT', 'managegroup.php');
  14  
  15  $templatelist = "managegroup_leaders_bit,managegroup_leaders,postbit_pm,postbit_email,managegroup_user_checkbox,managegroup_user,managegroup_adduser,managegroup_removeusers,managegroup,managegroup_joinrequests_request,managegroup_joinrequests";
  16  $templatelist .= ",managegroup_requestnote,managegroup_no_users,multipage_prevpage,multipage_start,multipage_page_current,multipage_page,multipage_end,multipage_nextpage,multipage";
  17  
  18  require_once  "./global.php";
  19  
  20  // Load language files
  21  $lang->load("managegroup");
  22  
  23  $gid = $mybb->input['gid'] = intval($mybb->input['gid']);
  24  $usergroup = $groupscache[$mybb->input['gid']];
  25  if(!$usergroup['gid'])
  26  {
  27      error($lang->invalid_group);
  28  }
  29  $lang->nav_group_management = $lang->sprintf($lang->nav_group_management, $usergroup['title']);
  30  add_breadcrumb($lang->nav_group_memberships, "usercp.php?action=usergroups");
  31  add_breadcrumb($lang->nav_group_management, "managegroup.php?gid=$gid");
  32  
  33  if($mybb->input['action'] == "joinrequests")
  34  {
  35      add_breadcrumb($lang->nav_join_requests);
  36  }
  37  
  38  // Check that this user is actually a leader of this group
  39  $query = $db->simple_select("groupleaders", "*", "uid='{$mybb->user['uid']}' AND gid='{$gid}'");
  40  $groupleader = $db->fetch_array($query);
  41  if(!$groupleader['uid'] && $mybb->user['cancp'] != 1)
  42  {
  43      error($lang->not_leader_of_this_group);
  44  }
  45  
  46  if($mybb->input['action'] == "do_add" && $mybb->request_method == "post")
  47  {
  48      // Verify incoming POST request
  49      verify_post_check($mybb->input['my_post_key']);
  50  
  51      if($groupleader['canmanagemembers'] == 0)
  52      {
  53          error_no_permission();
  54      }
  55      $query = $db->simple_select("users", "uid, additionalgroups, usergroup", "username = '".$db->escape_string($mybb->input['username'])."'", array("limit" => 1));
  56      $user = $db->fetch_array($query);
  57      if($user['uid'])
  58      {
  59          $additionalgroups = explode(',', $user['additionalgroups']);
  60          if ($user['usergroup'] != $gid && !in_array($gid, $additionalgroups))
  61          {
  62              join_usergroup($user['uid'], $gid);
  63              redirect("managegroup.php?gid=".$gid, $lang->user_added);
  64          }
  65          else 
  66          {
  67              error($lang->error_alreadyingroup);
  68          }
  69      }
  70      else
  71      {
  72          error($lang->error_invalidusername);
  73      }
  74  }
  75  elseif($mybb->input['action'] == "do_joinrequests" && $mybb->request_method == "post")
  76  {
  77      // Verify incoming POST request
  78      verify_post_check($mybb->input['my_post_key']);
  79  
  80      if($groupleader['canmanagerequests'] == 0)
  81      {
  82          error_no_permission();
  83      }
  84  
  85      $plugins->run_hooks("managegroup_do_joinrequests_start");
  86  
  87      if(is_array($mybb->input['request']))
  88      {
  89          foreach($mybb->input['request'] as $uid => $what)
  90          {
  91              if($what == "accept")
  92              {
  93                  join_usergroup($uid, $gid);
  94                  $uidin[] = intval($uid);
  95              }
  96              elseif($what == "decline")
  97              {
  98                  $uidin[] = intval($uid);
  99              }
 100          }
 101      }
 102      if(is_array($uidin))
 103      {
 104          $uids = implode(",", $uidin);
 105          $db->delete_query("joinrequests", "uid IN ({$uids}) AND gid='{$gid}'");
 106      }
 107  
 108      $plugins->run_hooks("managegroup_do_joinrequests_end");
 109  
 110      redirect("managegroup.php?gid={$gid}", $lang->join_requests_moderated);
 111  }
 112  elseif($mybb->input['action'] == "joinrequests")
 113  {
 114      $users = "";
 115      $plugins->run_hooks("managegroup_joinrequests_start");
 116  
 117      $query = $db->query("
 118          SELECT j.*, u.uid, u.username, u.postnum, u.regdate
 119          FROM ".TABLE_PREFIX."joinrequests j
 120          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=j.uid)
 121          WHERE j.gid='".$mybb->input['gid']."' AND j.uid != 0
 122          ORDER BY u.username ASC
 123      ");
 124      while($user = $db->fetch_array($query))
 125      {
 126          $user['reason'] = htmlspecialchars_uni($user['reason']);
 127          $altbg = alt_trow();
 128          $regdate = my_date($mybb->settings['dateformat'], $user['regdate']);
 129          $user['profilelink'] = build_profile_link($user['username'], $user['uid']);
 130          eval("\$users .= \"".$templates->get("managegroup_joinrequests_request")."\";");
 131      }
 132      if(!$users)
 133      {
 134          error($lang->no_requests);
 135      }
 136      $lang->join_requests = $lang->sprintf($lang->join_requests_title,htmlspecialchars_uni($usergroup['title']));
 137  
 138      $plugins->run_hooks("managegroup_joinrequests_end");
 139  
 140      eval("\$joinrequests = \"".$templates->get("managegroup_joinrequests")."\";");
 141      output_page($joinrequests);
 142  }
 143  elseif($mybb->input['action'] == "do_manageusers" && $mybb->request_method == "post")
 144  {
 145      // Verify incoming POST request
 146      verify_post_check($mybb->input['my_post_key']);
 147  
 148      if($groupleader['canmanagemembers'] == 0)
 149      {
 150          error_no_permission();
 151      }
 152  
 153      $plugins->run_hooks("managegroup_do_manageusers_start");
 154  
 155      if(is_array($mybb->input['removeuser']))
 156      {
 157          foreach($mybb->input['removeuser'] as $uid)
 158          {
 159              leave_usergroup($uid, $mybb->input['gid']);
 160          }
 161      }
 162      else
 163      {
 164          error($lang->no_users_selected);
 165      }
 166  
 167      $plugins->run_hooks("managegroup_do_manageusers_end");
 168  
 169      redirect("managegroup.php?gid={$gid}", $lang->users_removed);
 170  }
 171  else
 172  {
 173      $plugins->run_hooks("managegroup_start");
 174  
 175      $lang->members_of = $lang->sprintf($lang->members_of, $usergroup['title']);
 176      $lang->add_member = $lang->sprintf($lang->add_member, $usergroup['title']);
 177      if($usergroup['type'] == 4)
 178      {
 179          $query = $db->simple_select("joinrequests", "COUNT(*) AS req", "gid='".$mybb->input['gid']."'");
 180          $numrequests = $db->fetch_array($query);
 181          if($numrequests['req'])
 182          {
 183              $lang->num_requests_pending = $lang->sprintf($lang->num_requests_pending, $numrequests['req']);
 184              eval("\$joinrequests = \"".$templates->get("managegroup_requestnote")."\";");
 185          }
 186          $usergrouptype = $lang->group_public_moderated;
 187      }
 188      elseif($usergroup['type'] == 3)
 189      {
 190          $usergrouptype = $lang->group_public_not_moderated;
 191      }
 192      elseif($usergroup['type'] == 2)
 193      {
 194          $usergrouptype = $lang->group_private;
 195      }
 196      else
 197      {
 198          $usergrouptype = $lang->group_default;
 199      }
 200  
 201      // Display group leaders (if there is any)
 202      $query = $db->query("
 203          SELECT g.*, u.username, u.usergroup, u.displaygroup
 204          FROM ".TABLE_PREFIX."groupleaders g
 205          LEFT JOIN ".TABLE_PREFIX."users u ON (u.uid=g.uid)
 206          WHERE g.gid = '".$mybb->input['gid']."'
 207      ");
 208      if($db->num_rows($query))
 209      {
 210          $loop = 1;
 211          $leader_count = $db->num_rows($query);
 212          while($leader = $db->fetch_array($query))
 213          {
 214              $leader_name = format_name(htmlspecialchars_uni($leader['username']), $leader['usergroup'], $leader['displaygroup']);
 215              $leader_profile_link = build_profile_link($leader_name, $leader['uid']);
 216  
 217              // Get commas...
 218              if($loop != $leader_count)
 219              {
 220                  $comma = $lang->comma;
 221              }
 222              else
 223              {
 224                  $comma = '';
 225              }
 226  
 227              ++$loop;
 228              eval("\$leaders .= \"".$templates->get("managegroup_leaders_bit")."\";");
 229          }
 230  
 231          eval("\$group_leaders = \"".$templates->get("managegroup_leaders")."\";");
 232      }
 233  
 234      switch($db->type)
 235      {
 236          case "pgsql":
 237          case "sqlite":
 238              $query = $db->simple_select("users", "*", "','||additionalgroups||',' LIKE '%,".$mybb->input['gid'].",%' OR usergroup='".$mybb->input['gid']."'", array('order_by' => 'username'));
 239              break;
 240          default:
 241              $query = $db->simple_select("users", "*", "CONCAT(',',additionalgroups,',') LIKE '%,".$mybb->input['gid'].",%' OR usergroup='".$mybb->input['gid']."'", array('order_by' => 'username'));
 242      }
 243  
 244      $numusers = $db->num_rows($query);
 245      /*if(!$numusers && !$numrequests)
 246      {
 247          error($lang->group_no_members);
 248      }*/
 249      $perpage = $mybb->settings['membersperpage'];
 250      if($page && $page > 0)
 251      {
 252          $start = ($page-1) *$perpage;
 253      }
 254      else
 255      {
 256          $start = 0;
 257          $page = 1;
 258      }
 259      $multipage = multipage($numusers, $perpage, $page, "managegroup.php?gid=".$mybb->input['gid']);
 260      $users = "";
 261      while($user = $db->fetch_array($query))
 262      {
 263          $altbg = alt_trow();
 264          $regdate = my_date($mybb->settings['dateformat'].", ".$mybb->settings['timeformat'], $user['regdate']);
 265          $post = $user;
 266          $sendpm = $email = '';
 267          if($mybb->settings['enablepms'] == 1 && $post['receivepms'] != 0 && $mybb->usergroup['cansendpms'] == 1 && my_strpos(",".$post['ignorelist'].",", ",".$mybb->user['uid'].",") === false)
 268          {
 269              eval("\$sendpm = \"".$templates->get("postbit_pm")."\";");
 270          }
 271          
 272          if($user['hideemail'] != 1)
 273          {
 274              eval("\$email = \"".$templates->get("postbit_email")."\";");
 275          }
 276          else
 277          {
 278              $email = '';
 279          }
 280          $query1 = $db->simple_select("groupleaders", "uid", "uid='{$user['uid']}' AND gid='{$gid}'");
 281          $isleader = $db->fetch_array($query1);
 282          $user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
 283          $user['profilelink'] = build_profile_link($user['username'], $user['uid']);
 284          if($isleader['uid'])
 285          {
 286              $leader = $lang->leader;
 287          }
 288          else
 289          {
 290              $leader = '';
 291          }
 292  
 293          // Checkbox for user management - only if current user is allowed
 294          $checkbox = '';
 295          if($groupleader['canmanagemembers'] == 1)
 296          {
 297              eval("\$checkbox = \"".$templates->get("managegroup_user_checkbox")."\";");
 298          }
 299  
 300          eval("\$users .= \"".$templates->get("managegroup_user")."\";");
 301      }
 302  
 303      if(!$users)
 304      {
 305          eval("\$users = \"".$templates->get("managegroup_no_users")."\";");
 306      }
 307  
 308      $add_user = '';
 309      $remove_users = '';
 310      if($groupleader['canmanagemembers'] == 1)
 311      {
 312          eval("\$add_user = \"".$templates->get("managegroup_adduser")."\";");
 313          eval("\$remove_users = \"".$templates->get("managegroup_removeusers")."\";");
 314      }
 315  
 316      $plugins->run_hooks("managegroup_end");
 317  
 318      eval("\$manageusers = \"".$templates->get("managegroup")."\";");
 319      output_page($manageusers);
 320  }
 321  ?>


Generated: Tue Oct 8 19:19:50 2013 Cross-referenced by PHPXref 0.7.1