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