includes/mcp/mcp_warn.php
author indvdum (gotoindvdum[at]gmail[dot]com)
Fri, 09 Mar 2012 16:11:37 +0400
changeset 12 898199d067e7
parent 0 ceef6d64c21d
permissions -rw-r--r--
Ignoring cache
indvdum@0
     1
<?php
indvdum@0
     2
/**
indvdum@0
     3
*
indvdum@0
     4
* @package mcp
indvdum@0
     5
* @version $Id$
indvdum@0
     6
* @copyright (c) 2005 phpBB Group
indvdum@0
     7
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
indvdum@0
     8
*
indvdum@0
     9
*/
indvdum@0
    10
indvdum@0
    11
/**
indvdum@0
    12
* @ignore
indvdum@0
    13
*/
indvdum@0
    14
if (!defined('IN_PHPBB'))
indvdum@0
    15
{
indvdum@0
    16
	exit;
indvdum@0
    17
}
indvdum@0
    18
indvdum@0
    19
/**
indvdum@0
    20
* mcp_warn
indvdum@0
    21
* Handling warning the users
indvdum@0
    22
* @package mcp
indvdum@0
    23
*/
indvdum@0
    24
class mcp_warn
indvdum@0
    25
{
indvdum@0
    26
	var $p_master;
indvdum@0
    27
	var $u_action;
indvdum@0
    28
indvdum@0
    29
	function mcp_warn(&$p_master)
indvdum@0
    30
	{
indvdum@0
    31
		$this->p_master = &$p_master;
indvdum@0
    32
	}
indvdum@0
    33
indvdum@0
    34
	function main($id, $mode)
indvdum@0
    35
	{
indvdum@0
    36
		global $auth, $db, $user, $template;
indvdum@0
    37
		global $config, $phpbb_root_path, $phpEx;
indvdum@0
    38
indvdum@0
    39
		$action = request_var('action', array('' => ''));
indvdum@0
    40
indvdum@0
    41
		if (is_array($action))
indvdum@0
    42
		{
indvdum@0
    43
			list($action, ) = each($action);
indvdum@0
    44
		}
indvdum@0
    45
indvdum@0
    46
		$this->page_title = 'MCP_WARN';
indvdum@0
    47
indvdum@0
    48
		add_form_key('mcp_warn');
indvdum@0
    49
indvdum@0
    50
		switch ($mode)
indvdum@0
    51
		{
indvdum@0
    52
			case 'front':
indvdum@0
    53
				$this->mcp_warn_front_view();
indvdum@0
    54
				$this->tpl_name = 'mcp_warn_front';
indvdum@0
    55
			break;
indvdum@0
    56
indvdum@0
    57
			case 'list':
indvdum@0
    58
				$this->mcp_warn_list_view($action);
indvdum@0
    59
				$this->tpl_name = 'mcp_warn_list';
indvdum@0
    60
			break;
indvdum@0
    61
indvdum@0
    62
			case 'warn_post':
indvdum@0
    63
				$this->mcp_warn_post_view($action);
indvdum@0
    64
				$this->tpl_name = 'mcp_warn_post';
indvdum@0
    65
			break;
indvdum@0
    66
indvdum@0
    67
			case 'warn_user':
indvdum@0
    68
				$this->mcp_warn_user_view($action);
indvdum@0
    69
				$this->tpl_name = 'mcp_warn_user';
indvdum@0
    70
			break;
indvdum@0
    71
		}
indvdum@0
    72
	}
indvdum@0
    73
indvdum@0
    74
	/**
indvdum@0
    75
	* Generates the summary on the main page of the warning module
indvdum@0
    76
	*/
indvdum@0
    77
	function mcp_warn_front_view()
indvdum@0
    78
	{
indvdum@0
    79
		global $phpEx, $phpbb_root_path, $config;
indvdum@0
    80
		global $template, $db, $user, $auth;
indvdum@0
    81
indvdum@0
    82
		$template->assign_vars(array(
indvdum@0
    83
			'U_FIND_USERNAME'	=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=searchuser&amp;form=mcp&amp;field=username&amp;select_single=true'),
indvdum@0
    84
			'U_POST_ACTION'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user'),
indvdum@0
    85
		));
indvdum@0
    86
indvdum@0
    87
		// Obtain a list of the 5 naughtiest users....
indvdum@0
    88
		// These are the 5 users with the highest warning count
indvdum@0
    89
		$highest = array();
indvdum@0
    90
		$count = 0;
indvdum@0
    91
indvdum@0
    92
		view_warned_users($highest, $count, 5);
indvdum@0
    93
indvdum@0
    94
		foreach ($highest as $row)
indvdum@0
    95
		{
indvdum@0
    96
			$template->assign_block_vars('highest', array(
indvdum@0
    97
				'U_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $row['user_id']),
indvdum@0
    98
indvdum@0
    99
				'USERNAME_FULL'		=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
indvdum@0
   100
				'USERNAME'			=> $row['username'],
indvdum@0
   101
				'USERNAME_COLOUR'	=> ($row['user_colour']) ? '#' . $row['user_colour'] : '',
indvdum@0
   102
				'U_USER'			=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']),
indvdum@0
   103
indvdum@0
   104
				'WARNING_TIME'	=> $user->format_date($row['user_last_warning']),
indvdum@0
   105
				'WARNINGS'		=> $row['user_warnings'],
indvdum@0
   106
			));
indvdum@0
   107
		}
indvdum@0
   108
indvdum@0
   109
		// And now the 5 most recent users to get in trouble
indvdum@0
   110
		$sql = 'SELECT u.user_id, u.username, u.username_clean, u.user_colour, u.user_warnings, w.warning_time
indvdum@0
   111
			FROM ' . USERS_TABLE . ' u, ' . WARNINGS_TABLE . ' w
indvdum@0
   112
			WHERE u.user_id = w.user_id
indvdum@0
   113
			ORDER BY w.warning_time DESC';
indvdum@0
   114
		$result = $db->sql_query_limit($sql, 5);
indvdum@0
   115
indvdum@0
   116
		while ($row = $db->sql_fetchrow($result))
indvdum@0
   117
		{
indvdum@0
   118
			$template->assign_block_vars('latest', array(
indvdum@0
   119
				'U_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $row['user_id']),
indvdum@0
   120
indvdum@0
   121
				'USERNAME_FULL'		=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
indvdum@0
   122
				'USERNAME'			=> $row['username'],
indvdum@0
   123
				'USERNAME_COLOUR'	=> ($row['user_colour']) ? '#' . $row['user_colour'] : '',
indvdum@0
   124
				'U_USER'			=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']),
indvdum@0
   125
indvdum@0
   126
				'WARNING_TIME'	=> $user->format_date($row['warning_time']),
indvdum@0
   127
				'WARNINGS'		=> $row['user_warnings'],
indvdum@0
   128
			));
indvdum@0
   129
		}
indvdum@0
   130
		$db->sql_freeresult($result);
indvdum@0
   131
	}
indvdum@0
   132
indvdum@0
   133
	/**
indvdum@0
   134
	* Lists all users with warnings
indvdum@0
   135
	*/
indvdum@0
   136
	function mcp_warn_list_view($action)
indvdum@0
   137
	{
indvdum@0
   138
		global $phpEx, $phpbb_root_path, $config;
indvdum@0
   139
		global $template, $db, $user, $auth;
indvdum@0
   140
indvdum@0
   141
		$user->add_lang('memberlist');
indvdum@0
   142
indvdum@0
   143
		$start	= request_var('start', 0);
indvdum@0
   144
		$st		= request_var('st', 0);
indvdum@0
   145
		$sk		= request_var('sk', 'b');
indvdum@0
   146
		$sd		= request_var('sd', 'd');
indvdum@0
   147
indvdum@0
   148
		$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']);
indvdum@0
   149
		$sort_by_text = array('a' => $user->lang['SORT_USERNAME'], 'b' => $user->lang['SORT_DATE'], 'c' => $user->lang['SORT_WARNINGS']);
indvdum@0
   150
		$sort_by_sql = array('a' => 'username_clean', 'b' => 'user_last_warning', 'c' => 'user_warnings');
indvdum@0
   151
indvdum@0
   152
		$s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
indvdum@0
   153
		gen_sort_selects($limit_days, $sort_by_text, $st, $sk, $sd, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
indvdum@0
   154
indvdum@0
   155
		// Define where and sort sql for use in displaying logs
indvdum@0
   156
		$sql_where = ($st) ? (time() - ($st * 86400)) : 0;
indvdum@0
   157
		$sql_sort = $sort_by_sql[$sk] . ' ' . (($sd == 'd') ? 'DESC' : 'ASC');
indvdum@0
   158
indvdum@0
   159
		$users = array();
indvdum@0
   160
		$user_count = 0;
indvdum@0
   161
indvdum@0
   162
		view_warned_users($users, $user_count, $config['topics_per_page'], $start, $sql_where, $sql_sort);
indvdum@0
   163
indvdum@0
   164
		foreach ($users as $row)
indvdum@0
   165
		{
indvdum@0
   166
			$template->assign_block_vars('user', array(
indvdum@0
   167
				'U_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $row['user_id']),
indvdum@0
   168
indvdum@0
   169
				'USERNAME_FULL'		=> get_username_string('full', $row['user_id'], $row['username'], $row['user_colour']),
indvdum@0
   170
				'USERNAME'			=> $row['username'],
indvdum@0
   171
				'USERNAME_COLOUR'	=> ($row['user_colour']) ? '#' . $row['user_colour'] : '',
indvdum@0
   172
				'U_USER'			=> append_sid("{$phpbb_root_path}memberlist.$phpEx", 'mode=viewprofile&amp;u=' . $row['user_id']),
indvdum@0
   173
indvdum@0
   174
				'WARNING_TIME'	=> $user->format_date($row['user_last_warning']),
indvdum@0
   175
				'WARNINGS'		=> $row['user_warnings'],
indvdum@0
   176
			));
indvdum@0
   177
		}
indvdum@0
   178
indvdum@0
   179
		$template->assign_vars(array(
indvdum@0
   180
			'U_POST_ACTION'			=> $this->u_action,
indvdum@0
   181
			'S_CLEAR_ALLOWED'		=> ($auth->acl_get('a_clearlogs')) ? true : false,
indvdum@0
   182
			'S_SELECT_SORT_DIR'		=> $s_sort_dir,
indvdum@0
   183
			'S_SELECT_SORT_KEY'		=> $s_sort_key,
indvdum@0
   184
			'S_SELECT_SORT_DAYS'	=> $s_limit_days,
indvdum@0
   185
indvdum@0
   186
			'PAGE_NUMBER'		=> on_page($user_count, $config['topics_per_page'], $start),
indvdum@0
   187
			'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),
indvdum@0
   188
			'TOTAL_USERS'		=> ($user_count == 1) ? $user->lang['LIST_USER'] : sprintf($user->lang['LIST_USERS'], $user_count),
indvdum@0
   189
		));
indvdum@0
   190
	}
indvdum@0
   191
indvdum@0
   192
	/**
indvdum@0
   193
	* Handles warning the user when the warning is for a specific post
indvdum@0
   194
	*/
indvdum@0
   195
	function mcp_warn_post_view($action)
indvdum@0
   196
	{
indvdum@0
   197
		global $phpEx, $phpbb_root_path, $config;
indvdum@0
   198
		global $template, $db, $user, $auth;
indvdum@0
   199
indvdum@0
   200
		$post_id = request_var('p', 0);
indvdum@0
   201
		$forum_id = request_var('f', 0);
indvdum@0
   202
		$notify = (isset($_REQUEST['notify_user'])) ? true : false;
indvdum@0
   203
		$warning = utf8_normalize_nfc(request_var('warning', '', true));
indvdum@0
   204
indvdum@0
   205
		$sql = 'SELECT u.*, p.*
indvdum@0
   206
			FROM ' . POSTS_TABLE . ' p, ' . USERS_TABLE . " u
indvdum@0
   207
			WHERE p.post_id = $post_id
indvdum@0
   208
				AND u.user_id = p.poster_id";
indvdum@0
   209
		$result = $db->sql_query($sql);
indvdum@0
   210
		$user_row = $db->sql_fetchrow($result);
indvdum@0
   211
		$db->sql_freeresult($result);
indvdum@0
   212
indvdum@0
   213
		if (!$user_row)
indvdum@0
   214
		{
indvdum@0
   215
			trigger_error('NO_POST');
indvdum@0
   216
		}
indvdum@0
   217
indvdum@0
   218
		// There is no point issuing a warning to ignored users (ie anonymous and bots)
indvdum@0
   219
		if ($user_row['user_type'] == USER_IGNORE)
indvdum@0
   220
		{
indvdum@0
   221
			trigger_error('CANNOT_WARN_ANONYMOUS');
indvdum@0
   222
		}
indvdum@0
   223
indvdum@0
   224
		// Prevent someone from warning themselves
indvdum@0
   225
		if ($user_row['user_id'] == $user->data['user_id'])
indvdum@0
   226
		{
indvdum@0
   227
			trigger_error('CANNOT_WARN_SELF');
indvdum@0
   228
		}
indvdum@0
   229
indvdum@0
   230
		// Check if there is already a warning for this post to prevent multiple
indvdum@0
   231
		// warnings for the same offence
indvdum@0
   232
		$sql = 'SELECT post_id
indvdum@0
   233
			FROM ' . WARNINGS_TABLE . "
indvdum@0
   234
			WHERE post_id = $post_id";
indvdum@0
   235
		$result = $db->sql_query($sql);
indvdum@0
   236
		$row = $db->sql_fetchrow($result);
indvdum@0
   237
		$db->sql_freeresult($result);
indvdum@0
   238
indvdum@0
   239
		if ($row)
indvdum@0
   240
		{
indvdum@0
   241
			trigger_error('ALREADY_WARNED');
indvdum@0
   242
		}
indvdum@0
   243
indvdum@0
   244
		$user_id = $user_row['user_id'];
indvdum@0
   245
indvdum@0
   246
		if (strpos($this->u_action, "&amp;f=$forum_id&amp;p=$post_id") === false)
indvdum@0
   247
		{
indvdum@0
   248
			$this->p_master->adjust_url("&amp;f=$forum_id&amp;p=$post_id");
indvdum@0
   249
			$this->u_action .= "&amp;f=$forum_id&amp;p=$post_id";
indvdum@0
   250
		}
indvdum@0
   251
indvdum@0
   252
		// Check if can send a notification
indvdum@0
   253
		if ($config['allow_privmsg'])
indvdum@0
   254
		{
indvdum@0
   255
			$auth2 = new auth();
indvdum@0
   256
			$auth2->acl($user_row);
indvdum@0
   257
			$s_can_notify = ($auth2->acl_get('u_readpm')) ? true : false;
indvdum@0
   258
			unset($auth2);
indvdum@0
   259
		}
indvdum@0
   260
		else
indvdum@0
   261
		{
indvdum@0
   262
			$s_can_notify = false;
indvdum@0
   263
		}
indvdum@0
   264
indvdum@0
   265
		// Prevent against clever people
indvdum@0
   266
		if ($notify && !$s_can_notify)
indvdum@0
   267
		{
indvdum@0
   268
			$notify = false;
indvdum@0
   269
		}
indvdum@0
   270
indvdum@0
   271
		if ($warning && $action == 'add_warning')
indvdum@0
   272
		{
indvdum@0
   273
			if (check_form_key('mcp_warn'))
indvdum@0
   274
			{
indvdum@0
   275
				add_warning($user_row, $warning, $notify, $post_id);
indvdum@0
   276
				$msg = $user->lang['USER_WARNING_ADDED'];
indvdum@0
   277
			}
indvdum@0
   278
			else
indvdum@0
   279
			{
indvdum@0
   280
				$msg = $user->lang['FORM_INVALID'];
indvdum@0
   281
			}
indvdum@0
   282
			$redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=notes&amp;mode=user_notes&amp;u=$user_id");
indvdum@0
   283
			meta_refresh(2, $redirect);
indvdum@0
   284
			trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
indvdum@0
   285
		}
indvdum@0
   286
indvdum@0
   287
		// OK, they didn't submit a warning so lets build the page for them to do so
indvdum@0
   288
indvdum@0
   289
		// We want to make the message available here as a reminder
indvdum@0
   290
		// Parse the message and subject
indvdum@0
   291
		$message = censor_text($user_row['post_text']);
indvdum@0
   292
indvdum@0
   293
		// Second parse bbcode here
indvdum@0
   294
		if ($user_row['bbcode_bitfield'])
indvdum@0
   295
		{
indvdum@0
   296
			include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
indvdum@0
   297
indvdum@0
   298
			$bbcode = new bbcode($user_row['bbcode_bitfield']);
indvdum@0
   299
			$bbcode->bbcode_second_pass($message, $user_row['bbcode_uid'], $user_row['bbcode_bitfield']);
indvdum@0
   300
		}
indvdum@0
   301
indvdum@0
   302
		$message = bbcode_nl2br($message);
indvdum@0
   303
		$message = smiley_text($message);
indvdum@0
   304
indvdum@0
   305
		// Generate the appropriate user information for the user we are looking at
indvdum@0
   306
		if (!function_exists('get_user_avatar'))
indvdum@0
   307
		{
indvdum@0
   308
			include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
indvdum@0
   309
		}
indvdum@0
   310
indvdum@0
   311
		$rank_title = $rank_img = '';
indvdum@0
   312
		$avatar_img = get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']);
indvdum@0
   313
indvdum@0
   314
		$template->assign_vars(array(
indvdum@0
   315
			'U_POST_ACTION'		=> $this->u_action,
indvdum@0
   316
indvdum@0
   317
			'POST'				=> $message,
indvdum@0
   318
			'USERNAME'			=> $user_row['username'],
indvdum@0
   319
			'USER_COLOR'		=> (!empty($user_row['user_colour'])) ? $user_row['user_colour'] : '',
indvdum@0
   320
			'RANK_TITLE'		=> $rank_title,
indvdum@0
   321
			'JOINED'			=> $user->format_date($user_row['user_regdate']),
indvdum@0
   322
			'POSTS'				=> ($user_row['user_posts']) ? $user_row['user_posts'] : 0,
indvdum@0
   323
			'WARNINGS'			=> ($user_row['user_warnings']) ? $user_row['user_warnings'] : 0,
indvdum@0
   324
indvdum@0
   325
			'AVATAR_IMG'		=> $avatar_img,
indvdum@0
   326
			'RANK_IMG'			=> $rank_img,
indvdum@0
   327
indvdum@0
   328
			'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"),
indvdum@0
   329
indvdum@0
   330
			'S_CAN_NOTIFY'		=> $s_can_notify,
indvdum@0
   331
		));
indvdum@0
   332
	}
indvdum@0
   333
indvdum@0
   334
	/**
indvdum@0
   335
	* Handles warning the user
indvdum@0
   336
	*/
indvdum@0
   337
	function mcp_warn_user_view($action)
indvdum@0
   338
	{
indvdum@0
   339
		global $phpEx, $phpbb_root_path, $config, $module;
indvdum@0
   340
		global $template, $db, $user, $auth;
indvdum@0
   341
indvdum@0
   342
		$user_id = request_var('u', 0);
indvdum@0
   343
		$username = request_var('username', '', true);
indvdum@0
   344
		$notify = (isset($_REQUEST['notify_user'])) ? true : false;
indvdum@0
   345
		$warning = utf8_normalize_nfc(request_var('warning', '', true));
indvdum@0
   346
indvdum@0
   347
		$sql_where = ($user_id) ? "user_id = $user_id" : "username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'";
indvdum@0
   348
indvdum@0
   349
		$sql = 'SELECT *
indvdum@0
   350
			FROM ' . USERS_TABLE . '
indvdum@0
   351
			WHERE ' . $sql_where;
indvdum@0
   352
		$result = $db->sql_query($sql);
indvdum@0
   353
		$user_row = $db->sql_fetchrow($result);
indvdum@0
   354
		$db->sql_freeresult($result);
indvdum@0
   355
indvdum@0
   356
		if (!$user_row)
indvdum@0
   357
		{
indvdum@0
   358
			trigger_error('NO_USER');
indvdum@0
   359
		}
indvdum@0
   360
indvdum@0
   361
		// Prevent someone from warning themselves
indvdum@0
   362
		if ($user_row['user_id'] == $user->data['user_id'])
indvdum@0
   363
		{
indvdum@0
   364
			trigger_error('CANNOT_WARN_SELF');
indvdum@0
   365
		}
indvdum@0
   366
indvdum@0
   367
		$user_id = $user_row['user_id'];
indvdum@0
   368
indvdum@0
   369
		if (strpos($this->u_action, "&amp;u=$user_id") === false)
indvdum@0
   370
		{
indvdum@0
   371
			$this->p_master->adjust_url('&amp;u=' . $user_id);
indvdum@0
   372
			$this->u_action .= "&amp;u=$user_id";
indvdum@0
   373
		}
indvdum@0
   374
indvdum@0
   375
		// Check if can send a notification
indvdum@0
   376
		if ($config['allow_privmsg'])
indvdum@0
   377
		{
indvdum@0
   378
			$auth2 = new auth();
indvdum@0
   379
			$auth2->acl($user_row);
indvdum@0
   380
			$s_can_notify = ($auth2->acl_get('u_readpm')) ? true : false;
indvdum@0
   381
			unset($auth2);
indvdum@0
   382
		}
indvdum@0
   383
		else
indvdum@0
   384
		{
indvdum@0
   385
			$s_can_notify = false;
indvdum@0
   386
		}
indvdum@0
   387
indvdum@0
   388
		// Prevent against clever people
indvdum@0
   389
		if ($notify && !$s_can_notify)
indvdum@0
   390
		{
indvdum@0
   391
			$notify = false;
indvdum@0
   392
		}
indvdum@0
   393
indvdum@0
   394
		if ($warning && $action == 'add_warning')
indvdum@0
   395
		{
indvdum@0
   396
			if (check_form_key('mcp_warn'))
indvdum@0
   397
			{
indvdum@0
   398
				add_warning($user_row, $warning, $notify);
indvdum@0
   399
				$msg = $user->lang['USER_WARNING_ADDED'];
indvdum@0
   400
			}
indvdum@0
   401
			else
indvdum@0
   402
			{
indvdum@0
   403
				$msg = $user->lang['FORM_INVALID'];
indvdum@0
   404
			}
indvdum@0
   405
			$redirect = append_sid("{$phpbb_root_path}mcp.$phpEx", "i=notes&amp;mode=user_notes&amp;u=$user_id");
indvdum@0
   406
			meta_refresh(2, $redirect);
indvdum@0
   407
			trigger_error($msg . '<br /><br />' . sprintf($user->lang['RETURN_PAGE'], '<a href="' . $redirect . '">', '</a>'));
indvdum@0
   408
		}
indvdum@0
   409
indvdum@0
   410
		// Generate the appropriate user information for the user we are looking at
indvdum@0
   411
		if (!function_exists('get_user_avatar'))
indvdum@0
   412
		{
indvdum@0
   413
			include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
indvdum@0
   414
		}
indvdum@0
   415
indvdum@0
   416
		$rank_title = $rank_img = '';
indvdum@0
   417
		$avatar_img = get_user_avatar($user_row['user_avatar'], $user_row['user_avatar_type'], $user_row['user_avatar_width'], $user_row['user_avatar_height']);
indvdum@0
   418
indvdum@0
   419
		// OK, they didn't submit a warning so lets build the page for them to do so
indvdum@0
   420
		$template->assign_vars(array(
indvdum@0
   421
			'U_POST_ACTION'		=> $this->u_action,
indvdum@0
   422
indvdum@0
   423
			'RANK_TITLE'		=> $rank_title,
indvdum@0
   424
			'JOINED'			=> $user->format_date($user_row['user_regdate']),
indvdum@0
   425
			'POSTS'				=> ($user_row['user_posts']) ? $user_row['user_posts'] : 0,
indvdum@0
   426
			'WARNINGS'			=> ($user_row['user_warnings']) ? $user_row['user_warnings'] : 0,
indvdum@0
   427
indvdum@0
   428
			'USERNAME_FULL'		=> get_username_string('full', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
indvdum@0
   429
			'USERNAME_COLOUR'	=> get_username_string('colour', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
indvdum@0
   430
			'USERNAME'			=> get_username_string('username', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
indvdum@0
   431
			'U_PROFILE'			=> get_username_string('profile', $user_row['user_id'], $user_row['username'], $user_row['user_colour']),
indvdum@0
   432
indvdum@0
   433
			'AVATAR_IMG'		=> $avatar_img,
indvdum@0
   434
			'RANK_IMG'			=> $rank_img,
indvdum@0
   435
indvdum@0
   436
			'S_CAN_NOTIFY'		=> $s_can_notify,
indvdum@0
   437
		));
indvdum@0
   438
indvdum@0
   439
		return $user_id;
indvdum@0
   440
	}
indvdum@0
   441
}
indvdum@0
   442
indvdum@0
   443
/**
indvdum@0
   444
* Insert the warning into the database
indvdum@0
   445
*/
indvdum@0
   446
function add_warning($user_row, $warning, $send_pm = true, $post_id = 0)
indvdum@0
   447
{
indvdum@0
   448
	global $phpEx, $phpbb_root_path, $config;
indvdum@0
   449
	global $template, $db, $user, $auth;
indvdum@0
   450
indvdum@0
   451
	if ($send_pm)
indvdum@0
   452
	{
indvdum@0
   453
		include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
indvdum@0
   454
		include_once($phpbb_root_path . 'includes/message_parser.' . $phpEx);
indvdum@0
   455
indvdum@0
   456
		$user_row['user_lang'] = (file_exists($phpbb_root_path . 'language/' . $user_row['user_lang'] . "/mcp.$phpEx")) ? $user_row['user_lang'] : $config['default_lang'];
indvdum@0
   457
		include($phpbb_root_path . 'language/' . basename($user_row['user_lang']) . "/mcp.$phpEx");
indvdum@0
   458
indvdum@0
   459
		$message_parser = new parse_message();
indvdum@0
   460
indvdum@0
   461
		$message_parser->message = sprintf($lang['WARNING_PM_BODY'], $warning);
indvdum@0
   462
		$message_parser->parse(true, true, true, false, false, true, true);
indvdum@0
   463
indvdum@0
   464
		$pm_data = array(
indvdum@0
   465
			'from_user_id'			=> $user->data['user_id'],
indvdum@0
   466
			'from_user_ip'			=> $user->ip,
indvdum@0
   467
			'from_username'			=> $user->data['username'],
indvdum@0
   468
			'enable_sig'			=> false,
indvdum@0
   469
			'enable_bbcode'			=> true,
indvdum@0
   470
			'enable_smilies'		=> true,
indvdum@0
   471
			'enable_urls'			=> false,
indvdum@0
   472
			'icon_id'				=> 0,
indvdum@0
   473
			'bbcode_bitfield'		=> $message_parser->bbcode_bitfield,
indvdum@0
   474
			'bbcode_uid'			=> $message_parser->bbcode_uid,
indvdum@0
   475
			'message'				=> $message_parser->message,
indvdum@0
   476
			'address_list'			=> array('u' => array($user_row['user_id'] => 'to')),
indvdum@0
   477
		);
indvdum@0
   478
indvdum@0
   479
		submit_pm('post', $lang['WARNING_PM_SUBJECT'], $pm_data, false);
indvdum@0
   480
	}
indvdum@0
   481
indvdum@0
   482
	add_log('admin', 'LOG_USER_WARNING', $user_row['username']);
indvdum@0
   483
	$log_id = add_log('user', $user_row['user_id'], 'LOG_USER_WARNING_BODY', $warning);
indvdum@0
   484
indvdum@0
   485
	$sql_ary = array(
indvdum@0
   486
		'user_id'		=> $user_row['user_id'],
indvdum@0
   487
		'post_id'		=> $post_id,
indvdum@0
   488
		'log_id'		=> $log_id,
indvdum@0
   489
		'warning_time'	=> time(),
indvdum@0
   490
	);
indvdum@0
   491
indvdum@0
   492
	$db->sql_query('INSERT INTO ' . WARNINGS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary));
indvdum@0
   493
indvdum@0
   494
	$sql = 'UPDATE ' . USERS_TABLE . '
indvdum@0
   495
		SET user_warnings = user_warnings + 1,
indvdum@0
   496
			user_last_warning = ' . time() . '
indvdum@0
   497
		WHERE user_id = ' . $user_row['user_id'];
indvdum@0
   498
	$db->sql_query($sql);
indvdum@0
   499
indvdum@0
   500
	// We add this to the mod log too for moderators to see that a specific user got warned.
indvdum@0
   501
	$sql = 'SELECT forum_id, topic_id
indvdum@0
   502
		FROM ' . POSTS_TABLE . '
indvdum@0
   503
		WHERE post_id = ' . $post_id;
indvdum@0
   504
	$result = $db->sql_query($sql);
indvdum@0
   505
	$row = $db->sql_fetchrow($result);
indvdum@0
   506
	$db->sql_freeresult($result);
indvdum@0
   507
indvdum@0
   508
	add_log('mod', $row['forum_id'], $row['topic_id'], 'LOG_USER_WARNING', $user_row['username']);
indvdum@0
   509
}
indvdum@0
   510
indvdum@0
   511
?>