Blame Identity/Webenv/phpBB/3.0.4/report.php

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

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

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