Blame Identity/Webenv/phpBB/3.0.4/includes/acp/acp_ban.php

ef5584
ef5584
/**
ef5584
*
ef5584
* @package acp
ef5584
* @version $Id: acp_ban.php 8479 2008-03-29 00:22:48Z naderman $
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 acp
ef5584
*/
ef5584
class acp_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, $phpbb_admin_path, $phpEx, $table_prefix;
ef5584
ef5584
		include($phpbb_root_path . 'includes/functions_user.' . $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 = 'acp_ban';
ef5584
		$form_key = 'acp_ban';
ef5584
		add_form_key($form_key);
ef5584
ef5584
		if (($bansubmit || $unbansubmit) && !check_form_key($form_key))
ef5584
		{
ef5584
			trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
ef5584
		}
ef5584
ef5584
		// Ban submitted?
ef5584
		if ($bansubmit)
ef5584
		{
ef5584
			// Grab the list of entries
ef5584
			$ban				= utf8_normalize_nfc(request_var('ban', '', true));
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
				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'] . adm_back_link($this->u_action));
ef5584
			}
ef5584
		}
ef5584
		else if ($unbansubmit)
ef5584
		{
ef5584
			$ban = request_var('unban', array(''));
ef5584
ef5584
			if ($ban)
ef5584
			{
ef5584
				user_unban($mode, $ban);
ef5584
ef5584
				trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . adm_back_link($this->u_action));
ef5584
			}
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
		$this->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=acp_ban&field=ban'),
ef5584
		));
ef5584
	}
ef5584
ef5584
	/**
ef5584
	* Display ban options
ef5584
	*/
ef5584
	function display_ban_options($mode)
ef5584
	{
ef5584
		global $user, $db, $template;
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
		switch ($mode)
ef5584
		{
ef5584
			case 'user':
ef5584
ef5584
				$field = 'username';
ef5584
				$l_ban_cell = $user->lang['USERNAME'];
ef5584
ef5584
				$sql = 'SELECT b.*, u.user_id, u.username, u.username_clean
ef5584
					FROM ' . BANLIST_TABLE . ' b, ' . USERS_TABLE . ' u
ef5584
					WHERE (b.ban_end >= ' . time() . '
ef5584
							OR b.ban_end = 0)
ef5584
						AND u.user_id = b.ban_userid
ef5584
					ORDER BY u.username_clean ASC';
ef5584
			break;
ef5584
ef5584
			case 'ip':
ef5584
ef5584
				$field = 'ban_ip';
ef5584
				$l_ban_cell = $user->lang['IP_HOSTNAME'];
ef5584
ef5584
				$sql = 'SELECT *
ef5584
					FROM ' . BANLIST_TABLE . '
ef5584
					WHERE (ban_end >= ' . time() . "
ef5584
							OR ban_end = 0)
ef5584
						AND ban_ip <> ''";
ef5584
			break;
ef5584
ef5584
			case 'email':
ef5584
ef5584
				$field = 'ban_email';
ef5584
				$l_ban_cell = $user->lang['EMAIL_ADDRESS'];
ef5584
ef5584
				$sql = 'SELECT *
ef5584
					FROM ' . BANLIST_TABLE . '
ef5584
					WHERE (ban_end >= ' . time() . "
ef5584
							OR ban_end = 0)
ef5584
						AND ban_email <> ''";
ef5584
			break;
ef5584
		}
ef5584
		$result = $db->sql_query($sql);
ef5584
ef5584
		$banned_options = '';
ef5584
		$ban_length = $ban_reasons = $ban_give_reasons = array();
ef5584
ef5584
		while ($row = $db->sql_fetchrow($result))
ef5584
		{
ef5584
			$banned_options .= '<option' . (($row['ban_exclude']) ? ' class="sep"' : '') . ' value="' . $row['ban_id'] . '">' . $row[$field] . '</option>';
ef5584
ef5584
			$time_length = ($row['ban_end']) ? ($row['ban_end'] - $row['ban_start']) / 60 : 0;
ef5584
			$ban_length[$row['ban_id']] = (isset($ban_end_text[$time_length])) ? $ban_end_text[$time_length] : $user->lang['UNTIL'] . ' -> ' . $user->format_date($row['ban_end']);
ef5584
ef5584
			$ban_reasons[$row['ban_id']] = $row['ban_reason'];
ef5584
			$ban_give_reasons[$row['ban_id']] = $row['ban_give_reason'];
ef5584
		}
ef5584
		$db->sql_freeresult($result);
ef5584
ef5584
		if (sizeof($ban_length))
ef5584
		{
ef5584
			foreach ($ban_length as $ban_id => $length)
ef5584
			{
ef5584
				$template->assign_block_vars('ban_length', array(
ef5584
					'BAN_ID'	=> (int) $ban_id,
ef5584
					'LENGTH'	=> $length,
ef5584
					'A_LENGTH'	=> addslashes($length),
ef5584
				));
ef5584
			}
ef5584
		}
ef5584
ef5584
		if (sizeof($ban_reasons))
ef5584
		{
ef5584
			foreach ($ban_reasons as $ban_id => $reason)
ef5584
			{
ef5584
				$template->assign_block_vars('ban_reason', array(
ef5584
					'BAN_ID'	=> $ban_id,
ef5584
					'REASON'	=> $reason,
ef5584
					'A_REASON'	=> addslashes(htmlspecialchars_decode($reason)),
ef5584
				));
ef5584
			}
ef5584
		}
ef5584
ef5584
		if (sizeof($ban_give_reasons))
ef5584
		{
ef5584
			foreach ($ban_give_reasons as $ban_id => $reason)
ef5584
			{
ef5584
				$template->assign_block_vars('ban_give_reason', array(
ef5584
					'BAN_ID'	=> $ban_id,
ef5584
					'REASON'	=> $reason,
ef5584
					'A_REASON'	=> addslashes(htmlspecialchars_decode($reason)),
ef5584
				));
ef5584
			}
ef5584
		}
ef5584
ef5584
		$template->assign_vars(array(
ef5584
			'S_BAN_END_OPTIONS'	=> $ban_end_options,
ef5584
			'S_BANNED_OPTIONS'	=> ($banned_options) ? true : false,
ef5584
			'BANNED_OPTIONS'	=> $banned_options)
ef5584
		);
ef5584
	}
ef5584
}
ef5584
ef5584
?>