[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/includes/acp/ -> acp_groups.php (source)

   1  <?php
   2  /**
   3  *
   4  * @package acp
   5  * @version $Id$
   6  * @copyright (c) 2005 phpBB Group
   7  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
   8  *
   9  */
  10  
  11  /**
  12  * @ignore
  13  */
  14  if (!defined('IN_PHPBB'))
  15  {
  16      exit;
  17  }
  18  
  19  /**
  20  * @package acp
  21  */
  22  class acp_groups
  23  {
  24      var $u_action;
  25  
  26  	function main($id, $mode)
  27      {
  28          global $config, $db, $user, $auth, $template, $cache;
  29          global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
  30  
  31          $user->add_lang('acp/groups');
  32          $this->tpl_name = 'acp_groups';
  33          $this->page_title = 'ACP_GROUPS_MANAGE';
  34  
  35          $form_key = 'acp_groups';
  36          add_form_key($form_key);
  37  
  38          include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
  39  
  40          // Check and set some common vars
  41          $action        = (isset($_POST['add'])) ? 'add' : ((isset($_POST['addusers'])) ? 'addusers' : request_var('action', ''));
  42          $group_id    = request_var('g', 0);
  43          $mark_ary    = request_var('mark', array(0));
  44          $name_ary    = request_var('usernames', '', true);
  45          $leader        = request_var('leader', 0);
  46          $default    = request_var('default', 0);
  47          $start        = request_var('start', 0);
  48          $update        = (isset($_POST['update'])) ? true : false;
  49  
  50  
  51          // Clear some vars
  52          $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
  53          $group_row = array();
  54  
  55          // Grab basic data for group, if group_id is set and exists
  56          if ($group_id)
  57          {
  58              $sql = 'SELECT *
  59                  FROM ' . GROUPS_TABLE . "
  60                  WHERE group_id = $group_id";
  61              $result = $db->sql_query($sql);
  62              $group_row = $db->sql_fetchrow($result);
  63              $db->sql_freeresult($result);
  64  
  65              if (!$group_row)
  66              {
  67                  trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
  68              }
  69  
  70              // Check if the user is allowed to manage this group if set to founder only.
  71              if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage'])
  72              {
  73                  trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
  74              }
  75          }
  76  
  77          // Which page?
  78          switch ($action)
  79          {
  80              case 'approve':
  81              case 'demote':
  82              case 'promote':
  83                  if (!check_form_key($form_key))
  84                  {
  85                      trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
  86                  }
  87  
  88                  if (!$group_id)
  89                  {
  90                      trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
  91                  }
  92  
  93                  // Approve, demote or promote
  94                  $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
  95                  $error = group_user_attributes($action, $group_id, $mark_ary, false, $group_name);
  96  
  97                  if (!$error)
  98                  {
  99                      switch ($action)
 100                      {
 101                          case 'demote':
 102                              $message = 'GROUP_MODS_DEMOTED';
 103                          break;
 104  
 105                          case 'promote':
 106                              $message = 'GROUP_MODS_PROMOTED';
 107                          break;
 108  
 109                          case 'approve':
 110                              $message = 'USERS_APPROVED';
 111                          break;
 112                      }
 113  
 114                      trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id));
 115                  }
 116                  else
 117                  {
 118                      trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
 119                  }
 120  
 121              break;
 122  
 123              case 'default':
 124                  if (!$group_id)
 125                  {
 126                      trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
 127                  }
 128                  else if (empty($mark_ary))
 129                  {
 130                      trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
 131                  }
 132  
 133                  if (confirm_box(true))
 134                  {
 135                      $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
 136                      group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);    
 137                      trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id));
 138                  }
 139                  else
 140                  {
 141                      confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 142                          'mark'        => $mark_ary,
 143                          'g'            => $group_id,
 144                          'i'            => $id,
 145                          'mode'        => $mode,
 146                          'action'    => $action))
 147                      );
 148                  }
 149              break;
 150  
 151              case 'set_default_on_all':
 152                  if (confirm_box(true))
 153                  {
 154                      $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
 155  
 156                      $start = 0;
 157  
 158                      do
 159                      {
 160                          $sql = 'SELECT user_id
 161                              FROM ' . USER_GROUP_TABLE . "
 162                              WHERE group_id = $group_id
 163                              ORDER BY user_id";
 164                          $result = $db->sql_query_limit($sql, 200, $start);
 165  
 166                          $mark_ary = array();
 167                          if ($row = $db->sql_fetchrow($result))
 168                          {
 169                              do
 170                              {
 171                                  $mark_ary[] = $row['user_id'];
 172                              }
 173                              while ($row = $db->sql_fetchrow($result));
 174  
 175                              group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
 176  
 177                              $start = (sizeof($mark_ary) < 200) ? 0 : $start + 200;
 178                          }
 179                          else
 180                          {
 181                              $start = 0;
 182                          }
 183                          $db->sql_freeresult($result);
 184                      }
 185                      while ($start);
 186  
 187                      trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id));
 188                  }
 189                  else
 190                  {
 191                      confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 192                          'mark'        => $mark_ary,
 193                          'g'            => $group_id,
 194                          'i'            => $id,
 195                          'mode'        => $mode,
 196                          'action'    => $action))
 197                      );
 198                  }
 199              break;
 200  
 201              case 'deleteusers':
 202                  if (empty($mark_ary))
 203                  {
 204                      trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
 205                  }
 206              case 'delete':
 207                  if (!$group_id)
 208                  {
 209                      trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
 210                  }
 211                  else if ($action === 'delete' && $group_row['group_type'] == GROUP_SPECIAL)
 212                  {
 213                      trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
 214                  }
 215  
 216                  if (confirm_box(true))
 217                  {
 218                      $error = '';
 219  
 220                      switch ($action)
 221                      {
 222                          case 'delete':
 223                              if (!$auth->acl_get('a_groupdel'))
 224                              {
 225                                  trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
 226                              }
 227  
 228                              $error = group_delete($group_id, $group_row['group_name']);
 229                          break;
 230  
 231                          case 'deleteusers':
 232                              $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
 233                              $error = group_user_del($group_id, $mark_ary, false, $group_name);
 234                          break;
 235                      }
 236  
 237                      $back_link = ($action == 'delete') ? $this->u_action : $this->u_action . '&amp;action=list&amp;g=' . $group_id;
 238  
 239                      if ($error)
 240                      {
 241                          trigger_error($user->lang[$error] . adm_back_link($back_link), E_USER_WARNING);
 242                      }
 243  
 244                      $message = ($action == 'delete') ? 'GROUP_DELETED' : 'GROUP_USERS_REMOVE';
 245                      trigger_error($user->lang[$message] . adm_back_link($back_link));
 246                  }
 247                  else
 248                  {
 249                      confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
 250                          'mark'        => $mark_ary,
 251                          'g'            => $group_id,
 252                          'i'            => $id,
 253                          'mode'        => $mode,
 254                          'action'    => $action))
 255                      );
 256                  }
 257              break;
 258  
 259              case 'addusers':
 260                  if (!check_form_key($form_key))
 261                  {
 262                      trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
 263                  }
 264  
 265                  if (!$group_id)
 266                  {
 267                      trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
 268                  }
 269  
 270                  if (!$name_ary)
 271                  {
 272                      trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
 273                  }
 274  
 275                  $name_ary = array_unique(explode("\n", $name_ary));
 276                  $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
 277  
 278                  // Add user/s to group
 279                  if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, $leader, 0, $group_row))
 280                  {
 281                      trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id), E_USER_WARNING);
 282                  }
 283  
 284                  $message = ($leader) ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED';
 285                  trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&amp;action=list&amp;g=' . $group_id));
 286              break;
 287  
 288              case 'edit':
 289              case 'add':
 290  
 291                  include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
 292  
 293                  $data = $submit_ary = array();
 294  
 295                  if ($action == 'edit' && !$group_id)
 296                  {
 297                      trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
 298                  }
 299  
 300                  if ($action == 'add' && !$auth->acl_get('a_groupadd'))
 301                  {
 302                      trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
 303                  }
 304  
 305                  $error = array();
 306                  $user->add_lang('ucp');
 307  
 308                  $avatar_select = basename(request_var('avatar_select', ''));
 309                  $category = basename(request_var('category', ''));
 310  
 311                  // Did we submit?
 312                  if ($update)
 313                  {
 314                      if (!check_form_key($form_key))
 315                      {
 316                          trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
 317                      }
 318  
 319                      $group_name    = utf8_normalize_nfc(request_var('group_name', '', true));
 320                      $group_desc = utf8_normalize_nfc(request_var('group_desc', '', true));
 321                      $group_type    = request_var('group_type', GROUP_FREE);
 322  
 323                      $allow_desc_bbcode    = request_var('desc_parse_bbcode', false);
 324                      $allow_desc_urls    = request_var('desc_parse_urls', false);
 325                      $allow_desc_smilies    = request_var('desc_parse_smilies', false);
 326  
 327                      $data['uploadurl']    = request_var('uploadurl', '');
 328                      $data['remotelink']    = request_var('remotelink', '');
 329                      $data['width']        = request_var('width', '');
 330                      $data['height']        = request_var('height', '');
 331                      $delete                = request_var('delete', '');
 332  
 333                      $submit_ary = array(
 334                          'colour'            => request_var('group_colour', ''),
 335                          'rank'                => request_var('group_rank', 0),
 336                          'receive_pm'        => isset($_REQUEST['group_receive_pm']) ? 1 : 0,
 337                          'legend'            => isset($_REQUEST['group_legend']) ? 1 : 0,
 338                          'message_limit'        => request_var('group_message_limit', 0),
 339                          'max_recipients'    => request_var('group_max_recipients', 0),
 340                          'founder_manage'    => 0,
 341                          'skip_auth'            => request_var('group_skip_auth', 0),
 342                      );
 343  
 344                      if ($user->data['user_type'] == USER_FOUNDER)
 345                      {
 346                          $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0;
 347                      }
 348  
 349                      if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink'])
 350                      {
 351                          // Avatar stuff
 352                          $var_ary = array(
 353                              'uploadurl'        => array('string', true, 5, 255),
 354                              'remotelink'    => array('string', true, 5, 255),
 355                              'width'            => array('string', true, 1, 3),
 356                              'height'        => array('string', true, 1, 3),
 357                          );
 358  
 359                          if (!($error = validate_data($data, $var_ary)))
 360                          {
 361                              $data['user_id'] = "g$group_id";
 362  
 363                              if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload)
 364                              {
 365                                  list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error);
 366                              }
 367                              else if ($data['remotelink'])
 368                              {
 369                                  list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error);
 370                              }
 371                          }
 372                      }
 373                      else if ($avatar_select && $config['allow_avatar_local'])
 374                      {
 375                          // check avatar gallery
 376                          if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category))
 377                          {
 378                              $submit_ary['avatar_type'] = AVATAR_GALLERY;
 379  
 380                              list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select);
 381                              $submit_ary['avatar'] = $category . '/' . $avatar_select;
 382                          }
 383                      }
 384                      else if ($delete)
 385                      {
 386                          $submit_ary['avatar'] = '';
 387                          $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0;
 388                      }
 389                      else if ($data['width'] && $data['height'])
 390                      {
 391                          // Only update the dimensions?
 392                          if ($config['avatar_max_width'] || $config['avatar_max_height'])
 393                          {
 394                              if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height'])
 395                              {
 396                                  $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']);
 397                              }
 398                          }
 399  
 400                          if (!sizeof($error))
 401                          {
 402                              if ($config['avatar_min_width'] || $config['avatar_min_height'])
 403                              {
 404                                  if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height'])
 405                                  {
 406                                      $error[] = sprintf($user->lang['AVATAR_WRONG_SIZE'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], $data['width'], $data['height']);
 407                                  }
 408                              }
 409                          }
 410  
 411                          if (!sizeof($error))
 412                          {
 413                              $submit_ary['avatar_width'] = $data['width'];
 414                              $submit_ary['avatar_height'] = $data['height'];
 415                          }
 416                      }
 417  
 418                      if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']))) || $delete)
 419                      {
 420                          if (isset($group_row['group_avatar']) && $group_row['group_avatar'])
 421                          {
 422                              avatar_delete('group', $group_row, true);
 423                          }
 424                      }
 425  
 426                      /*
 427                      * Validate the length of "Maximum number of allowed recipients per
 428                      * private message" setting. We use 16777215 as a maximum because it matches
 429                      * MySQL unsigned mediumint maximum value which is the lowest amongst DBMSes
 430                      * supported by phpBB3. Also validate the submitted colour value.
 431                      */
 432                      $validation_checks = array(
 433                          'max_recipients' => array('num', false, 0, 16777215),
 434                          'colour'    => array('hex_colour', true),
 435                      );
 436  
 437                      if ($validation_error = validate_data($submit_ary, $validation_checks))
 438                      {
 439                          // Replace "error" string with its real, localised form
 440                          $error = array_merge($error, $validation_error);
 441                      }
 442  
 443                      if (!sizeof($error))
 444                      {
 445                          // Only set the rank, colour, etc. if it's changed or if we're adding a new
 446                          // group. This prevents existing group members being updated if no changes
 447                          // were made.
 448  
 449                          $group_attributes = array();
 450                          $test_variables = array(
 451                              'rank'            => 'int',
 452                              'colour'        => 'string',
 453                              'avatar'        => 'string',
 454                              'avatar_type'    => 'int',
 455                              'avatar_width'    => 'int',
 456                              'avatar_height'    => 'int',
 457                              'receive_pm'    => 'int',
 458                              'legend'        => 'int',
 459                              'message_limit'    => 'int',
 460                              'max_recipients'=> 'int',
 461                              'founder_manage'=> 'int',
 462                              'skip_auth'        => 'int',
 463                          );
 464  
 465                          foreach ($test_variables as $test => $type)
 466                          {
 467                              if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test]))
 468                              {
 469                                  settype($submit_ary[$test], $type);
 470                                  $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
 471                              }
 472                          }
 473  
 474                          if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies)))
 475                          {
 476                              $group_perm_from = request_var('group_perm_from', 0);
 477  
 478                              // Copy permissions?
 479                              // If the user has the a_authgroups permission and at least one additional permission ability set the permissions are fully transferred.
 480                              // We do not limit on one auth category because this can lead to incomplete permissions being tricky to fix for the admin, roles being assigned or added non-default permissions.
 481                              // Since the user only has the option to copy permissions from non leader managed groups this seems to be a good compromise.
 482                              if ($group_perm_from && $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth'))
 483                              {
 484                                  $sql = 'SELECT group_founder_manage
 485                                      FROM ' . GROUPS_TABLE . '
 486                                      WHERE group_id = ' . $group_perm_from;
 487                                  $result = $db->sql_query($sql);
 488                                  $check_row = $db->sql_fetchrow($result);
 489                                  $db->sql_freeresult($result);
 490  
 491                                  // Check the group if non-founder
 492                                  if ($check_row && ($user->data['user_type'] == USER_FOUNDER || $check_row['group_founder_manage'] == 0))
 493                                  {
 494                                      // From the mysql documentation:
 495                                      // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
 496                                      // Due to this we stay on the safe side if we do the insertion "the manual way"
 497  
 498                                      // Copy permisisons from/to the acl groups table (only group_id gets changed)
 499                                      $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting
 500                                          FROM ' . ACL_GROUPS_TABLE . '
 501                                          WHERE group_id = ' . $group_perm_from;
 502                                      $result = $db->sql_query($sql);
 503  
 504                                      $groups_sql_ary = array();
 505                                      while ($row = $db->sql_fetchrow($result))
 506                                      {
 507                                          $groups_sql_ary[] = array(
 508                                              'group_id'            => (int) $group_id,
 509                                              'forum_id'            => (int) $row['forum_id'],
 510                                              'auth_option_id'    => (int) $row['auth_option_id'],
 511                                              'auth_role_id'        => (int) $row['auth_role_id'],
 512                                              'auth_setting'        => (int) $row['auth_setting']
 513                                          );
 514                                      }
 515                                      $db->sql_freeresult($result);
 516  
 517                                      // Now insert the data
 518                                      $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
 519  
 520                                      $auth->acl_clear_prefetch();
 521                                  }
 522                              }
 523  
 524                              $cache->destroy('sql', GROUPS_TABLE);
 525  
 526                              $message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED';
 527                              trigger_error($user->lang[$message] . adm_back_link($this->u_action));
 528                          }
 529                      }
 530  
 531                      if (sizeof($error))
 532                      {
 533                          $error = array_map(array(&$user, 'lang'), $error);
 534                          $group_rank = $submit_ary['rank'];
 535  
 536                          $group_desc_data = array(
 537                              'text'            => $group_desc,
 538                              'allow_bbcode'    => $allow_desc_bbcode,
 539                              'allow_smilies'    => $allow_desc_smilies,
 540                              'allow_urls'    => $allow_desc_urls
 541                          );
 542                      }
 543                  }
 544                  else if (!$group_id)
 545                  {
 546                      $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
 547                      $group_desc_data = array(
 548                          'text'            => '',
 549                          'allow_bbcode'    => true,
 550                          'allow_smilies'    => true,
 551                          'allow_urls'    => true
 552                      );
 553                      $group_rank = 0;
 554                      $group_type = GROUP_OPEN;
 555                  }
 556                  else
 557                  {
 558                      $group_name = $group_row['group_name'];
 559                      $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']);
 560                      $group_type = $group_row['group_type'];
 561                      $group_rank = $group_row['group_rank'];
 562                  }
 563  
 564                  $sql = 'SELECT *
 565                      FROM ' . RANKS_TABLE . '
 566                      WHERE rank_special = 1
 567                      ORDER BY rank_title';
 568                  $result = $db->sql_query($sql);
 569  
 570                  $rank_options = '<option value="0"' . ((!$group_rank) ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>';
 571  
 572                  while ($row = $db->sql_fetchrow($result))
 573                  {
 574                      $selected = ($group_rank && $row['rank_id'] == $group_rank) ? ' selected="selected"' : '';
 575                      $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
 576                  }
 577                  $db->sql_freeresult($result);
 578  
 579                  $type_free        = ($group_type == GROUP_FREE) ? ' checked="checked"' : '';
 580                  $type_open        = ($group_type == GROUP_OPEN) ? ' checked="checked"' : '';
 581                  $type_closed    = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : '';
 582                  $type_hidden    = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : '';
 583  
 584                  $avatar_img = (!empty($group_row['group_avatar'])) ? get_user_avatar($group_row['group_avatar'], $group_row['group_avatar_type'], $group_row['group_avatar_width'], $group_row['group_avatar_height'], 'GROUP_AVATAR') : '<img src="' . $phpbb_admin_path . 'images/no_avatar.gif" alt="" />';
 585  
 586                  $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
 587  
 588                  if ($config['allow_avatar_local'] && $display_gallery)
 589                  {
 590                      avatar_gallery($category, $avatar_select, 4);
 591                  }
 592  
 593                  $back_link = request_var('back_link', '');
 594  
 595                  switch ($back_link)
 596                  {
 597                      case 'acp_users_groups':
 598                          $u_back = append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&amp;mode=groups&amp;u=' . request_var('u', 0));
 599                      break;
 600  
 601                      default:
 602                          $u_back = $this->u_action;
 603                      break;
 604                  }
 605  
 606                  $template->assign_vars(array(
 607                      'S_EDIT'            => true,
 608                      'S_ADD_GROUP'        => ($action == 'add') ? true : false,
 609                      'S_GROUP_PERM'        => ($action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) ? true : false,
 610                      'S_INCLUDE_SWATCH'    => true,
 611                      'S_CAN_UPLOAD'        => $can_upload,
 612                      'S_ERROR'            => (sizeof($error)) ? true : false,
 613                      'S_SPECIAL_GROUP'    => ($group_type == GROUP_SPECIAL) ? true : false,
 614                      'S_DISPLAY_GALLERY'    => ($config['allow_avatar_local'] && !$display_gallery) ? true : false,
 615                      'S_IN_GALLERY'        => ($config['allow_avatar_local'] && $display_gallery) ? true : false,
 616                      'S_USER_FOUNDER'    => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
 617  
 618                      'ERROR_MSG'                => (sizeof($error)) ? implode('<br />', $error) : '',
 619                      'GROUP_NAME'            => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name,
 620                      'GROUP_INTERNAL_NAME'    => $group_name,
 621                      'GROUP_DESC'            => $group_desc_data['text'],
 622                      'GROUP_RECEIVE_PM'        => (isset($group_row['group_receive_pm']) && $group_row['group_receive_pm']) ? ' checked="checked"' : '',
 623                      'GROUP_FOUNDER_MANAGE'    => (isset($group_row['group_founder_manage']) && $group_row['group_founder_manage']) ? ' checked="checked"' : '',
 624                      'GROUP_LEGEND'            => (isset($group_row['group_legend']) && $group_row['group_legend']) ? ' checked="checked"' : '',
 625                      'GROUP_MESSAGE_LIMIT'    => (isset($group_row['group_message_limit'])) ? $group_row['group_message_limit'] : 0,
 626                      'GROUP_MAX_RECIPIENTS'    => (isset($group_row['group_max_recipients'])) ? $group_row['group_max_recipients'] : 0,
 627                      'GROUP_COLOUR'            => (isset($group_row['group_colour'])) ? $group_row['group_colour'] : '',
 628                      'GROUP_SKIP_AUTH'        => (!empty($group_row['group_skip_auth'])) ? ' checked="checked"' : '',
 629  
 630                      'S_DESC_BBCODE_CHECKED'    => $group_desc_data['allow_bbcode'],
 631                      'S_DESC_URLS_CHECKED'    => $group_desc_data['allow_urls'],
 632                      'S_DESC_SMILIES_CHECKED'=> $group_desc_data['allow_smilies'],
 633  
 634                      'S_RANK_OPTIONS'        => $rank_options,
 635                      'S_GROUP_OPTIONS'        => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)),
 636                      'AVATAR'                => $avatar_img,
 637                      'AVATAR_IMAGE'            => $avatar_img,
 638                      'AVATAR_MAX_FILESIZE'    => $config['avatar_filesize'],
 639                      'AVATAR_WIDTH'            => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '',
 640                      'AVATAR_HEIGHT'            => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '',
 641  
 642                      'GROUP_TYPE_FREE'        => GROUP_FREE,
 643                      'GROUP_TYPE_OPEN'        => GROUP_OPEN,
 644                      'GROUP_TYPE_CLOSED'        => GROUP_CLOSED,
 645                      'GROUP_TYPE_HIDDEN'        => GROUP_HIDDEN,
 646                      'GROUP_TYPE_SPECIAL'    => GROUP_SPECIAL,
 647  
 648                      'GROUP_FREE'        => $type_free,
 649                      'GROUP_OPEN'        => $type_open,
 650                      'GROUP_CLOSED'        => $type_closed,
 651                      'GROUP_HIDDEN'        => $type_hidden,
 652  
 653                      'U_BACK'            => $u_back,
 654                      'U_SWATCH'            => append_sid("{$phpbb_admin_path}swatch.$phpEx", 'form=settings&amp;name=group_colour'),
 655                      'U_ACTION'            => "{$this->u_action}&amp;action=$action&amp;g=$group_id",
 656                      'L_AVATAR_EXPLAIN'    => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)),
 657                  ));
 658  
 659                  return;
 660              break;
 661  
 662              case 'list':
 663  
 664                  if (!$group_id)
 665                  {
 666                      trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
 667                  }
 668  
 669                  $this->page_title = 'GROUP_MEMBERS';
 670  
 671                  // Grab the leaders - always, on every page...
 672                  $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_colour, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
 673                      FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
 674                      WHERE ug.group_id = $group_id
 675                          AND u.user_id = ug.user_id
 676                          AND ug.group_leader = 1
 677                      ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean";
 678                  $result = $db->sql_query($sql);
 679  
 680                  while ($row = $db->sql_fetchrow($result))
 681                  {
 682                      $template->assign_block_vars('leader', array(
 683                          'U_USER_EDIT'        => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;action=edit&amp;u={$row['user_id']}"),
 684  
 685                          'USERNAME'            => $row['username'],
 686                          'USERNAME_COLOUR'    => $row['user_colour'],
 687                          'S_GROUP_DEFAULT'    => ($row['group_id'] == $group_id) ? true : false,
 688                          'JOINED'            => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
 689                          'USER_POSTS'        => $row['user_posts'],
 690                          'USER_ID'            => $row['user_id'],
 691                      ));
 692                  }
 693                  $db->sql_freeresult($result);
 694  
 695                  // Total number of group members (non-leaders)
 696                  $sql = 'SELECT COUNT(user_id) AS total_members
 697                      FROM ' . USER_GROUP_TABLE . "
 698                      WHERE group_id = $group_id
 699                          AND group_leader = 0";
 700                  $result = $db->sql_query($sql);
 701                  $total_members = (int) $db->sql_fetchfield('total_members');
 702                  $db->sql_freeresult($result);
 703  
 704                  $s_action_options = '';
 705                  $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE');
 706  
 707                  foreach ($options as $option => $lang)
 708                  {
 709                      $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>';
 710                  }
 711  
 712                  $template->assign_vars(array(
 713                      'S_LIST'            => true,
 714                      'S_GROUP_SPECIAL'    => ($group_row['group_type'] == GROUP_SPECIAL) ? true : false,
 715                      'S_ACTION_OPTIONS'    => $s_action_options,
 716  
 717                      'S_ON_PAGE'        => on_page($total_members, $config['topics_per_page'], $start),
 718                      'PAGINATION'    => generate_pagination($this->u_action . "&amp;action=$action&amp;g=$group_id", $total_members, $config['topics_per_page'], $start, true),
 719                      'GROUP_NAME'    => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
 720  
 721                      'U_ACTION'            => $this->u_action . "&amp;g=$group_id",
 722                      'U_BACK'            => $this->u_action,
 723                      'U_FIND_USERNAME'    => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=list&amp;field=usernames'),
 724                      'U_DEFAULT_ALL'        => "{$this->u_action}&amp;action=set_default_on_all&amp;g=$group_id",
 725                  ));
 726  
 727                  // Grab the members
 728                  $sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
 729                      FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
 730                      WHERE ug.group_id = $group_id
 731                          AND u.user_id = ug.user_id
 732                          AND ug.group_leader = 0
 733                      ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean";
 734                  $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
 735  
 736                  $pending = false;
 737  
 738                  while ($row = $db->sql_fetchrow($result))
 739                  {
 740                      if ($row['user_pending'] && !$pending)
 741                      {
 742                          $template->assign_block_vars('member', array(
 743                              'S_PENDING'        => true)
 744                          );
 745  
 746                          $pending = true;
 747                      }
 748  
 749                      $template->assign_block_vars('member', array(
 750                          'U_USER_EDIT'        => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&amp;action=edit&amp;u={$row['user_id']}"),
 751  
 752                          'USERNAME'            => $row['username'],
 753                          'USERNAME_COLOUR'    => $row['user_colour'],
 754                          'S_GROUP_DEFAULT'    => ($row['group_id'] == $group_id) ? true : false,
 755                          'JOINED'            => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
 756                          'USER_POSTS'        => $row['user_posts'],
 757                          'USER_ID'            => $row['user_id'])
 758                      );
 759                  }
 760                  $db->sql_freeresult($result);
 761  
 762                  return;
 763              break;
 764          }
 765  
 766          $template->assign_vars(array(
 767              'U_ACTION'        => $this->u_action,
 768              'S_GROUP_ADD'    => ($auth->acl_get('a_groupadd')) ? true : false)
 769          );
 770  
 771          // Get us all the groups
 772          $sql = 'SELECT g.group_id, g.group_name, g.group_type
 773              FROM ' . GROUPS_TABLE . ' g
 774              ORDER BY g.group_type ASC, g.group_name';
 775          $result = $db->sql_query($sql);
 776  
 777          $lookup = $cached_group_data = array();
 778          while ($row = $db->sql_fetchrow($result))
 779          {
 780              $type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : 'normal';
 781  
 782              // used to determine what type a group is
 783              $lookup[$row['group_id']] = $type;
 784  
 785              // used for easy access to the data within a group
 786              $cached_group_data[$type][$row['group_id']] = $row;
 787              $cached_group_data[$type][$row['group_id']]['total_members'] = 0;
 788          }
 789          $db->sql_freeresult($result);
 790  
 791          // How many people are in which group?
 792          $sql = 'SELECT COUNT(ug.user_id) AS total_members, ug.group_id
 793              FROM ' . USER_GROUP_TABLE . ' ug
 794              WHERE ' . $db->sql_in_set('ug.group_id', array_keys($lookup)) . '
 795              GROUP BY ug.group_id';
 796          $result = $db->sql_query($sql);
 797  
 798          while ($row = $db->sql_fetchrow($result))
 799          {
 800              $type = $lookup[$row['group_id']];
 801              $cached_group_data[$type][$row['group_id']]['total_members'] = $row['total_members'];
 802          }
 803          $db->sql_freeresult($result);
 804  
 805          // The order is... normal, then special
 806          ksort($cached_group_data);
 807  
 808          foreach ($cached_group_data as $type => $row_ary)
 809          {
 810              if ($type == 'special')
 811              {
 812                  $template->assign_block_vars('groups', array(
 813                      'S_SPECIAL'            => true)
 814                  );
 815              }
 816  
 817              foreach ($row_ary as $group_id => $row)
 818              {
 819                  $group_name = (!empty($user->lang['G_' . $row['group_name']]))? $user->lang['G_' . $row['group_name']] : $row['group_name'];
 820  
 821                  $template->assign_block_vars('groups', array(
 822                      'U_LIST'        => "{$this->u_action}&amp;action=list&amp;g=$group_id",
 823                      'U_EDIT'        => "{$this->u_action}&amp;action=edit&amp;g=$group_id",
 824                      'U_DELETE'        => ($auth->acl_get('a_groupdel')) ? "{$this->u_action}&amp;action=delete&amp;g=$group_id" : '',
 825  
 826                      'S_GROUP_SPECIAL'    => ($row['group_type'] == GROUP_SPECIAL) ? true : false,
 827  
 828                      'GROUP_NAME'    => $group_name,
 829                      'TOTAL_MEMBERS'    => $row['total_members'],
 830                  ));
 831              }
 832          }
 833      }
 834  }
 835  
 836  ?>


Generated: Wed Oct 2 15:03:47 2013 Cross-referenced by PHPXref 0.7.1