report.php
changeset 0 ceef6d64c21d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/report.php	Wed Mar 07 16:41:10 2012 +0400
     1.3 @@ -0,0 +1,247 @@
     1.4 +<?php
     1.5 +/**
     1.6 +*
     1.7 +* @package phpBB3
     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 +define('IN_PHPBB', true);
    1.18 +$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
    1.19 +$phpEx = substr(strrchr(__FILE__, '.'), 1);
    1.20 +include($phpbb_root_path . 'common.' . $phpEx);
    1.21 +include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
    1.22 +
    1.23 +// Start session management
    1.24 +$user->session_begin();
    1.25 +$auth->acl($user->data);
    1.26 +$user->setup('mcp');
    1.27 +
    1.28 +$forum_id		= request_var('f', 0);
    1.29 +$post_id		= request_var('p', 0);
    1.30 +$pm_id			= request_var('pm', 0);
    1.31 +$reason_id		= request_var('reason_id', 0);
    1.32 +$report_text	= utf8_normalize_nfc(request_var('report_text', '', true));
    1.33 +$user_notify	= ($user->data['is_registered']) ? request_var('notify', 0) : false;
    1.34 +
    1.35 +$submit = (isset($_POST['submit'])) ? true : false;
    1.36 +
    1.37 +if (!$post_id && (!$pm_id || !$config['allow_pm_report']))
    1.38 +{
    1.39 +	trigger_error('NO_POST_SELECTED');
    1.40 +}
    1.41 +
    1.42 +if ($post_id)
    1.43 +{
    1.44 +	$redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;p=$post_id") . "#p$post_id";
    1.45 +	$return_forum_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
    1.46 +	$pm_id = 0;
    1.47 +}
    1.48 +else
    1.49 +{
    1.50 +	$redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&p=$pm_id");
    1.51 +	$return_forum_url = '';
    1.52 +	$post_id = 0;
    1.53 +	$forum_id = 0;
    1.54 +}
    1.55 +
    1.56 +// Has the report been cancelled?
    1.57 +if (isset($_POST['cancel']))
    1.58 +{
    1.59 +	redirect($redirect_url);
    1.60 +}
    1.61 +
    1.62 +if ($post_id)
    1.63 +{
    1.64 +	// Grab all relevant data
    1.65 +	$sql = 'SELECT t.*, p.*
    1.66 +		FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
    1.67 +		WHERE p.post_id = $post_id
    1.68 +			AND p.topic_id = t.topic_id";
    1.69 +	$result = $db->sql_query($sql);
    1.70 +	$report_data = $db->sql_fetchrow($result);
    1.71 +	$db->sql_freeresult($result);
    1.72 +
    1.73 +	if (!$report_data)
    1.74 +	{
    1.75 +		trigger_error('POST_NOT_EXIST');
    1.76 +	}
    1.77 +
    1.78 +	$forum_id = (int) ($report_data['forum_id']) ? $report_data['forum_id'] : $forum_id;
    1.79 +	$topic_id = (int) $report_data['topic_id'];
    1.80 +
    1.81 +	$sql = 'SELECT *
    1.82 +		FROM ' . FORUMS_TABLE . '
    1.83 +		WHERE forum_id = ' . $forum_id;
    1.84 +	$result = $db->sql_query($sql);
    1.85 +	$forum_data = $db->sql_fetchrow($result);
    1.86 +	$db->sql_freeresult($result);
    1.87 +
    1.88 +	if (!$forum_data)
    1.89 +	{
    1.90 +		trigger_error('FORUM_NOT_EXIST');
    1.91 +	}
    1.92 +
    1.93 +	// Check required permissions
    1.94 +	$acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
    1.95 +
    1.96 +	foreach ($acl_check_ary as $acl => $error)
    1.97 +	{
    1.98 +		if (!$auth->acl_get($acl, $forum_id))
    1.99 +		{
   1.100 +			trigger_error($error);
   1.101 +		}
   1.102 +	}
   1.103 +	unset($acl_check_ary);
   1.104 +
   1.105 +	if ($report_data['post_reported'])
   1.106 +	{
   1.107 +		$message = $user->lang['ALREADY_REPORTED'];
   1.108 +		$message .= '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
   1.109 +		$message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
   1.110 +		trigger_error($message);
   1.111 +	}
   1.112 +}
   1.113 +else
   1.114 +{
   1.115 +	// Grab all relevant data
   1.116 +	$sql = 'SELECT p.*, pt.*
   1.117 +		FROM ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TO_TABLE . " pt
   1.118 +		WHERE p.msg_id = $pm_id
   1.119 +			AND p.msg_id = pt.msg_id
   1.120 +			AND (p.author_id = " . $user->data['user_id'] . " OR pt.user_id = " . $user->data['user_id'] . ")";
   1.121 +	$result = $db->sql_query($sql);
   1.122 +	$report_data = $db->sql_fetchrow($result);
   1.123 +	$db->sql_freeresult($result);
   1.124 +
   1.125 +	if (!$report_data)
   1.126 +	{
   1.127 +		$user->add_lang('ucp');
   1.128 +		trigger_error('NO_MESSAGE');
   1.129 +	}
   1.130 +
   1.131 +	if ($report_data['message_reported'])
   1.132 +	{
   1.133 +		$message = $user->lang['ALREADY_REPORTED_PM'];
   1.134 +		$message .= '<br /><br />' . sprintf($user->lang['RETURN_PM'], '<a href="' . $redirect_url . '">', '</a>');
   1.135 +		trigger_error($message);
   1.136 +	}
   1.137 +}
   1.138 +
   1.139 +// Submit report?
   1.140 +if ($submit && $reason_id)
   1.141 +{
   1.142 +	$sql = 'SELECT *
   1.143 +		FROM ' . REPORTS_REASONS_TABLE . "
   1.144 +		WHERE reason_id = $reason_id";
   1.145 +	$result = $db->sql_query($sql);
   1.146 +	$row = $db->sql_fetchrow($result);
   1.147 +	$db->sql_freeresult($result);
   1.148 +
   1.149 +	if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
   1.150 +	{
   1.151 +		trigger_error('EMPTY_REPORT');
   1.152 +	}
   1.153 +
   1.154 +	$sql_ary = array(
   1.155 +		'reason_id'		=> (int) $reason_id,
   1.156 +		'post_id'		=> $post_id,
   1.157 +		'pm_id'			=> $pm_id,
   1.158 +		'user_id'		=> (int) $user->data['user_id'],
   1.159 +		'user_notify'	=> (int) $user_notify,
   1.160 +		'report_closed'	=> 0,
   1.161 +		'report_time'	=> (int) time(),
   1.162 +		'report_text'	=> (string) $report_text
   1.163 +	);
   1.164 +
   1.165 +	$sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
   1.166 +	$db->sql_query($sql);
   1.167 +	$report_id = $db->sql_nextid();
   1.168 +
   1.169 +	if ($post_id)
   1.170 +	{
   1.171 +		$sql = 'UPDATE ' . POSTS_TABLE . '
   1.172 +			SET post_reported = 1
   1.173 +			WHERE post_id = ' . $post_id;
   1.174 +		$db->sql_query($sql);
   1.175 +
   1.176 +		if (!$report_data['topic_reported'])
   1.177 +		{
   1.178 +			$sql = 'UPDATE ' . TOPICS_TABLE . '
   1.179 +				SET topic_reported = 1
   1.180 +				WHERE topic_id = ' . $report_data['topic_id'] . '
   1.181 +					OR topic_moved_id = ' . $report_data['topic_id'];
   1.182 +			$db->sql_query($sql);
   1.183 +		}
   1.184 +
   1.185 +		$lang_return = $user->lang['RETURN_TOPIC'];
   1.186 +		$lang_success = $user->lang['POST_REPORTED_SUCCESS'];
   1.187 +	}
   1.188 +	else
   1.189 +	{
   1.190 +		$sql = 'UPDATE ' . PRIVMSGS_TABLE . '
   1.191 +			SET message_reported = 1
   1.192 +			WHERE msg_id = ' . $pm_id;
   1.193 +		$db->sql_query($sql);
   1.194 +
   1.195 +		$sql_ary = array(
   1.196 +			'msg_id'		=> $pm_id,
   1.197 +			'user_id'		=> ANONYMOUS,
   1.198 +			'author_id'		=> (int) $report_data['author_id'],
   1.199 +			'pm_deleted'	=> 0,
   1.200 +			'pm_new'		=> 0,
   1.201 +			'pm_unread'		=> 0,
   1.202 +			'pm_replied'	=> 0,
   1.203 +			'pm_marked'		=> 0,
   1.204 +			'pm_forwarded'	=> 0,
   1.205 +			'folder_id'		=> PRIVMSGS_INBOX,
   1.206 +		);
   1.207 +
   1.208 +		$sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
   1.209 +		$db->sql_query($sql);
   1.210 +
   1.211 +		$lang_return = $user->lang['RETURN_PM'];
   1.212 +		$lang_success = $user->lang['PM_REPORTED_SUCCESS'];
   1.213 +	}
   1.214 +
   1.215 +	meta_refresh(3, $redirect_url);
   1.216 +
   1.217 +	$message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
   1.218 +	if ($return_forum_url)
   1.219 +	{
   1.220 +		$message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
   1.221 +	}
   1.222 +	trigger_error($message);
   1.223 +}
   1.224 +
   1.225 +// Generate the reasons
   1.226 +display_reasons($reason_id);
   1.227 +
   1.228 +$page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST'];
   1.229 +
   1.230 +$template->assign_vars(array(
   1.231 +	'S_REPORT_POST'		=> ($pm_id) ? false : true,
   1.232 +	'REPORT_TEXT'		=> $report_text,
   1.233 +	'S_REPORT_ACTION'	=> append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $post_id . '&amp;pm=' . $pm_id),
   1.234 +
   1.235 +	'S_NOTIFY'			=> $user_notify,
   1.236 +	'S_CAN_NOTIFY'		=> ($user->data['is_registered']) ? true : false)
   1.237 +);
   1.238 +
   1.239 +generate_forum_nav($forum_data);
   1.240 +
   1.241 +// Start output of page
   1.242 +page_header($page_title);
   1.243 +
   1.244 +$template->set_filenames(array(
   1.245 +	'body' => 'report_body.html')
   1.246 +);
   1.247 +
   1.248 +page_footer();
   1.249 +
   1.250 +?>
   1.251 \ No newline at end of file