source: trunk/forum/report.php

Last change on this file was 702, checked in by george, 15 years ago
  • Upraveno: Aktualizace fóra.
File size: 6.0 KB
Line 
1<?php
2/**
3*
4* @package phpBB3
5* @version $Id$
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14define('IN_PHPBB', true);
15$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
16$phpEx = substr(strrchr(__FILE__, '.'), 1);
17include($phpbb_root_path . 'common.' . $phpEx);
18include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
19
20// Start session management
21$user->session_begin();
22$auth->acl($user->data);
23$user->setup('mcp');
24
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;
31
32$submit = (isset($_POST['submit'])) ? true : false;
33
34if (!$post_id && (!$pm_id || !$config['allow_pm_report']))
35{
36 trigger_error('NO_POST_SELECTED');
37}
38
39if ($post_id)
40{
41 $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;p=$post_id") . "#p$post_id";
42 $pm_id = 0;
43}
44else
45{
46 $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&p=$pm_id");
47 $post_id = 0;
48 $forum_id = 0;
49}
50
51// Has the report been cancelled?
52if (isset($_POST['cancel']))
53{
54 redirect($redirect_url);
55}
56
57if ($post_id)
58{
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);
67
68 if (!$report_data)
69 {
70 trigger_error('POST_NOT_EXIST');
71 }
72
73 $forum_id = (int) ($report_data['forum_id']) ? $report_data['forum_id'] : $forum_id;
74 $topic_id = (int) $report_data['topic_id'];
75
76 $sql = 'SELECT *
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);
82
83 if (!$forum_data)
84 {
85 trigger_error('FORUM_NOT_EXIST');
86 }
87
88 // Check required permissions
89 $acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
90
91 foreach ($acl_check_ary as $acl => $error)
92 {
93 if (!$auth->acl_get($acl, $forum_id))
94 {
95 trigger_error($error);
96 }
97 }
98 unset($acl_check_ary);
99
100 if ($report_data['post_reported'])
101 {
102 $message = $user->lang['ALREADY_REPORTED'];
103 $message .= '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
104 trigger_error($message);
105 }
106}
107else
108{
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);
118
119 if (!$report_data)
120 {
121 $user->add_lang('ucp');
122 trigger_error('NO_MESSAGE');
123 }
124
125 if ($report_data['message_reported'])
126 {
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);
130 }
131}
132
133// Submit report?
134if ($submit && $reason_id)
135{
136 $sql = 'SELECT *
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);
142
143 if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
144 {
145 trigger_error('EMPTY_REPORT');
146 }
147
148 $sql_ary = array(
149 'reason_id' => (int) $reason_id,
150 'post_id' => $post_id,
151 'pm_id' => $pm_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
157 );
158
159 $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
160 $db->sql_query($sql);
161 $report_id = $db->sql_nextid();
162
163 if ($post_id)
164 {
165 $sql = 'UPDATE ' . POSTS_TABLE . '
166 SET post_reported = 1
167 WHERE post_id = ' . $post_id;
168 $db->sql_query($sql);
169
170 if (!$report_data['topic_reported'])
171 {
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);
177 }
178
179 $lang_return = $user->lang['RETURN_TOPIC'];
180 $lang_success = $user->lang['POST_REPORTED_SUCCESS'];
181 }
182 else
183 {
184 $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
185 SET message_reported = 1
186 WHERE msg_id = ' . $pm_id;
187 $db->sql_query($sql);
188
189 $sql_ary = array(
190 'msg_id' => $pm_id,
191 'user_id' => ANONYMOUS,
192 'author_id' => (int) $report_data['author_id'],
193 'pm_deleted' => 0,
194 'pm_new' => 0,
195 'pm_unread' => 0,
196 'pm_replied' => 0,
197 'pm_marked' => 0,
198 'pm_forwarded' => 0,
199 'folder_id' => PRIVMSGS_INBOX,
200 );
201
202 $sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
203 $db->sql_query($sql);
204
205 $lang_return = $user->lang['RETURN_PM'];
206 $lang_success = $user->lang['PM_REPORTED_SUCCESS'];
207 }
208
209 meta_refresh(3, $redirect_url);
210
211 $message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
212 trigger_error($message);
213}
214
215// Generate the reasons
216display_reasons($reason_id);
217
218$page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST'];
219
220$template->assign_vars(array(
221 'S_REPORT_POST' => ($pm_id) ? false : true,
222 'REPORT_TEXT' => $report_text,
223 'S_REPORT_ACTION' => append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $post_id . '&amp;pm=' . $pm_id),
224
225 'S_NOTIFY' => $user_notify,
226 'S_CAN_NOTIFY' => ($user->data['is_registered']) ? true : false)
227);
228
229generate_forum_nav($forum_data);
230
231// Start output of page
232page_header($page_title);
233
234$template->set_filenames(array(
235 'body' => 'report_body.html')
236);
237
238page_footer();
239
240?>
Note: See TracBrowser for help on using the repository browser.