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

