Blame Extras/phpBB/3.0.4/includes/mcp/mcp_ban.php

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

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

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