includes/mcp/mcp_warn.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/mcp/mcp_warn.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,511 @@
     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 +* mcp_warn
    1.24 +* Handling warning the users
    1.25 +* @package mcp
    1.26 +*/
    1.27 +class mcp_warn
    1.28 +{
    1.29 +	var $p_master;
    1.30 +	var $u_action;
    1.31 +
    1.32 +	function mcp_warn(&$p_master)
    1.33 +	{
    1.34 +		$this->p_master = &$p_master;
    1.35 +	}
    1.36 +
    1.37 +	function main($id, $mode)
    1.38 +	{
    1.39 +		global $auth, $db, $user, $template;
    1.40 +		global $config, $phpbb_root_path, $phpEx;
    1.41 +
    1.42 +		$action = request_var('action', array('' => ''));
    1.43 +
    1.44 +		if (is_array($action))
    1.45 +		{
    1.46 +			list($action, ) = each($action);
    1.47 +		}
    1.48 +
    1.49 +		$this->page_title = 'MCP_WARN';
    1.50 +
    1.51 +		add_form_key('mcp_warn');
    1.52 +
    1.53 +		switch ($mode)
    1.54 +		{
    1.55 +			case 'front':
    1.56 +				$this->mcp_warn_front_view();
    1.57 +				$this->tpl_name = 'mcp_warn_front';
    1.58 +			break;
    1.59 +
    1.60 +			case 'list':
    1.61 +				$this->mcp_warn_list_view($action);
    1.62 +				$this->tpl_name = 'mcp_warn_list';
    1.63 +			break;
    1.64 +
    1.65 +			case 'warn_post':
    1.66 +				$this->mcp_warn_post_view($action);
    1.67 +				$this->tpl_name = 'mcp_warn_post';
    1.68 +			break;
    1.69 +
    1.70 +			case 'warn_user':
    1.71 +				$this->mcp_warn_user_view($action);
    1.72 +				$this->tpl_name = 'mcp_warn_user';
    1.73 +			break;
    1.74 +		}
    1.75 +	}
    1.76 +
    1.77 +	/**
    1.78 +	* Generates the summary on the main page of the warning module
    1.79 +	*/
    1.80 +	function mcp_warn_front_view()
    1.81 +	{
    1.82 +		global $phpEx, $phpbb_root_path, $config;
    1.83 +		global $template, $db, $user, $auth;
    1.84 +
    1.85 +		$template->assign_vars(array(
    1.86 +			'U_FIND_USERNAME'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=mcp&amp;field=username&amp;select_single=true'),
    1.87 +			'U_POST_ACTION'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user'),
    1.88 +		));
    1.89 +
    1.90 +		// Obtain a list of the 5 naughtiest users....
    1.91 +		// These are the 5 users with the highest warning count
    1.92 +		$highest = array();
    1.93 +		$count = 0;
    1.94 +
    1.95 +		view_warned_users($highest, $count, 5);
    1.96 +
    1.97 +		foreach ($highest as $row)
    1.98 +		{
    1.99 +			$template->assign_block_vars('highest', array(
   1.100 +				'U_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $row['user_id']),
   1.101 +
   1.102 +				'USERNAME_FULL'		=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
   1.103 +				'USERNAME'			=> $row['username'],
   1.104 +				'USERNAME_COLOUR'	=> ($row['user_colour']) ? '#' . $row['user_colour'] : '',
   1.105 +				'U_USER'			=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']),
   1.106 +
   1.107 +				'WARNING_TIME'	=> $user->format_date($row['user_last_warning']),
   1.108 +				'WARNINGS'		=> $row['user_warnings'],
   1.109 +			));
   1.110 +		}
   1.111 +
   1.112 +		// And now the 5 most recent users to get in trouble
   1.113 +		$sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_warnings, w.warning_time
   1.114 +			FROM ' . USERS_TABLE . ' u, ' . WARNINGS_TABLE . ' w
   1.115 +			WHERE u.user_id = w.user_id
   1.116 +			ORDER BY w.warning_time DESC';
   1.117 +		$result = $db->sql_query_limit($sql, 5);
   1.118 +
   1.119 +		while ($row = $db->sql_fetchrow($result))
   1.120 +		{
   1.121 +			$template->assign_block_vars('latest', array(
   1.122 +				'U_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $row['user_id']),
   1.123 +
   1.124 +				'USERNAME_FULL'		=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
   1.125 +				'USERNAME'			=> $row['username'],
   1.126 +				'USERNAME_COLOUR'	=> ($row['user_colour']) ? '#' . $row['user_colour'] : '',
   1.127 +				'U_USER'			=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']),
   1.128 +
   1.129 +				'WARNING_TIME'	=> $user->format_date($row['warning_time']),
   1.130 +				'WARNINGS'		=> $row['user_warnings'],
   1.131 +			));
   1.132 +		}
   1.133 +		$db->sql_freeresult($result);
   1.134 +	}
   1.135 +
   1.136 +	/**
   1.137 +	* Lists all users with warnings
   1.138 +	*/
   1.139 +	function mcp_warn_list_view($action)
   1.140 +	{
   1.141 +		global $phpEx, $phpbb_root_path, $config;
   1.142 +		global $template, $db, $user, $auth;
   1.143 +
   1.144 +		$user->add_lang('memberlist');
   1.145 +
   1.146 +		$start	= request_var('start', 0);
   1.147 +		$st		= request_var('st', 0);
   1.148 +		$sk		= request_var('sk', 'b');
   1.149 +		$sd		= request_var('sd', 'd');
   1.150 +
   1.151 +		$limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
   1.152 +		$sort_by_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_DATE'], 'c' => $user->lang['SORT_WARNINGS']);
   1.153 +		$sort_by_sql = array('a' => 'username_clean', 'b' => 'user_last_warning', 'c' => 'user_warnings');
   1.154 +
   1.155 +		$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
   1.156 +		gen_sort_selects($limit_days, $sort_by_text, $st, $sk, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
   1.157 +
   1.158 +		// Define where and sort sql for use in displaying logs
   1.159 +		$sql_where = ($st) ? (time() - ($st * 86400)) : 0;
   1.160 +		$sql_sort = $sort_by_sql[$sk] . ' ' . (($sd == 'd') ? 'DESC' : 'ASC');
   1.161 +
   1.162 +		$users = array();
   1.163 +		$user_count = 0;
   1.164 +
   1.165 +		view_warned_users($users, $user_count, $config['topics_per_page'], $start, $sql_where, $sql_sort);
   1.166 +
   1.167 +		foreach ($users as $row)
   1.168 +		{
   1.169 +			$template->assign_block_vars('user', array(
   1.170 +				'U_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $row['user_id']),
   1.171 +
   1.172 +				'USERNAME_FULL'		=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
   1.173 +				'USERNAME'			=> $row['username'],
   1.174 +				'USERNAME_COLOUR'	=> ($row['user_colour']) ? '#' . $row['user_colour'] : '',
   1.175 +				'U_USER'			=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']),
   1.176 +
   1.177 +				'WARNING_TIME'	=> $user->format_date($row['user_last_warning']),
   1.178 +				'WARNINGS'		=> $row['user_warnings'],
   1.179 +			));
   1.180 +		}
   1.181 +
   1.182 +		$template->assign_vars(array(
   1.183 +			'U_POST_ACTION'			=> $this->u_action,
   1.184 +			'S_CLEAR_ALLOWED'		=> ($auth->acl_get('a_clearlogs')) ? true : false,
   1.185 +			'S_SELECT_SORT_DIR'		=> $s_sort_dir,
   1.186 +			'S_SELECT_SORT_KEY'		=> $s_sort_key,
   1.187 +			'S_SELECT_SORT_DAYS'	=> $s_limit_days,
   1.188 +
   1.189 +			'PAGE_NUMBER'		=> on_page($user_count, $config['topics_per_page'], $start),
   1.190 +			'PAGINATION'		=> generate_pagination(append_sid("{$phpbb_root_path}mcp.$phpEx", "i=warn&amp;mode=list&amp;st=$st&amp;sk=$sk&amp;sd=$sd"), $user_count, $config['topics_per_page'], $start),
   1.191 +			'TOTAL_USERS'		=> ($user_count == 1) ? $user->lang['LIST_USER'] : sprintf($user->lang['LIST_USERS'], $user_count),
   1.192 +		));
   1.193 +	}
   1.194 +
   1.195 +	/**
   1.196 +	* Handles warning the user when the warning is for a specific post
   1.197 +	*/
   1.198 +	function mcp_warn_post_view($action)
   1.199 +	{
   1.200 +		global $phpEx, $phpbb_root_path, $config;
   1.201 +		global $template, $db, $user, $auth;
   1.202 +
   1.203 +		$post_id = request_var('p', 0);
   1.204 +		$forum_id = request_var('f', 0);
   1.205 +		$notify = (isset($_REQUEST['notify_user'])) ? true : false;
   1.206 +		$warning = utf8_normalize_nfc(request_var('warning', '', true));
   1.207 +
   1.208 +		$sql = 'SELECT u.*, p.*
   1.209 +			FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
   1.210 +			WHERE p.post_id = $post_id
   1.211 +				AND u.user_id = p.poster_id";
   1.212 +		$result = $db->sql_query($sql);
   1.213 +		$user_row = $db->sql_fetchrow($result);
   1.214 +		$db->sql_freeresult($result);
   1.215 +
   1.216 +		if (!$user_row)
   1.217 +		{
   1.218 +			trigger_error('NO_POST');
   1.219 +		}
   1.220 +
   1.221 +		// There is no point issuing a warning to ignored users (ie anonymous and bots)
   1.222 +		if ($user_row['user_type'] == USER_IGNORE)
   1.223 +		{
   1.224 +			trigger_error('CANNOT_WARN_ANONYMOUS');
   1.225 +		}
   1.226 +
   1.227 +		// Prevent someone from warning themselves
   1.228 +		if ($user_row['user_id'] == $user->data['user_id'])
   1.229 +		{
   1.230 +			trigger_error('CANNOT_WARN_SELF');
   1.231 +		}
   1.232 +
   1.233 +		// Check if there is already a warning for this post to prevent multiple
   1.234 +		// warnings for the same offence
   1.235 +		$sql = 'SELECT post_id
   1.236 +			FROM ' . WARNINGS_TABLE . "
   1.237 +			WHERE post_id = $post_id";
   1.238 +		$result = $db->sql_query($sql);
   1.239 +		$row = $db->sql_fetchrow($result);
   1.240 +		$db->sql_freeresult($result);
   1.241 +
   1.242 +		if ($row)
   1.243 +		{
   1.244 +			trigger_error('ALREADY_WARNED');
   1.245 +		}
   1.246 +
   1.247 +		$user_id = $user_row['user_id'];
   1.248 +
   1.249 +		if (strpos($this->u_action, "&amp;f=$forum_id&amp;p=$post_id") === false)
   1.250 +		{
   1.251 +			$this->p_master->adjust_url("&amp;f=$forum_id&amp;p=$post_id");
   1.252 +			$this->u_action .= "&amp;f=$forum_id&amp;p=$post_id";
   1.253 +		}
   1.254 +
   1.255 +		// Check if can send a notification
   1.256 +		if ($config['allow_privmsg'])
   1.257 +		{
   1.258 +			$auth2 = new auth();
   1.259 +			$auth2->acl($user_row);
   1.260 +			$s_can_notify = ($auth2->acl_get('u_readpm')) ? true : false;
   1.261 +			unset($auth2);
   1.262 +		}
   1.263 +		else
   1.264 +		{
   1.265 +			$s_can_notify = false;
   1.266 +		}
   1.267 +
   1.268 +		// Prevent against clever people
   1.269 +		if ($notify && !$s_can_notify)
   1.270 +		{
   1.271 +			$notify = false;
   1.272 +		}
   1.273 +
   1.274 +		if ($warning && $action == 'add_warning')
   1.275 +		{
   1.276 +			if (check_form_key('mcp_warn'))
   1.277 +			{
   1.278 +				add_warning($user_row, $warning, $notify, $post_id);
   1.279 +				$msg = $user->lang['USER_WARNING_ADDED'];
   1.280 +			}
   1.281 +			else
   1.282 +			{
   1.283 +				$msg = $user->lang['FORM_INVALID'];
   1.284 +			}
   1.285 +			$redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=notes&amp;mode=user_notes&amp;u=$user_id");
   1.286 +			meta_refresh(2, $redirect);
   1.287 +			trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
   1.288 +		}
   1.289 +
   1.290 +		// OK, they didn't submit a warning so lets build the page for them to do so
   1.291 +
   1.292 +		// We want to make the message available here as a reminder
   1.293 +		// Parse the message and subject
   1.294 +		$message = censor_text($user_row['post_text']);
   1.295 +
   1.296 +		// Second parse bbcode here
   1.297 +		if ($user_row['bbcode_bitfield'])
   1.298 +		{
   1.299 +			include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
   1.300 +
   1.301 +			$bbcode = new bbcode($user_row['bbcode_bitfield']);
   1.302 +			$bbcode->bbcode_second_pass($message, $user_row['bbcode_uid'], $user_row['bbcode_bitfield']);
   1.303 +		}
   1.304 +
   1.305 +		$message = bbcode_nl2br($message);
   1.306 +		$message = smiley_text($message);
   1.307 +
   1.308 +		// Generate the appropriate user information for the user we are looking at
   1.309 +		if (!function_exists('get_user_avatar'))
   1.310 +		{
   1.311 +			include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
   1.312 +		}
   1.313 +
   1.314 +		$rank_title = $rank_img = '';
   1.315 +		$avatar_img = get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']);
   1.316 +
   1.317 +		$template->assign_vars(array(
   1.318 +			'U_POST_ACTION'		=> $this->u_action,
   1.319 +
   1.320 +			'POST'				=> $message,
   1.321 +			'USERNAME'			=> $user_row['username'],
   1.322 +			'USER_COLOR'		=> (!empty($user_row['user_colour'])) ? $user_row['user_colour'] : '',
   1.323 +			'RANK_TITLE'		=> $rank_title,
   1.324 +			'JOINED'			=> $user->format_date($user_row['user_regdate']),
   1.325 +			'POSTS'				=> ($user_row['user_posts']) ? $user_row['user_posts'] : 0,
   1.326 +			'WARNINGS'			=> ($user_row['user_warnings']) ? $user_row['user_warnings'] : 0,
   1.327 +
   1.328 +			'AVATAR_IMG'		=> $avatar_img,
   1.329 +			'RANK_IMG'			=> $rank_img,
   1.330 +
   1.331 +			'L_WARNING_POST_DEFAULT'	=> sprintf($user->lang['WARNING_POST_DEFAULT'], generate_board_url() . "/viewtopic.$phpEx?f=$forum_id&amp;p=$post_id#p$post_id"),
   1.332 +
   1.333 +			'S_CAN_NOTIFY'		=> $s_can_notify,
   1.334 +		));
   1.335 +	}
   1.336 +
   1.337 +	/**
   1.338 +	* Handles warning the user
   1.339 +	*/
   1.340 +	function mcp_warn_user_view($action)
   1.341 +	{
   1.342 +		global $phpEx, $phpbb_root_path, $config, $module;
   1.343 +		global $template, $db, $user, $auth;
   1.344 +
   1.345 +		$user_id = request_var('u', 0);
   1.346 +		$username = request_var('username', '', true);
   1.347 +		$notify = (isset($_REQUEST['notify_user'])) ? true : false;
   1.348 +		$warning = utf8_normalize_nfc(request_var('warning', '', true));
   1.349 +
   1.350 +		$sql_where = ($user_id) ? "user_id = $user_id" : "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
   1.351 +
   1.352 +		$sql = 'SELECT *
   1.353 +			FROM ' . USERS_TABLE . '
   1.354 +			WHERE ' . $sql_where;
   1.355 +		$result = $db->sql_query($sql);
   1.356 +		$user_row = $db->sql_fetchrow($result);
   1.357 +		$db->sql_freeresult($result);
   1.358 +
   1.359 +		if (!$user_row)
   1.360 +		{
   1.361 +			trigger_error('NO_USER');
   1.362 +		}
   1.363 +
   1.364 +		// Prevent someone from warning themselves
   1.365 +		if ($user_row['user_id'] == $user->data['user_id'])
   1.366 +		{
   1.367 +			trigger_error('CANNOT_WARN_SELF');
   1.368 +		}
   1.369 +
   1.370 +		$user_id = $user_row['user_id'];
   1.371 +
   1.372 +		if (strpos($this->u_action, "&amp;u=$user_id") === false)
   1.373 +		{
   1.374 +			$this->p_master->adjust_url('&amp;u=' . $user_id);
   1.375 +			$this->u_action .= "&amp;u=$user_id";
   1.376 +		}
   1.377 +
   1.378 +		// Check if can send a notification
   1.379 +		if ($config['allow_privmsg'])
   1.380 +		{
   1.381 +			$auth2 = new auth();
   1.382 +			$auth2->acl($user_row);
   1.383 +			$s_can_notify = ($auth2->acl_get('u_readpm')) ? true : false;
   1.384 +			unset($auth2);
   1.385 +		}
   1.386 +		else
   1.387 +		{
   1.388 +			$s_can_notify = false;
   1.389 +		}
   1.390 +
   1.391 +		// Prevent against clever people
   1.392 +		if ($notify && !$s_can_notify)
   1.393 +		{
   1.394 +			$notify = false;
   1.395 +		}
   1.396 +
   1.397 +		if ($warning && $action == 'add_warning')
   1.398 +		{
   1.399 +			if (check_form_key('mcp_warn'))
   1.400 +			{
   1.401 +				add_warning($user_row, $warning, $notify);
   1.402 +				$msg = $user->lang['USER_WARNING_ADDED'];
   1.403 +			}
   1.404 +			else
   1.405 +			{
   1.406 +				$msg = $user->lang['FORM_INVALID'];
   1.407 +			}
   1.408 +			$redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=notes&amp;mode=user_notes&amp;u=$user_id");
   1.409 +			meta_refresh(2, $redirect);
   1.410 +			trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
   1.411 +		}
   1.412 +
   1.413 +		// Generate the appropriate user information for the user we are looking at
   1.414 +		if (!function_exists('get_user_avatar'))
   1.415 +		{
   1.416 +			include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
   1.417 +		}
   1.418 +
   1.419 +		$rank_title = $rank_img = '';
   1.420 +		$avatar_img = get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']);
   1.421 +
   1.422 +		// OK, they didn't submit a warning so lets build the page for them to do so
   1.423 +		$template->assign_vars(array(
   1.424 +			'U_POST_ACTION'		=> $this->u_action,
   1.425 +
   1.426 +			'RANK_TITLE'		=> $rank_title,
   1.427 +			'JOINED'			=> $user->format_date($user_row['user_regdate']),
   1.428 +			'POSTS'				=> ($user_row['user_posts']) ? $user_row['user_posts'] : 0,
   1.429 +			'WARNINGS'			=> ($user_row['user_warnings']) ? $user_row['user_warnings'] : 0,
   1.430 +
   1.431 +			'USERNAME_FULL'		=> get_username_string('full', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
   1.432 +			'USERNAME_COLOUR'	=> get_username_string('colour', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
   1.433 +			'USERNAME'			=> get_username_string('username', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
   1.434 +			'U_PROFILE'			=> get_username_string('profile', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
   1.435 +
   1.436 +			'AVATAR_IMG'		=> $avatar_img,
   1.437 +			'RANK_IMG'			=> $rank_img,
   1.438 +
   1.439 +			'S_CAN_NOTIFY'		=> $s_can_notify,
   1.440 +		));
   1.441 +
   1.442 +		return $user_id;
   1.443 +	}
   1.444 +}
   1.445 +
   1.446 +/**
   1.447 +* Insert the warning into the database
   1.448 +*/
   1.449 +function add_warning($user_row, $warning, $send_pm = true, $post_id = 0)
   1.450 +{
   1.451 +	global $phpEx, $phpbb_root_path, $config;
   1.452 +	global $template, $db, $user, $auth;
   1.453 +
   1.454 +	if ($send_pm)
   1.455 +	{
   1.456 +		include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
   1.457 +		include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
   1.458 +
   1.459 +		$user_row['user_lang'] = (file_exists($phpbb_root_path . 'language/' . $user_row['user_lang'] . "/mcp.$phpEx")) ? $user_row['user_lang'] : $config['default_lang'];
   1.460 +		include($phpbb_root_path . 'language/' . basename($user_row['user_lang']) . "/mcp.$phpEx");
   1.461 +
   1.462 +		$message_parser = new parse_message();
   1.463 +
   1.464 +		$message_parser->message = sprintf($lang['WARNING_PM_BODY'], $warning);
   1.465 +		$message_parser->parse(true, true, true, false, false, true, true);
   1.466 +
   1.467 +		$pm_data = array(
   1.468 +			'from_user_id'			=> $user->data['user_id'],
   1.469 +			'from_user_ip'			=> $user->ip,
   1.470 +			'from_username'			=> $user->data['username'],
   1.471 +			'enable_sig'			=> false,
   1.472 +			'enable_bbcode'			=> true,
   1.473 +			'enable_smilies'		=> true,
   1.474 +			'enable_urls'			=> false,
   1.475 +			'icon_id'				=> 0,
   1.476 +			'bbcode_bitfield'		=> $message_parser->bbcode_bitfield,
   1.477 +			'bbcode_uid'			=> $message_parser->bbcode_uid,
   1.478 +			'message'				=> $message_parser->message,
   1.479 +			'address_list'			=> array('u' => array($user_row['user_id'] => 'to')),
   1.480 +		);
   1.481 +
   1.482 +		submit_pm('post', $lang['WARNING_PM_SUBJECT'], $pm_data, false);
   1.483 +	}
   1.484 +
   1.485 +	add_log('admin', 'LOG_USER_WARNING', $user_row['username']);
   1.486 +	$log_id = add_log('user', $user_row['user_id'], 'LOG_USER_WARNING_BODY', $warning);
   1.487 +
   1.488 +	$sql_ary = array(
   1.489 +		'user_id'		=> $user_row['user_id'],
   1.490 +		'post_id'		=> $post_id,
   1.491 +		'log_id'		=> $log_id,
   1.492 +		'warning_time'	=> time(),
   1.493 +	);
   1.494 +
   1.495 +	$db->sql_query('INSERT INTO ' . WARNINGS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
   1.496 +
   1.497 +	$sql = 'UPDATE ' . USERS_TABLE . '
   1.498 +		SET user_warnings = user_warnings + 1,
   1.499 +			user_last_warning = ' . time() . '
   1.500 +		WHERE user_id = ' . $user_row['user_id'];
   1.501 +	$db->sql_query($sql);
   1.502 +
   1.503 +	// We add this to the mod log too for moderators to see that a specific user got warned.
   1.504 +	$sql = 'SELECT forum_id, topic_id
   1.505 +		FROM ' . POSTS_TABLE . '
   1.506 +		WHERE post_id = ' . $post_id;
   1.507 +	$result = $db->sql_query($sql);
   1.508 +	$row = $db->sql_fetchrow($result);
   1.509 +	$db->sql_freeresult($result);
   1.510 +
   1.511 +	add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_USER_WARNING', $user_row['username']);
   1.512 +}
   1.513 +
   1.514 +?>
   1.515 \ No newline at end of file