phpBB
Statistics
| Revision:

root / trunk / phpBB / report.php

History | View | Annotate | Download (6.3 kB)

1
<?php
2
/**
3
*
4
* @package phpBB3
5
* @copyright (c) 2005 phpBB Group
6
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
7
*
8
*/
9
10
/**
11
* @ignore
12
*/
13
define('IN_PHPBB', true);
14
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
15
$phpEx = substr(strrchr(__FILE__, '.'), 1);
16
include($phpbb_root_path . 'common.' . $phpEx);
17
include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
18
19
// Start session management
20
$user->session_begin();
21
$auth->acl($user->data);
22
$user->setup('mcp');
23
24
$forum_id                = request_var('f', 0);
25
$post_id                = request_var('p', 0);
26
$pm_id                        = request_var('pm', 0);
27
$reason_id                = request_var('reason_id', 0);
28
$report_text        = utf8_normalize_nfc(request_var('report_text', '', true));
29
$user_notify        = ($user->data['is_registered']) ? request_var('notify', 0) : false;
30
31
$submit = (isset($_POST['submit'])) ? true : false;
32
33
if (!$post_id && (!$pm_id || !$config['allow_pm_report']))
34
{
35
        trigger_error('NO_POST_SELECTED');
36
}
37
38
if ($post_id)
39
{
40
        $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;p=$post_id") . "#p$post_id";
41
        $return_forum_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
42
        $pm_id = 0;
43
}
44
else
45
{
46
        $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&p=$pm_id");
47
        $return_forum_url = '';
48
        $post_id = 0;
49
        $forum_id = 0;
50
}
51
52
// Has the report been cancelled?
53
if (isset($_POST['cancel']))
54
{
55
        redirect($redirect_url);
56
}
57
58
if ($post_id)
59
{
60
        // Grab all relevant data
61
        $sql = 'SELECT t.*, p.*
62
                FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
63
                WHERE p.post_id = $post_id
64
                        AND p.topic_id = t.topic_id";
65
        $result = $db->sql_query($sql);
66
        $report_data = $db->sql_fetchrow($result);
67
        $db->sql_freeresult($result);
68
69
        if (!$report_data)
70
        {
71
                trigger_error('POST_NOT_EXIST');
72
        }
73
74
        $forum_id = (int) $report_data['forum_id'];
75
        $topic_id = (int) $report_data['topic_id'];
76
77
        $sql = 'SELECT *
78
                FROM ' . FORUMS_TABLE . '
79
                WHERE forum_id = ' . $forum_id;
80
        $result = $db->sql_query($sql);
81
        $forum_data = $db->sql_fetchrow($result);
82
        $db->sql_freeresult($result);
83
84
        if (!$forum_data)
85
        {
86
                trigger_error('FORUM_NOT_EXIST');
87
        }
88
89
        // Check required permissions
90
        $acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
91
92
        foreach ($acl_check_ary as $acl => $error)
93
        {
94
                if (!$auth->acl_get($acl, $forum_id))
95
                {
96
                        trigger_error($error);
97
                }
98
        }
99
        unset($acl_check_ary);
100
101
        if ($report_data['post_reported'])
102
        {
103
                $message = $user->lang['ALREADY_REPORTED'];
104
                $message .= '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
105
                $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
106
                trigger_error($message);
107
        }
108
}
109
else
110
{
111
        // Grab all relevant data
112
        $sql = 'SELECT p.*, pt.*
113
                FROM ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TO_TABLE . " pt
114
                WHERE p.msg_id = $pm_id
115
                        AND p.msg_id = pt.msg_id
116
                        AND (p.author_id = " . $user->data['user_id'] . " OR pt.user_id = " . $user->data['user_id'] . ")";
117
        $result = $db->sql_query($sql);
118
        $report_data = $db->sql_fetchrow($result);
119
        $db->sql_freeresult($result);
120
121
        if (!$report_data)
122
        {
123
                $user->add_lang('ucp');
124
                trigger_error('NO_MESSAGE');
125
        }
126
127
        if ($report_data['message_reported'])
128
        {
129
                $message = $user->lang['ALREADY_REPORTED_PM'];
130
                $message .= '<br /><br />' . sprintf($user->lang['RETURN_PM'], '<a href="' . $redirect_url . '">', '</a>');
131
                trigger_error($message);
132
        }
133
}
134
135
// Submit report?
136
if ($submit && $reason_id)
137
{
138
        $sql = 'SELECT *
139
                FROM ' . REPORTS_REASONS_TABLE . "
140
                WHERE reason_id = $reason_id";
141
        $result = $db->sql_query($sql);
142
        $row = $db->sql_fetchrow($result);
143
        $db->sql_freeresult($result);
144
145
        if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
146
        {
147
                trigger_error('EMPTY_REPORT');
148
        }
149
150
        $sql_ary = array(
151
                'reason_id'                => (int) $reason_id,
152
                'post_id'                => $post_id,
153
                'pm_id'                        => $pm_id,
154
                'user_id'                => (int) $user->data['user_id'],
155
                'user_notify'        => (int) $user_notify,
156
                'report_closed'        => 0,
157
                'report_time'        => (int) time(),
158
                'report_text'        => (string) $report_text
159
        );
160
161
        $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
162
        $db->sql_query($sql);
163
        $report_id = $db->sql_nextid();
164
165
        if ($post_id)
166
        {
167
                $sql = 'UPDATE ' . POSTS_TABLE . '
168
                        SET post_reported = 1
169
                        WHERE post_id = ' . $post_id;
170
                $db->sql_query($sql);
171
172
                if (!$report_data['topic_reported'])
173
                {
174
                        $sql = 'UPDATE ' . TOPICS_TABLE . '
175
                                SET topic_reported = 1
176
                                WHERE topic_id = ' . $report_data['topic_id'] . '
177
                                        OR topic_moved_id = ' . $report_data['topic_id'];
178
                        $db->sql_query($sql);
179
                }
180
181
                $lang_return = $user->lang['RETURN_TOPIC'];
182
                $lang_success = $user->lang['POST_REPORTED_SUCCESS'];
183
        }
184
        else
185
        {
186
                $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
187
                        SET message_reported = 1
188
                        WHERE msg_id = ' . $pm_id;
189
                $db->sql_query($sql);
190
191
                $sql_ary = array(
192
                        'msg_id'                => $pm_id,
193
                        'user_id'                => ANONYMOUS,
194
                        'author_id'                => (int) $report_data['author_id'],
195
                        'pm_deleted'        => 0,
196
                        'pm_new'                => 0,
197
                        'pm_unread'                => 0,
198
                        'pm_replied'        => 0,
199
                        'pm_marked'                => 0,
200
                        'pm_forwarded'        => 0,
201
                        'folder_id'                => PRIVMSGS_INBOX,
202
                );
203
204
                $sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
205
                $db->sql_query($sql);
206
207
                $lang_return = $user->lang['RETURN_PM'];
208
                $lang_success = $user->lang['PM_REPORTED_SUCCESS'];
209
        }
210
211
        meta_refresh(3, $redirect_url);
212
213
        $message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
214
        if ($return_forum_url)
215
        {
216
                $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
217
        }
218
        trigger_error($message);
219
}
220
221
// Generate the reasons
222
display_reasons($reason_id);
223
224
$page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST'];
225
226
$template->assign_vars(array(
227
        'S_REPORT_POST'                => ($pm_id) ? false : true,
228
        'REPORT_TEXT'                => $report_text,
229
        'S_REPORT_ACTION'        => append_sid("{$phpbb_root_path}report.$phpEx", 'f=' . $forum_id . '&amp;p=' . $post_id . '&amp;pm=' . $pm_id),
230
231
        'S_NOTIFY'                        => $user_notify,
232
        'S_CAN_NOTIFY'                => ($user->data['is_registered']) ? true : false)
233
);
234
235
generate_forum_nav($forum_data);
236
237
// Start output of page
238
page_header($page_title);
239
240
$template->set_filenames(array(
241
        'body' => 'report_body.html')
242
);
243
244
page_footer();