includes/mcp/mcp_pm_reports.php
author indvdum (gotoindvdum[at]gmail[dot]com)
Wed, 07 Mar 2012 23:03:48 +0400
changeset 3 2e6be5f7e4cf
parent 0 ceef6d64c21d
permissions -rw-r--r--
HG ignore
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_reports
indvdum@0
    21
* Handling the reports queue
indvdum@0
    22
* @package mcp
indvdum@0
    23
*/
indvdum@0
    24
class mcp_pm_reports
indvdum@0
    25
{
indvdum@0
    26
	var $p_master;
indvdum@0
    27
	var $u_action;
indvdum@0
    28
indvdum@0
    29
	function mcp_pm_reports(&$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, $cache;
indvdum@0
    37
		global $config, $phpbb_root_path, $phpEx, $action;
indvdum@0
    38
indvdum@0
    39
		include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
indvdum@0
    40
		include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
indvdum@0
    41
indvdum@0
    42
		$start = request_var('start', 0);
indvdum@0
    43
indvdum@0
    44
		$this->page_title = 'MCP_PM_REPORTS';
indvdum@0
    45
indvdum@0
    46
		switch ($action)
indvdum@0
    47
		{
indvdum@0
    48
			case 'close':
indvdum@0
    49
			case 'delete':
indvdum@0
    50
				include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
indvdum@0
    51
indvdum@0
    52
				$report_id_list = request_var('report_id_list', array(0));
indvdum@0
    53
indvdum@0
    54
				if (!sizeof($report_id_list))
indvdum@0
    55
				{
indvdum@0
    56
					trigger_error('NO_REPORT_SELECTED');
indvdum@0
    57
				}
indvdum@0
    58
indvdum@0
    59
				if (!function_exists('close_report'))
indvdum@0
    60
				{
indvdum@0
    61
					include($phpbb_root_path . 'includes/mcp/mcp_reports.' . $phpEx);
indvdum@0
    62
				}
indvdum@0
    63
indvdum@0
    64
				close_report($report_id_list, $mode, $action, true);
indvdum@0
    65
indvdum@0
    66
			break;
indvdum@0
    67
		}
indvdum@0
    68
indvdum@0
    69
		switch ($mode)
indvdum@0
    70
		{
indvdum@0
    71
			case 'pm_report_details':
indvdum@0
    72
indvdum@0
    73
				$user->add_lang(array('posting', 'viewforum', 'viewtopic', 'ucp'));
indvdum@0
    74
indvdum@0
    75
				$report_id = request_var('r', 0);
indvdum@0
    76
indvdum@0
    77
				$sql = 'SELECT r.pm_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour
indvdum@0
    78
					FROM ' . REPORTS_TABLE . ' r, ' . REPORTS_REASONS_TABLE . ' rr, ' . USERS_TABLE . ' u
indvdum@0
    79
					WHERE r.report_id = ' . $report_id . '
indvdum@0
    80
						AND rr.reason_id = r.reason_id
indvdum@0
    81
						AND r.user_id = u.user_id
indvdum@0
    82
						AND r.post_id = 0
indvdum@0
    83
					ORDER BY report_closed ASC';
indvdum@0
    84
				$result = $db->sql_query_limit($sql, 1);
indvdum@0
    85
				$report = $db->sql_fetchrow($result);
indvdum@0
    86
				$db->sql_freeresult($result);
indvdum@0
    87
indvdum@0
    88
				if (!$report_id || !$report)
indvdum@0
    89
				{
indvdum@0
    90
					trigger_error('NO_REPORT');
indvdum@0
    91
				}
indvdum@0
    92
indvdum@0
    93
				$pm_id = $report['pm_id'];
indvdum@0
    94
				$report_id = $report['report_id'];
indvdum@0
    95
indvdum@0
    96
				$pm_info = get_pm_data(array($pm_id));
indvdum@0
    97
indvdum@0
    98
				if (!sizeof($pm_info))
indvdum@0
    99
				{
indvdum@0
   100
					trigger_error('NO_REPORT_SELECTED');
indvdum@0
   101
				}
indvdum@0
   102
indvdum@0
   103
				$pm_info = $pm_info[$pm_id];
indvdum@0
   104
indvdum@0
   105
				write_pm_addresses(array('to' => $pm_info['to_address'], 'bcc' => $pm_info['bcc_address']), (int) $pm_info['author_id']);
indvdum@0
   106
indvdum@0
   107
				$reason = array('title' => $report['reason_title'], 'description' => $report['reason_description']);
indvdum@0
   108
				if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])]))
indvdum@0
   109
				{
indvdum@0
   110
					$reason['description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])];
indvdum@0
   111
					$reason['title'] = $user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])];
indvdum@0
   112
				}
indvdum@0
   113
indvdum@0
   114
				// Process message, leave it uncensored
indvdum@0
   115
				$message = $pm_info['message_text'];
indvdum@0
   116
indvdum@0
   117
				if ($pm_info['bbcode_bitfield'])
indvdum@0
   118
				{
indvdum@0
   119
					include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
indvdum@0
   120
					$bbcode = new bbcode($pm_info['bbcode_bitfield']);
indvdum@0
   121
					$bbcode->bbcode_second_pass($message, $pm_info['bbcode_uid'], $pm_info['bbcode_bitfield']);
indvdum@0
   122
				}
indvdum@0
   123
indvdum@0
   124
				$message = bbcode_nl2br($message);
indvdum@0
   125
				$message = smiley_text($message);
indvdum@0
   126
indvdum@0
   127
				if ($pm_info['message_attachment'] && $auth->acl_get('u_pm_download'))
indvdum@0
   128
				{
indvdum@0
   129
					$sql = 'SELECT *
indvdum@0
   130
						FROM ' . ATTACHMENTS_TABLE . '
indvdum@0
   131
						WHERE post_msg_id = ' . $pm_id . '
indvdum@0
   132
							AND in_message = 1
indvdum@0
   133
						ORDER BY filetime DESC';
indvdum@0
   134
					$result = $db->sql_query($sql);
indvdum@0
   135
indvdum@0
   136
					while ($row = $db->sql_fetchrow($result))
indvdum@0
   137
					{
indvdum@0
   138
						$attachments[] = $row;
indvdum@0
   139
					}
indvdum@0
   140
					$db->sql_freeresult($result);
indvdum@0
   141
indvdum@0
   142
					if (sizeof($attachments))
indvdum@0
   143
					{
indvdum@0
   144
						$update_count = array();
indvdum@0
   145
						parse_attachments(0, $message, $attachments, $update_count);
indvdum@0
   146
					}
indvdum@0
   147
indvdum@0
   148
					// Display not already displayed Attachments for this post, we already parsed them. ;)
indvdum@0
   149
					if (!empty($attachments))
indvdum@0
   150
					{
indvdum@0
   151
						$template->assign_var('S_HAS_ATTACHMENTS', true);
indvdum@0
   152
indvdum@0
   153
						foreach ($attachments as $attachment)
indvdum@0
   154
						{
indvdum@0
   155
							$template->assign_block_vars('attachment', array(
indvdum@0
   156
								'DISPLAY_ATTACHMENT'	=> $attachment)
indvdum@0
   157
							);
indvdum@0
   158
						}
indvdum@0
   159
					}
indvdum@0
   160
				}
indvdum@0
   161
indvdum@0
   162
				$template->assign_vars(array(
indvdum@0
   163
					'S_MCP_REPORT'			=> true,
indvdum@0
   164
					'S_PM'					=> true,
indvdum@0
   165
					'S_CLOSE_ACTION'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=pm_reports&amp;mode=pm_report_details&amp;r=' . $report_id),
indvdum@0
   166
					'S_CAN_VIEWIP'			=> $auth->acl_getf_global('m_info'),
indvdum@0
   167
					'S_POST_REPORTED'		=> $pm_info['message_reported'],
indvdum@0
   168
					'S_USER_NOTES'			=> true,
indvdum@0
   169
indvdum@0
   170
					'U_MCP_REPORT'				=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=pm_reports&amp;mode=pm_report_details&amp;r=' . $report_id),
indvdum@0
   171
					'U_MCP_REPORTER_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $report['user_id']),
indvdum@0
   172
					'U_MCP_USER_NOTES'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $pm_info['author_id']),
indvdum@0
   173
					'U_MCP_WARN_REPORTER'		=> ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user&amp;u=' . $report['user_id']) : '',
indvdum@0
   174
					'U_MCP_WARN_USER'			=> ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user&amp;u=' . $pm_info['author_id']) : '',
indvdum@0
   175
					
indvdum@0
   176
					'EDIT_IMG'				=> $user->img('icon_post_edit', $user->lang['EDIT_POST']),
indvdum@0
   177
					'MINI_POST_IMG'			=> $user->img('icon_post_target', 'POST'),
indvdum@0
   178
indvdum@0
   179
					'RETURN_REPORTS'			=> sprintf($user->lang['RETURN_REPORTS'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=pm_reports' . (($pm_info['message_reported']) ? '&amp;mode=pm_reports' : '&amp;mode=pm_reports_closed') . '&amp;start=' . $start) . '">', '</a>'),
indvdum@0
   180
					'REPORTED_IMG'				=> $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
indvdum@0
   181
					'REPORT_DATE'				=> $user->format_date($report['report_time']),
indvdum@0
   182
					'REPORT_ID'					=> $report_id,
indvdum@0
   183
					'REPORT_REASON_TITLE'		=> $reason['title'],
indvdum@0
   184
					'REPORT_REASON_DESCRIPTION'	=> $reason['description'],
indvdum@0
   185
					'REPORT_TEXT'				=> $report['report_text'],
indvdum@0
   186
indvdum@0
   187
					'POST_AUTHOR_FULL'		=> get_username_string('full', $pm_info['author_id'], $pm_info['username'], $pm_info['user_colour']),
indvdum@0
   188
					'POST_AUTHOR_COLOUR'	=> get_username_string('colour', $pm_info['author_id'], $pm_info['username'], $pm_info['user_colour']),
indvdum@0
   189
					'POST_AUTHOR'			=> get_username_string('username', $pm_info['author_id'], $pm_info['username'], $pm_info['user_colour']),
indvdum@0
   190
					'U_POST_AUTHOR'			=> get_username_string('profile', $pm_info['author_id'], $pm_info['username'], $pm_info['user_colour']),
indvdum@0
   191
indvdum@0
   192
					'REPORTER_FULL'				=> get_username_string('full', $report['user_id'], $report['username'], $report['user_colour']),
indvdum@0
   193
					'REPORTER_COLOUR'			=> get_username_string('colour', $report['user_id'], $report['username'], $report['user_colour']),
indvdum@0
   194
					'REPORTER_NAME'				=> get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']),
indvdum@0
   195
					'U_VIEW_REPORTER_PROFILE'	=> get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']),
indvdum@0
   196
indvdum@0
   197
					'POST_PREVIEW'			=> $message,
indvdum@0
   198
					'POST_SUBJECT'			=> ($pm_info['message_subject']) ? $pm_info['message_subject'] : $user->lang['NO_SUBJECT'],
indvdum@0
   199
					'POST_DATE'				=> $user->format_date($pm_info['message_time']),
indvdum@0
   200
					'POST_IP'				=> $pm_info['author_ip'],
indvdum@0
   201
					'POST_IPADDR'			=> ($auth->acl_getf_global('m_info') && request_var('lookup', '')) ? @gethostbyaddr($pm_info['author_ip']) : '',
indvdum@0
   202
					'POST_ID'				=> $pm_info['msg_id'],
indvdum@0
   203
indvdum@0
   204
					'U_LOOKUP_IP'			=> ($auth->acl_getf_global('m_info')) ? $this->u_action . '&amp;r=' . $report_id . '&amp;pm=' . $pm_id . '&amp;lookup=' . $pm_info['author_ip'] . '#ip' : '',
indvdum@0
   205
				));
indvdum@0
   206
indvdum@0
   207
				$this->tpl_name = 'mcp_post';
indvdum@0
   208
indvdum@0
   209
			break;
indvdum@0
   210
indvdum@0
   211
			case 'pm_reports':
indvdum@0
   212
			case 'pm_reports_closed':
indvdum@0
   213
				$user->add_lang(array('ucp'));
indvdum@0
   214
indvdum@0
   215
				$sort_days = $total = 0;
indvdum@0
   216
				$sort_key = $sort_dir = '';
indvdum@0
   217
				$sort_by_sql = $sort_order_sql = array();
indvdum@0
   218
				mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total);
indvdum@0
   219
indvdum@0
   220
				$limit_time_sql = ($sort_days) ? 'AND r.report_time >= ' . (time() - ($sort_days * 86400)) : '';
indvdum@0
   221
indvdum@0
   222
				if ($mode == 'pm_reports')
indvdum@0
   223
				{
indvdum@0
   224
					$report_state = 'p.message_reported = 1 AND r.report_closed = 0';
indvdum@0
   225
				}
indvdum@0
   226
				else
indvdum@0
   227
				{
indvdum@0
   228
					$report_state = 'r.report_closed = 1';
indvdum@0
   229
				}
indvdum@0
   230
indvdum@0
   231
				$sql = 'SELECT r.report_id
indvdum@0
   232
					FROM ' . PRIVMSGS_TABLE . ' p, ' . REPORTS_TABLE . ' r ' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . (($sort_order_sql[0] == 'r') ? ', ' . USERS_TABLE . ' ru' : '') . "
indvdum@0
   233
					WHERE $report_state
indvdum@0
   234
						AND r.pm_id = p.msg_id
indvdum@0
   235
						" . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.author_id' : '') . '
indvdum@0
   236
						' . (($sort_order_sql[0] == 'r') ? 'AND ru.user_id = r.user_id' : '') . "
indvdum@0
   237
						AND r.post_id = 0
indvdum@0
   238
						$limit_time_sql
indvdum@0
   239
					ORDER BY $sort_order_sql";
indvdum@0
   240
				$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
indvdum@0
   241
indvdum@0
   242
				$i = 0;
indvdum@0
   243
				$report_ids = array();
indvdum@0
   244
				while ($row = $db->sql_fetchrow($result))
indvdum@0
   245
				{
indvdum@0
   246
					$report_ids[] = $row['report_id'];
indvdum@0
   247
					$row_num[$row['report_id']] = $i++;
indvdum@0
   248
				}
indvdum@0
   249
				$db->sql_freeresult($result);
indvdum@0
   250
indvdum@0
   251
				if (sizeof($report_ids))
indvdum@0
   252
				{
indvdum@0
   253
					$sql = 'SELECT p.*, u.username, u.username_clean, u.user_colour, r.user_id as reporter_id, ru.username as reporter_name, ru.user_colour as reporter_colour, r.report_time, r.report_id
indvdum@0
   254
						FROM ' . REPORTS_TABLE . ' r, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u, ' . USERS_TABLE . ' ru
indvdum@0
   255
						WHERE ' . $db->sql_in_set('r.report_id', $report_ids) . "
indvdum@0
   256
							AND r.pm_id = p.msg_id
indvdum@0
   257
							AND p.author_id = u.user_id
indvdum@0
   258
							AND ru.user_id = r.user_id
indvdum@0
   259
						ORDER BY $sort_order_sql";
indvdum@0
   260
					$result = $db->sql_query($sql);
indvdum@0
   261
indvdum@0
   262
					$pm_list = $pm_by_id = array();
indvdum@0
   263
					while ($row = $db->sql_fetchrow($result))
indvdum@0
   264
					{
indvdum@0
   265
						$pm_by_id[(int) $row['msg_id']] = $row;
indvdum@0
   266
						$pm_list[] = (int) $row['msg_id'];
indvdum@0
   267
					}
indvdum@0
   268
					$db->sql_freeresult($result);
indvdum@0
   269
indvdum@0
   270
					if (sizeof($pm_list))
indvdum@0
   271
					{
indvdum@0
   272
						$address_list = get_recipient_strings($pm_by_id);
indvdum@0
   273
indvdum@0
   274
						foreach ($pm_list as $message_id)
indvdum@0
   275
						{
indvdum@0
   276
							$row = $pm_by_id[$message_id];
indvdum@0
   277
							$template->assign_block_vars('postrow', array(
indvdum@0
   278
								'U_VIEW_DETAILS'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=pm_reports&amp;mode=pm_report_details&amp;r={$row['report_id']}"),
indvdum@0
   279
indvdum@0
   280
								'PM_AUTHOR_FULL'		=> get_username_string('full', $row['author_id'], $row['username'], $row['user_colour']),
indvdum@0
   281
								'PM_AUTHOR_COLOUR'		=> get_username_string('colour', $row['author_id'], $row['username'], $row['user_colour']),
indvdum@0
   282
								'PM_AUTHOR'				=> get_username_string('username', $row['author_id'], $row['username'], $row['user_colour']),
indvdum@0
   283
								'U_PM_AUTHOR'			=> get_username_string('profile', $row['author_id'], $row['username'], $row['user_colour']),
indvdum@0
   284
indvdum@0
   285
								'REPORTER_FULL'			=> get_username_string('full', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
indvdum@0
   286
								'REPORTER_COLOUR'		=> get_username_string('colour', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
indvdum@0
   287
								'REPORTER'				=> get_username_string('username', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
indvdum@0
   288
								'U_REPORTER'			=> get_username_string('profile', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
indvdum@0
   289
indvdum@0
   290
								'PM_SUBJECT'			=> ($row['message_subject']) ? $row['message_subject'] : $user->lang['NO_SUBJECT'],
indvdum@0
   291
								'PM_TIME'				=> $user->format_date($row['message_time']),
indvdum@0
   292
								'REPORT_ID'				=> $row['report_id'],
indvdum@0
   293
								'REPORT_TIME'			=> $user->format_date($row['report_time']),
indvdum@0
   294
indvdum@0
   295
								'RECIPIENTS'			=> implode(', ', $address_list[$row['msg_id']]),
indvdum@0
   296
							));
indvdum@0
   297
						}
indvdum@0
   298
					}
indvdum@0
   299
				}
indvdum@0
   300
indvdum@0
   301
				// Now display the page
indvdum@0
   302
				$template->assign_vars(array(
indvdum@0
   303
					'L_EXPLAIN'				=> ($mode == 'pm_reports') ? $user->lang['MCP_PM_REPORTS_OPEN_EXPLAIN'] : $user->lang['MCP_PM_REPORTS_CLOSED_EXPLAIN'],
indvdum@0
   304
					'L_TITLE'				=> ($mode == 'pm_reports') ? $user->lang['MCP_PM_REPORTS_OPEN'] : $user->lang['MCP_PM_REPORTS_CLOSED'],
indvdum@0
   305
					
indvdum@0
   306
					'S_PM'					=> true,
indvdum@0
   307
					'S_MCP_ACTION'			=> $this->u_action,
indvdum@0
   308
					'S_CLOSED'				=> ($mode == 'pm_reports_closed') ? true : false,
indvdum@0
   309
indvdum@0
   310
					'PAGINATION'			=> generate_pagination($this->u_action . "&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir", $total, $config['topics_per_page'], $start),
indvdum@0
   311
					'PAGE_NUMBER'			=> on_page($total, $config['topics_per_page'], $start),
indvdum@0
   312
					'TOTAL'					=> $total,
indvdum@0
   313
					'TOTAL_REPORTS'			=> ($total == 1) ? $user->lang['LIST_REPORT'] : sprintf($user->lang['LIST_REPORTS'], $total),					
indvdum@0
   314
					)
indvdum@0
   315
				);
indvdum@0
   316
indvdum@0
   317
				$this->tpl_name = 'mcp_reports';
indvdum@0
   318
			break;
indvdum@0
   319
		}
indvdum@0
   320
	}
indvdum@0
   321
}
indvdum@0
   322
indvdum@0
   323
?>