6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
26 function main($id, $mode)
28 global $config, $db, $user, $auth, $template, $cache;
29 global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
31 $user->add_lang('acp/groups');
32 $this->tpl_name
= 'acp_groups';
33 $this->page_title
= 'ACP_GROUPS_MANAGE';
35 $form_key = 'acp_groups';
36 add_form_key($form_key);
38 include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
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;
52 $can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable
($phpbb_root_path . $config['avatar_path']) && $file_uploads) ?
true : false;
55 // Grab basic data for group, if group_id is set and exists
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);
67 trigger_error($user->lang
['NO_GROUP'] . adm_back_link($this->u_action
), E_USER_WARNING
);
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'])
73 trigger_error($user->lang
['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action
), E_USER_WARNING
);
85 trigger_error($user->lang
['NO_GROUP'] . adm_back_link($this->u_action
), E_USER_WARNING
);
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);
97 $message = 'GROUP_MODS_DEMOTED';
101 $message = 'GROUP_MODS_PROMOTED';
105 $message = 'USERS_APPROVED';
109 trigger_error($user->lang
[$message] . adm_back_link($this->u_action
. '&action=list&g=' . $group_id));
113 trigger_error($user->lang
[$error] . adm_back_link($this->u_action
. '&action=list&g=' . $group_id), E_USER_WARNING
);
121 trigger_error($user->lang
['NO_GROUP'] . adm_back_link($this->u_action
), E_USER_WARNING
);
124 if (confirm_box(true))
126 $group_name = ($group_row['group_type'] == GROUP_SPECIAL
) ?
$user->lang
['G_' . $group_row['group_name']] : $group_row['group_name'];
128 if (!sizeof($mark_ary))
134 $sql = 'SELECT user_id
135 FROM ' . USER_GROUP_TABLE
. "
136 WHERE group_id = $group_id
138 $result = $db->sql_query_limit($sql, 200, $start);
141 if ($row = $db->sql_fetchrow($result))
145 $mark_ary[] = $row['user_id'];
147 while ($row = $db->sql_fetchrow($result));
149 group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
151 $start = (sizeof($mark_ary) < 200) ?
0 : $start +
200;
157 $db->sql_freeresult($result);
163 group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
166 trigger_error($user->lang
['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action
. '&action=list&g=' . $group_id));
170 confirm_box(false, $user->lang
['CONFIRM_OPERATION'], build_hidden_fields(array(
175 'action' => $action))
185 trigger_error($user->lang
['NO_GROUP'] . adm_back_link($this->u_action
), E_USER_WARNING
);
187 else if ($action === 'delete' && $group_row['group_type'] == GROUP_SPECIAL
)
189 trigger_error($user->lang
['NO_AUTH_OPERATION'] . adm_back_link($this->u_action
), E_USER_WARNING
);
192 if (confirm_box(true))
199 if (!$auth->acl_get('a_groupdel'))
201 trigger_error($user->lang
['NO_AUTH_OPERATION'] . adm_back_link($this->u_action
), E_USER_WARNING
);
204 $error = group_delete($group_id, $group_row['group_name']);
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);
213 $back_link = ($action == 'delete') ?
$this->u_action
: $this->u_action
. '&action=list&g=' . $group_id;
217 trigger_error($user->lang
[$error] . adm_back_link($back_link), E_USER_WARNING
);
220 $message = ($action == 'delete') ?
'GROUP_DELETED' : 'GROUP_USERS_REMOVE';
221 trigger_error($user->lang
[$message] . adm_back_link($back_link));
225 confirm_box(false, $user->lang
['CONFIRM_OPERATION'], build_hidden_fields(array(
230 'action' => $action))
238 trigger_error($user->lang
['NO_GROUP'] . adm_back_link($this->u_action
), E_USER_WARNING
);
243 trigger_error($user->lang
['NO_USERS'] . adm_back_link($this->u_action
. '&action=list&g=' . $group_id), E_USER_WARNING
);
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'];
249 // Add user/s to group
250 if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, $leader, 0, $group_row))
252 trigger_error($user->lang
[$error] . adm_back_link($this->u_action
. '&action=list&g=' . $group_id), E_USER_WARNING
);
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));
262 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
264 $data = $submit_ary = array();
266 if ($action == 'edit' && !$group_id)
268 trigger_error($user->lang
['NO_GROUP'] . adm_back_link($this->u_action
), E_USER_WARNING
);
271 if ($action == 'add' && !$auth->acl_get('a_groupadd'))
273 trigger_error($user->lang
['NO_AUTH_OPERATION'] . adm_back_link($this->u_action
), E_USER_WARNING
);
277 $user->add_lang('ucp');
279 $avatar_select = basename(request_var('avatar_select', ''));
280 $category = basename(request_var('category', ''));
285 if (!check_form_key($form_key))
287 trigger_error($user->lang
['FORM_INVALID'] . adm_back_link($this->u_action
), E_USER_WARNING
);
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
);
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);
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', '');
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),
315 if ($user->data
['user_type'] == USER_FOUNDER
)
317 $submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ?
1 : 0;
320 if (!empty($_FILES['uploadfile']['tmp_name']) ||
$data['uploadurl'] ||
$data['remotelink'])
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),
330 if (!($error = validate_data($data, $var_ary)))
332 $data['user_id'] = "g$group_id";
334 if ((!empty($_FILES['uploadfile']['tmp_name']) ||
$data['uploadurl']) && $can_upload)
336 list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error);
338 else if ($data['remotelink'])
340 list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error);
344 else if ($avatar_select && $config['allow_avatar_local'])
346 // check avatar gallery
347 if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category))
349 $submit_ary['avatar_type'] = AVATAR_GALLERY
;
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;
357 $submit_ary['avatar'] = '';
358 $submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0;
360 else if ($data['width'] && $data['height'])
362 // Only update the dimensions?
363 if ($config['avatar_max_width'] ||
$config['avatar_max_height'])
365 if ($data['width'] > $config['avatar_max_width'] ||
$data['height'] > $config['avatar_max_height'])
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']);
373 if ($config['avatar_min_width'] ||
$config['avatar_min_height'])
375 if ($data['width'] < $config['avatar_min_width'] ||
$data['height'] < $config['avatar_min_height'])
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']);
384 $submit_ary['avatar_width'] = $data['width'];
385 $submit_ary['avatar_height'] = $data['height'];
389 if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']))) ||
$delete)
391 if (isset($group_row['group_avatar']) && $group_row['group_avatar'])
393 avatar_delete('group', $group_row, true);
399 // Only set the rank, colour, etc. if it's changed or if we're adding a new
400 // group. This prevents existing group members being updated if no changes
403 $group_attributes = array();
404 $test_variables = array(
406 'colour' => 'string',
407 'avatar' => 'string',
408 'avatar_type' => 'int',
409 'avatar_width' => 'int',
410 'avatar_height' => 'int',
411 'receive_pm' => 'int',
413 'message_limit' => 'int',
414 'max_recipients'=> 'int',
415 'founder_manage'=> 'int',
416 'skip_auth' => 'int',
419 foreach ($test_variables as $test => $type)
421 if (isset($submit_ary[$test]) && ($action == 'add' ||
$group_row['group_' . $test] != $submit_ary[$test]))
423 settype($submit_ary[$test], $type);
424 $group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
428 if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies)))
430 $group_perm_from = request_var('group_perm_from', 0);
433 // If the user has the a_authgroups permission and at least one additional permission ability set the permissions are fully transferred.
434 // 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.
435 // Since the user only has the option to copy permissions from non leader managed groups this seems to be a good compromise.
436 if ($group_perm_from && $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth'))
438 $sql = 'SELECT group_founder_manage
439 FROM ' . GROUPS_TABLE
. '
440 WHERE group_id = ' . $group_perm_from;
441 $result = $db->sql_query($sql);
442 $check_row = $db->sql_fetchrow($result);
443 $db->sql_freeresult($result);
445 // Check the group if non-founder
446 if ($check_row && ($user->data
['user_type'] == USER_FOUNDER ||
$check_row['group_founder_manage'] == 0))
448 // From the mysql documentation:
449 // 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.
450 // Due to this we stay on the safe side if we do the insertion "the manual way"
452 // Copy permisisons from/to the acl groups table (only group_id gets changed)
453 $sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting
454 FROM ' . ACL_GROUPS_TABLE
. '
455 WHERE group_id = ' . $group_perm_from;
456 $result = $db->sql_query($sql);
458 $groups_sql_ary = array();
459 while ($row = $db->sql_fetchrow($result))
461 $groups_sql_ary[] = array(
462 'group_id' => (int) $group_id,
463 'forum_id' => (int) $row['forum_id'],
464 'auth_option_id' => (int) $row['auth_option_id'],
465 'auth_role_id' => (int) $row['auth_role_id'],
466 'auth_setting' => (int) $row['auth_setting']
469 $db->sql_freeresult($result);
471 // Now insert the data
472 $db->sql_multi_insert(ACL_GROUPS_TABLE
, $groups_sql_ary);
474 $auth->acl_clear_prefetch();
478 $cache->destroy('sql', GROUPS_TABLE
);
480 $message = ($action == 'edit') ?
'GROUP_UPDATED' : 'GROUP_CREATED';
481 trigger_error($user->lang
[$message] . adm_back_link($this->u_action
));
487 $group_rank = $submit_ary['rank'];
489 $group_desc_data = array(
490 'text' => $group_desc,
491 'allow_bbcode' => $allow_desc_bbcode,
492 'allow_smilies' => $allow_desc_smilies,
493 'allow_urls' => $allow_desc_urls
499 $group_name = utf8_normalize_nfc(request_var('group_name', '', true));
500 $group_desc_data = array(
502 'allow_bbcode' => true,
503 'allow_smilies' => true,
507 $group_type = GROUP_OPEN
;
511 $group_name = $group_row['group_name'];
512 $group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']);
513 $group_type = $group_row['group_type'];
514 $group_rank = $group_row['group_rank'];
518 FROM ' . RANKS_TABLE
. '
519 WHERE rank_special = 1
520 ORDER BY rank_title';
521 $result = $db->sql_query($sql);
523 $rank_options = '<option value="0"' . ((!$group_rank) ?
' selected="selected"' : '') . '>' . $user->lang
['USER_DEFAULT'] . '</option>';
525 while ($row = $db->sql_fetchrow($result))
527 $selected = ($group_rank && $row['rank_id'] == $group_rank) ?
' selected="selected"' : '';
528 $rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
530 $db->sql_freeresult($result);
532 $type_free = ($group_type == GROUP_FREE
) ?
' checked="checked"' : '';
533 $type_open = ($group_type == GROUP_OPEN
) ?
' checked="checked"' : '';
534 $type_closed = ($group_type == GROUP_CLOSED
) ?
' checked="checked"' : '';
535 $type_hidden = ($group_type == GROUP_HIDDEN
) ?
' checked="checked"' : '';
537 $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="" />';
539 $display_gallery = (isset($_POST['display_gallery'])) ?
true : false;
541 if ($config['allow_avatar_local'] && $display_gallery)
543 avatar_gallery($category, $avatar_select, 4);
546 $back_link = request_var('back_link', '');
550 case 'acp_users_groups':
551 $u_back = append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=groups&u=' . request_var('u', 0));
555 $u_back = $this->u_action
;
559 $template->assign_vars(array(
561 'S_ADD_GROUP' => ($action == 'add') ?
true : false,
562 'S_GROUP_PERM' => ($action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) ?
true : false,
563 'S_INCLUDE_SWATCH' => true,
564 'S_CAN_UPLOAD' => $can_upload,
565 'S_ERROR' => (sizeof($error)) ?
true : false,
566 'S_SPECIAL_GROUP' => ($group_type == GROUP_SPECIAL
) ?
true : false,
567 'S_DISPLAY_GALLERY' => ($config['allow_avatar_local'] && !$display_gallery) ?
true : false,
568 'S_IN_GALLERY' => ($config['allow_avatar_local'] && $display_gallery) ?
true : false,
569 'S_USER_FOUNDER' => ($user->data
['user_type'] == USER_FOUNDER
) ?
true : false,
571 'ERROR_MSG' => (sizeof($error)) ?
implode('<br />', $error) : '',
572 'GROUP_NAME' => ($group_type == GROUP_SPECIAL
) ?
$user->lang
['G_' . $group_name] : $group_name,
573 'GROUP_INTERNAL_NAME' => $group_name,
574 'GROUP_DESC' => $group_desc_data['text'],
575 'GROUP_RECEIVE_PM' => (isset($group_row['group_receive_pm']) && $group_row['group_receive_pm']) ?
' checked="checked"' : '',
576 'GROUP_FOUNDER_MANAGE' => (isset($group_row['group_founder_manage']) && $group_row['group_founder_manage']) ?
' checked="checked"' : '',
577 'GROUP_LEGEND' => (isset($group_row['group_legend']) && $group_row['group_legend']) ?
' checked="checked"' : '',
578 'GROUP_MESSAGE_LIMIT' => (isset($group_row['group_message_limit'])) ?
$group_row['group_message_limit'] : 0,
579 'GROUP_MAX_RECIPIENTS' => (isset($group_row['group_max_recipients'])) ?
$group_row['group_max_recipients'] : 0,
580 'GROUP_COLOUR' => (isset($group_row['group_colour'])) ?
$group_row['group_colour'] : '',
581 'GROUP_SKIP_AUTH' => (!empty($group_row['group_skip_auth'])) ?
' checked="checked"' : '',
583 'S_DESC_BBCODE_CHECKED' => $group_desc_data['allow_bbcode'],
584 'S_DESC_URLS_CHECKED' => $group_desc_data['allow_urls'],
585 'S_DESC_SMILIES_CHECKED'=> $group_desc_data['allow_smilies'],
587 'S_RANK_OPTIONS' => $rank_options,
588 'S_GROUP_OPTIONS' => group_select_options(false, false, (($user->data
['user_type'] == USER_FOUNDER
) ?
false : 0)),
589 'AVATAR' => $avatar_img,
590 'AVATAR_IMAGE' => $avatar_img,
591 'AVATAR_MAX_FILESIZE' => $config['avatar_filesize'],
592 'AVATAR_WIDTH' => (isset($group_row['group_avatar_width'])) ?
$group_row['group_avatar_width'] : '',
593 'AVATAR_HEIGHT' => (isset($group_row['group_avatar_height'])) ?
$group_row['group_avatar_height'] : '',
595 'GROUP_TYPE_FREE' => GROUP_FREE
,
596 'GROUP_TYPE_OPEN' => GROUP_OPEN
,
597 'GROUP_TYPE_CLOSED' => GROUP_CLOSED
,
598 'GROUP_TYPE_HIDDEN' => GROUP_HIDDEN
,
599 'GROUP_TYPE_SPECIAL' => GROUP_SPECIAL
,
601 'GROUP_FREE' => $type_free,
602 'GROUP_OPEN' => $type_open,
603 'GROUP_CLOSED' => $type_closed,
604 'GROUP_HIDDEN' => $type_hidden,
607 'U_SWATCH' => append_sid("{$phpbb_admin_path}swatch.$phpEx", 'form=settings&name=group_colour'),
608 'U_ACTION' => "{$this->u_action}&action=$action&g=$group_id",
609 'L_AVATAR_EXPLAIN' => sprintf($user->lang
['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)),
619 trigger_error($user->lang
['NO_GROUP'] . adm_back_link($this->u_action
), E_USER_WARNING
);
622 $this->page_title
= 'GROUP_MEMBERS';
624 // Grab the leaders - always, on every page...
625 $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
626 FROM ' . USERS_TABLE
. ' u, ' . USER_GROUP_TABLE
. " ug
627 WHERE ug.group_id = $group_id
628 AND u.user_id = ug.user_id
629 AND ug.group_leader = 1
630 ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean";
631 $result = $db->sql_query($sql);
633 while ($row = $db->sql_fetchrow($result))
635 $template->assign_block_vars('leader', array(
636 'U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&action=edit&u={$row['user_id']}"),
638 'USERNAME' => $row['username'],
639 'USERNAME_COLOUR' => $row['user_colour'],
640 'S_GROUP_DEFAULT' => ($row['group_id'] == $group_id) ?
true : false,
641 'JOINED' => ($row['user_regdate']) ?
$user->format_date($row['user_regdate']) : ' - ',
642 'USER_POSTS' => $row['user_posts'],
643 'USER_ID' => $row['user_id'],
646 $db->sql_freeresult($result);
648 // Total number of group members (non-leaders)
649 $sql = 'SELECT COUNT(user_id) AS total_members
650 FROM ' . USER_GROUP_TABLE
. "
651 WHERE group_id = $group_id
652 AND group_leader = 0";
653 $result = $db->sql_query($sql);
654 $total_members = (int) $db->sql_fetchfield('total_members');
655 $db->sql_freeresult($result);
657 $s_action_options = '';
658 $options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE');
660 foreach ($options as $option => $lang)
662 $s_action_options .= '<option value="' . $option . '">' . $user->lang
['GROUP_' . $lang] . '</option>';
665 $template->assign_vars(array(
667 'S_GROUP_SPECIAL' => ($group_row['group_type'] == GROUP_SPECIAL
) ?
true : false,
668 'S_ACTION_OPTIONS' => $s_action_options,
670 'S_ON_PAGE' => on_page($total_members, $config['topics_per_page'], $start),
671 'PAGINATION' => generate_pagination($this->u_action
. "&action=$action&g=$group_id", $total_members, $config['topics_per_page'], $start, true),
672 'GROUP_NAME' => ($group_row['group_type'] == GROUP_SPECIAL
) ?
$user->lang
['G_' . $group_row['group_name']] : $group_row['group_name'],
674 'U_ACTION' => $this->u_action
. "&g=$group_id",
675 'U_BACK' => $this->u_action
,
676 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=list&field=usernames'),
677 'U_DEFAULT_ALL' => "{$this->u_action}&action=default&g=$group_id",
681 $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
682 FROM ' . USERS_TABLE
. ' u, ' . USER_GROUP_TABLE
. " ug
683 WHERE ug.group_id = $group_id
684 AND u.user_id = ug.user_id
685 AND ug.group_leader = 0
686 ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean";
687 $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
691 while ($row = $db->sql_fetchrow($result))
693 if ($row['user_pending'] && !$pending)
695 $template->assign_block_vars('member', array(
702 $template->assign_block_vars('member', array(
703 'U_USER_EDIT' => append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&action=edit&u={$row['user_id']}"),
705 'USERNAME' => $row['username'],
706 'USERNAME_COLOUR' => $row['user_colour'],
707 'S_GROUP_DEFAULT' => ($row['group_id'] == $group_id) ?
true : false,
708 'JOINED' => ($row['user_regdate']) ?
$user->format_date($row['user_regdate']) : ' - ',
709 'USER_POSTS' => $row['user_posts'],
710 'USER_ID' => $row['user_id'])
713 $db->sql_freeresult($result);
719 $template->assign_vars(array(
720 'U_ACTION' => $this->u_action
,
721 'S_GROUP_ADD' => ($auth->acl_get('a_groupadd')) ?
true : false)
724 // Get us all the groups
725 $sql = 'SELECT g.group_id, g.group_name, g.group_type
726 FROM ' . GROUPS_TABLE
. ' g
727 ORDER BY g.group_type ASC, g.group_name';
728 $result = $db->sql_query($sql);
730 $lookup = $cached_group_data = array();
731 while ($row = $db->sql_fetchrow($result))
733 $type = ($row['group_type'] == GROUP_SPECIAL
) ?
'special' : 'normal';
735 // used to determine what type a group is
736 $lookup[$row['group_id']] = $type;
738 // used for easy access to the data within a group
739 $cached_group_data[$type][$row['group_id']] = $row;
740 $cached_group_data[$type][$row['group_id']]['total_members'] = 0;
742 $db->sql_freeresult($result);
744 // How many people are in which group?
745 $sql = 'SELECT COUNT(ug.user_id) AS total_members, ug.group_id
746 FROM ' . USER_GROUP_TABLE
. ' ug
747 WHERE ' . $db->sql_in_set('ug.group_id', array_keys($lookup)) . '
748 GROUP BY ug.group_id';
749 $result = $db->sql_query($sql);
751 while ($row = $db->sql_fetchrow($result))
753 $type = $lookup[$row['group_id']];
754 $cached_group_data[$type][$row['group_id']]['total_members'] = $row['total_members'];
756 $db->sql_freeresult($result);
758 // The order is... normal, then special
759 ksort($cached_group_data);
761 foreach ($cached_group_data as $type => $row_ary)
763 if ($type == 'special')
765 $template->assign_block_vars('groups', array(
770 foreach ($row_ary as $group_id => $row)
772 $group_name = (!empty($user->lang
['G_' . $row['group_name']]))?
$user->lang
['G_' . $row['group_name']] : $row['group_name'];
774 $template->assign_block_vars('groups', array(
775 'U_LIST' => "{$this->u_action}&action=list&g=$group_id",
776 'U_EDIT' => "{$this->u_action}&action=edit&g=$group_id",
777 'U_DELETE' => ($auth->acl_get('a_groupdel')) ?
"{$this->u_action}&action=delete&g=$group_id" : '',
779 'S_GROUP_SPECIAL' => ($row['group_type'] == GROUP_SPECIAL
) ?
true : false,
781 'GROUP_NAME' => $group_name,
782 'TOTAL_MEMBERS' => $row['total_members'],