includes/mcp/mcp_ban.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/mcp/mcp_ban.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,219 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package mcp
     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 mcp
    1.24 +*/
    1.25 +class mcp_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, $phpEx;
    1.33 +
    1.34 +		include($phpbb_root_path . 'includes/functions_user.' . $phpEx);
    1.35 +
    1.36 +		// Include the admin banning interface...
    1.37 +		include($phpbb_root_path . 'includes/acp/acp_ban.' . $phpEx);
    1.38 +
    1.39 +		$bansubmit		= (isset($_POST['bansubmit'])) ? true : false;
    1.40 +		$unbansubmit	= (isset($_POST['unbansubmit'])) ? true : false;
    1.41 +		$current_time	= time();
    1.42 +
    1.43 +		$user->add_lang(array('acp/ban', 'acp/users'));
    1.44 +		$this->tpl_name = 'mcp_ban';
    1.45 +
    1.46 +		// Ban submitted?
    1.47 +		if ($bansubmit)
    1.48 +		{
    1.49 +			// Grab the list of entries
    1.50 +			$ban				= request_var('ban', '', ($mode === 'user') ? true : false);
    1.51 +
    1.52 +			if ($mode === 'user')
    1.53 +			{
    1.54 +				$ban = utf8_normalize_nfc($ban);
    1.55 +			}
    1.56 +
    1.57 +			$ban_len			= request_var('banlength', 0);
    1.58 +			$ban_len_other		= request_var('banlengthother', '');
    1.59 +			$ban_exclude		= request_var('banexclude', 0);
    1.60 +			$ban_reason			= utf8_normalize_nfc(request_var('banreason', '', true));
    1.61 +			$ban_give_reason	= utf8_normalize_nfc(request_var('bangivereason', '', true));
    1.62 +
    1.63 +			if ($ban)
    1.64 +			{
    1.65 +				if (confirm_box(true))
    1.66 +				{
    1.67 +					user_ban($mode, $ban, $ban_len, $ban_len_other, $ban_exclude, $ban_reason, $ban_give_reason);
    1.68 +
    1.69 +					trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">&laquo; ' . $user->lang['BACK_TO_PREV'] . '</a>');
    1.70 +				}
    1.71 +				else
    1.72 +				{
    1.73 +					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
    1.74 +						'mode'				=> $mode,
    1.75 +						'ban'				=> $ban,
    1.76 +						'bansubmit'			=> true,
    1.77 +						'banlength'			=> $ban_len,
    1.78 +						'banlengthother'	=> $ban_len_other,
    1.79 +						'banexclude'		=> $ban_exclude,
    1.80 +						'banreason'			=> $ban_reason,
    1.81 +						'bangivereason'		=> $ban_give_reason)));
    1.82 +				}
    1.83 +			}
    1.84 +		}
    1.85 +		else if ($unbansubmit)
    1.86 +		{
    1.87 +			$ban = request_var('unban', array(''));
    1.88 +
    1.89 +			if ($ban)
    1.90 +			{
    1.91 +				if (confirm_box(true))
    1.92 +				{
    1.93 +					user_unban($mode, $ban);
    1.94 +
    1.95 +					trigger_error($user->lang['BAN_UPDATE_SUCCESSFUL'] . '<br /><br /><a href="' . $this->u_action . '">&laquo; ' . $user->lang['BACK_TO_PREV'] . '</a>');
    1.96 +				}
    1.97 +				else
    1.98 +				{
    1.99 +					confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
   1.100 +						'mode'			=> $mode,
   1.101 +						'unbansubmit'	=> true,
   1.102 +						'unban'			=> $ban)));
   1.103 +				}
   1.104 +			}
   1.105 +		}
   1.106 +
   1.107 +		// Ban length options
   1.108 +		$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.109 +
   1.110 +		$ban_end_options = '';
   1.111 +		foreach ($ban_end_text as $length => $text)
   1.112 +		{
   1.113 +			$ban_end_options .= '<option value="' . $length . '">' . $text . '</option>';
   1.114 +		}
   1.115 +
   1.116 +		// Define language vars
   1.117 +		$this->page_title = $user->lang[strtoupper($mode) . '_BAN'];
   1.118 +
   1.119 +		$l_ban_explain = $user->lang[strtoupper($mode) . '_BAN_EXPLAIN'];
   1.120 +		$l_ban_exclude_explain = $user->lang[strtoupper($mode) . '_BAN_EXCLUDE_EXPLAIN'];
   1.121 +		$l_unban_title = $user->lang[strtoupper($mode) . '_UNBAN'];
   1.122 +		$l_unban_explain = $user->lang[strtoupper($mode) . '_UNBAN_EXPLAIN'];
   1.123 +		$l_no_ban_cell = $user->lang[strtoupper($mode) . '_NO_BANNED'];
   1.124 +
   1.125 +		switch ($mode)
   1.126 +		{
   1.127 +			case 'user':
   1.128 +				$l_ban_cell = $user->lang['USERNAME'];
   1.129 +			break;
   1.130 +
   1.131 +			case 'ip':
   1.132 +				$l_ban_cell = $user->lang['IP_HOSTNAME'];
   1.133 +			break;
   1.134 +
   1.135 +			case 'email':
   1.136 +				$l_ban_cell = $user->lang['EMAIL_ADDRESS'];
   1.137 +			break;
   1.138 +		}
   1.139 +
   1.140 +		acp_ban::display_ban_options($mode);
   1.141 +
   1.142 +		$template->assign_vars(array(
   1.143 +			'L_TITLE'				=> $this->page_title,
   1.144 +			'L_EXPLAIN'				=> $l_ban_explain,
   1.145 +			'L_UNBAN_TITLE'			=> $l_unban_title,
   1.146 +			'L_UNBAN_EXPLAIN'		=> $l_unban_explain,
   1.147 +			'L_BAN_CELL'			=> $l_ban_cell,
   1.148 +			'L_BAN_EXCLUDE_EXPLAIN'	=> $l_ban_exclude_explain,
   1.149 +			'L_NO_BAN_CELL'			=> $l_no_ban_cell,
   1.150 +
   1.151 +			'S_USERNAME_BAN'	=> ($mode == 'user') ? true : false,
   1.152 +
   1.153 +			'U_ACTION'			=> $this->u_action,
   1.154 +			'U_FIND_USERNAME'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=mcp_ban&amp;field=ban'),
   1.155 +		));
   1.156 +
   1.157 +		if ($mode === 'email' && !$auth->acl_get('a_user'))
   1.158 +		{
   1.159 +			return;
   1.160 +		}
   1.161 +
   1.162 +		// As a "service" we will check if any post id is specified and populate the username of the poster id if given
   1.163 +		$post_id = request_var('p', 0);
   1.164 +		$user_id = request_var('u', 0);
   1.165 +		$username = $pre_fill = false;
   1.166 +
   1.167 +		if ($user_id && $user_id <> ANONYMOUS)
   1.168 +		{
   1.169 +			$sql = 'SELECT username, user_email, user_ip
   1.170 +				FROM ' . USERS_TABLE . '
   1.171 +				WHERE user_id = ' . $user_id;
   1.172 +			$result = $db->sql_query($sql);
   1.173 +			switch ($mode)
   1.174 +			{
   1.175 +				case 'user':
   1.176 +					$pre_fill = (string) $db->sql_fetchfield('username');
   1.177 +				break;
   1.178 +				
   1.179 +				case 'ip':
   1.180 +					$pre_fill = (string) $db->sql_fetchfield('user_ip');
   1.181 +				break;
   1.182 +
   1.183 +				case 'email':
   1.184 +					$pre_fill = (string) $db->sql_fetchfield('user_email');
   1.185 +				break;
   1.186 +			}
   1.187 +			$db->sql_freeresult($result);
   1.188 +		}
   1.189 +		else if ($post_id)
   1.190 +		{
   1.191 +			$post_info = get_post_data($post_id, 'm_ban');
   1.192 +
   1.193 +			if (sizeof($post_info) && !empty($post_info[$post_id]))
   1.194 +			{
   1.195 +				switch ($mode)
   1.196 +				{
   1.197 +					case 'user':
   1.198 +						$pre_fill = $post_info[$post_id]['username'];
   1.199 +					break;
   1.200 +
   1.201 +					case 'ip':
   1.202 +						$pre_fill = $post_info[$post_id]['poster_ip'];
   1.203 +					break;
   1.204 +
   1.205 +					case 'email':
   1.206 +						$pre_fill = $post_info[$post_id]['user_email'];
   1.207 +					break;
   1.208 +				}
   1.209 +
   1.210 +			}
   1.211 +		}
   1.212 +
   1.213 +		if ($pre_fill)
   1.214 +		{
   1.215 +			// left for legacy template compatibility
   1.216 +			$template->assign_var('USERNAMES', $pre_fill);
   1.217 +			$template->assign_var('BAN_QUANTIFIER', $pre_fill);
   1.218 +		}
   1.219 +	}
   1.220 +}
   1.221 +
   1.222 +?>
   1.223 \ No newline at end of file