1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/acp/acp_groups.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,798 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package acp
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* @package acp
1.24 +*/
1.25 +class acp_groups
1.26 +{
1.27 + var $u_action;
1.28 +
1.29 + function main($id, $mode)
1.30 + {
1.31 + global $config, $db, $user, $auth, $template, $cache;
1.32 + global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
1.33 +
1.34 + $user->add_lang('acp/groups');
1.35 + $this->tpl_name = 'acp_groups';
1.36 + $this->page_title = 'ACP_GROUPS_MANAGE';
1.37 +
1.38 + $form_key = 'acp_groups';
1.39 + add_form_key($form_key);
1.40 +
1.41 + include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
1.42 +
1.43 + // Check and set some common vars
1.44 + $action = (isset($_POST['add'])) ? 'add' : ((isset($_POST['addusers'])) ? 'addusers' : request_var('action', ''));
1.45 + $group_id = request_var('g', 0);
1.46 + $mark_ary = request_var('mark', array(0));
1.47 + $name_ary = request_var('usernames', '', true);
1.48 + $leader = request_var('leader', 0);
1.49 + $default = request_var('default', 0);
1.50 + $start = request_var('start', 0);
1.51 + $update = (isset($_POST['update'])) ? true : false;
1.52 +
1.53 +
1.54 + // Clear some vars
1.55 + $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
1.56 + $group_row = array();
1.57 +
1.58 + // Grab basic data for group, if group_id is set and exists
1.59 + if ($group_id)
1.60 + {
1.61 + $sql = 'SELECT *
1.62 + FROM ' . GROUPS_TABLE . "
1.63 + WHERE group_id = $group_id";
1.64 + $result = $db->sql_query($sql);
1.65 + $group_row = $db->sql_fetchrow($result);
1.66 + $db->sql_freeresult($result);
1.67 +
1.68 + if (!$group_row)
1.69 + {
1.70 + trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
1.71 + }
1.72 +
1.73 + // Check if the user is allowed to manage this group if set to founder only.
1.74 + if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage'])
1.75 + {
1.76 + trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
1.77 + }
1.78 + }
1.79 +
1.80 + // Which page?
1.81 + switch ($action)
1.82 + {
1.83 + case 'approve':
1.84 + case 'demote':
1.85 + case 'promote':
1.86 + if (!$group_id)
1.87 + {
1.88 + trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
1.89 + }
1.90 +
1.91 + // Approve, demote or promote
1.92 + $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
1.93 + $error = group_user_attributes($action, $group_id, $mark_ary, false, $group_name);
1.94 +
1.95 + if (!$error)
1.96 + {
1.97 + switch ($action)
1.98 + {
1.99 + case 'demote':
1.100 + $message = 'GROUP_MODS_DEMOTED';
1.101 + break;
1.102 +
1.103 + case 'promote':
1.104 + $message = 'GROUP_MODS_PROMOTED';
1.105 + break;
1.106 +
1.107 + case 'approve':
1.108 + $message = 'USERS_APPROVED';
1.109 + break;
1.110 + }
1.111 +
1.112 + trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id));
1.113 + }
1.114 + else
1.115 + {
1.116 + trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING);
1.117 + }
1.118 +
1.119 + break;
1.120 +
1.121 + case 'default':
1.122 + if (!$group_id)
1.123 + {
1.124 + trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
1.125 + }
1.126 +
1.127 + if (confirm_box(true))
1.128 + {
1.129 + $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
1.130 +
1.131 + if (!sizeof($mark_ary))
1.132 + {
1.133 + $start = 0;
1.134 +
1.135 + do
1.136 + {
1.137 + $sql = 'SELECT user_id
1.138 + FROM ' . USER_GROUP_TABLE . "
1.139 + WHERE group_id = $group_id
1.140 + ORDER BY user_id";
1.141 + $result = $db->sql_query_limit($sql, 200, $start);
1.142 +
1.143 + $mark_ary = array();
1.144 + if ($row = $db->sql_fetchrow($result))
1.145 + {
1.146 + do
1.147 + {
1.148 + $mark_ary[] = $row['user_id'];
1.149 + }
1.150 + while ($row = $db->sql_fetchrow($result));
1.151 +
1.152 + group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
1.153 +
1.154 + $start = (sizeof($mark_ary) < 200) ? 0 : $start + 200;
1.155 + }
1.156 + else
1.157 + {
1.158 + $start = 0;
1.159 + }
1.160 + $db->sql_freeresult($result);
1.161 + }
1.162 + while ($start);
1.163 + }
1.164 + else
1.165 + {
1.166 + group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
1.167 + }
1.168 +
1.169 + trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id));
1.170 + }
1.171 + else
1.172 + {
1.173 + confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
1.174 + 'mark' => $mark_ary,
1.175 + 'g' => $group_id,
1.176 + 'i' => $id,
1.177 + 'mode' => $mode,
1.178 + 'action' => $action))
1.179 + );
1.180 + }
1.181 +
1.182 + break;
1.183 +
1.184 + case 'deleteusers':
1.185 + case 'delete':
1.186 + if (!$group_id)
1.187 + {
1.188 + trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
1.189 + }
1.190 + else if ($action === 'delete' && $group_row['group_type'] == GROUP_SPECIAL)
1.191 + {
1.192 + trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
1.193 + }
1.194 +
1.195 + if (confirm_box(true))
1.196 + {
1.197 + $error = '';
1.198 +
1.199 + switch ($action)
1.200 + {
1.201 + case 'delete':
1.202 + if (!$auth->acl_get('a_groupdel'))
1.203 + {
1.204 + trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
1.205 + }
1.206 +
1.207 + $error = group_delete($group_id, $group_row['group_name']);
1.208 + break;
1.209 +
1.210 + case 'deleteusers':
1.211 + $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
1.212 + $error = group_user_del($group_id, $mark_ary, false, $group_name);
1.213 + break;
1.214 + }
1.215 +
1.216 + $back_link = ($action == 'delete') ? $this->u_action : $this->u_action . '&action=list&g=' . $group_id;
1.217 +
1.218 + if ($error)
1.219 + {
1.220 + trigger_error($user->lang[$error] . adm_back_link($back_link), E_USER_WARNING);
1.221 + }
1.222 +
1.223 + $message = ($action == 'delete') ? 'GROUP_DELETED' : 'GROUP_USERS_REMOVE';
1.224 + trigger_error($user->lang[$message] . adm_back_link($back_link));
1.225 + }
1.226 + else
1.227 + {
1.228 + confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
1.229 + 'mark' => $mark_ary,
1.230 + 'g' => $group_id,
1.231 + 'i' => $id,
1.232 + 'mode' => $mode,
1.233 + 'action' => $action))
1.234 + );
1.235 + }
1.236 + break;
1.237 +
1.238 + case 'addusers':
1.239 + if (!$group_id)
1.240 + {
1.241 + trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
1.242 + }
1.243 +
1.244 + if (!$name_ary)
1.245 + {
1.246 + trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING);
1.247 + }
1.248 +
1.249 + $name_ary = array_unique(explode("\n", $name_ary));
1.250 + $group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
1.251 +
1.252 + // Add user/s to group
1.253 + if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, $leader, 0, $group_row))
1.254 + {
1.255 + trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING);
1.256 + }
1.257 +
1.258 + $message = ($leader) ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED';
1.259 + trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id));
1.260 + break;
1.261 +
1.262 + case 'edit':
1.263 + case 'add':
1.264 +
1.265 + include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
1.266 +
1.267 + $data = $submit_ary = array();
1.268 +
1.269 + if ($action == 'edit' && !$group_id)
1.270 + {
1.271 + trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
1.272 + }
1.273 +
1.274 + if ($action == 'add' && !$auth->acl_get('a_groupadd'))
1.275 + {
1.276 + trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
1.277 + }
1.278 +
1.279 + $error = array();
1.280 + $user->add_lang('ucp');
1.281 +
1.282 + $avatar_select = basename(request_var('avatar_select', ''));
1.283 + $category = basename(request_var('category', ''));
1.284 +
1.285 + // Did we submit?
1.286 + if ($update)
1.287 + {
1.288 + if (!check_form_key($form_key))
1.289 + {
1.290 + trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
1.291 + }
1.292 +
1.293 + $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
1.294 + $group_desc = utf8_normalize_nfc(request_var('group_desc', '', true));
1.295 + $group_type = request_var('group_type', GROUP_FREE);
1.296 +
1.297 + $allow_desc_bbcode = request_var('desc_parse_bbcode', false);
1.298 + $allow_desc_urls = request_var('desc_parse_urls', false);
1.299 + $allow_desc_smilies = request_var('desc_parse_smilies', false);
1.300 +
1.301 + $data['uploadurl'] = request_var('uploadurl', '');
1.302 + $data['remotelink'] = request_var('remotelink', '');
1.303 + $data['width'] = request_var('width', '');
1.304 + $data['height'] = request_var('height', '');
1.305 + $delete = request_var('delete', '');
1.306 +
1.307 + $submit_ary = array(
1.308 + 'colour' => request_var('group_colour', ''),
1.309 + 'rank' => request_var('group_rank', 0),
1.310 + 'receive_pm' => isset($_REQUEST['group_receive_pm']) ? 1 : 0,
1.311 + 'legend' => isset($_REQUEST['group_legend']) ? 1 : 0,
1.312 + 'message_limit' => request_var('group_message_limit', 0),
1.313 + 'max_recipients' => request_var('group_max_recipients', 0),
1.314 + 'founder_manage' => 0,
1.315 + 'skip_auth' => request_var('group_skip_auth', 0),
1.316 + );
1.317 +
1.318 + if ($user->data['user_type'] == USER_FOUNDER)
1.319 + {
1.320 + $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0;
1.321 + }
1.322 +
1.323 + if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink'])
1.324 + {
1.325 + // Avatar stuff
1.326 + $var_ary = array(
1.327 + 'uploadurl' => array('string', true, 5, 255),
1.328 + 'remotelink' => array('string', true, 5, 255),
1.329 + 'width' => array('string', true, 1, 3),
1.330 + 'height' => array('string', true, 1, 3),
1.331 + );
1.332 +
1.333 + if (!($error = validate_data($data, $var_ary)))
1.334 + {
1.335 + $data['user_id'] = "g$group_id";
1.336 +
1.337 + if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload)
1.338 + {
1.339 + list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error);
1.340 + }
1.341 + else if ($data['remotelink'])
1.342 + {
1.343 + list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error);
1.344 + }
1.345 + }
1.346 + }
1.347 + else if ($avatar_select && $config['allow_avatar_local'])
1.348 + {
1.349 + // check avatar gallery
1.350 + if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category))
1.351 + {
1.352 + $submit_ary['avatar_type'] = AVATAR_GALLERY;
1.353 +
1.354 + list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select);
1.355 + $submit_ary['avatar'] = $category . '/' . $avatar_select;
1.356 + }
1.357 + }
1.358 + else if ($delete)
1.359 + {
1.360 + $submit_ary['avatar'] = '';
1.361 + $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0;
1.362 + }
1.363 + else if ($data['width'] && $data['height'])
1.364 + {
1.365 + // Only update the dimensions?
1.366 + if ($config['avatar_max_width'] || $config['avatar_max_height'])
1.367 + {
1.368 + if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height'])
1.369 + {
1.370 + $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']);
1.371 + }
1.372 + }
1.373 +
1.374 + if (!sizeof($error))
1.375 + {
1.376 + if ($config['avatar_min_width'] || $config['avatar_min_height'])
1.377 + {
1.378 + if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height'])
1.379 + {
1.380 + $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']);
1.381 + }
1.382 + }
1.383 + }
1.384 +
1.385 + if (!sizeof($error))
1.386 + {
1.387 + $submit_ary['avatar_width'] = $data['width'];
1.388 + $submit_ary['avatar_height'] = $data['height'];
1.389 + }
1.390 + }
1.391 +
1.392 + if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']))) || $delete)
1.393 + {
1.394 + if (isset($group_row['group_avatar']) && $group_row['group_avatar'])
1.395 + {
1.396 + avatar_delete('group', $group_row, true);
1.397 + }
1.398 + }
1.399 +
1.400 + // Validate the length of "Maximum number of allowed recipients per private message" setting.
1.401 + // We use 16777215 as a maximum because it matches MySQL unsigned mediumint maximum value
1.402 + // which is the lowest amongst DBMSes supported by phpBB3
1.403 + if ($max_recipients_error = validate_data($submit_ary, array('max_recipients' => array('num', false, 0, 16777215))))
1.404 + {
1.405 + // Replace "error" string with its real, localised form
1.406 + $error = array_merge($error, array_map(array(&$user, 'lang'), $max_recipients_error));
1.407 + }
1.408 +
1.409 + if (!sizeof($error))
1.410 + {
1.411 + // Only set the rank, colour, etc. if it's changed or if we're adding a new
1.412 + // group. This prevents existing group members being updated if no changes
1.413 + // were made.
1.414 +
1.415 + $group_attributes = array();
1.416 + $test_variables = array(
1.417 + 'rank' => 'int',
1.418 + 'colour' => 'string',
1.419 + 'avatar' => 'string',
1.420 + 'avatar_type' => 'int',
1.421 + 'avatar_width' => 'int',
1.422 + 'avatar_height' => 'int',
1.423 + 'receive_pm' => 'int',
1.424 + 'legend' => 'int',
1.425 + 'message_limit' => 'int',
1.426 + 'max_recipients'=> 'int',
1.427 + 'founder_manage'=> 'int',
1.428 + 'skip_auth' => 'int',
1.429 + );
1.430 +
1.431 + foreach ($test_variables as $test => $type)
1.432 + {
1.433 + if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test]))
1.434 + {
1.435 + settype($submit_ary[$test], $type);
1.436 + $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
1.437 + }
1.438 + }
1.439 +
1.440 + if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies)))
1.441 + {
1.442 + $group_perm_from = request_var('group_perm_from', 0);
1.443 +
1.444 + // Copy permissions?
1.445 + // If the user has the a_authgroups permission and at least one additional permission ability set the permissions are fully transferred.
1.446 + // 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.
1.447 + // Since the user only has the option to copy permissions from non leader managed groups this seems to be a good compromise.
1.448 + if ($group_perm_from && $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth'))
1.449 + {
1.450 + $sql = 'SELECT group_founder_manage
1.451 + FROM ' . GROUPS_TABLE . '
1.452 + WHERE group_id = ' . $group_perm_from;
1.453 + $result = $db->sql_query($sql);
1.454 + $check_row = $db->sql_fetchrow($result);
1.455 + $db->sql_freeresult($result);
1.456 +
1.457 + // Check the group if non-founder
1.458 + if ($check_row && ($user->data['user_type'] == USER_FOUNDER || $check_row['group_founder_manage'] == 0))
1.459 + {
1.460 + // From the mysql documentation:
1.461 + // 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.
1.462 + // Due to this we stay on the safe side if we do the insertion "the manual way"
1.463 +
1.464 + // Copy permisisons from/to the acl groups table (only group_id gets changed)
1.465 + $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting
1.466 + FROM ' . ACL_GROUPS_TABLE . '
1.467 + WHERE group_id = ' . $group_perm_from;
1.468 + $result = $db->sql_query($sql);
1.469 +
1.470 + $groups_sql_ary = array();
1.471 + while ($row = $db->sql_fetchrow($result))
1.472 + {
1.473 + $groups_sql_ary[] = array(
1.474 + 'group_id' => (int) $group_id,
1.475 + 'forum_id' => (int) $row['forum_id'],
1.476 + 'auth_option_id' => (int) $row['auth_option_id'],
1.477 + 'auth_role_id' => (int) $row['auth_role_id'],
1.478 + 'auth_setting' => (int) $row['auth_setting']
1.479 + );
1.480 + }
1.481 + $db->sql_freeresult($result);
1.482 +
1.483 + // Now insert the data
1.484 + $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
1.485 +
1.486 + $auth->acl_clear_prefetch();
1.487 + }
1.488 + }
1.489 +
1.490 + $cache->destroy('sql', GROUPS_TABLE);
1.491 +
1.492 + $message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED';
1.493 + trigger_error($user->lang[$message] . adm_back_link($this->u_action));
1.494 + }
1.495 + }
1.496 +
1.497 + if (sizeof($error))
1.498 + {
1.499 + $group_rank = $submit_ary['rank'];
1.500 +
1.501 + $group_desc_data = array(
1.502 + 'text' => $group_desc,
1.503 + 'allow_bbcode' => $allow_desc_bbcode,
1.504 + 'allow_smilies' => $allow_desc_smilies,
1.505 + 'allow_urls' => $allow_desc_urls
1.506 + );
1.507 + }
1.508 + }
1.509 + else if (!$group_id)
1.510 + {
1.511 + $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
1.512 + $group_desc_data = array(
1.513 + 'text' => '',
1.514 + 'allow_bbcode' => true,
1.515 + 'allow_smilies' => true,
1.516 + 'allow_urls' => true
1.517 + );
1.518 + $group_rank = 0;
1.519 + $group_type = GROUP_OPEN;
1.520 + }
1.521 + else
1.522 + {
1.523 + $group_name = $group_row['group_name'];
1.524 + $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']);
1.525 + $group_type = $group_row['group_type'];
1.526 + $group_rank = $group_row['group_rank'];
1.527 + }
1.528 +
1.529 + $sql = 'SELECT *
1.530 + FROM ' . RANKS_TABLE . '
1.531 + WHERE rank_special = 1
1.532 + ORDER BY rank_title';
1.533 + $result = $db->sql_query($sql);
1.534 +
1.535 + $rank_options = '<option value="0"' . ((!$group_rank) ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>';
1.536 +
1.537 + while ($row = $db->sql_fetchrow($result))
1.538 + {
1.539 + $selected = ($group_rank && $row['rank_id'] == $group_rank) ? ' selected="selected"' : '';
1.540 + $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
1.541 + }
1.542 + $db->sql_freeresult($result);
1.543 +
1.544 + $type_free = ($group_type == GROUP_FREE) ? ' checked="checked"' : '';
1.545 + $type_open = ($group_type == GROUP_OPEN) ? ' checked="checked"' : '';
1.546 + $type_closed = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : '';
1.547 + $type_hidden = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : '';
1.548 +
1.549 + $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="" />';
1.550 +
1.551 + $display_gallery = (isset($_POST['display_gallery'])) ? true : false;
1.552 +
1.553 + if ($config['allow_avatar_local'] && $display_gallery)
1.554 + {
1.555 + avatar_gallery($category, $avatar_select, 4);
1.556 + }
1.557 +
1.558 + $back_link = request_var('back_link', '');
1.559 +
1.560 + switch ($back_link)
1.561 + {
1.562 + case 'acp_users_groups':
1.563 + $u_back = append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=groups&u=' . request_var('u', 0));
1.564 + break;
1.565 +
1.566 + default:
1.567 + $u_back = $this->u_action;
1.568 + break;
1.569 + }
1.570 +
1.571 + $template->assign_vars(array(
1.572 + 'S_EDIT' => true,
1.573 + 'S_ADD_GROUP' => ($action == 'add') ? true : false,
1.574 + 'S_GROUP_PERM' => ($action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) ? true : false,
1.575 + 'S_INCLUDE_SWATCH' => true,
1.576 + 'S_CAN_UPLOAD' => $can_upload,
1.577 + 'S_ERROR' => (sizeof($error)) ? true : false,
1.578 + 'S_SPECIAL_GROUP' => ($group_type == GROUP_SPECIAL) ? true : false,
1.579 + 'S_DISPLAY_GALLERY' => ($config['allow_avatar_local'] && !$display_gallery) ? true : false,
1.580 + 'S_IN_GALLERY' => ($config['allow_avatar_local'] && $display_gallery) ? true : false,
1.581 + 'S_USER_FOUNDER' => ($user->data['user_type'] == USER_FOUNDER) ? true : false,
1.582 +
1.583 + 'ERROR_MSG' => (sizeof($error)) ? implode('<br />', $error) : '',
1.584 + 'GROUP_NAME' => ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name,
1.585 + 'GROUP_INTERNAL_NAME' => $group_name,
1.586 + 'GROUP_DESC' => $group_desc_data['text'],
1.587 + 'GROUP_RECEIVE_PM' => (isset($group_row['group_receive_pm']) && $group_row['group_receive_pm']) ? ' checked="checked"' : '',
1.588 + 'GROUP_FOUNDER_MANAGE' => (isset($group_row['group_founder_manage']) && $group_row['group_founder_manage']) ? ' checked="checked"' : '',
1.589 + 'GROUP_LEGEND' => (isset($group_row['group_legend']) && $group_row['group_legend']) ? ' checked="checked"' : '',
1.590 + 'GROUP_MESSAGE_LIMIT' => (isset($group_row['group_message_limit'])) ? $group_row['group_message_limit'] : 0,
1.591 + 'GROUP_MAX_RECIPIENTS' => (isset($group_row['group_max_recipients'])) ? $group_row['group_max_recipients'] : 0,
1.592 + 'GROUP_COLOUR' => (isset($group_row['group_colour'])) ? $group_row['group_colour'] : '',
1.593 + 'GROUP_SKIP_AUTH' => (!empty($group_row['group_skip_auth'])) ? ' checked="checked"' : '',
1.594 +
1.595 + 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'],
1.596 + 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'],
1.597 + 'S_DESC_SMILIES_CHECKED'=> $group_desc_data['allow_smilies'],
1.598 +
1.599 + 'S_RANK_OPTIONS' => $rank_options,
1.600 + 'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)),
1.601 + 'AVATAR' => $avatar_img,
1.602 + 'AVATAR_IMAGE' => $avatar_img,
1.603 + 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'],
1.604 + 'AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '',
1.605 + 'AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '',
1.606 +
1.607 + 'GROUP_TYPE_FREE' => GROUP_FREE,
1.608 + 'GROUP_TYPE_OPEN' => GROUP_OPEN,
1.609 + 'GROUP_TYPE_CLOSED' => GROUP_CLOSED,
1.610 + 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN,
1.611 + 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL,
1.612 +
1.613 + 'GROUP_FREE' => $type_free,
1.614 + 'GROUP_OPEN' => $type_open,
1.615 + 'GROUP_CLOSED' => $type_closed,
1.616 + 'GROUP_HIDDEN' => $type_hidden,
1.617 +
1.618 + 'U_BACK' => $u_back,
1.619 + 'U_SWATCH' => append_sid("{$phpbb_admin_path}swatch.$phpEx", 'form=settings&name=group_colour'),
1.620 + 'U_ACTION' => "{$this->u_action}&action=$action&g=$group_id",
1.621 + 'L_AVATAR_EXPLAIN' => sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)),
1.622 + ));
1.623 +
1.624 + return;
1.625 + break;
1.626 +
1.627 + case 'list':
1.628 +
1.629 + if (!$group_id)
1.630 + {
1.631 + trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
1.632 + }
1.633 +
1.634 + $this->page_title = 'GROUP_MEMBERS';
1.635 +
1.636 + // Grab the leaders - always, on every page...
1.637 + $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
1.638 + FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
1.639 + WHERE ug.group_id = $group_id
1.640 + AND u.user_id = ug.user_id
1.641 + AND ug.group_leader = 1
1.642 + ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean";
1.643 + $result = $db->sql_query($sql);
1.644 +
1.645 + while ($row = $db->sql_fetchrow($result))
1.646 + {
1.647 + $template->assign_block_vars('leader', array(
1.648 + 'U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&action=edit&u={$row['user_id']}"),
1.649 +
1.650 + 'USERNAME' => $row['username'],
1.651 + 'USERNAME_COLOUR' => $row['user_colour'],
1.652 + 'S_GROUP_DEFAULT' => ($row['group_id'] == $group_id) ? true : false,
1.653 + 'JOINED' => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
1.654 + 'USER_POSTS' => $row['user_posts'],
1.655 + 'USER_ID' => $row['user_id'],
1.656 + ));
1.657 + }
1.658 + $db->sql_freeresult($result);
1.659 +
1.660 + // Total number of group members (non-leaders)
1.661 + $sql = 'SELECT COUNT(user_id) AS total_members
1.662 + FROM ' . USER_GROUP_TABLE . "
1.663 + WHERE group_id = $group_id
1.664 + AND group_leader = 0";
1.665 + $result = $db->sql_query($sql);
1.666 + $total_members = (int) $db->sql_fetchfield('total_members');
1.667 + $db->sql_freeresult($result);
1.668 +
1.669 + $s_action_options = '';
1.670 + $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE');
1.671 +
1.672 + foreach ($options as $option => $lang)
1.673 + {
1.674 + $s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>';
1.675 + }
1.676 +
1.677 + $template->assign_vars(array(
1.678 + 'S_LIST' => true,
1.679 + 'S_GROUP_SPECIAL' => ($group_row['group_type'] == GROUP_SPECIAL) ? true : false,
1.680 + 'S_ACTION_OPTIONS' => $s_action_options,
1.681 +
1.682 + 'S_ON_PAGE' => on_page($total_members, $config['topics_per_page'], $start),
1.683 + 'PAGINATION' => generate_pagination($this->u_action . "&action=$action&g=$group_id", $total_members, $config['topics_per_page'], $start, true),
1.684 + 'GROUP_NAME' => ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
1.685 +
1.686 + 'U_ACTION' => $this->u_action . "&g=$group_id",
1.687 + 'U_BACK' => $this->u_action,
1.688 + 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=list&field=usernames'),
1.689 + 'U_DEFAULT_ALL' => "{$this->u_action}&action=default&g=$group_id",
1.690 + ));
1.691 +
1.692 + // Grab the members
1.693 + $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
1.694 + FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
1.695 + WHERE ug.group_id = $group_id
1.696 + AND u.user_id = ug.user_id
1.697 + AND ug.group_leader = 0
1.698 + ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean";
1.699 + $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
1.700 +
1.701 + $pending = false;
1.702 +
1.703 + while ($row = $db->sql_fetchrow($result))
1.704 + {
1.705 + if ($row['user_pending'] && !$pending)
1.706 + {
1.707 + $template->assign_block_vars('member', array(
1.708 + 'S_PENDING' => true)
1.709 + );
1.710 +
1.711 + $pending = true;
1.712 + }
1.713 +
1.714 + $template->assign_block_vars('member', array(
1.715 + 'U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&action=edit&u={$row['user_id']}"),
1.716 +
1.717 + 'USERNAME' => $row['username'],
1.718 + 'USERNAME_COLOUR' => $row['user_colour'],
1.719 + 'S_GROUP_DEFAULT' => ($row['group_id'] == $group_id) ? true : false,
1.720 + 'JOINED' => ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
1.721 + 'USER_POSTS' => $row['user_posts'],
1.722 + 'USER_ID' => $row['user_id'])
1.723 + );
1.724 + }
1.725 + $db->sql_freeresult($result);
1.726 +
1.727 + return;
1.728 + break;
1.729 + }
1.730 +
1.731 + $template->assign_vars(array(
1.732 + 'U_ACTION' => $this->u_action,
1.733 + 'S_GROUP_ADD' => ($auth->acl_get('a_groupadd')) ? true : false)
1.734 + );
1.735 +
1.736 + // Get us all the groups
1.737 + $sql = 'SELECT g.group_id, g.group_name, g.group_type
1.738 + FROM ' . GROUPS_TABLE . ' g
1.739 + ORDER BY g.group_type ASC, g.group_name';
1.740 + $result = $db->sql_query($sql);
1.741 +
1.742 + $lookup = $cached_group_data = array();
1.743 + while ($row = $db->sql_fetchrow($result))
1.744 + {
1.745 + $type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : 'normal';
1.746 +
1.747 + // used to determine what type a group is
1.748 + $lookup[$row['group_id']] = $type;
1.749 +
1.750 + // used for easy access to the data within a group
1.751 + $cached_group_data[$type][$row['group_id']] = $row;
1.752 + $cached_group_data[$type][$row['group_id']]['total_members'] = 0;
1.753 + }
1.754 + $db->sql_freeresult($result);
1.755 +
1.756 + // How many people are in which group?
1.757 + $sql = 'SELECT COUNT(ug.user_id) AS total_members, ug.group_id
1.758 + FROM ' . USER_GROUP_TABLE . ' ug
1.759 + WHERE ' . $db->sql_in_set('ug.group_id', array_keys($lookup)) . '
1.760 + GROUP BY ug.group_id';
1.761 + $result = $db->sql_query($sql);
1.762 +
1.763 + while ($row = $db->sql_fetchrow($result))
1.764 + {
1.765 + $type = $lookup[$row['group_id']];
1.766 + $cached_group_data[$type][$row['group_id']]['total_members'] = $row['total_members'];
1.767 + }
1.768 + $db->sql_freeresult($result);
1.769 +
1.770 + // The order is... normal, then special
1.771 + ksort($cached_group_data);
1.772 +
1.773 + foreach ($cached_group_data as $type => $row_ary)
1.774 + {
1.775 + if ($type == 'special')
1.776 + {
1.777 + $template->assign_block_vars('groups', array(
1.778 + 'S_SPECIAL' => true)
1.779 + );
1.780 + }
1.781 +
1.782 + foreach ($row_ary as $group_id => $row)
1.783 + {
1.784 + $group_name = (!empty($user->lang['G_' . $row['group_name']]))? $user->lang['G_' . $row['group_name']] : $row['group_name'];
1.785 +
1.786 + $template->assign_block_vars('groups', array(
1.787 + 'U_LIST' => "{$this->u_action}&action=list&g=$group_id",
1.788 + 'U_EDIT' => "{$this->u_action}&action=edit&g=$group_id",
1.789 + 'U_DELETE' => ($auth->acl_get('a_groupdel')) ? "{$this->u_action}&action=delete&g=$group_id" : '',
1.790 +
1.791 + 'S_GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL) ? true : false,
1.792 +
1.793 + 'GROUP_NAME' => $group_name,
1.794 + 'TOTAL_MEMBERS' => $row['total_members'],
1.795 + ));
1.796 + }
1.797 + }
1.798 + }
1.799 +}
1.800 +
1.801 +?>
1.802 \ No newline at end of file