Blame Extras/phpBB/3.0.4/report.php

4c79b5
4c79b5
/**
4c79b5
*
4c79b5
* @package phpBB3
4c79b5
* @version $Id: report.php 8479 2008-03-29 00:22:48Z naderman $
4c79b5
* @copyright (c) 2005 phpBB Group
4c79b5
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
4c79b5
*
4c79b5
*/
4c79b5
4c79b5
/**
4c79b5
* @ignore
4c79b5
*/
4c79b5
define('IN_PHPBB', true);
4c79b5
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
4c79b5
$phpEx = substr(strrchr(__FILE__, '.'), 1);
4c79b5
include($phpbb_root_path . 'common.' . $phpEx);
4c79b5
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
4c79b5
4c79b5
// Start session management
4c79b5
$user->session_begin();
4c79b5
$auth->acl($user->data);
4c79b5
$user->setup('mcp');
4c79b5
4c79b5
$forum_id		= request_var('f', 0);
4c79b5
$post_id		= request_var('p', 0);
4c79b5
$reason_id		= request_var('reason_id', 0);
4c79b5
$report_text	= utf8_normalize_nfc(request_var('report_text', '', true));
4c79b5
$user_notify	= ($user->data['is_registered']) ? request_var('notify', 0) : false;
4c79b5
4c79b5
$submit = (isset($_POST['submit'])) ? true : false;
4c79b5
4c79b5
if (!$post_id)
4c79b5
{
4c79b5
	trigger_error('NO_POST_SELECTED');
4c79b5
}
4c79b5
4c79b5
$redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&p=$post_id") . "#p$post_id";
4c79b5
4c79b5
// Has the report been cancelled?
4c79b5
if (isset($_POST['cancel']))
4c79b5
{
4c79b5
	redirect($redirect_url);
4c79b5
}
4c79b5
4c79b5
// Grab all relevant data
4c79b5
$sql = 'SELECT t.*, p.*
4c79b5
	FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
4c79b5
	WHERE p.post_id = $post_id
4c79b5
		AND p.topic_id = t.topic_id";
4c79b5
$result = $db->sql_query($sql);
4c79b5
$report_data = $db->sql_fetchrow($result);
4c79b5
$db->sql_freeresult($result);
4c79b5
4c79b5
if (!$report_data)
4c79b5
{
4c79b5
	trigger_error('POST_NOT_EXIST');
4c79b5
}
4c79b5
4c79b5
$forum_id = (int) ($report_data['forum_id']) ? $report_data['forum_id'] : $forum_id;
4c79b5
$topic_id = (int) $report_data['topic_id'];
4c79b5
4c79b5
$sql = 'SELECT *
4c79b5
	FROM ' . FORUMS_TABLE . '
4c79b5
	WHERE forum_id = ' . $forum_id;
4c79b5
$result = $db->sql_query($sql);
4c79b5
$forum_data = $db->sql_fetchrow($result);
4c79b5
$db->sql_freeresult($result);
4c79b5
4c79b5
if (!$forum_data)
4c79b5
{
4c79b5
	trigger_error('FORUM_NOT_EXIST');
4c79b5
}
4c79b5
4c79b5
// Check required permissions
4c79b5
$acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
4c79b5
4c79b5
foreach ($acl_check_ary as $acl => $error)
4c79b5
{
4c79b5
	if (!$auth->acl_get($acl, $forum_id))
4c79b5
	{
4c79b5
		trigger_error($error);
4c79b5
	}
4c79b5
}
4c79b5
unset($acl_check_ary);
4c79b5
4c79b5
if ($report_data['post_reported'])
4c79b5
{
4c79b5
	$message = $user->lang['ALREADY_REPORTED'];
4c79b5
	$message .= '

' . sprintf($user->lang['RETURN_TOPIC'], '', '');
4c79b5
	trigger_error($message);
4c79b5
}
4c79b5
4c79b5
// Submit report?
4c79b5
if ($submit && $reason_id)
4c79b5
{
4c79b5
	$sql = 'SELECT *
4c79b5
		FROM ' . REPORTS_REASONS_TABLE . "
4c79b5
		WHERE reason_id = $reason_id";
4c79b5
	$result = $db->sql_query($sql);
4c79b5
	$row = $db->sql_fetchrow($result);
4c79b5
	$db->sql_freeresult($result);
4c79b5
4c79b5
	if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
4c79b5
	{
4c79b5
		trigger_error('EMPTY_REPORT');
4c79b5
	}
4c79b5
4c79b5
	$sql_ary = array(
4c79b5
		'reason_id'		=> (int) $reason_id,
4c79b5
		'post_id'		=> $post_id,
4c79b5
		'user_id'		=> (int) $user->data['user_id'],
4c79b5
		'user_notify'	=> (int) $user_notify,
4c79b5
		'report_closed'	=> 0,
4c79b5
		'report_time'	=> (int) time(),
4c79b5
		'report_text'	=> (string) $report_text
4c79b5
	);
4c79b5
4c79b5
	$sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
4c79b5
	$db->sql_query($sql);
4c79b5
	$report_id = $db->sql_nextid();
4c79b5
4c79b5
	if (!$report_data['post_reported'])
4c79b5
	{
4c79b5
		$sql = 'UPDATE ' . POSTS_TABLE . '
4c79b5
			SET post_reported = 1
4c79b5
			WHERE post_id = ' . $post_id;
4c79b5
		$db->sql_query($sql);
4c79b5
	}
4c79b5
4c79b5
	if (!$report_data['topic_reported'])
4c79b5
	{
4c79b5
		$sql = 'UPDATE ' . TOPICS_TABLE . '
4c79b5
			SET topic_reported = 1
4c79b5
			WHERE topic_id = ' . $report_data['topic_id'] . '
4c79b5
				OR topic_moved_id = ' . $report_data['topic_id'];
4c79b5
		$db->sql_query($sql);
4c79b5
	}
4c79b5
4c79b5
	meta_refresh(3, $redirect_url);
4c79b5
4c79b5
	$message = $user->lang['POST_REPORTED_SUCCESS'] . '

' . sprintf($user->lang['RETURN_TOPIC'], '', '');
4c79b5
	trigger_error($message);
4c79b5
}
4c79b5
4c79b5
// Generate the reasons
4c79b5
display_reasons($reason_id);
4c79b5
4c79b5
$template->assign_vars(array(
4c79b5
	'REPORT_TEXT'		=> $report_text,
4c79b5
	'S_REPORT_ACTION'	=> append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&p=' . $post_id),
4c79b5
4c79b5
	'S_NOTIFY'			=> $user_notify,
4c79b5
	'S_CAN_NOTIFY'		=> ($user->data['is_registered']) ? true : false)
4c79b5
);
4c79b5
4c79b5
generate_forum_nav($forum_data);
4c79b5
4c79b5
// Start output of page
4c79b5
page_header($user->lang['REPORT_POST']);
4c79b5
4c79b5
$template->set_filenames(array(
4c79b5
	'body' => 'report_body.html')
4c79b5
);
4c79b5
4c79b5
page_footer();
4c79b5
4c79b5
?>