includes/acp/acp_ban.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/acp/acp_ban.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,276 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package acp
     1.8 +* @version $Id$
     1.9 +* @copyright (c) 2005 phpBB Group
    1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
    1.11 +*
    1.12 +*/
    1.13 +
    1.14 +/**
    1.15 +* @ignore
    1.16 +*/
    1.17 +if (!defined('IN_PHPBB'))
    1.18 +{
    1.19 +	exit;
    1.20 +}
    1.21 +
    1.22 +/**
    1.23 +* @package acp
    1.24 +*/
    1.25 +class acp_ban
    1.26 +{
    1.27 +	var $u_action;
    1.28 +
    1.29 +	function main($id, $mode)
    1.30 +	{
    1.31 +		global $config, $db, $user, $auth, $template, $cache;
    1.32 +		global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix;
    1.33 +
    1.34 +		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
    1.35 +
    1.36 +		$bansubmit	= (isset($_POST['bansubmit'])) ? true : false;
    1.37 +		$unbansubmit = (isset($_POST['unbansubmit'])) ? true : false;
    1.38 +		$current_time = time();
    1.39 +
    1.40 +		$user->add_lang(array('acp/ban', 'acp/users'));
    1.41 +		$this->tpl_name = 'acp_ban';
    1.42 +		$form_key = 'acp_ban';
    1.43 +		add_form_key($form_key);
    1.44 +
    1.45 +		if (($bansubmit || $unbansubmit) && !check_form_key($form_key))
    1.46 +		{
    1.47 +			trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING);
    1.48 +		}
    1.49 +
    1.50 +		// Ban submitted?
    1.51 +		if ($bansubmit)
    1.52 +		{
    1.53 +			// Grab the list of entries
    1.54 +			$ban				= utf8_normalize_nfc(request_var('ban', '', true));
    1.55 +			$ban_len			= request_var('banlength', 0);
    1.56 +			$ban_len_other		= request_var('banlengthother', '');
    1.57 +			$ban_exclude		= request_var('banexclude', 0);
    1.58 +			$ban_reason			= utf8_normalize_nfc(request_var('banreason', '', true));
    1.59 +			$ban_give_reason	= utf8_normalize_nfc(request_var('bangivereason', '', true));
    1.60 +
    1.61 +			if ($ban)
    1.62 +			{
    1.63 +				user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason);
    1.64 +
    1.65 +				trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . adm_back_link($this->u_action));
    1.66 +			}
    1.67 +		}
    1.68 +		else if ($unbansubmit)
    1.69 +		{
    1.70 +			$ban = request_var('unban', array(''));
    1.71 +
    1.72 +			if ($ban)
    1.73 +			{
    1.74 +				user_unban($mode, $ban);
    1.75 +
    1.76 +				trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . adm_back_link($this->u_action));
    1.77 +			}
    1.78 +		}
    1.79 +
    1.80 +		// Define language vars
    1.81 +		$this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
    1.82 +
    1.83 +		$l_ban_explain = $user->lang[strtoupper($mode) . '_BAN_EXPLAIN'];
    1.84 +		$l_ban_exclude_explain = $user->lang[strtoupper($mode) . '_BAN_EXCLUDE_EXPLAIN'];
    1.85 +		$l_unban_title = $user->lang[strtoupper($mode) . '_UNBAN'];
    1.86 +		$l_unban_explain = $user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN'];
    1.87 +		$l_no_ban_cell = $user->lang[strtoupper($mode) . '_NO_BANNED'];
    1.88 +
    1.89 +		switch ($mode)
    1.90 +		{
    1.91 +			case 'user':
    1.92 +				$l_ban_cell = $user->lang['USERNAME'];
    1.93 +			break;
    1.94 +
    1.95 +			case 'ip':
    1.96 +				$l_ban_cell = $user->lang['IP_HOSTNAME'];
    1.97 +			break;
    1.98 +
    1.99 +			case 'email':
   1.100 +				$l_ban_cell = $user->lang['EMAIL_ADDRESS'];
   1.101 +			break;
   1.102 +		}
   1.103 +
   1.104 +		$this->display_ban_options($mode);
   1.105 +
   1.106 +		$template->assign_vars(array(
   1.107 +			'L_TITLE'				=> $this->page_title,
   1.108 +			'L_EXPLAIN'				=> $l_ban_explain,
   1.109 +			'L_UNBAN_TITLE'			=> $l_unban_title,
   1.110 +			'L_UNBAN_EXPLAIN'		=> $l_unban_explain,
   1.111 +			'L_BAN_CELL'			=> $l_ban_cell,
   1.112 +			'L_BAN_EXCLUDE_EXPLAIN'	=> $l_ban_exclude_explain,
   1.113 +			'L_NO_BAN_CELL'			=> $l_no_ban_cell,
   1.114 +
   1.115 +			'S_USERNAME_BAN'	=> ($mode == 'user') ? true : false,
   1.116 +			
   1.117 +			'U_ACTION'			=> $this->u_action,
   1.118 +			'U_FIND_USERNAME'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=acp_ban&amp;field=ban'),
   1.119 +		));
   1.120 +	}
   1.121 +
   1.122 +	/**
   1.123 +	* Display ban options
   1.124 +	*/
   1.125 +	function display_ban_options($mode)
   1.126 +	{
   1.127 +		global $user, $db, $template;
   1.128 +
   1.129 +		// Ban length options
   1.130 +		$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'] . ' -&gt; ');
   1.131 +
   1.132 +		$ban_end_options = '';
   1.133 +		foreach ($ban_end_text as $length => $text)
   1.134 +		{
   1.135 +			$ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
   1.136 +		}
   1.137 +
   1.138 +		switch ($mode)
   1.139 +		{
   1.140 +			case 'user':
   1.141 +
   1.142 +				$field = 'username';
   1.143 +				$l_ban_cell = $user->lang['USERNAME'];
   1.144 +
   1.145 +				$sql = 'SELECT b.*, u.user_id, u.username, u.username_clean
   1.146 +					FROM ' . BANLIST_TABLE . ' b, ' . USERS_TABLE . ' u
   1.147 +					WHERE (b.ban_end >= ' . time() . '
   1.148 +							OR b.ban_end = 0)
   1.149 +						AND u.user_id = b.ban_userid
   1.150 +					ORDER BY u.username_clean ASC';
   1.151 +			break;
   1.152 +
   1.153 +			case 'ip':
   1.154 +
   1.155 +				$field = 'ban_ip';
   1.156 +				$l_ban_cell = $user->lang['IP_HOSTNAME'];
   1.157 +
   1.158 +				$sql = 'SELECT *
   1.159 +					FROM ' . BANLIST_TABLE . '
   1.160 +					WHERE (ban_end >= ' . time() . "
   1.161 +							OR ban_end = 0)
   1.162 +						AND ban_ip <> ''
   1.163 +					ORDER BY ban_ip";
   1.164 +			break;
   1.165 +
   1.166 +			case 'email':
   1.167 +
   1.168 +				$field = 'ban_email';
   1.169 +				$l_ban_cell = $user->lang['EMAIL_ADDRESS'];
   1.170 +
   1.171 +				$sql = 'SELECT *
   1.172 +					FROM ' . BANLIST_TABLE . '
   1.173 +					WHERE (ban_end >= ' . time() . "
   1.174 +							OR ban_end = 0)
   1.175 +						AND ban_email <> ''
   1.176 +					ORDER BY ban_email";
   1.177 +			break;
   1.178 +		}
   1.179 +		$result = $db->sql_query($sql);
   1.180 +
   1.181 +		$banned_options = $excluded_options = array();
   1.182 +		$ban_length = $ban_reasons = $ban_give_reasons = array();
   1.183 +
   1.184 +		while ($row = $db->sql_fetchrow($result))
   1.185 +		{
   1.186 +			$option = '<option value="' . $row['ban_id'] . '">' . $row[$field] . '</option>';
   1.187 +
   1.188 +			if ($row['ban_exclude'])
   1.189 +			{
   1.190 +				$excluded_options[] = $option;
   1.191 +			}
   1.192 +			else
   1.193 +			{
   1.194 +				$banned_options[] = $option;
   1.195 +			}
   1.196 +
   1.197 +			$time_length = ($row['ban_end']) ? ($row['ban_end'] - $row['ban_start']) / 60 : 0;
   1.198 +
   1.199 +			if ($time_length == 0)
   1.200 +			{
   1.201 +				// Banned permanently
   1.202 +				$ban_length[$row['ban_id']] = $user->lang['PERMANENT'];
   1.203 +			}
   1.204 +			else if (isset($ban_end_text[$time_length]))
   1.205 +			{
   1.206 +				// Banned for a given duration
   1.207 +				$ban_length[$row['ban_id']] = sprintf($user->lang['BANNED_UNTIL_DURATION'], $ban_end_text[$time_length], $user->format_date($row['ban_end'], false, true));
   1.208 +			}
   1.209 +			else
   1.210 +			{
   1.211 +				// Banned until given date
   1.212 +				$ban_length[$row['ban_id']] = sprintf($user->lang['BANNED_UNTIL_DATE'], $user->format_date($row['ban_end'], false, true));
   1.213 +			}
   1.214 +
   1.215 +			$ban_reasons[$row['ban_id']] = $row['ban_reason'];
   1.216 +			$ban_give_reasons[$row['ban_id']] = $row['ban_give_reason'];
   1.217 +		}
   1.218 +		$db->sql_freeresult($result);
   1.219 +
   1.220 +		if (sizeof($ban_length))
   1.221 +		{
   1.222 +			foreach ($ban_length as $ban_id => $length)
   1.223 +			{
   1.224 +				$template->assign_block_vars('ban_length', array(
   1.225 +					'BAN_ID'	=> (int) $ban_id,
   1.226 +					'LENGTH'	=> $length,
   1.227 +					'A_LENGTH'	=> addslashes($length),
   1.228 +				));
   1.229 +			}
   1.230 +		}
   1.231 +
   1.232 +		if (sizeof($ban_reasons))
   1.233 +		{
   1.234 +			foreach ($ban_reasons as $ban_id => $reason)
   1.235 +			{
   1.236 +				$template->assign_block_vars('ban_reason', array(
   1.237 +					'BAN_ID'	=> $ban_id,
   1.238 +					'REASON'	=> $reason,
   1.239 +					'A_REASON'	=> addslashes($reason),
   1.240 +				));
   1.241 +			}
   1.242 +		}
   1.243 +
   1.244 +		if (sizeof($ban_give_reasons))
   1.245 +		{
   1.246 +			foreach ($ban_give_reasons as $ban_id => $reason)
   1.247 +			{
   1.248 +				$template->assign_block_vars('ban_give_reason', array(
   1.249 +					'BAN_ID'	=> $ban_id,
   1.250 +					'REASON'	=> $reason,
   1.251 +					'A_REASON'	=> addslashes($reason),
   1.252 +				));
   1.253 +			}
   1.254 +		}
   1.255 +
   1.256 +		$options = '';
   1.257 +		if ($excluded_options)
   1.258 +		{
   1.259 +			$options .= '<optgroup label="' . $user->lang['OPTIONS_EXCLUDED'] . '">';
   1.260 +			$options .= implode('', $excluded_options);
   1.261 +			$options .= '</optgroup>';
   1.262 +		}
   1.263 +
   1.264 +		if ($banned_options)
   1.265 +		{
   1.266 +			$options .= '<optgroup label="' . $user->lang['OPTIONS_BANNED'] . '">';
   1.267 +			$options .= implode('', $banned_options);
   1.268 +			$options .= '</optgroup>';
   1.269 +		}
   1.270 +
   1.271 +		$template->assign_vars(array(
   1.272 +			'S_BAN_END_OPTIONS'	=> $ban_end_options,
   1.273 +			'S_BANNED_OPTIONS'	=> ($banned_options || $excluded_options) ? true : false,
   1.274 +			'BANNED_OPTIONS'	=> $options,
   1.275 +		));
   1.276 +	}
   1.277 +}
   1.278 +
   1.279 +?>
   1.280 \ No newline at end of file