Blame Identity/Webenv/phpBB/3.0.4/includes/mcp/mcp_ban.php

ef5584
ef5584
/**
ef5584
*
ef5584
* @package mcp
ef5584
* @version $Id: mcp_ban.php 8589 2008-06-04 11:11:48Z acydburn $
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
* @package mcp
ef5584
*/
ef5584
class mcp_ban
ef5584
{
ef5584
	var $u_action;
ef5584
ef5584
	function main($id, $mode)
ef5584
	{
ef5584
		global $config, $db, $user, $auth, $template, $cache;
ef5584
		global $phpbb_root_path, $phpEx;
ef5584
ef5584
		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
ef5584
ef5584
		// Include the admin banning interface...
ef5584
		include($phpbb_root_path . 'includes/acp/acp_ban.' . $phpEx);
ef5584
ef5584
		$bansubmit		= (isset($_POST['bansubmit'])) ? true : false;
ef5584
		$unbansubmit	= (isset($_POST['unbansubmit'])) ? true : false;
ef5584
		$current_time	= time();
ef5584
ef5584
		$user->add_lang(array('acp/ban', 'acp/users'));
ef5584
		$this->tpl_name = 'mcp_ban';
ef5584
ef5584
		// Ban submitted?
ef5584
		if ($bansubmit)
ef5584
		{
ef5584
			// Grab the list of entries
ef5584
			$ban				= request_var('ban', '', ($mode === 'user') ? true : false);
ef5584
ef5584
			if ($mode === 'user')
ef5584
			{
ef5584
				$ban = utf8_normalize_nfc($ban);
ef5584
			}
ef5584
ef5584
			$ban_len			= request_var('banlength', 0);
ef5584
			$ban_len_other		= request_var('banlengthother', '');
ef5584
			$ban_exclude		= request_var('banexclude', 0);
ef5584
			$ban_reason			= utf8_normalize_nfc(request_var('banreason', '', true));
ef5584
			$ban_give_reason	= utf8_normalize_nfc(request_var('bangivereason', '', true));
ef5584
ef5584
			if ($ban)
ef5584
			{
ef5584
				if (confirm_box(true))
ef5584
				{
ef5584
					user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason);
ef5584
ef5584
					trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '

« ' . $user->lang['BACK_TO_PREV'] . '');
ef5584
				}
ef5584
				else
ef5584
				{
ef5584
					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
ef5584
						'mode'				=> $mode,
ef5584
						'ban'				=> $ban,
ef5584
						'bansubmit'			=> true,
ef5584
						'banlength'			=> $ban_len,
ef5584
						'banlengthother'	=> $ban_len_other,
ef5584
						'banexclude'		=> $ban_exclude,
ef5584
						'banreason'			=> $ban_reason,
ef5584
						'bangivereason'		=> $ban_give_reason)));
ef5584
				}
ef5584
			}
ef5584
		}
ef5584
		else if ($unbansubmit)
ef5584
		{
ef5584
			$ban = request_var('unban', array(''));
ef5584
ef5584
			if ($ban)
ef5584
			{
ef5584
				if (confirm_box(true))
ef5584
				{
ef5584
					user_unban($mode, $ban);
ef5584
ef5584
					trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '

« ' . $user->lang['BACK_TO_PREV'] . '');
ef5584
				}
ef5584
				else
ef5584
				{
ef5584
					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
ef5584
						'mode'			=> $mode,
ef5584
						'unbansubmit'	=> true,
ef5584
						'unban'			=> $ban)));
ef5584
				}
ef5584
			}
ef5584
		}
ef5584
ef5584
		// Ban length options
ef5584
		$ban_end_text = array(0 => $user->lang['PERMANENT'], 30 => $user->lang['30_MINS'], 60 => $user->lang['1_HOUR'], 360 => $user->lang['6_HOURS'], 1440 => $user->lang['1_DAY'], 10080 => $user->lang['7_DAYS'], 20160 => $user->lang['2_WEEKS'], 40320 => $user->lang['1_MONTH'], -1 => $user->lang['UNTIL'] . ' -> ');
ef5584
ef5584
		$ban_end_options = '';
ef5584
		foreach ($ban_end_text as $length => $text)
ef5584
		{
ef5584
			$ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
ef5584
		}
ef5584
ef5584
		// Define language vars
ef5584
		$this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
ef5584
ef5584
		$l_ban_explain = $user->lang[strtoupper($mode) . '_BAN_EXPLAIN'];
ef5584
		$l_ban_exclude_explain = $user->lang[strtoupper($mode) . '_BAN_EXCLUDE_EXPLAIN'];
ef5584
		$l_unban_title = $user->lang[strtoupper($mode) . '_UNBAN'];
ef5584
		$l_unban_explain = $user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN'];
ef5584
		$l_no_ban_cell = $user->lang[strtoupper($mode) . '_NO_BANNED'];
ef5584
ef5584
		switch ($mode)
ef5584
		{
ef5584
			case 'user':
ef5584
				$l_ban_cell = $user->lang['USERNAME'];
ef5584
			break;
ef5584
ef5584
			case 'ip':
ef5584
				$l_ban_cell = $user->lang['IP_HOSTNAME'];
ef5584
			break;
ef5584
ef5584
			case 'email':
ef5584
				$l_ban_cell = $user->lang['EMAIL_ADDRESS'];
ef5584
			break;
ef5584
		}
ef5584
ef5584
		acp_ban::display_ban_options($mode);
ef5584
ef5584
		$template->assign_vars(array(
ef5584
			'L_TITLE'				=> $this->page_title,
ef5584
			'L_EXPLAIN'				=> $l_ban_explain,
ef5584
			'L_UNBAN_TITLE'			=> $l_unban_title,
ef5584
			'L_UNBAN_EXPLAIN'		=> $l_unban_explain,
ef5584
			'L_BAN_CELL'			=> $l_ban_cell,
ef5584
			'L_BAN_EXCLUDE_EXPLAIN'	=> $l_ban_exclude_explain,
ef5584
			'L_NO_BAN_CELL'			=> $l_no_ban_cell,
ef5584
ef5584
			'S_USERNAME_BAN'	=> ($mode == 'user') ? true : false,
ef5584
ef5584
			'U_ACTION'			=> $this->u_action,
ef5584
			'U_FIND_USERNAME'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&form=mcp_ban&field=ban'),
ef5584
		));
ef5584
ef5584
		if ($mode === 'email' && !$auth->acl_get('a_user'))
ef5584
		{
ef5584
			return;
ef5584
		}
ef5584
ef5584
		// As a "service" we will check if any post id is specified and populate the username of the poster id if given
ef5584
		$post_id = request_var('p', 0);
ef5584
		$user_id = request_var('u', 0);
ef5584
		$username = $pre_fill = false;
ef5584
ef5584
		if ($user_id && $user_id <> ANONYMOUS)
ef5584
		{
ef5584
			$sql = 'SELECT username, user_email, user_ip
ef5584
				FROM ' . USERS_TABLE . '
ef5584
				WHERE user_id = ' . $user_id;
ef5584
			$result = $db->sql_query($sql);
ef5584
			switch ($mode)
ef5584
			{
ef5584
				case 'user':
ef5584
					$pre_fill = (string) $db->sql_fetchfield('username');
ef5584
				break;
ef5584
				
ef5584
				case 'ip':
ef5584
					$pre_fill = (string) $db->sql_fetchfield('user_ip');
ef5584
				break;
ef5584
ef5584
				case 'email':
ef5584
					$pre_fill = (string) $db->sql_fetchfield('user_email');
ef5584
				break;
ef5584
			}
ef5584
			$db->sql_freeresult($result);
ef5584
		}
ef5584
		else if ($post_id)
ef5584
		{
ef5584
			$post_info = get_post_data($post_id, 'm_ban');
ef5584
ef5584
			if (sizeof($post_info) && !empty($post_info[$post_id]))
ef5584
			{
ef5584
				switch ($mode)
ef5584
				{
ef5584
					case 'user':
ef5584
						$pre_fill = $post_info[$post_id]['username'];
ef5584
					break;
ef5584
ef5584
					case 'ip':
ef5584
						$pre_fill = $post_info[$post_id]['poster_ip'];
ef5584
					break;
ef5584
ef5584
					case 'email':
ef5584
						$pre_fill = $post_info[$post_id]['user_email'];
ef5584
					break;
ef5584
				}
ef5584
ef5584
			}
ef5584
		}
ef5584
ef5584
		if ($pre_fill)
ef5584
		{
ef5584
			// left for legacy template compatibility
ef5584
			$template->assign_var('USERNAMES', $pre_fill);
ef5584
			$template->assign_var('BAN_QUANTIFIER', $pre_fill);
ef5584
		}
ef5584
	}
ef5584
}
ef5584
ef5584
?>