6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 define('IN_PHPBB', true);
15 $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH
: './';
16 $phpEx = substr(strrchr(__FILE__
, '.'), 1);
17 include($phpbb_root_path . 'common.' . $phpEx);
18 include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
20 // Start session management
21 $user->session_begin();
22 $auth->acl($user->data
);
25 $forum_id = request_var('f', 0);
26 $post_id = request_var('p', 0);
27 $pm_id = request_var('pm', 0);
28 $reason_id = request_var('reason_id', 0);
29 $report_text = utf8_normalize_nfc(request_var('report_text', '', true));
30 $user_notify = ($user->data
['is_registered']) ?
request_var('notify', 0) : false;
32 $submit = (isset($_POST['submit'])) ?
true : false;
34 if (!$post_id && (!$pm_id ||
!$config['allow_pm_report']))
36 trigger_error('NO_POST_SELECTED');
41 $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&p=$post_id") . "#p$post_id";
46 $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&p=$pm_id");
51 // Has the report been cancelled?
52 if (isset($_POST['cancel']))
54 redirect($redirect_url);
59 // Grab all relevant data
60 $sql = 'SELECT t.*, p.*
61 FROM ' . POSTS_TABLE
. ' p, ' . TOPICS_TABLE
. " t
62 WHERE p.post_id = $post_id
63 AND p.topic_id = t.topic_id";
64 $result = $db->sql_query($sql);
65 $report_data = $db->sql_fetchrow($result);
66 $db->sql_freeresult($result);
70 trigger_error('POST_NOT_EXIST');
73 $forum_id = (int) ($report_data['forum_id']) ?
$report_data['forum_id'] : $forum_id;
74 $topic_id = (int) $report_data['topic_id'];
77 FROM ' . FORUMS_TABLE
. '
78 WHERE forum_id = ' . $forum_id;
79 $result = $db->sql_query($sql);
80 $forum_data = $db->sql_fetchrow($result);
81 $db->sql_freeresult($result);
85 trigger_error('FORUM_NOT_EXIST');
88 // Check required permissions
89 $acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
91 foreach ($acl_check_ary as $acl => $error)
93 if (!$auth->acl_get($acl, $forum_id))
95 trigger_error($error);
98 unset($acl_check_ary);
100 if ($report_data['post_reported'])
102 $message = $user->lang
['ALREADY_REPORTED'];
103 $message .= '<br /><br />' . sprintf($user->lang
['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
104 trigger_error($message);
109 // Grab all relevant data
110 $sql = 'SELECT p.*, pt.*
111 FROM ' . PRIVMSGS_TABLE
. ' p, ' . PRIVMSGS_TO_TABLE
. " pt
112 WHERE p.msg_id = $pm_id
113 AND p.msg_id = pt.msg_id
114 AND (p.author_id = " . $user->data
['user_id'] . " OR pt.user_id = " . $user->data
['user_id'] . ")";
115 $result = $db->sql_query($sql);
116 $report_data = $db->sql_fetchrow($result);
117 $db->sql_freeresult($result);
121 $user->add_lang('ucp');
122 trigger_error('NO_MESSAGE');
125 if ($report_data['message_reported'])
127 $message = $user->lang
['ALREADY_REPORTED_PM'];
128 $message .= '<br /><br />' . sprintf($user->lang
['RETURN_PM'], '<a href="' . $redirect_url . '">', '</a>');
129 trigger_error($message);
134 if ($submit && $reason_id)
137 FROM ' . REPORTS_REASONS_TABLE
. "
138 WHERE reason_id = $reason_id";
139 $result = $db->sql_query($sql);
140 $row = $db->sql_fetchrow($result);
141 $db->sql_freeresult($result);
143 if (!$row ||
(!$report_text && strtolower($row['reason_title']) == 'other'))
145 trigger_error('EMPTY_REPORT');
149 'reason_id' => (int) $reason_id,
150 'post_id' => $post_id,
152 'user_id' => (int) $user->data
['user_id'],
153 'user_notify' => (int) $user_notify,
154 'report_closed' => 0,
155 'report_time' => (int) time(),
156 'report_text' => (string) $report_text
159 $sql = 'INSERT INTO ' . REPORTS_TABLE
. ' ' . $db->sql_build_array('INSERT', $sql_ary);
160 $db->sql_query($sql);
161 $report_id = $db->sql_nextid();
165 $sql = 'UPDATE ' . POSTS_TABLE
. '
166 SET post_reported = 1
167 WHERE post_id = ' . $post_id;
168 $db->sql_query($sql);
170 if (!$report_data['topic_reported'])
172 $sql = 'UPDATE ' . TOPICS_TABLE
. '
173 SET topic_reported = 1
174 WHERE topic_id = ' . $report_data['topic_id'] . '
175 OR topic_moved_id = ' . $report_data['topic_id'];
176 $db->sql_query($sql);
179 $lang_return = $user->lang
['RETURN_TOPIC'];
180 $lang_success = $user->lang
['POST_REPORTED_SUCCESS'];
184 $sql = 'UPDATE ' . PRIVMSGS_TABLE
. '
185 SET message_reported = 1
186 WHERE msg_id = ' . $pm_id;
187 $db->sql_query($sql);
191 'user_id' => ANONYMOUS
,
192 'author_id' => (int) $report_data['author_id'],
199 'folder_id' => PRIVMSGS_INBOX
,
202 $sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE
. ' ' . $db->sql_build_array('INSERT', $sql_ary);
203 $db->sql_query($sql);
205 $lang_return = $user->lang
['RETURN_PM'];
206 $lang_success = $user->lang
['PM_REPORTED_SUCCESS'];
209 meta_refresh(3, $redirect_url);
211 $message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
212 trigger_error($message);
215 // Generate the reasons
216 display_reasons($reason_id);
218 $template->assign_vars(array(
219 'S_REPORT_POST' => ($pm_id) ?
false : true,
220 'REPORT_TEXT' => $report_text,
221 'S_REPORT_ACTION' => append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&p=' . $post_id . '&pm=' . $pm_id),
223 'S_NOTIFY' => $user_notify,
224 'S_CAN_NOTIFY' => ($user->data
['is_registered']) ?
true : false)
227 generate_forum_nav($forum_data);
229 // Start output of page
230 page_header($user->lang
['REPORT_POST']);
232 $template->set_filenames(array(
233 'body' => 'report_body.html')