Blame Identity/Webenv/phpBB/3.0.4/includes/ucp/ucp_groups.php

ef5584
ef5584
/**
ef5584
*
ef5584
* @package ucp
ef5584
* @version $Id: ucp_groups.php 9067 2008-11-21 13:21:53Z Kellanved $
ef5584
* @copyright (c) 2005 phpBB Group
ef5584
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
ef5584
*
ef5584
*/
ef5584
ef5584
/**
ef5584
* @ignore
ef5584
*/
ef5584
if (!defined('IN_PHPBB'))
ef5584
{
ef5584
	exit;
ef5584
}
ef5584
ef5584
/**
ef5584
* ucp_groups
ef5584
* @package ucp
ef5584
*/
ef5584
class ucp_groups
ef5584
{
ef5584
	var $u_action;
ef5584
ef5584
	function main($id, $mode)
ef5584
	{
ef5584
		global $config, $phpbb_root_path, $phpEx;
ef5584
		global $db, $user, $auth, $cache, $template;
ef5584
ef5584
		$user->add_lang('groups');
ef5584
ef5584
		$return_page = '

' . sprintf($user->lang['RETURN_PAGE'], '', '');
ef5584
ef5584
		$mark_ary	= request_var('mark', array(0));
ef5584
		$submit		= (!empty($_POST['submit'])) ? true : false;
ef5584
		$delete		= (!empty($_POST['delete'])) ? true : false;
ef5584
		$error = $data = array();
ef5584
ef5584
		switch ($mode)
ef5584
		{
ef5584
			case 'membership':
ef5584
		
ef5584
				$this->page_title = 'UCP_USERGROUPS_MEMBER';
ef5584
ef5584
				if ($submit || isset($_POST['change_default']))
ef5584
				{
ef5584
					$action = (isset($_POST['change_default'])) ? 'change_default' : request_var('action', '');
ef5584
					$group_id = ($action == 'change_default') ? request_var('default', 0) : request_var('selected', 0);
ef5584
ef5584
					if (!$group_id)
ef5584
					{
ef5584
						trigger_error('NO_GROUP_SELECTED');
ef5584
					}
ef5584
ef5584
					$sql = 'SELECT group_id, group_name, group_type
ef5584
						FROM ' . GROUPS_TABLE . "
ef5584
						WHERE group_id IN ($group_id, {$user->data['group_id']})";
ef5584
					$result = $db->sql_query($sql);
ef5584
ef5584
					$group_row = array();
ef5584
					while ($row = $db->sql_fetchrow($result))
ef5584
					{
ef5584
						$row['group_name'] = ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'];
ef5584
						$group_row[$row['group_id']] = $row;
ef5584
					}
ef5584
					$db->sql_freeresult($result);
ef5584
ef5584
					if (!sizeof($group_row))
ef5584
					{
ef5584
						trigger_error('GROUP_NOT_EXIST');
ef5584
					}
ef5584
ef5584
					switch ($action)
ef5584
					{
ef5584
						case 'change_default':
ef5584
							// User already having this group set as default?
ef5584
							if ($group_id == $user->data['group_id'])
ef5584
							{
ef5584
								trigger_error($user->lang['ALREADY_DEFAULT_GROUP'] . $return_page);
ef5584
							}
ef5584
ef5584
							if (!$auth->acl_get('u_chggrp'))
ef5584
							{
ef5584
								trigger_error($user->lang['NOT_AUTHORISED'] . $return_page);
ef5584
							}
ef5584
ef5584
							// User needs to be member of the group in order to make it default
ef5584
							if (!group_memberships($group_id, $user->data['user_id'], true))
ef5584
							{
ef5584
								trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
ef5584
							}
ef5584
ef5584
							if (confirm_box(true))
ef5584
							{
ef5584
								group_user_attributes('default', $group_id, $user->data['user_id']);
ef5584
ef5584
								add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_CHANGE', sprintf($user->lang['USER_GROUP_CHANGE'], $group_row[$user->data['group_id']]['group_name'], $group_row[$group_id]['group_name']));
ef5584
ef5584
								meta_refresh(3, $this->u_action);
ef5584
								trigger_error($user->lang['CHANGED_DEFAULT_GROUP'] . $return_page);
ef5584
							}
ef5584
							else
ef5584
							{
ef5584
								$s_hidden_fields = array(
ef5584
									'default'		=> $group_id,
ef5584
									'change_default'=> true
ef5584
								);
ef5584
ef5584
								confirm_box(false, sprintf($user->lang['GROUP_CHANGE_DEFAULT'], $group_row[$group_id]['group_name']), build_hidden_fields($s_hidden_fields));
ef5584
							}
ef5584
ef5584
						break;
ef5584
ef5584
						case 'resign':
ef5584
ef5584
							// User tries to resign from default group but is not allowed to change it?
ef5584
							if ($group_id == $user->data['group_id'] && !$auth->acl_get('u_chggrp'))
ef5584
							{
ef5584
								trigger_error($user->lang['NOT_RESIGN_FROM_DEFAULT_GROUP'] . $return_page);
ef5584
							}
ef5584
ef5584
							if (!($row = group_memberships($group_id, $user->data['user_id'])))
ef5584
							{
ef5584
								trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
ef5584
							}
ef5584
							list(, $row) = each($row);
ef5584
ef5584
							$sql = 'SELECT group_type
ef5584
								FROM ' . GROUPS_TABLE . '
ef5584
								WHERE group_id = ' . $group_id;
ef5584
							$result = $db->sql_query($sql);
ef5584
							$group_type = (int) $db->sql_fetchfield('group_type');
ef5584
							$db->sql_freeresult($result);
ef5584
ef5584
							if ($group_type != GROUP_OPEN && $group_type != GROUP_FREE)
ef5584
							{
ef5584
								trigger_error($user->lang['CANNOT_RESIGN_GROUP'] . $return_page);
ef5584
							}
ef5584
ef5584
							if (confirm_box(true))
ef5584
							{
ef5584
								group_user_del($group_id, $user->data['user_id']);
ef5584
ef5584
								add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_RESIGN', $group_row[$group_id]['group_name']);
ef5584
ef5584
								meta_refresh(3, $this->u_action);
ef5584
								trigger_error($user->lang[($row['user_pending']) ? 'GROUP_RESIGNED_PENDING' : 'GROUP_RESIGNED_MEMBERSHIP'] . $return_page);
ef5584
							}
ef5584
							else
ef5584
							{
ef5584
								$s_hidden_fields = array(
ef5584
									'selected'		=> $group_id,
ef5584
									'action'		=> 'resign',
ef5584
									'submit'		=> true
ef5584
								);
ef5584
ef5584
								confirm_box(false, ($row['user_pending']) ? 'GROUP_RESIGN_PENDING' : 'GROUP_RESIGN_MEMBERSHIP', build_hidden_fields($s_hidden_fields));
ef5584
							}
ef5584
ef5584
						break;
ef5584
ef5584
						case 'join':
ef5584
ef5584
							$sql = 'SELECT ug.*, u.username, u.username_clean, u.user_email
ef5584
								FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u
ef5584
								WHERE ug.user_id = u.user_id
ef5584
									AND ug.group_id = ' . $group_id . '
ef5584
									AND ug.user_id = ' . $user->data['user_id'];
ef5584
							$result = $db->sql_query($sql);
ef5584
							$row = $db->sql_fetchrow($result);
ef5584
							$db->sql_freeresult($result);
ef5584
ef5584
							if ($row)
ef5584
							{
ef5584
								if ($row['user_pending'])
ef5584
								{
ef5584
									trigger_error($user->lang['ALREADY_IN_GROUP_PENDING'] . $return_page);
ef5584
								}
ef5584
ef5584
								trigger_error($user->lang['ALREADY_IN_GROUP'] . $return_page);
ef5584
							}
ef5584
ef5584
							// Check permission to join (open group or request)
ef5584
							if ($group_row[$group_id]['group_type'] != GROUP_OPEN && $group_row[$group_id]['group_type'] != GROUP_FREE)
ef5584
							{
ef5584
								trigger_error($user->lang['CANNOT_JOIN_GROUP'] . $return_page);
ef5584
							}
ef5584
ef5584
							if (confirm_box(true))
ef5584
							{
ef5584
								if ($group_row[$group_id]['group_type'] == GROUP_FREE)
ef5584
								{
ef5584
									group_user_add($group_id, $user->data['user_id']);
ef5584
ef5584
									$email_template = 'group_added';
ef5584
								}
ef5584
								else
ef5584
								{
ef5584
									group_user_add($group_id, $user->data['user_id'], false, false, false, 0, 1);
ef5584
ef5584
									$email_template = 'group_request';
ef5584
								}
ef5584
ef5584
								include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
ef5584
								$messenger = new messenger();
ef5584
ef5584
								$sql = 'SELECT u.username, u.username_clean, u.user_email, u.user_notify_type, u.user_jabber, u.user_lang
ef5584
									FROM ' . USER_GROUP_TABLE . ' ug, ' . USERS_TABLE . ' u
ef5584
									WHERE ug.user_id = u.user_id
ef5584
										AND ' . (($group_row[$group_id]['group_type'] == GROUP_FREE) ? "ug.user_id = {$user->data['user_id']}" : 'ug.group_leader = 1') . "
ef5584
										AND ug.group_id = $group_id";
ef5584
								$result = $db->sql_query($sql);
ef5584
ef5584
								while ($row = $db->sql_fetchrow($result))
ef5584
								{
ef5584
									$messenger->template($email_template, $row['user_lang']);
ef5584
ef5584
									$messenger->to($row['user_email'], $row['username']);
ef5584
									$messenger->im($row['user_jabber'], $row['username']);
ef5584
ef5584
									$messenger->assign_vars(array(
ef5584
										'USERNAME'			=> htmlspecialchars_decode($row['username']),
ef5584
										'GROUP_NAME'		=> htmlspecialchars_decode($group_row[$group_id]['group_name']),
ef5584
										'REQUEST_USERNAME'	=> $user->data['username'],
ef5584
ef5584
										'U_PENDING'		=> generate_board_url() . "/ucp.$phpEx?i=groups&mode=manage&action=list&g=$group_id",
ef5584
										'U_GROUP'		=> generate_board_url() . "/memberlist.$phpEx?mode=group&g=$group_id")
ef5584
									);
ef5584
ef5584
									$messenger->send($row['user_notify_type']);
ef5584
								}
ef5584
								$db->sql_freeresult($result);
ef5584
ef5584
								$messenger->save_queue();
ef5584
ef5584
								add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_JOIN' . (($group_row[$group_id]['group_type'] == GROUP_FREE) ? '' : '_PENDING'), $group_row[$group_id]['group_name']);
ef5584
ef5584
								meta_refresh(3, $this->u_action);
ef5584
								trigger_error($user->lang[($group_row[$group_id]['group_type'] == GROUP_FREE) ? 'GROUP_JOINED' : 'GROUP_JOINED_PENDING'] . $return_page);
ef5584
							}
ef5584
							else
ef5584
							{
ef5584
								$s_hidden_fields = array(
ef5584
									'selected'		=> $group_id,
ef5584
									'action'		=> 'join',
ef5584
									'submit'		=> true
ef5584
								);
ef5584
ef5584
								confirm_box(false, ($group_row[$group_id]['group_type'] == GROUP_FREE) ? 'GROUP_JOIN' : 'GROUP_JOIN_PENDING', build_hidden_fields($s_hidden_fields));
ef5584
							}
ef5584
ef5584
						break;
ef5584
ef5584
						case 'demote':
ef5584
ef5584
							if (!($row = group_memberships($group_id, $user->data['user_id'])))
ef5584
							{
ef5584
								trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
ef5584
							}
ef5584
							list(, $row) = each($row);
ef5584
ef5584
							if (!$row['group_leader'])
ef5584
							{
ef5584
								trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
ef5584
							}
ef5584
ef5584
							if (confirm_box(true))
ef5584
							{
ef5584
								group_user_attributes('demote', $group_id, $user->data['user_id']);
ef5584
ef5584
								add_log('user', $user->data['user_id'], 'LOG_USER_GROUP_DEMOTE', $group_row[$group_id]['group_name']);
ef5584
ef5584
								meta_refresh(3, $this->u_action);
ef5584
								trigger_error($user->lang['USER_GROUP_DEMOTED'] . $return_page);
ef5584
							}
ef5584
							else
ef5584
							{
ef5584
								$s_hidden_fields = array(
ef5584
									'selected'		=> $group_id,
ef5584
									'action'		=> 'demote',
ef5584
									'submit'		=> true
ef5584
								);
ef5584
ef5584
								confirm_box(false, 'USER_GROUP_DEMOTE', build_hidden_fields($s_hidden_fields));
ef5584
							}
ef5584
ef5584
						break;
ef5584
					}
ef5584
				}
ef5584
ef5584
				$sql = 'SELECT g.*, ug.group_leader, ug.user_pending
ef5584
					FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
ef5584
					WHERE ug.user_id = ' . $user->data['user_id'] . '
ef5584
						AND g.group_id = ug.group_id
ef5584
					ORDER BY g.group_type DESC, g.group_name';
ef5584
				$result = $db->sql_query($sql);
ef5584
ef5584
				$group_id_ary = array();
ef5584
				$leader_count = $member_count = $pending_count = 0;
ef5584
				while ($row = $db->sql_fetchrow($result))
ef5584
				{
ef5584
					$block = ($row['group_leader']) ? 'leader' : (($row['user_pending']) ? 'pending' : 'member');
ef5584
ef5584
					switch ($row['group_type'])
ef5584
					{
ef5584
						case GROUP_OPEN:
ef5584
							$group_status = 'OPEN';
ef5584
						break;
ef5584
ef5584
						case GROUP_CLOSED:
ef5584
							$group_status = 'CLOSED';
ef5584
						break;
ef5584
ef5584
						case GROUP_HIDDEN:
ef5584
							$group_status = 'HIDDEN';
ef5584
						break;
ef5584
ef5584
						case GROUP_SPECIAL:
ef5584
							$group_status = 'SPECIAL';
ef5584
						break;
ef5584
ef5584
						case GROUP_FREE:
ef5584
							$group_status = 'FREE';
ef5584
						break;
ef5584
					}
ef5584
ef5584
					$template->assign_block_vars($block, array(
ef5584
						'GROUP_ID'		=> $row['group_id'],
ef5584
						'GROUP_NAME'	=> ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'],
ef5584
						'GROUP_DESC'	=> ($row['group_type'] <> GROUP_SPECIAL) ? generate_text_for_display($row['group_desc'], $row['group_desc_uid'], $row['group_desc_bitfield'], $row['group_desc_options']) : $user->lang['GROUP_IS_SPECIAL'],
ef5584
						'GROUP_SPECIAL'	=> ($row['group_type'] <> GROUP_SPECIAL) ? false : true,
ef5584
						'GROUP_STATUS'	=> $user->lang['GROUP_IS_' . $group_status],
ef5584
						'GROUP_COLOUR'	=> $row['group_colour'],
ef5584
ef5584
						'U_VIEW_GROUP'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $row['group_id']),
ef5584
ef5584
						'S_GROUP_DEFAULT'	=> ($row['group_id'] == $user->data['group_id']) ? true : false,
ef5584
						'S_ROW_COUNT'		=> ${$block . '_count'}++)
ef5584
					);
ef5584
ef5584
					$group_id_ary[] = $row['group_id'];
ef5584
				}
ef5584
				$db->sql_freeresult($result);
ef5584
ef5584
				// Hide hidden groups unless user is an admin with group privileges
ef5584
				$sql_and = ($auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? '<> ' . GROUP_SPECIAL : 'NOT IN (' . GROUP_SPECIAL . ', ' . GROUP_HIDDEN . ')';
ef5584
ef5584
				$sql = 'SELECT group_id, group_name, group_colour, group_desc, group_desc_uid, group_desc_bitfield, group_desc_options, group_type, group_founder_manage
ef5584
					FROM ' . GROUPS_TABLE . '
ef5584
					WHERE ' . ((sizeof($group_id_ary)) ? $db->sql_in_set('group_id', $group_id_ary, true) . ' AND ' : '') . "
ef5584
						group_type $sql_and
ef5584
					ORDER BY group_type DESC, group_name";
ef5584
				$result = $db->sql_query($sql);
ef5584
ef5584
				$nonmember_count = 0;
ef5584
				while ($row = $db->sql_fetchrow($result))
ef5584
				{
ef5584
					switch ($row['group_type'])
ef5584
					{
ef5584
						case GROUP_OPEN:
ef5584
							$group_status = 'OPEN';
ef5584
						break;
ef5584
ef5584
						case GROUP_CLOSED:
ef5584
							$group_status = 'CLOSED';
ef5584
						break;
ef5584
ef5584
						case GROUP_HIDDEN:
ef5584
							$group_status = 'HIDDEN';
ef5584
						break;
ef5584
ef5584
						case GROUP_SPECIAL:
ef5584
							$group_status = 'SPECIAL';
ef5584
						break;
ef5584
ef5584
						case GROUP_FREE:
ef5584
							$group_status = 'FREE';
ef5584
						break;
ef5584
					}
ef5584
ef5584
					$template->assign_block_vars('nonmember', array(
ef5584
						'GROUP_ID'		=> $row['group_id'],
ef5584
						'GROUP_NAME'	=> ($row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $row['group_name']] : $row['group_name'],
ef5584
						'GROUP_DESC'	=> ($row['group_type'] <> GROUP_SPECIAL) ? generate_text_for_display($row['group_desc'], $row['group_desc_uid'], $row['group_desc_bitfield'], $row['group_desc_options']) : $user->lang['GROUP_IS_SPECIAL'],
ef5584
						'GROUP_SPECIAL'	=> ($row['group_type'] <> GROUP_SPECIAL) ? false : true,
ef5584
						'GROUP_CLOSED'	=> ($row['group_type'] <> GROUP_CLOSED || $auth->acl_gets('a_group', 'a_groupadd', 'a_groupdel')) ? false : true,
ef5584
						'GROUP_STATUS'	=> $user->lang['GROUP_IS_' . $group_status],
ef5584
						'S_CAN_JOIN'	=> ($row['group_type'] == GROUP_OPEN || $row['group_type'] == GROUP_FREE) ? true : false,
ef5584
						'GROUP_COLOUR'	=> $row['group_colour'],
ef5584
ef5584
						'U_VIEW_GROUP'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=group&g=' . $row['group_id']),
ef5584
ef5584
						'S_ROW_COUNT'	=> $nonmember_count++)
ef5584
					);
ef5584
				}
ef5584
				$db->sql_freeresult($result);
ef5584
ef5584
				$template->assign_vars(array(
ef5584
					'S_CHANGE_DEFAULT'	=> ($auth->acl_get('u_chggrp')) ? true : false,
ef5584
					'S_LEADER_COUNT'	=> $leader_count,
ef5584
					'S_MEMBER_COUNT'	=> $member_count,
ef5584
					'S_PENDING_COUNT'	=> $pending_count,
ef5584
					'S_NONMEMBER_COUNT'	=> $nonmember_count,
ef5584
ef5584
					'S_UCP_ACTION'			=> $this->u_action)
ef5584
				);
ef5584
ef5584
			break;
ef5584
ef5584
			case 'manage':
ef5584
ef5584
				$this->page_title = 'UCP_USERGROUPS_MANAGE';
ef5584
				$action		= (isset($_POST['addusers'])) ? 'addusers' : request_var('action', '');
ef5584
				$group_id	= request_var('g', 0);
ef5584
				
ef5584
				include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
ef5584
ef5584
				add_form_key('ucp_groups');
ef5584
ef5584
				if ($group_id)
ef5584
				{
ef5584
					$sql = 'SELECT *
ef5584
						FROM ' . GROUPS_TABLE . "
ef5584
						WHERE group_id = $group_id";
ef5584
					$result = $db->sql_query($sql);
ef5584
					$group_row = $db->sql_fetchrow($result);
ef5584
					$db->sql_freeresult($result);
ef5584
ef5584
					if (!$group_row)
ef5584
					{
ef5584
						trigger_error($user->lang['NO_GROUP'] . $return_page);
ef5584
					}
ef5584
ef5584
					// Check if the user is allowed to manage this group if set to founder only.
ef5584
					if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage'])
ef5584
					{
ef5584
						trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . $return_page, E_USER_WARNING);
ef5584
					}
ef5584
					
ef5584
					$group_name = $group_row['group_name'];
ef5584
					$group_type = $group_row['group_type'];
ef5584
					
ef5584
					$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') : '';
ef5584
ef5584
					$template->assign_vars(array(
ef5584
						'GROUP_NAME'			=> ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name,
ef5584
						'GROUP_INTERNAL_NAME'	=> $group_name,
ef5584
						'GROUP_COLOUR'			=> (isset($group_row['group_colour'])) ? $group_row['group_colour'] : '',
ef5584
						'GROUP_DESC_DISP'		=> generate_text_for_display($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_bitfield'], $group_row['group_desc_options']),
ef5584
						'GROUP_TYPE'			=> $group_row['group_type'],
ef5584
						
ef5584
						'AVATAR'				=> $avatar_img,
ef5584
						'AVATAR_IMAGE'			=> $avatar_img,
ef5584
						'AVATAR_WIDTH'			=> (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '',
ef5584
						'AVATAR_HEIGHT'			=> (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '',
ef5584
					));
ef5584
				}
ef5584
ef5584
				switch ($action)
ef5584
				{
ef5584
					case 'edit':
ef5584
ef5584
						if (!$group_id)
ef5584
						{
ef5584
							trigger_error($user->lang['NO_GROUP'] . $return_page);
ef5584
						}
ef5584
ef5584
						if (!($row = group_memberships($group_id, $user->data['user_id'])))
ef5584
						{
ef5584
							trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
ef5584
						}
ef5584
						list(, $row) = each($row);
ef5584
ef5584
						if (!$row['group_leader'])
ef5584
						{
ef5584
							trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
ef5584
						}
ef5584
ef5584
						$file_uploads = (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on') ? true : false;
ef5584
						$user->add_lang(array('acp/groups', 'acp/common'));
ef5584
ef5584
						$data = $submit_ary = array();
ef5584
ef5584
						$update	= (isset($_POST['update'])) ? true : false;
ef5584
ef5584
						$error = array();
ef5584
ef5584
						$avatar_select = basename(request_var('avatar_select', ''));
ef5584
						$category = basename(request_var('category', ''));
ef5584
ef5584
						$can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
ef5584
ef5584
						// Did we submit?
ef5584
						if ($update)
ef5584
						{
ef5584
							$group_name	= utf8_normalize_nfc(request_var('group_name', '', true));
ef5584
							$group_desc = utf8_normalize_nfc(request_var('group_desc', '', true));
ef5584
							$group_type	= request_var('group_type', GROUP_FREE);
ef5584
ef5584
							$allow_desc_bbcode	= request_var('desc_parse_bbcode', false);
ef5584
							$allow_desc_urls	= request_var('desc_parse_urls', false);
ef5584
							$allow_desc_smilies	= request_var('desc_parse_smilies', false);
ef5584
ef5584
							$submit_ary = array(
ef5584
								'colour'		=> request_var('group_colour', ''),
ef5584
								'rank'			=> request_var('group_rank', 0),
ef5584
								'receive_pm'	=> isset($_REQUEST['group_receive_pm']) ? 1 : 0,
ef5584
								'message_limit'	=> request_var('group_message_limit', 0),
ef5584
								'max_recipients'=> request_var('group_max_recipients', 0),
ef5584
							);
ef5584
ef5584
							$data['uploadurl']	= request_var('uploadurl', '');
ef5584
							$data['remotelink'] = request_var('remotelink', '');
ef5584
							$data['width']		= request_var('width', '');
ef5584
							$data['height']		= request_var('height', '');
ef5584
							$delete				= request_var('delete', '');
ef5584
ef5584
							if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink'])
ef5584
							{
ef5584
								// Avatar stuff
ef5584
								$var_ary = array(
ef5584
									'uploadurl'		=> array('string', true, 5, 255),
ef5584
									'remotelink'	=> array('string', true, 5, 255),
ef5584
									'width'			=> array('string', true, 1, 3),
ef5584
									'height'		=> array('string', true, 1, 3),
ef5584
								);
ef5584
ef5584
								if (!($error = validate_data($data, $var_ary)))
ef5584
								{
ef5584
									$data['user_id'] = "g$group_id";
ef5584
ef5584
									if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload)
ef5584
									{
ef5584
										list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error);
ef5584
									}
ef5584
									else if ($data['remotelink'])
ef5584
									{
ef5584
										list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error);
ef5584
									}
ef5584
								}
ef5584
							}
ef5584
							else if ($avatar_select && $config['allow_avatar_local'])
ef5584
							{
ef5584
								// check avatar gallery
ef5584
								if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category))
ef5584
								{
ef5584
									$submit_ary['avatar_type'] = AVATAR_GALLERY;
ef5584
ef5584
									list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select);
ef5584
									$submit_ary['avatar'] = $category . '/' . $avatar_select;
ef5584
								}
ef5584
							}
ef5584
							else if ($delete)
ef5584
							{
ef5584
								$submit_ary['avatar'] = '';
ef5584
								$submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0;
ef5584
							}
ef5584
							else if ($data['width'] && $data['height'])
ef5584
							{
ef5584
								// Only update the dimensions?
ef5584
								if ($config['avatar_max_width'] || $config['avatar_max_height'])
ef5584
								{
ef5584
									if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height'])
ef5584
									{
ef5584
										$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']);
ef5584
									}
ef5584
								}
ef5584
ef5584
								if (!sizeof($error))
ef5584
								{
ef5584
									if ($config['avatar_min_width'] || $config['avatar_min_height'])
ef5584
									{
ef5584
										if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height'])
ef5584
										{
ef5584
											$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']);
ef5584
										}
ef5584
									}
ef5584
								}
ef5584
ef5584
								if (!sizeof($error))
ef5584
								{
ef5584
									$submit_ary['avatar_width'] = $data['width'];
ef5584
									$submit_ary['avatar_height'] = $data['height'];
ef5584
								}
ef5584
							}
ef5584
ef5584
							if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']))) || $delete)
ef5584
							{
ef5584
								if (isset($group_row['group_avatar']) && $group_row['group_avatar'])
ef5584
								{
ef5584
									avatar_delete('group', $group_row, true);
ef5584
								}
ef5584
							}
ef5584
ef5584
							if (!check_form_key('ucp_groups'))
ef5584
							{
ef5584
								$error[] = $user->lang['FORM_INVALID'];
ef5584
							}
ef5584
ef5584
							if (!sizeof($error))
ef5584
							{
ef5584
								// Only set the rank, colour, etc. if it's changed or if we're adding a new
ef5584
								// group. This prevents existing group members being updated if no changes
ef5584
								// were made.
ef5584
						
ef5584
								$group_attributes = array();
ef5584
								$test_variables = array('rank', 'colour', 'avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'receive_pm', 'legend', 'message_limit', 'max_recipients');
ef5584
								foreach ($test_variables as $test)
ef5584
								{
ef5584
									if ($action == 'add' || (isset($submit_ary[$test]) && $group_row['group_' . $test] != $submit_ary[$test]))
ef5584
									{
ef5584
										$group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
ef5584
									}
ef5584
								}
ef5584
ef5584
								if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies)))
ef5584
								{
ef5584
									$cache->destroy('sql', GROUPS_TABLE);
ef5584
ef5584
									$message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED';
ef5584
									trigger_error($user->lang[$message] . $return_page);
ef5584
								}
ef5584
							}
ef5584
ef5584
							if (sizeof($error))
ef5584
							{
ef5584
								$group_rank = $submit_ary['rank'];
ef5584
ef5584
								$group_desc_data = array(
ef5584
									'text'			=> $group_desc,
ef5584
									'allow_bbcode'	=> $allow_desc_bbcode,
ef5584
									'allow_smilies'	=> $allow_desc_smilies,
ef5584
									'allow_urls'	=> $allow_desc_urls
ef5584
								);
ef5584
							}
ef5584
						}
ef5584
						else if (!$group_id)
ef5584
						{
ef5584
							$group_name = utf8_normalize_nfc(request_var('group_name', '', true));
ef5584
							$group_desc_data = array(
ef5584
								'text'			=> '',
ef5584
								'allow_bbcode'	=> true,
ef5584
								'allow_smilies'	=> true,
ef5584
								'allow_urls'	=> true
ef5584
							);
ef5584
							$group_rank = 0;
ef5584
							$group_type = GROUP_OPEN;
ef5584
						}
ef5584
						else
ef5584
						{
ef5584
							$group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']);
ef5584
							$group_rank = $group_row['group_rank'];
ef5584
						}
ef5584
ef5584
						$sql = 'SELECT *
ef5584
							FROM ' . RANKS_TABLE . '
ef5584
							WHERE rank_special = 1
ef5584
							ORDER BY rank_title';
ef5584
						$result = $db->sql_query($sql);
ef5584
ef5584
						$rank_options = '<option value="0"' . ((!$group_rank) ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>';
ef5584
						while ($row = $db->sql_fetchrow($result))
ef5584
						{
ef5584
							$selected = ($group_rank && $row['rank_id'] == $group_rank) ? ' selected="selected"' : '';
ef5584
							$rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
ef5584
						}
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						$type_free		= ($group_type == GROUP_FREE) ? ' checked="checked"' : '';
ef5584
						$type_open		= ($group_type == GROUP_OPEN) ? ' checked="checked"' : '';
ef5584
						$type_closed	= ($group_type == GROUP_CLOSED) ? ' checked="checked"' : '';
ef5584
						$type_hidden	= ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : '';
ef5584
ef5584
						$display_gallery = (isset($_POST['display_gallery'])) ? true : false;
ef5584
ef5584
						if ($config['allow_avatar_local'] && $display_gallery)
ef5584
						{
ef5584
							avatar_gallery($category, $avatar_select, 4);
ef5584
						}
ef5584
						
ef5584
						$avatars_enabled = ($can_upload || ($config['allow_avatar_local'] || $config['allow_avatar_remote'])) ? true : false;
ef5584
ef5584
						$template->assign_vars(array(
ef5584
							'S_EDIT'			=> true,
ef5584
							'S_INCLUDE_SWATCH'	=> true,
ef5584
							'S_CAN_UPLOAD'		=> $can_upload,
ef5584
							'S_FORM_ENCTYPE'	=> ($can_upload) ? ' enctype="multipart/form-data"' : '',
ef5584
							'S_ERROR'			=> (sizeof($error)) ? true : false,
ef5584
							'S_SPECIAL_GROUP'	=> ($group_type == GROUP_SPECIAL) ? true : false,
ef5584
							'S_AVATARS_ENABLED'	=> $avatars_enabled,
ef5584
							'S_DISPLAY_GALLERY'	=> ($config['allow_avatar_local'] && !$display_gallery) ? true : false,
ef5584
							'S_IN_GALLERY'		=> ($config['allow_avatar_local'] && $display_gallery) ? true : false,
ef5584
ef5584
							'ERROR_MSG'				=> (sizeof($error)) ? implode('
', $error) : '',
ef5584
							'GROUP_RECEIVE_PM'		=> (isset($group_row['group_receive_pm']) && $group_row['group_receive_pm']) ? ' checked="checked"' : '',
ef5584
							'GROUP_MESSAGE_LIMIT'	=> (isset($group_row['group_message_limit'])) ? $group_row['group_message_limit'] : 0,
ef5584
							'GROUP_MAX_RECIPIENTS'	=> (isset($group_row['group_max_recipients'])) ? $group_row['group_max_recipients'] : 0,
ef5584
							
ef5584
							'GROUP_DESC'			=> $group_desc_data['text'],
ef5584
							'S_DESC_BBCODE_CHECKED'	=> $group_desc_data['allow_bbcode'],
ef5584
							'S_DESC_URLS_CHECKED'	=> $group_desc_data['allow_urls'],
ef5584
							'S_DESC_SMILIES_CHECKED'=> $group_desc_data['allow_smilies'],
ef5584
ef5584
							'S_RANK_OPTIONS'		=> $rank_options,
ef5584
							'AVATAR_MAX_FILESIZE'	=> $config['avatar_filesize'],
ef5584
ef5584
							'GROUP_TYPE_FREE'		=> GROUP_FREE,
ef5584
							'GROUP_TYPE_OPEN'		=> GROUP_OPEN,
ef5584
							'GROUP_TYPE_CLOSED'		=> GROUP_CLOSED,
ef5584
							'GROUP_TYPE_HIDDEN'		=> GROUP_HIDDEN,
ef5584
							'GROUP_TYPE_SPECIAL'	=> GROUP_SPECIAL,
ef5584
ef5584
							'GROUP_FREE'		=> $type_free,
ef5584
							'GROUP_OPEN'		=> $type_open,
ef5584
							'GROUP_CLOSED'		=> $type_closed,
ef5584
							'GROUP_HIDDEN'		=> $type_hidden,
ef5584
ef5584
							'U_SWATCH'			=> append_sid("{$phpbb_root_path}adm/swatch.$phpEx", 'form=ucp&name=group_colour'),
ef5584
							'S_UCP_ACTION'		=> $this->u_action . "&action=$action&g=$group_id",
ef5584
							'L_AVATAR_EXPLAIN'	=> sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], $config['avatar_filesize'] / 1024),
ef5584
						));
ef5584
ef5584
					break;
ef5584
ef5584
					case 'list':
ef5584
ef5584
						if (!$group_id)
ef5584
						{
ef5584
							trigger_error($user->lang['NO_GROUP'] . $return_page);
ef5584
						}
ef5584
ef5584
						if (!($row = group_memberships($group_id, $user->data['user_id'])))
ef5584
						{
ef5584
							trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
ef5584
						}
ef5584
						list(, $row) = each($row);
ef5584
ef5584
						if (!$row['group_leader'])
ef5584
						{
ef5584
							trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
ef5584
						}
ef5584
ef5584
						$user->add_lang(array('acp/groups', 'acp/common'));
ef5584
						$start = request_var('start', 0);
ef5584
ef5584
						// Grab the leaders - always, on every page...
ef5584
						$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
ef5584
							FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
ef5584
							WHERE ug.group_id = $group_id
ef5584
								AND u.user_id = ug.user_id
ef5584
								AND ug.group_leader = 1
ef5584
							ORDER BY ug.user_pending DESC, u.username_clean";
ef5584
						$result = $db->sql_query($sql);
ef5584
ef5584
						while ($row = $db->sql_fetchrow($result))
ef5584
						{
ef5584
							$template->assign_block_vars('leader', array(
ef5584
								'USERNAME'			=> $row['username'],
ef5584
								'USERNAME_COLOUR'	=> $row['user_colour'],
ef5584
								'USERNAME_FULL'		=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
ef5584
								'U_USER_VIEW'		=> get_username_string('profile', $row['user_id'], $row['username']),
ef5584
								'S_GROUP_DEFAULT'	=> ($row['group_id'] == $group_id) ? true : false,
ef5584
								'JOINED'			=> ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
ef5584
								'USER_POSTS'		=> $row['user_posts'],
ef5584
								'USER_ID'			=> $row['user_id'])
ef5584
							);
ef5584
						}
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						// Total number of group members (non-leaders)
ef5584
						$sql = 'SELECT COUNT(user_id) AS total_members
ef5584
							FROM ' . USER_GROUP_TABLE . "
ef5584
							WHERE group_id = $group_id
ef5584
								AND group_leader = 0";
ef5584
						$result = $db->sql_query($sql);
ef5584
						$total_members = (int) $db->sql_fetchfield('total_members');
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						// Grab the members
ef5584
						$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
ef5584
							FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
ef5584
							WHERE ug.group_id = $group_id
ef5584
								AND u.user_id = ug.user_id
ef5584
								AND ug.group_leader = 0
ef5584
							ORDER BY ug.user_pending DESC, u.username_clean";
ef5584
						$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
ef5584
ef5584
						$pending = false;
ef5584
						$approved = false;
ef5584
ef5584
						while ($row = $db->sql_fetchrow($result))
ef5584
						{
ef5584
							if ($row['user_pending'] && !$pending)
ef5584
							{
ef5584
								$template->assign_block_vars('member', array(
ef5584
									'S_PENDING'		=> true)
ef5584
								);
ef5584
								$template->assign_var('S_PENDING_SET', true);
ef5584
ef5584
								$pending = true;
ef5584
							}
ef5584
							else if (!$row['user_pending'] && !$approved)
ef5584
							{
ef5584
								$template->assign_block_vars('member', array(
ef5584
									'S_APPROVED'		=> true)
ef5584
								);
ef5584
								$template->assign_var('S_APPROVED_SET', true);
ef5584
ef5584
								$approved = true;
ef5584
							}
ef5584
ef5584
							$template->assign_block_vars('member', array(
ef5584
								'USERNAME'			=> $row['username'],
ef5584
								'USERNAME_COLOUR'	=> $row['user_colour'],
ef5584
								'USERNAME_FULL'		=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
ef5584
								'U_USER_VIEW'		=> get_username_string('profile', $row['user_id'], $row['username']),
ef5584
								'S_GROUP_DEFAULT'	=> ($row['group_id'] == $group_id) ? true : false,
ef5584
								'JOINED'			=> ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
ef5584
								'USER_POSTS'		=> $row['user_posts'],
ef5584
								'USER_ID'			=> $row['user_id'])
ef5584
							);
ef5584
						}
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
						$s_action_options = '';
ef5584
						$options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'deleteusers' => 'DELETE');
ef5584
ef5584
						foreach ($options as $option => $lang)
ef5584
						{
ef5584
							$s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>';
ef5584
						}
ef5584
ef5584
						$template->assign_vars(array(
ef5584
							'S_LIST'			=> true,
ef5584
							'S_ACTION_OPTIONS'	=> $s_action_options,
ef5584
							'S_ON_PAGE'			=> on_page($total_members, $config['topics_per_page'], $start),
ef5584
							'PAGINATION'		=> generate_pagination($this->u_action . "&action=$action&g=$group_id", $total_members, $config['topics_per_page'], $start),
ef5584
ef5584
							'U_ACTION'			=> $this->u_action . "&g=$group_id",
ef5584
							'U_FIND_USERNAME'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=ucp&field=usernames'),
ef5584
						));
ef5584
ef5584
					break;
ef5584
ef5584
					case 'approve':
ef5584
ef5584
						if (!$group_id)
ef5584
						{
ef5584
							trigger_error($user->lang['NO_GROUP'] . $return_page);
ef5584
						}
ef5584
ef5584
						if (!($row = group_memberships($group_id, $user->data['user_id'])))
ef5584
						{
ef5584
							trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
ef5584
						}
ef5584
						list(, $row) = each($row);
ef5584
ef5584
						if (!$row['group_leader'])
ef5584
						{
ef5584
							trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
ef5584
						}
ef5584
ef5584
						$user->add_lang('acp/groups');
ef5584
ef5584
						// Approve, demote or promote
ef5584
						group_user_attributes('approve', $group_id, $mark_ary, false, false);
ef5584
ef5584
						trigger_error($user->lang['USERS_APPROVED'] . '

' . sprintf($user->lang['RETURN_PAGE'], '', ''));
ef5584
ef5584
					break;
ef5584
ef5584
					case 'default':
ef5584
ef5584
						if (!$group_id)
ef5584
						{
ef5584
							trigger_error($user->lang['NO_GROUP'] . $return_page);
ef5584
						}
ef5584
ef5584
						if (!($row = group_memberships($group_id, $user->data['user_id'])))
ef5584
						{
ef5584
							trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
ef5584
						}
ef5584
						list(, $row) = each($row);
ef5584
ef5584
						if (!$row['group_leader'])
ef5584
						{
ef5584
							trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
ef5584
						}
ef5584
ef5584
						$group_row['group_name'] = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
ef5584
ef5584
						if (confirm_box(true))
ef5584
						{
ef5584
							if (!sizeof($mark_ary))
ef5584
							{
ef5584
								$start = 0;
ef5584
				
ef5584
								do
ef5584
								{
ef5584
									$sql = 'SELECT user_id
ef5584
										FROM ' . USER_GROUP_TABLE . "
ef5584
										WHERE group_id = $group_id
ef5584
										ORDER BY user_id";
ef5584
									$result = $db->sql_query_limit($sql, 200, $start);
ef5584
ef5584
									$mark_ary = array();
ef5584
									if ($row = $db->sql_fetchrow($result))
ef5584
									{
ef5584
										do
ef5584
										{
ef5584
											$mark_ary[] = $row['user_id'];
ef5584
										}
ef5584
										while ($row = $db->sql_fetchrow($result));
ef5584
ef5584
										group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row);
ef5584
ef5584
										$start = (sizeof($mark_ary) < 200) ? 0 : $start + 200;
ef5584
									}
ef5584
									else
ef5584
									{
ef5584
										$start = 0;
ef5584
									}
ef5584
									$db->sql_freeresult($result);
ef5584
								}
ef5584
								while ($start);
ef5584
							}
ef5584
							else
ef5584
							{
ef5584
								group_user_attributes('default', $group_id, $mark_ary, false, $group_row['group_name'], $group_row);
ef5584
							}
ef5584
ef5584
							$user->add_lang('acp/groups');
ef5584
ef5584
							trigger_error($user->lang['GROUP_DEFS_UPDATED'] . '

' . sprintf($user->lang['RETURN_PAGE'], '', ''));
ef5584
						}
ef5584
						else
ef5584
						{
ef5584
							$user->add_lang('acp/common');
ef5584
ef5584
							confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
ef5584
								'mark'		=> $mark_ary,
ef5584
								'g'			=> $group_id,
ef5584
								'i'			=> $id,
ef5584
								'mode'		=> $mode,
ef5584
								'action'	=> $action))
ef5584
							);
ef5584
						}
ef5584
ef5584
					break;
ef5584
ef5584
					case 'deleteusers':
ef5584
ef5584
						$user->add_lang(array('acp/groups', 'acp/common'));
ef5584
ef5584
						if (!($row = group_memberships($group_id, $user->data['user_id'])))
ef5584
						{
ef5584
							trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
ef5584
						}
ef5584
						list(, $row) = each($row);
ef5584
ef5584
						if (!$row['group_leader'])
ef5584
						{
ef5584
							trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
ef5584
						}
ef5584
ef5584
						$group_row['group_name'] = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
ef5584
ef5584
						if (confirm_box(true))
ef5584
						{
ef5584
							if (!$group_id)
ef5584
							{
ef5584
								trigger_error($user->lang['NO_GROUP'] . $return_page);
ef5584
							}
ef5584
ef5584
							$error = group_user_del($group_id, $mark_ary, false, $group_row['group_name']);
ef5584
ef5584
							if ($error)
ef5584
							{
ef5584
								trigger_error($user->lang[$error] . '

' . sprintf($user->lang['RETURN_PAGE'], '', ''));
ef5584
							}
ef5584
ef5584
							trigger_error($user->lang['GROUP_USERS_REMOVE'] . '

' . sprintf($user->lang['RETURN_PAGE'], '', ''));
ef5584
						}
ef5584
						else
ef5584
						{
ef5584
							confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
ef5584
								'mark'		=> $mark_ary,
ef5584
								'g'			=> $group_id,
ef5584
								'i'			=> $id,
ef5584
								'mode'		=> $mode,
ef5584
								'action'	=> $action))
ef5584
							);
ef5584
						}
ef5584
ef5584
					break;
ef5584
ef5584
					case 'addusers':
ef5584
ef5584
						$user->add_lang(array('acp/groups', 'acp/common'));
ef5584
ef5584
						$names = utf8_normalize_nfc(request_var('usernames', '', true));
ef5584
ef5584
						if (!$group_id)
ef5584
						{
ef5584
							trigger_error($user->lang['NO_GROUP'] . $return_page);
ef5584
						}
ef5584
ef5584
						if (!$names)
ef5584
						{
ef5584
							trigger_error($user->lang['NO_USERS'] . $return_page);
ef5584
						}
ef5584
ef5584
						if (!($row = group_memberships($group_id, $user->data['user_id'])))
ef5584
						{
ef5584
							trigger_error($user->lang['NOT_MEMBER_OF_GROUP'] . $return_page);
ef5584
						}
ef5584
						list(, $row) = each($row);
ef5584
ef5584
						if (!$row['group_leader'])
ef5584
						{
ef5584
							trigger_error($user->lang['NOT_LEADER_OF_GROUP'] . $return_page);
ef5584
						}
ef5584
ef5584
						$name_ary = array_unique(explode("\n", $names));
ef5584
						$group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
ef5584
ef5584
						$default = request_var('default', 0);
ef5584
						
ef5584
						if (confirm_box(true))
ef5584
						{
ef5584
							// Add user/s to group
ef5584
							if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, 0, 0, $group_row))
ef5584
							{
ef5584
								trigger_error($user->lang[$error] . $return_page);
ef5584
							}
ef5584
ef5584
							trigger_error($user->lang['GROUP_USERS_ADDED'] . '

' . sprintf($user->lang['RETURN_PAGE'], '', ''));
ef5584
						}
ef5584
						else
ef5584
						{
ef5584
							$s_hidden_fields = array(
ef5584
								'default'	=> $default,
ef5584
								'usernames'	=> $names,
ef5584
								'g'			=> $group_id,
ef5584
								'i'			=> $id,
ef5584
								'mode'		=> $mode,
ef5584
								'action'	=> $action
ef5584
							);
ef5584
							confirm_box(false, sprintf($user->lang['GROUP_CONFIRM_ADD_USER' . ((sizeof($name_ary) == 1) ? '' : 'S')], implode(', ', $name_ary)), build_hidden_fields($s_hidden_fields));
ef5584
						}
ef5584
ef5584
						trigger_error($user->lang['NO_USERS_ADDED'] . '

' . sprintf($user->lang['RETURN_PAGE'], '', ''));
ef5584
ef5584
					break;
ef5584
ef5584
					default:
ef5584
						$user->add_lang('acp/common');
ef5584
ef5584
						$sql = 'SELECT g.group_id, g.group_name, g.group_colour, g.group_desc, g.group_desc_uid, g.group_desc_bitfield, g.group_desc_options, g.group_type, ug.group_leader
ef5584
							FROM ' . GROUPS_TABLE . ' g, ' . USER_GROUP_TABLE . ' ug
ef5584
							WHERE ug.user_id = ' . $user->data['user_id'] . '
ef5584
								AND g.group_id = ug.group_id
ef5584
								AND ug.group_leader = 1
ef5584
							ORDER BY g.group_type DESC, g.group_name';
ef5584
						$result = $db->sql_query($sql);
ef5584
ef5584
						while ($value = $db->sql_fetchrow($result))
ef5584
						{
ef5584
							$template->assign_block_vars('leader', array(
ef5584
								'GROUP_NAME'	=> ($value['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $value['group_name']] : $value['group_name'],
ef5584
								'GROUP_DESC'	=> generate_text_for_display($value['group_desc'], $value['group_desc_uid'], $value['group_desc_bitfield'], $value['group_desc_options']),
ef5584
								'GROUP_TYPE'	=> $value['group_type'],
ef5584
								'GROUP_ID'		=> $value['group_id'],
ef5584
								'GROUP_COLOUR'	=> $value['group_colour'],
ef5584
ef5584
								'U_LIST'	=> $this->u_action . "&action=list&g={$value['group_id']}",
ef5584
								'U_EDIT'	=> $this->u_action . "&action=edit&g={$value['group_id']}")
ef5584
							);
ef5584
						}
ef5584
						$db->sql_freeresult($result);
ef5584
ef5584
					break;
ef5584
				}
ef5584
ef5584
			break;
ef5584
		}
ef5584
ef5584
		$this->tpl_name = 'ucp_groups_' . $mode;
ef5584
	}
ef5584
}
ef5584
ef5584
?>