Blame Extras/phpBB/3.0.4/includes/acp/acp_groups.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package acp
4c79b5
* @version $Id: acp_groups.php 9053 2008-11-09 15:10:40Z acydburn $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
if (!defined('IN_PHPBB'))
4c79b5
{
4c79b5
	exit;
4c79b5
}
4c79b5
4c79b5
/**
4c79b5
* @package acp
4c79b5
*/
4c79b5
class acp_groups
4c79b5
{
4c79b5
	var $u_action;
4c79b5
4c79b5
	function main($id, $mode)
4c79b5
	{
4c79b5
		global $config, $db, $user, $auth, $template, $cache;
4c79b5
		global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads;
4c79b5
4c79b5
		$user->add_lang('acp/groups');
4c79b5
		$this->tpl_name = 'acp_groups';
4c79b5
		$this->page_title = 'ACP_GROUPS_MANAGE';
4c79b5
4c79b5
		$form_key = 'acp_groups';
4c79b5
		add_form_key($form_key);
4c79b5
4c79b5
		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
4c79b5
4c79b5
		// Check and set some common vars
4c79b5
		$action		= (isset($_POST['add'])) ? 'add' : ((isset($_POST['addusers'])) ? 'addusers' : request_var('action', ''));
4c79b5
		$group_id	= request_var('g', 0);
4c79b5
		$mark_ary	= request_var('mark', array(0));
4c79b5
		$name_ary	= request_var('usernames', '', true);
4c79b5
		$leader		= request_var('leader', 0);
4c79b5
		$default	= request_var('default', 0);
4c79b5
		$start		= request_var('start', 0);
4c79b5
		$update		= (isset($_POST['update'])) ? true : false;
4c79b5
4c79b5
4c79b5
		// Clear some vars
4c79b5
		$can_upload = (file_exists($phpbb_root_path . $config['avatar_path']) && @is_writable($phpbb_root_path . $config['avatar_path']) && $file_uploads) ? true : false;
4c79b5
		$group_row = array();
4c79b5
4c79b5
		// Grab basic data for group, if group_id is set and exists
4c79b5
		if ($group_id)
4c79b5
		{
4c79b5
			$sql = 'SELECT *
4c79b5
				FROM ' . GROUPS_TABLE . "
4c79b5
				WHERE group_id = $group_id";
4c79b5
			$result = $db->sql_query($sql);
4c79b5
			$group_row = $db->sql_fetchrow($result);
4c79b5
			$db->sql_freeresult($result);
4c79b5
4c79b5
			if (!$group_row)
4c79b5
			{
4c79b5
				trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
			}
4c79b5
4c79b5
			// Check if the user is allowed to manage this group if set to founder only.
4c79b5
			if ($user->data['user_type'] != USER_FOUNDER && $group_row['group_founder_manage'])
4c79b5
			{
4c79b5
				trigger_error($user->lang['NOT_ALLOWED_MANAGE_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
			}
4c79b5
		}
4c79b5
4c79b5
		// Which page?
4c79b5
		switch ($action)
4c79b5
		{
4c79b5
			case 'approve':
4c79b5
			case 'demote':
4c79b5
			case 'promote':
4c79b5
				if (!$group_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				// Approve, demote or promote
4c79b5
				$group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
4c79b5
				$error = group_user_attributes($action, $group_id, $mark_ary, false, $group_name);
4c79b5
4c79b5
				if (!$error)
4c79b5
				{
4c79b5
					switch ($action)
4c79b5
					{
4c79b5
						case 'demote':
4c79b5
							$message = 'GROUP_MODS_DEMOTED';
4c79b5
						break;
4c79b5
4c79b5
						case 'promote':
4c79b5
							$message = 'GROUP_MODS_PROMOTED';
4c79b5
						break;
4c79b5
4c79b5
						case 'approve':
4c79b5
							$message = 'USERS_APPROVED';
4c79b5
						break;
4c79b5
					}
4c79b5
4c79b5
					trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id));
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'default':
4c79b5
				if (!$group_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				if (confirm_box(true))
4c79b5
				{
4c79b5
					$group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
4c79b5
4c79b5
					if (!sizeof($mark_ary))
4c79b5
					{
4c79b5
						$start = 0;
4c79b5
4c79b5
						do
4c79b5
						{
4c79b5
							$sql = 'SELECT user_id
4c79b5
								FROM ' . USER_GROUP_TABLE . "
4c79b5
								WHERE group_id = $group_id
4c79b5
								ORDER BY user_id";
4c79b5
							$result = $db->sql_query_limit($sql, 200, $start);
4c79b5
4c79b5
							$mark_ary = array();
4c79b5
							if ($row = $db->sql_fetchrow($result))
4c79b5
							{
4c79b5
								do
4c79b5
								{
4c79b5
									$mark_ary[] = $row['user_id'];
4c79b5
								}
4c79b5
								while ($row = $db->sql_fetchrow($result));
4c79b5
4c79b5
								group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
4c79b5
4c79b5
								$start = (sizeof($mark_ary) < 200) ? 0 : $start + 200;
4c79b5
							}
4c79b5
							else
4c79b5
							{
4c79b5
								$start = 0;
4c79b5
							}
4c79b5
							$db->sql_freeresult($result);
4c79b5
						}
4c79b5
						while ($start);
4c79b5
					}
4c79b5
					else
4c79b5
					{
4c79b5
						group_user_attributes('default', $group_id, $mark_ary, false, $group_name, $group_row);
4c79b5
					}
4c79b5
4c79b5
					trigger_error($user->lang['GROUP_DEFS_UPDATED'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id));
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
4c79b5
						'mark'		=> $mark_ary,
4c79b5
						'g'			=> $group_id,
4c79b5
						'i'			=> $id,
4c79b5
						'mode'		=> $mode,
4c79b5
						'action'	=> $action))
4c79b5
					);
4c79b5
				}
4c79b5
4c79b5
			break;
4c79b5
4c79b5
			case 'deleteusers':
4c79b5
			case 'delete':
4c79b5
				if (!$group_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
				else if ($action === 'delete' && $group_row['group_type'] == GROUP_SPECIAL)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				if (confirm_box(true))
4c79b5
				{
4c79b5
					$error = '';
4c79b5
4c79b5
					switch ($action)
4c79b5
					{
4c79b5
						case 'delete':
4c79b5
							if (!$auth->acl_get('a_groupdel'))
4c79b5
							{
4c79b5
								trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
							}
4c79b5
4c79b5
							$error = group_delete($group_id, $group_row['group_name']);
4c79b5
						break;
4c79b5
4c79b5
						case 'deleteusers':
4c79b5
							$group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
4c79b5
							$error = group_user_del($group_id, $mark_ary, false, $group_name);
4c79b5
						break;
4c79b5
					}
4c79b5
4c79b5
					$back_link = ($action == 'delete') ? $this->u_action : $this->u_action . '&action=list&g=' . $group_id;
4c79b5
4c79b5
					if ($error)
4c79b5
					{
4c79b5
						trigger_error($user->lang[$error] . adm_back_link($back_link), E_USER_WARNING);
4c79b5
					}
4c79b5
4c79b5
					$message = ($action == 'delete') ? 'GROUP_DELETED' : 'GROUP_USERS_REMOVE';
4c79b5
					trigger_error($user->lang[$message] . adm_back_link($back_link));
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
4c79b5
						'mark'		=> $mark_ary,
4c79b5
						'g'			=> $group_id,
4c79b5
						'i'			=> $id,
4c79b5
						'mode'		=> $mode,
4c79b5
						'action'	=> $action))
4c79b5
					);
4c79b5
				}
4c79b5
			break;
4c79b5
4c79b5
			case 'addusers':
4c79b5
				if (!$group_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				if (!$name_ary)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_USERS'] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$name_ary = array_unique(explode("\n", $name_ary));
4c79b5
				$group_name = ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'];
4c79b5
4c79b5
				// Add user/s to group
4c79b5
				if ($error = group_user_add($group_id, false, $name_ary, $group_name, $default, $leader, 0, $group_row))
4c79b5
				{
4c79b5
					trigger_error($user->lang[$error] . adm_back_link($this->u_action . '&action=list&g=' . $group_id), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$message = ($leader) ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED';
4c79b5
				trigger_error($user->lang[$message] . adm_back_link($this->u_action . '&action=list&g=' . $group_id));
4c79b5
			break;
4c79b5
4c79b5
			case 'edit':
4c79b5
			case 'add':
4c79b5
4c79b5
				include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
4c79b5
4c79b5
				$data = $submit_ary = array();
4c79b5
4c79b5
				if ($action == 'edit' && !$group_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				if ($action == 'add' && !$auth->acl_get('a_groupadd'))
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_AUTH_OPERATION'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$error = array();
4c79b5
				$user->add_lang('ucp');
4c79b5
4c79b5
				$avatar_select = basename(request_var('avatar_select', ''));
4c79b5
				$category = basename(request_var('category', ''));
4c79b5
4c79b5
				// Did we submit?
4c79b5
				if ($update)
4c79b5
				{
4c79b5
					if (!check_form_key($form_key))
4c79b5
					{
4c79b5
						trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
					}
4c79b5
4c79b5
					$group_name	= utf8_normalize_nfc(request_var('group_name', '', true));
4c79b5
					$group_desc = utf8_normalize_nfc(request_var('group_desc', '', true));
4c79b5
					$group_type	= request_var('group_type', GROUP_FREE);
4c79b5
4c79b5
					$allow_desc_bbcode	= request_var('desc_parse_bbcode', false);
4c79b5
					$allow_desc_urls	= request_var('desc_parse_urls', false);
4c79b5
					$allow_desc_smilies	= request_var('desc_parse_smilies', false);
4c79b5
4c79b5
					$data['uploadurl']	= request_var('uploadurl', '');
4c79b5
					$data['remotelink']	= request_var('remotelink', '');
4c79b5
					$data['width']		= request_var('width', '');
4c79b5
					$data['height']		= request_var('height', '');
4c79b5
					$delete				= request_var('delete', '');
4c79b5
4c79b5
					$submit_ary = array(
4c79b5
						'colour'			=> request_var('group_colour', ''),
4c79b5
						'rank'				=> request_var('group_rank', 0),
4c79b5
						'receive_pm'		=> isset($_REQUEST['group_receive_pm']) ? 1 : 0,
4c79b5
						'legend'			=> isset($_REQUEST['group_legend']) ? 1 : 0,
4c79b5
						'message_limit'		=> request_var('group_message_limit', 0),
4c79b5
						'max_recipients'	=> request_var('group_max_recipients', 0),
4c79b5
						'founder_manage'	=> 0,
4c79b5
					);
4c79b5
4c79b5
					if ($user->data['user_type'] == USER_FOUNDER)
4c79b5
					{
4c79b5
						$submit_ary['founder_manage'] = isset($_REQUEST['group_founder_manage']) ? 1 : 0;
4c79b5
					}
4c79b5
4c79b5
					if (!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl'] || $data['remotelink'])
4c79b5
					{
4c79b5
						// Avatar stuff
4c79b5
						$var_ary = array(
4c79b5
							'uploadurl'		=> array('string', true, 5, 255),
4c79b5
							'remotelink'	=> array('string', true, 5, 255),
4c79b5
							'width'			=> array('string', true, 1, 3),
4c79b5
							'height'		=> array('string', true, 1, 3),
4c79b5
						);
4c79b5
4c79b5
						if (!($error = validate_data($data, $var_ary)))
4c79b5
						{
4c79b5
							$data['user_id'] = "g$group_id";
4c79b5
4c79b5
							if ((!empty($_FILES['uploadfile']['tmp_name']) || $data['uploadurl']) && $can_upload)
4c79b5
							{
4c79b5
								list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_upload($data, $error);
4c79b5
							}
4c79b5
							else if ($data['remotelink'])
4c79b5
							{
4c79b5
								list($submit_ary['avatar_type'], $submit_ary['avatar'], $submit_ary['avatar_width'], $submit_ary['avatar_height']) = avatar_remote($data, $error);
4c79b5
							}
4c79b5
						}
4c79b5
					}
4c79b5
					else if ($avatar_select && $config['allow_avatar_local'])
4c79b5
					{
4c79b5
						// check avatar gallery
4c79b5
						if (is_dir($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category))
4c79b5
						{
4c79b5
							$submit_ary['avatar_type'] = AVATAR_GALLERY;
4c79b5
4c79b5
							list($submit_ary['avatar_width'], $submit_ary['avatar_height']) = getimagesize($phpbb_root_path . $config['avatar_gallery_path'] . '/' . $category . '/' . $avatar_select);
4c79b5
							$submit_ary['avatar'] = $category . '/' . $avatar_select;
4c79b5
						}
4c79b5
					}
4c79b5
					else if ($delete)
4c79b5
					{
4c79b5
						$submit_ary['avatar'] = '';
4c79b5
						$submit_ary['avatar_type'] = $submit_ary['avatar_width'] = $submit_ary['avatar_height'] = 0;
4c79b5
					}
4c79b5
					else if ($data['width'] && $data['height'])
4c79b5
					{
4c79b5
						// Only update the dimensions?
4c79b5
						if ($config['avatar_max_width'] || $config['avatar_max_height'])
4c79b5
						{
4c79b5
							if ($data['width'] > $config['avatar_max_width'] || $data['height'] > $config['avatar_max_height'])
4c79b5
							{
4c79b5
								$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']);
4c79b5
							}
4c79b5
						}
4c79b5
4c79b5
						if (!sizeof($error))
4c79b5
						{
4c79b5
							if ($config['avatar_min_width'] || $config['avatar_min_height'])
4c79b5
							{
4c79b5
								if ($data['width'] < $config['avatar_min_width'] || $data['height'] < $config['avatar_min_height'])
4c79b5
								{
4c79b5
									$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']);
4c79b5
								}
4c79b5
							}
4c79b5
						}
4c79b5
4c79b5
						if (!sizeof($error))
4c79b5
						{
4c79b5
							$submit_ary['avatar_width'] = $data['width'];
4c79b5
							$submit_ary['avatar_height'] = $data['height'];
4c79b5
						}
4c79b5
					}
4c79b5
4c79b5
					if ((isset($submit_ary['avatar']) && $submit_ary['avatar'] && (!isset($group_row['group_avatar']))) || $delete)
4c79b5
					{
4c79b5
						if (isset($group_row['group_avatar']) && $group_row['group_avatar'])
4c79b5
						{
4c79b5
							avatar_delete('group', $group_row, true);
4c79b5
						}
4c79b5
					}
4c79b5
4c79b5
					if (!sizeof($error))
4c79b5
					{
4c79b5
						// Only set the rank, colour, etc. if it's changed or if we're adding a new
4c79b5
						// group. This prevents existing group members being updated if no changes
4c79b5
						// were made.
4c79b5
4c79b5
						$group_attributes = array();
4c79b5
						$test_variables = array('rank', 'colour', 'avatar', 'avatar_type', 'avatar_width', 'avatar_height', 'receive_pm', 'legend', 'message_limit', 'max_recipients', 'founder_manage');
4c79b5
						foreach ($test_variables as $test)
4c79b5
						{
4c79b5
							if (isset($submit_ary[$test]) && ($action == 'add' || $group_row['group_' . $test] != $submit_ary[$test]))
4c79b5
							{
4c79b5
								$group_attributes['group_' . $test] = $group_row['group_' . $test] = $submit_ary[$test];
4c79b5
							}
4c79b5
						}
4c79b5
4c79b5
						if (!($error = group_create($group_id, $group_type, $group_name, $group_desc, $group_attributes, $allow_desc_bbcode, $allow_desc_urls, $allow_desc_smilies)))
4c79b5
						{
4c79b5
							$group_perm_from = request_var('group_perm_from', 0);
4c79b5
4c79b5
							// Copy permissions?
4c79b5
							// If the user has the a_authgroups permission and at least one additional permission ability set the permissions are fully transferred.
4c79b5
							// 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.
4c79b5
							// Since the user only has the option to copy permissions from non leader managed groups this seems to be a good compromise.
4c79b5
							if ($group_perm_from && $action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth'))
4c79b5
							{
4c79b5
								$sql = 'SELECT group_founder_manage
4c79b5
									FROM ' . GROUPS_TABLE . '
4c79b5
									WHERE group_id = ' . $group_perm_from;
4c79b5
								$result = $db->sql_query($sql);
4c79b5
								$check_row = $db->sql_fetchrow($result);
4c79b5
								$db->sql_freeresult($result);
4c79b5
4c79b5
								// Check the group if non-founder
4c79b5
								if ($check_row && ($user->data['user_type'] == USER_FOUNDER || $check_row['group_founder_manage'] == 0))
4c79b5
								{
4c79b5
									// From the mysql documentation:
4c79b5
									// 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.
4c79b5
									// Due to this we stay on the safe side if we do the insertion "the manual way"
4c79b5
4c79b5
									// Copy permisisons from/to the acl groups table (only group_id gets changed)
4c79b5
									$sql = 'SELECT forum_id, auth_option_id, auth_role_id, auth_setting
4c79b5
										FROM ' . ACL_GROUPS_TABLE . '
4c79b5
										WHERE group_id = ' . $group_perm_from;
4c79b5
									$result = $db->sql_query($sql);
4c79b5
4c79b5
									$groups_sql_ary = array();
4c79b5
									while ($row = $db->sql_fetchrow($result))
4c79b5
									{
4c79b5
										$groups_sql_ary[] = array(
4c79b5
											'group_id'			=> (int) $group_id,
4c79b5
											'forum_id'			=> (int) $row['forum_id'],
4c79b5
											'auth_option_id'	=> (int) $row['auth_option_id'],
4c79b5
											'auth_role_id'		=> (int) $row['auth_role_id'],
4c79b5
											'auth_setting'		=> (int) $row['auth_setting']
4c79b5
										);
4c79b5
									}
4c79b5
									$db->sql_freeresult($result);
4c79b5
4c79b5
									// Now insert the data
4c79b5
									$db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
4c79b5
4c79b5
									$auth->acl_clear_prefetch();
4c79b5
								}
4c79b5
							}
4c79b5
4c79b5
							$cache->destroy('sql', GROUPS_TABLE);
4c79b5
4c79b5
							$message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED';
4c79b5
							trigger_error($user->lang[$message] . adm_back_link($this->u_action));
4c79b5
						}
4c79b5
					}
4c79b5
4c79b5
					if (sizeof($error))
4c79b5
					{
4c79b5
						$group_rank = $submit_ary['rank'];
4c79b5
4c79b5
						$group_desc_data = array(
4c79b5
							'text'			=> $group_desc,
4c79b5
							'allow_bbcode'	=> $allow_desc_bbcode,
4c79b5
							'allow_smilies'	=> $allow_desc_smilies,
4c79b5
							'allow_urls'	=> $allow_desc_urls
4c79b5
						);
4c79b5
					}
4c79b5
				}
4c79b5
				else if (!$group_id)
4c79b5
				{
4c79b5
					$group_name = utf8_normalize_nfc(request_var('group_name', '', true));
4c79b5
					$group_desc_data = array(
4c79b5
						'text'			=> '',
4c79b5
						'allow_bbcode'	=> true,
4c79b5
						'allow_smilies'	=> true,
4c79b5
						'allow_urls'	=> true
4c79b5
					);
4c79b5
					$group_rank = 0;
4c79b5
					$group_type = GROUP_OPEN;
4c79b5
				}
4c79b5
				else
4c79b5
				{
4c79b5
					$group_name = $group_row['group_name'];
4c79b5
					$group_desc_data = generate_text_for_edit($group_row['group_desc'], $group_row['group_desc_uid'], $group_row['group_desc_options']);
4c79b5
					$group_type = $group_row['group_type'];
4c79b5
					$group_rank = $group_row['group_rank'];
4c79b5
				}
4c79b5
4c79b5
				$sql = 'SELECT *
4c79b5
					FROM ' . RANKS_TABLE . '
4c79b5
					WHERE rank_special = 1
4c79b5
					ORDER BY rank_title';
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				$rank_options = '<option value="0"' . ((!$group_rank) ? ' selected="selected"' : '') . '>' . $user->lang['USER_DEFAULT'] . '</option>';
4c79b5
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$selected = ($group_rank && $row['rank_id'] == $group_rank) ? ' selected="selected"' : '';
4c79b5
					$rank_options .= '<option value="' . $row['rank_id'] . '"' . $selected . '>' . $row['rank_title'] . '</option>';
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$type_free		= ($group_type == GROUP_FREE) ? ' checked="checked"' : '';
4c79b5
				$type_open		= ($group_type == GROUP_OPEN) ? ' checked="checked"' : '';
4c79b5
				$type_closed	= ($group_type == GROUP_CLOSED) ? ' checked="checked"' : '';
4c79b5
				$type_hidden	= ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : '';
4c79b5
4c79b5
				$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') : '';
4c79b5
4c79b5
				$display_gallery = (isset($_POST['display_gallery'])) ? true : false;
4c79b5
4c79b5
				if ($config['allow_avatar_local'] && $display_gallery)
4c79b5
				{
4c79b5
					avatar_gallery($category, $avatar_select, 4);
4c79b5
				}
4c79b5
4c79b5
				$back_link = request_var('back_link', '');
4c79b5
4c79b5
				switch ($back_link)
4c79b5
				{
4c79b5
					case 'acp_users_groups':
4c79b5
						$u_back = append_sid("{$phpbb_admin_path}index.$phpEx", 'i=users&mode=groups&u=' . request_var('u', 0));
4c79b5
					break;
4c79b5
4c79b5
					default:
4c79b5
						$u_back = $this->u_action;
4c79b5
					break;
4c79b5
				}
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_EDIT'			=> true,
4c79b5
					'S_ADD_GROUP'		=> ($action == 'add') ? true : false,
4c79b5
					'S_GROUP_PERM'		=> ($action == 'add' && $auth->acl_get('a_authgroups') && $auth->acl_gets('a_aauth', 'a_fauth', 'a_mauth', 'a_uauth')) ? true : false,
4c79b5
					'S_INCLUDE_SWATCH'	=> true,
4c79b5
					'S_CAN_UPLOAD'		=> $can_upload,
4c79b5
					'S_ERROR'			=> (sizeof($error)) ? true : false,
4c79b5
					'S_SPECIAL_GROUP'	=> ($group_type == GROUP_SPECIAL) ? true : false,
4c79b5
					'S_DISPLAY_GALLERY'	=> ($config['allow_avatar_local'] && !$display_gallery) ? true : false,
4c79b5
					'S_IN_GALLERY'		=> ($config['allow_avatar_local'] && $display_gallery) ? true : false,
4c79b5
					'S_USER_FOUNDER'	=> ($user->data['user_type'] == USER_FOUNDER) ? true : false,
4c79b5
4c79b5
					'ERROR_MSG'				=> (sizeof($error)) ? implode('
', $error) : '',
4c79b5
					'GROUP_NAME'			=> ($group_type == GROUP_SPECIAL) ? $user->lang['G_' . $group_name] : $group_name,
4c79b5
					'GROUP_INTERNAL_NAME'	=> $group_name,
4c79b5
					'GROUP_DESC'			=> $group_desc_data['text'],
4c79b5
					'GROUP_RECEIVE_PM'		=> (isset($group_row['group_receive_pm']) && $group_row['group_receive_pm']) ? ' checked="checked"' : '',
4c79b5
					'GROUP_FOUNDER_MANAGE'	=> (isset($group_row['group_founder_manage']) && $group_row['group_founder_manage']) ? ' checked="checked"' : '',
4c79b5
					'GROUP_LEGEND'			=> (isset($group_row['group_legend']) && $group_row['group_legend']) ? ' checked="checked"' : '',
4c79b5
					'GROUP_MESSAGE_LIMIT'	=> (isset($group_row['group_message_limit'])) ? $group_row['group_message_limit'] : 0,
4c79b5
					'GROUP_MAX_RECIPIENTS'	=> (isset($group_row['group_max_recipients'])) ? $group_row['group_max_recipients'] : 0,
4c79b5
					'GROUP_COLOUR'			=> (isset($group_row['group_colour'])) ? $group_row['group_colour'] : '',
4c79b5
4c79b5
4c79b5
					'S_DESC_BBCODE_CHECKED'	=> $group_desc_data['allow_bbcode'],
4c79b5
					'S_DESC_URLS_CHECKED'	=> $group_desc_data['allow_urls'],
4c79b5
					'S_DESC_SMILIES_CHECKED'=> $group_desc_data['allow_smilies'],
4c79b5
4c79b5
					'S_RANK_OPTIONS'		=> $rank_options,
4c79b5
					'S_GROUP_OPTIONS'		=> group_select_options(false, false, (($user->data['user_type'] == USER_FOUNDER) ? false : 0)),
4c79b5
					'AVATAR'				=> $avatar_img,
4c79b5
					'AVATAR_IMAGE'			=> $avatar_img,
4c79b5
					'AVATAR_MAX_FILESIZE'	=> $config['avatar_filesize'],
4c79b5
					'AVATAR_WIDTH'			=> (isset($group_row['group_avatar_width'])) ? $group_row['group_avatar_width'] : '',
4c79b5
					'AVATAR_HEIGHT'			=> (isset($group_row['group_avatar_height'])) ? $group_row['group_avatar_height'] : '',
4c79b5
4c79b5
					'GROUP_TYPE_FREE'		=> GROUP_FREE,
4c79b5
					'GROUP_TYPE_OPEN'		=> GROUP_OPEN,
4c79b5
					'GROUP_TYPE_CLOSED'		=> GROUP_CLOSED,
4c79b5
					'GROUP_TYPE_HIDDEN'		=> GROUP_HIDDEN,
4c79b5
					'GROUP_TYPE_SPECIAL'	=> GROUP_SPECIAL,
4c79b5
4c79b5
					'GROUP_FREE'		=> $type_free,
4c79b5
					'GROUP_OPEN'		=> $type_open,
4c79b5
					'GROUP_CLOSED'		=> $type_closed,
4c79b5
					'GROUP_HIDDEN'		=> $type_hidden,
4c79b5
4c79b5
					'U_BACK'			=> $u_back,
4c79b5
					'U_SWATCH'			=> append_sid("{$phpbb_admin_path}swatch.$phpEx", 'form=settings&name=group_colour'),
4c79b5
					'U_ACTION'			=> "{$this->u_action}&action=$action&g=$group_id",
4c79b5
					'L_AVATAR_EXPLAIN'	=> sprintf($user->lang['AVATAR_EXPLAIN'], $config['avatar_max_width'], $config['avatar_max_height'], round($config['avatar_filesize'] / 1024)),
4c79b5
					)
4c79b5
				);
4c79b5
4c79b5
				return;
4c79b5
			break;
4c79b5
4c79b5
			case 'list':
4c79b5
4c79b5
				if (!$group_id)
4c79b5
				{
4c79b5
					trigger_error($user->lang['NO_GROUP'] . adm_back_link($this->u_action), E_USER_WARNING);
4c79b5
				}
4c79b5
4c79b5
				$this->page_title = 'GROUP_MEMBERS';
4c79b5
4c79b5
				// Grab the leaders - always, on every page...
4c79b5
				$sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
4c79b5
					FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
4c79b5
					WHERE ug.group_id = $group_id
4c79b5
						AND u.user_id = ug.user_id
4c79b5
						AND ug.group_leader = 1
4c79b5
					ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean";
4c79b5
				$result = $db->sql_query($sql);
4c79b5
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					$template->assign_block_vars('leader', array(
4c79b5
						'U_USER_EDIT'		=> append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&action=edit&u={$row['user_id']}"),
4c79b5
4c79b5
						'USERNAME'			=> $row['username'],
4c79b5
						'S_GROUP_DEFAULT'	=> ($row['group_id'] == $group_id) ? true : false,
4c79b5
						'JOINED'			=> ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
4c79b5
						'USER_POSTS'		=> $row['user_posts'],
4c79b5
						'USER_ID'			=> $row['user_id'])
4c79b5
					);
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				// Total number of group members (non-leaders)
4c79b5
				$sql = 'SELECT COUNT(user_id) AS total_members
4c79b5
					FROM ' . USER_GROUP_TABLE . "
4c79b5
					WHERE group_id = $group_id
4c79b5
						AND group_leader = 0";
4c79b5
				$result = $db->sql_query($sql);
4c79b5
				$total_members = (int) $db->sql_fetchfield('total_members');
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				$s_action_options = '';
4c79b5
				$options = array('default' => 'DEFAULT', 'approve' => 'APPROVE', 'demote' => 'DEMOTE', 'promote' => 'PROMOTE', 'deleteusers' => 'DELETE');
4c79b5
4c79b5
				foreach ($options as $option => $lang)
4c79b5
				{
4c79b5
					$s_action_options .= '<option value="' . $option . '">' . $user->lang['GROUP_' . $lang] . '</option>';
4c79b5
				}
4c79b5
4c79b5
				$template->assign_vars(array(
4c79b5
					'S_LIST'			=> true,
4c79b5
					'S_GROUP_SPECIAL'	=> ($group_row['group_type'] == GROUP_SPECIAL) ? true : false,
4c79b5
					'S_ACTION_OPTIONS'	=> $s_action_options,
4c79b5
4c79b5
					'S_ON_PAGE'		=> on_page($total_members, $config['topics_per_page'], $start),
4c79b5
					'PAGINATION'	=> generate_pagination($this->u_action . "&action=$action&g=$group_id", $total_members, $config['topics_per_page'], $start, true),
4c79b5
					'GROUP_NAME'	=> ($group_row['group_type'] == GROUP_SPECIAL) ? $user->lang['G_' . $group_row['group_name']] : $group_row['group_name'],
4c79b5
4c79b5
					'U_ACTION'			=> $this->u_action . "&g=$group_id",
4c79b5
					'U_BACK'			=> $this->u_action,
4c79b5
					'U_FIND_USERNAME'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=list&field=usernames'),
4c79b5
					'U_DEFAULT_ALL'		=> "{$this->u_action}&action=default&g=$group_id",
4c79b5
				));
4c79b5
4c79b5
				// Grab the members
4c79b5
				$sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_regdate, u.user_posts, u.group_id, ug.group_leader, ug.user_pending
4c79b5
					FROM ' . USERS_TABLE . ' u, ' . USER_GROUP_TABLE . " ug
4c79b5
					WHERE ug.group_id = $group_id
4c79b5
						AND u.user_id = ug.user_id
4c79b5
						AND ug.group_leader = 0
4c79b5
					ORDER BY ug.group_leader DESC, ug.user_pending ASC, u.username_clean";
4c79b5
				$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
4c79b5
4c79b5
				$pending = false;
4c79b5
4c79b5
				while ($row = $db->sql_fetchrow($result))
4c79b5
				{
4c79b5
					if ($row['user_pending'] && !$pending)
4c79b5
					{
4c79b5
						$template->assign_block_vars('member', array(
4c79b5
							'S_PENDING'		=> true)
4c79b5
						);
4c79b5
4c79b5
						$pending = true;
4c79b5
					}
4c79b5
4c79b5
					$template->assign_block_vars('member', array(
4c79b5
						'U_USER_EDIT'		=> append_sid("{$phpbb_admin_path}index.$phpEx", "i=users&action=edit&u={$row['user_id']}"),
4c79b5
4c79b5
						'USERNAME'			=> $row['username'],
4c79b5
						'S_GROUP_DEFAULT'	=> ($row['group_id'] == $group_id) ? true : false,
4c79b5
						'JOINED'			=> ($row['user_regdate']) ? $user->format_date($row['user_regdate']) : ' - ',
4c79b5
						'USER_POSTS'		=> $row['user_posts'],
4c79b5
						'USER_ID'			=> $row['user_id'])
4c79b5
					);
4c79b5
				}
4c79b5
				$db->sql_freeresult($result);
4c79b5
4c79b5
				return;
4c79b5
			break;
4c79b5
		}
4c79b5
4c79b5
		$template->assign_vars(array(
4c79b5
			'U_ACTION'		=> $this->u_action,
4c79b5
			'S_GROUP_ADD'	=> ($auth->acl_get('a_groupadd')) ? true : false)
4c79b5
		);
4c79b5
4c79b5
		// Get us all the groups
4c79b5
		$sql = 'SELECT g.group_id, g.group_name, g.group_type
4c79b5
			FROM ' . GROUPS_TABLE . ' g
4c79b5
			ORDER BY g.group_type ASC, g.group_name';
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		$lookup = $cached_group_data = array();
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$type = ($row['group_type'] == GROUP_SPECIAL) ? 'special' : 'normal';
4c79b5
4c79b5
			// used to determine what type a group is
4c79b5
			$lookup[$row['group_id']] = $type;
4c79b5
4c79b5
			// used for easy access to the data within a group
4c79b5
			$cached_group_data[$type][$row['group_id']] = $row;
4c79b5
			$cached_group_data[$type][$row['group_id']]['total_members'] = 0;
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		// How many people are in which group?
4c79b5
		$sql = 'SELECT COUNT(ug.user_id) AS total_members, ug.group_id
4c79b5
			FROM ' . USER_GROUP_TABLE . ' ug
4c79b5
			WHERE ' . $db->sql_in_set('ug.group_id', array_keys($lookup)) . '
4c79b5
			GROUP BY ug.group_id';
4c79b5
		$result = $db->sql_query($sql);
4c79b5
4c79b5
		while ($row = $db->sql_fetchrow($result))
4c79b5
		{
4c79b5
			$type = $lookup[$row['group_id']];
4c79b5
			$cached_group_data[$type][$row['group_id']]['total_members'] = $row['total_members'];
4c79b5
		}
4c79b5
		$db->sql_freeresult($result);
4c79b5
4c79b5
		// The order is... normal, then special
4c79b5
		ksort($cached_group_data);
4c79b5
4c79b5
		foreach ($cached_group_data as $type => $row_ary)
4c79b5
		{
4c79b5
			if ($type == 'special')
4c79b5
			{
4c79b5
				$template->assign_block_vars('groups', array(
4c79b5
					'S_SPECIAL'			=> true)
4c79b5
				);
4c79b5
			}
4c79b5
4c79b5
			foreach ($row_ary as $group_id => $row)
4c79b5
			{
4c79b5
				$group_name = (!empty($user->lang['G_' . $row['group_name']]))? $user->lang['G_' . $row['group_name']] : $row['group_name'];
4c79b5
4c79b5
				$template->assign_block_vars('groups', array(
4c79b5
					'U_LIST'		=> "{$this->u_action}&action=list&g=$group_id",
4c79b5
					'U_EDIT'		=> "{$this->u_action}&action=edit&g=$group_id",
4c79b5
					'U_DELETE'		=> ($auth->acl_get('a_groupdel')) ? "{$this->u_action}&action=delete&g=$group_id" : '',
4c79b5
4c79b5
					'S_GROUP_SPECIAL'	=> ($row['group_type'] == GROUP_SPECIAL) ? true : false,
4c79b5
4c79b5
					'GROUP_NAME'	=> $group_name,
4c79b5
					'TOTAL_MEMBERS'	=> $row['total_members'],
4c79b5
					)
4c79b5
				);
4c79b5
			}
4c79b5
		}
4c79b5
	}
4c79b5
}
4c79b5
4c79b5
?>