includes/mcp/mcp_pm_reports.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/includes/mcp/mcp_pm_reports.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,323 @@
     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_reports
    1.24 +* Handling the reports queue
    1.25 +* @package mcp
    1.26 +*/
    1.27 +class mcp_pm_reports
    1.28 +{
    1.29 +	var $p_master;
    1.30 +	var $u_action;
    1.31 +
    1.32 +	function mcp_pm_reports(&$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, $cache;
    1.40 +		global $config, $phpbb_root_path, $phpEx, $action;
    1.41 +
    1.42 +		include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
    1.43 +		include_once($phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx);
    1.44 +
    1.45 +		$start = request_var('start', 0);
    1.46 +
    1.47 +		$this->page_title = 'MCP_PM_REPORTS';
    1.48 +
    1.49 +		switch ($action)
    1.50 +		{
    1.51 +			case 'close':
    1.52 +			case 'delete':
    1.53 +				include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
    1.54 +
    1.55 +				$report_id_list = request_var('report_id_list', array(0));
    1.56 +
    1.57 +				if (!sizeof($report_id_list))
    1.58 +				{
    1.59 +					trigger_error('NO_REPORT_SELECTED');
    1.60 +				}
    1.61 +
    1.62 +				if (!function_exists('close_report'))
    1.63 +				{
    1.64 +					include($phpbb_root_path . 'includes/mcp/mcp_reports.' . $phpEx);
    1.65 +				}
    1.66 +
    1.67 +				close_report($report_id_list, $mode, $action, true);
    1.68 +
    1.69 +			break;
    1.70 +		}
    1.71 +
    1.72 +		switch ($mode)
    1.73 +		{
    1.74 +			case 'pm_report_details':
    1.75 +
    1.76 +				$user->add_lang(array('posting', 'viewforum', 'viewtopic', 'ucp'));
    1.77 +
    1.78 +				$report_id = request_var('r', 0);
    1.79 +
    1.80 +				$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
    1.81 +					FROM ' . REPORTS_TABLE . ' r, ' . REPORTS_REASONS_TABLE . ' rr, ' . USERS_TABLE . ' u
    1.82 +					WHERE r.report_id = ' . $report_id . '
    1.83 +						AND rr.reason_id = r.reason_id
    1.84 +						AND r.user_id = u.user_id
    1.85 +						AND r.post_id = 0
    1.86 +					ORDER BY report_closed ASC';
    1.87 +				$result = $db->sql_query_limit($sql, 1);
    1.88 +				$report = $db->sql_fetchrow($result);
    1.89 +				$db->sql_freeresult($result);
    1.90 +
    1.91 +				if (!$report_id || !$report)
    1.92 +				{
    1.93 +					trigger_error('NO_REPORT');
    1.94 +				}
    1.95 +
    1.96 +				$pm_id = $report['pm_id'];
    1.97 +				$report_id = $report['report_id'];
    1.98 +
    1.99 +				$pm_info = get_pm_data(array($pm_id));
   1.100 +
   1.101 +				if (!sizeof($pm_info))
   1.102 +				{
   1.103 +					trigger_error('NO_REPORT_SELECTED');
   1.104 +				}
   1.105 +
   1.106 +				$pm_info = $pm_info[$pm_id];
   1.107 +
   1.108 +				write_pm_addresses(array('to' => $pm_info['to_address'], 'bcc' => $pm_info['bcc_address']), (int) $pm_info['author_id']);
   1.109 +
   1.110 +				$reason = array('title' => $report['reason_title'], 'description' => $report['reason_description']);
   1.111 +				if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])]))
   1.112 +				{
   1.113 +					$reason['description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])];
   1.114 +					$reason['title'] = $user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])];
   1.115 +				}
   1.116 +
   1.117 +				// Process message, leave it uncensored
   1.118 +				$message = $pm_info['message_text'];
   1.119 +
   1.120 +				if ($pm_info['bbcode_bitfield'])
   1.121 +				{
   1.122 +					include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
   1.123 +					$bbcode = new bbcode($pm_info['bbcode_bitfield']);
   1.124 +					$bbcode->bbcode_second_pass($message, $pm_info['bbcode_uid'], $pm_info['bbcode_bitfield']);
   1.125 +				}
   1.126 +
   1.127 +				$message = bbcode_nl2br($message);
   1.128 +				$message = smiley_text($message);
   1.129 +
   1.130 +				if ($pm_info['message_attachment'] && $auth->acl_get('u_pm_download'))
   1.131 +				{
   1.132 +					$sql = 'SELECT *
   1.133 +						FROM ' . ATTACHMENTS_TABLE . '
   1.134 +						WHERE post_msg_id = ' . $pm_id . '
   1.135 +							AND in_message = 1
   1.136 +						ORDER BY filetime DESC';
   1.137 +					$result = $db->sql_query($sql);
   1.138 +
   1.139 +					while ($row = $db->sql_fetchrow($result))
   1.140 +					{
   1.141 +						$attachments[] = $row;
   1.142 +					}
   1.143 +					$db->sql_freeresult($result);
   1.144 +
   1.145 +					if (sizeof($attachments))
   1.146 +					{
   1.147 +						$update_count = array();
   1.148 +						parse_attachments(0, $message, $attachments, $update_count);
   1.149 +					}
   1.150 +
   1.151 +					// Display not already displayed Attachments for this post, we already parsed them. ;)
   1.152 +					if (!empty($attachments))
   1.153 +					{
   1.154 +						$template->assign_var('S_HAS_ATTACHMENTS', true);
   1.155 +
   1.156 +						foreach ($attachments as $attachment)
   1.157 +						{
   1.158 +							$template->assign_block_vars('attachment', array(
   1.159 +								'DISPLAY_ATTACHMENT'	=> $attachment)
   1.160 +							);
   1.161 +						}
   1.162 +					}
   1.163 +				}
   1.164 +
   1.165 +				$template->assign_vars(array(
   1.166 +					'S_MCP_REPORT'			=> true,
   1.167 +					'S_PM'					=> true,
   1.168 +					'S_CLOSE_ACTION'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=pm_reports&amp;mode=pm_report_details&amp;r=' . $report_id),
   1.169 +					'S_CAN_VIEWIP'			=> $auth->acl_getf_global('m_info'),
   1.170 +					'S_POST_REPORTED'		=> $pm_info['message_reported'],
   1.171 +					'S_USER_NOTES'			=> true,
   1.172 +
   1.173 +					'U_MCP_REPORT'				=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=pm_reports&amp;mode=pm_report_details&amp;r=' . $report_id),
   1.174 +					'U_MCP_REPORTER_NOTES'		=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $report['user_id']),
   1.175 +					'U_MCP_USER_NOTES'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $pm_info['author_id']),
   1.176 +					'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']) : '',
   1.177 +					'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']) : '',
   1.178 +					
   1.179 +					'EDIT_IMG'				=> $user->img('icon_post_edit', $user->lang['EDIT_POST']),
   1.180 +					'MINI_POST_IMG'			=> $user->img('icon_post_target', 'POST'),
   1.181 +
   1.182 +					'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>'),
   1.183 +					'REPORTED_IMG'				=> $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
   1.184 +					'REPORT_DATE'				=> $user->format_date($report['report_time']),
   1.185 +					'REPORT_ID'					=> $report_id,
   1.186 +					'REPORT_REASON_TITLE'		=> $reason['title'],
   1.187 +					'REPORT_REASON_DESCRIPTION'	=> $reason['description'],
   1.188 +					'REPORT_TEXT'				=> $report['report_text'],
   1.189 +
   1.190 +					'POST_AUTHOR_FULL'		=> get_username_string('full', $pm_info['author_id'], $pm_info['username'], $pm_info['user_colour']),
   1.191 +					'POST_AUTHOR_COLOUR'	=> get_username_string('colour', $pm_info['author_id'], $pm_info['username'], $pm_info['user_colour']),
   1.192 +					'POST_AUTHOR'			=> get_username_string('username', $pm_info['author_id'], $pm_info['username'], $pm_info['user_colour']),
   1.193 +					'U_POST_AUTHOR'			=> get_username_string('profile', $pm_info['author_id'], $pm_info['username'], $pm_info['user_colour']),
   1.194 +
   1.195 +					'REPORTER_FULL'				=> get_username_string('full', $report['user_id'], $report['username'], $report['user_colour']),
   1.196 +					'REPORTER_COLOUR'			=> get_username_string('colour', $report['user_id'], $report['username'], $report['user_colour']),
   1.197 +					'REPORTER_NAME'				=> get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']),
   1.198 +					'U_VIEW_REPORTER_PROFILE'	=> get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']),
   1.199 +
   1.200 +					'POST_PREVIEW'			=> $message,
   1.201 +					'POST_SUBJECT'			=> ($pm_info['message_subject']) ? $pm_info['message_subject'] : $user->lang['NO_SUBJECT'],
   1.202 +					'POST_DATE'				=> $user->format_date($pm_info['message_time']),
   1.203 +					'POST_IP'				=> $pm_info['author_ip'],
   1.204 +					'POST_IPADDR'			=> ($auth->acl_getf_global('m_info') && request_var('lookup', '')) ? @gethostbyaddr($pm_info['author_ip']) : '',
   1.205 +					'POST_ID'				=> $pm_info['msg_id'],
   1.206 +
   1.207 +					'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' : '',
   1.208 +				));
   1.209 +
   1.210 +				$this->tpl_name = 'mcp_post';
   1.211 +
   1.212 +			break;
   1.213 +
   1.214 +			case 'pm_reports':
   1.215 +			case 'pm_reports_closed':
   1.216 +				$user->add_lang(array('ucp'));
   1.217 +
   1.218 +				$sort_days = $total = 0;
   1.219 +				$sort_key = $sort_dir = '';
   1.220 +				$sort_by_sql = $sort_order_sql = array();
   1.221 +				mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total);
   1.222 +
   1.223 +				$limit_time_sql = ($sort_days) ? 'AND r.report_time >= ' . (time() - ($sort_days * 86400)) : '';
   1.224 +
   1.225 +				if ($mode == 'pm_reports')
   1.226 +				{
   1.227 +					$report_state = 'p.message_reported = 1 AND r.report_closed = 0';
   1.228 +				}
   1.229 +				else
   1.230 +				{
   1.231 +					$report_state = 'r.report_closed = 1';
   1.232 +				}
   1.233 +
   1.234 +				$sql = 'SELECT r.report_id
   1.235 +					FROM ' . PRIVMSGS_TABLE . ' p, ' . REPORTS_TABLE . ' r ' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . (($sort_order_sql[0] == 'r') ? ', ' . USERS_TABLE . ' ru' : '') . "
   1.236 +					WHERE $report_state
   1.237 +						AND r.pm_id = p.msg_id
   1.238 +						" . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.author_id' : '') . '
   1.239 +						' . (($sort_order_sql[0] == 'r') ? 'AND ru.user_id = r.user_id' : '') . "
   1.240 +						AND r.post_id = 0
   1.241 +						$limit_time_sql
   1.242 +					ORDER BY $sort_order_sql";
   1.243 +				$result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
   1.244 +
   1.245 +				$i = 0;
   1.246 +				$report_ids = array();
   1.247 +				while ($row = $db->sql_fetchrow($result))
   1.248 +				{
   1.249 +					$report_ids[] = $row['report_id'];
   1.250 +					$row_num[$row['report_id']] = $i++;
   1.251 +				}
   1.252 +				$db->sql_freeresult($result);
   1.253 +
   1.254 +				if (sizeof($report_ids))
   1.255 +				{
   1.256 +					$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
   1.257 +						FROM ' . REPORTS_TABLE . ' r, ' . PRIVMSGS_TABLE . ' p, ' . USERS_TABLE . ' u, ' . USERS_TABLE . ' ru
   1.258 +						WHERE ' . $db->sql_in_set('r.report_id', $report_ids) . "
   1.259 +							AND r.pm_id = p.msg_id
   1.260 +							AND p.author_id = u.user_id
   1.261 +							AND ru.user_id = r.user_id
   1.262 +						ORDER BY $sort_order_sql";
   1.263 +					$result = $db->sql_query($sql);
   1.264 +
   1.265 +					$pm_list = $pm_by_id = array();
   1.266 +					while ($row = $db->sql_fetchrow($result))
   1.267 +					{
   1.268 +						$pm_by_id[(int) $row['msg_id']] = $row;
   1.269 +						$pm_list[] = (int) $row['msg_id'];
   1.270 +					}
   1.271 +					$db->sql_freeresult($result);
   1.272 +
   1.273 +					if (sizeof($pm_list))
   1.274 +					{
   1.275 +						$address_list = get_recipient_strings($pm_by_id);
   1.276 +
   1.277 +						foreach ($pm_list as $message_id)
   1.278 +						{
   1.279 +							$row = $pm_by_id[$message_id];
   1.280 +							$template->assign_block_vars('postrow', array(
   1.281 +								'U_VIEW_DETAILS'			=> append_sid("{$phpbb_root_path}mcp.$phpEx", "i=pm_reports&amp;mode=pm_report_details&amp;r={$row['report_id']}"),
   1.282 +
   1.283 +								'PM_AUTHOR_FULL'		=> get_username_string('full', $row['author_id'], $row['username'], $row['user_colour']),
   1.284 +								'PM_AUTHOR_COLOUR'		=> get_username_string('colour', $row['author_id'], $row['username'], $row['user_colour']),
   1.285 +								'PM_AUTHOR'				=> get_username_string('username', $row['author_id'], $row['username'], $row['user_colour']),
   1.286 +								'U_PM_AUTHOR'			=> get_username_string('profile', $row['author_id'], $row['username'], $row['user_colour']),
   1.287 +
   1.288 +								'REPORTER_FULL'			=> get_username_string('full', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
   1.289 +								'REPORTER_COLOUR'		=> get_username_string('colour', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
   1.290 +								'REPORTER'				=> get_username_string('username', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
   1.291 +								'U_REPORTER'			=> get_username_string('profile', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
   1.292 +
   1.293 +								'PM_SUBJECT'			=> ($row['message_subject']) ? $row['message_subject'] : $user->lang['NO_SUBJECT'],
   1.294 +								'PM_TIME'				=> $user->format_date($row['message_time']),
   1.295 +								'REPORT_ID'				=> $row['report_id'],
   1.296 +								'REPORT_TIME'			=> $user->format_date($row['report_time']),
   1.297 +
   1.298 +								'RECIPIENTS'			=> implode(', ', $address_list[$row['msg_id']]),
   1.299 +							));
   1.300 +						}
   1.301 +					}
   1.302 +				}
   1.303 +
   1.304 +				// Now display the page
   1.305 +				$template->assign_vars(array(
   1.306 +					'L_EXPLAIN'				=> ($mode == 'pm_reports') ? $user->lang['MCP_PM_REPORTS_OPEN_EXPLAIN'] : $user->lang['MCP_PM_REPORTS_CLOSED_EXPLAIN'],
   1.307 +					'L_TITLE'				=> ($mode == 'pm_reports') ? $user->lang['MCP_PM_REPORTS_OPEN'] : $user->lang['MCP_PM_REPORTS_CLOSED'],
   1.308 +					
   1.309 +					'S_PM'					=> true,
   1.310 +					'S_MCP_ACTION'			=> $this->u_action,
   1.311 +					'S_CLOSED'				=> ($mode == 'pm_reports_closed') ? true : false,
   1.312 +
   1.313 +					'PAGINATION'			=> generate_pagination($this->u_action . "&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir", $total, $config['topics_per_page'], $start),
   1.314 +					'PAGE_NUMBER'			=> on_page($total, $config['topics_per_page'], $start),
   1.315 +					'TOTAL'					=> $total,
   1.316 +					'TOTAL_REPORTS'			=> ($total == 1) ? $user->lang['LIST_REPORT'] : sprintf($user->lang['LIST_REPORTS'], $total),					
   1.317 +					)
   1.318 +				);
   1.319 +
   1.320 +				$this->tpl_name = 'mcp_reports';
   1.321 +			break;
   1.322 +		}
   1.323 +	}
   1.324 +}
   1.325 +
   1.326 +?>
   1.327 \ No newline at end of file