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";
42 $return_forum_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
47 $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&p=$pm_id");
48 $return_forum_url = '';
53 // Has the report been cancelled?
54 if (isset($_POST['cancel']))
56 redirect($redirect_url);
61 // Grab all relevant data
62 $sql = 'SELECT t.*, p.*
63 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
64 WHERE p.post_id = $post_id
65 AND p.topic_id = t.topic_id";
66 $result = $db->sql_query($sql);
67 $report_data = $db->sql_fetchrow($result);
68 $db->sql_freeresult($result);
72 trigger_error('POST_NOT_EXIST');
75 $forum_id = (int) ($report_data['forum_id']) ? $report_data['forum_id'] : $forum_id;
76 $topic_id = (int) $report_data['topic_id'];
79 FROM ' . FORUMS_TABLE . '
80 WHERE forum_id = ' . $forum_id;
81 $result = $db->sql_query($sql);
82 $forum_data = $db->sql_fetchrow($result);
83 $db->sql_freeresult($result);
87 trigger_error('FORUM_NOT_EXIST');
90 // Check required permissions
91 $acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
93 foreach ($acl_check_ary as $acl => $error)
95 if (!$auth->acl_get($acl, $forum_id))
97 trigger_error($error);
100 unset($acl_check_ary);
102 if ($report_data['post_reported'])
104 $message = $user->lang['ALREADY_REPORTED'];
105 $message .= '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
106 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
107 trigger_error($message);
112 // Grab all relevant data
113 $sql = 'SELECT p.*, pt.*
114 FROM ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TO_TABLE . " pt
115 WHERE p.msg_id = $pm_id
116 AND p.msg_id = pt.msg_id
117 AND (p.author_id = " . $user->data['user_id'] . " OR pt.user_id = " . $user->data['user_id'] . ")";
118 $result = $db->sql_query($sql);
119 $report_data = $db->sql_fetchrow($result);
120 $db->sql_freeresult($result);
124 $user->add_lang('ucp');
125 trigger_error('NO_MESSAGE');
128 if ($report_data['message_reported'])
130 $message = $user->lang['ALREADY_REPORTED_PM'];
131 $message .= '<br /><br />' . sprintf($user->lang['RETURN_PM'], '<a href="' . $redirect_url . '">', '</a>');
132 trigger_error($message);
137 if ($submit && $reason_id)
140 FROM ' . REPORTS_REASONS_TABLE . "
141 WHERE reason_id = $reason_id";
142 $result = $db->sql_query($sql);
143 $row = $db->sql_fetchrow($result);
144 $db->sql_freeresult($result);
146 if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
148 trigger_error('EMPTY_REPORT');
152 'reason_id' => (int) $reason_id,
153 'post_id' => $post_id,
155 'user_id' => (int) $user->data['user_id'],
156 'user_notify' => (int) $user_notify,
157 'report_closed' => 0,
158 'report_time' => (int) time(),
159 'report_text' => (string) $report_text
162 $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
163 $db->sql_query($sql);
164 $report_id = $db->sql_nextid();
168 $sql = 'UPDATE ' . POSTS_TABLE . '
169 SET post_reported = 1
170 WHERE post_id = ' . $post_id;
171 $db->sql_query($sql);
173 if (!$report_data['topic_reported'])
175 $sql = 'UPDATE ' . TOPICS_TABLE . '
176 SET topic_reported = 1
177 WHERE topic_id = ' . $report_data['topic_id'] . '
178 OR topic_moved_id = ' . $report_data['topic_id'];
179 $db->sql_query($sql);
182 $lang_return = $user->lang['RETURN_TOPIC'];
183 $lang_success = $user->lang['POST_REPORTED_SUCCESS'];
187 $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
188 SET message_reported = 1
189 WHERE msg_id = ' . $pm_id;
190 $db->sql_query($sql);
194 'user_id' => ANONYMOUS,
195 'author_id' => (int) $report_data['author_id'],
202 'folder_id' => PRIVMSGS_INBOX,
205 $sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
206 $db->sql_query($sql);
208 $lang_return = $user->lang['RETURN_PM'];
209 $lang_success = $user->lang['PM_REPORTED_SUCCESS'];
212 meta_refresh(3, $redirect_url);
214 $message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
215 if ($return_forum_url)
217 $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
219 trigger_error($message);
222 // Generate the reasons
223 display_reasons($reason_id);
225 $page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST'];
227 $template->assign_vars(array(
228 'S_REPORT_POST' => ($pm_id) ? false : true,
229 'REPORT_TEXT' => $report_text,
230 'S_REPORT_ACTION' => append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&p=' . $post_id . '&pm=' . $pm_id),
232 'S_NOTIFY' => $user_notify,
233 'S_CAN_NOTIFY' => ($user->data['is_registered']) ? true : false)
236 generate_forum_nav($forum_data);
238 // Start output of page
239 page_header($page_title);
241 $template->set_filenames(array(
242 'body' => 'report_body.html')