phpBB
Statistics
| Revision:

root / branches / phpBB-3_0_0 / phpBB / report.php

History | View | Annotate | Download (6.3 kB)

1
<?php
2
/**
3
*
4
* @package phpBB3
5
* @version $Id: report.php 11318 2011-07-17 02:45:07Z git-gate $
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
*/
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);
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
34
if (!$post_id && (!$pm_id || !$config['allow_pm_report']))
35
{
36
        trigger_error('NO_POST_SELECTED');
37
}
38
39
if ($post_id)
40
{
41
        $redirect_url = append_sid("{$phpbb_root_path}viewtopic.$phpEx", "f=$forum_id&amp;p=$post_id") . "#p$post_id";
42
        $return_forum_url = append_sid("{$phpbb_root_path}viewforum.$phpEx", "f=$forum_id");
43
        $pm_id = 0;
44
}
45
else
46
{
47
        $redirect_url = append_sid("{$phpbb_root_path}ucp.$phpEx", "i=pm&mode=view&p=$pm_id");
48
        $return_forum_url = '';
49
        $post_id = 0;
50
        $forum_id = 0;
51
}
52
53
// Has the report been cancelled?
54
if (isset($_POST['cancel']))
55
{
56
        redirect($redirect_url);
57
}
58
59
if ($post_id)
60
{
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);
69
70
        if (!$report_data)
71
        {
72
                trigger_error('POST_NOT_EXIST');
73
        }
74
75
        $forum_id = (int) ($report_data['forum_id']) ? $report_data['forum_id'] : $forum_id;
76
        $topic_id = (int) $report_data['topic_id'];
77
78
        $sql = 'SELECT *
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);
84
85
        if (!$forum_data)
86
        {
87
                trigger_error('FORUM_NOT_EXIST');
88
        }
89
90
        // Check required permissions
91
        $acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
92
93
        foreach ($acl_check_ary as $acl => $error)
94
        {
95
                if (!$auth->acl_get($acl, $forum_id))
96
                {
97
                        trigger_error($error);
98
                }
99
        }
100
        unset($acl_check_ary);
101
102
        if ($report_data['post_reported'])
103
        {
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);
108
        }
109
}
110
else
111
{
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);
121
122
        if (!$report_data)
123
        {
124
                $user->add_lang('ucp');
125
                trigger_error('NO_MESSAGE');
126
        }
127
128
        if ($report_data['message_reported'])
129
        {
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);
133
        }
134
}
135
136
// Submit report?
137
if ($submit && $reason_id)
138
{
139
        $sql = 'SELECT *
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);
145
146
        if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
147
        {
148
                trigger_error('EMPTY_REPORT');
149
        }
150
151
        $sql_ary = array(
152
                'reason_id'                => (int) $reason_id,
153
                'post_id'                => $post_id,
154
                'pm_id'                        => $pm_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
160
        );
161
162
        $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
163
        $db->sql_query($sql);
164
        $report_id = $db->sql_nextid();
165
166
        if ($post_id)
167
        {
168
                $sql = 'UPDATE ' . POSTS_TABLE . '
169
                        SET post_reported = 1
170
                        WHERE post_id = ' . $post_id;
171
                $db->sql_query($sql);
172
173
                if (!$report_data['topic_reported'])
174
                {
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);
180
                }
181
182
                $lang_return = $user->lang['RETURN_TOPIC'];
183
                $lang_success = $user->lang['POST_REPORTED_SUCCESS'];
184
        }
185
        else
186
        {
187
                $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
188
                        SET message_reported = 1
189
                        WHERE msg_id = ' . $pm_id;
190
                $db->sql_query($sql);
191
192
                $sql_ary = array(
193
                        'msg_id'                => $pm_id,
194
                        'user_id'                => ANONYMOUS,
195
                        'author_id'                => (int) $report_data['author_id'],
196
                        'pm_deleted'        => 0,
197
                        'pm_new'                => 0,
198
                        'pm_unread'                => 0,
199
                        'pm_replied'        => 0,
200
                        'pm_marked'                => 0,
201
                        'pm_forwarded'        => 0,
202
                        'folder_id'                => PRIVMSGS_INBOX,
203
                );
204
205
                $sql = 'INSERT INTO ' . PRIVMSGS_TO_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
206
                $db->sql_query($sql);
207
208
                $lang_return = $user->lang['RETURN_PM'];
209
                $lang_success = $user->lang['PM_REPORTED_SUCCESS'];
210
        }
211
212
        meta_refresh(3, $redirect_url);
213
214
        $message = $lang_success . '<br /><br />' . sprintf($lang_return, '<a href="' . $redirect_url . '">', '</a>');
215
        if ($return_forum_url)
216
        {
217
                $message .= '<br /><br />' . sprintf($user->lang['RETURN_FORUM'], '<a href="' . $return_forum_url . '">', '</a>');
218
        }
219
        trigger_error($message);
220
}
221
222
// Generate the reasons
223
display_reasons($reason_id);
224
225
$page_title = ($pm_id) ? $user->lang['REPORT_MESSAGE'] : $user->lang['REPORT_POST'];
226
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 . '&amp;p=' . $post_id . '&amp;pm=' . $pm_id),
231
232
        'S_NOTIFY'                        => $user_notify,
233
        'S_CAN_NOTIFY'                => ($user->data['is_registered']) ? true : false)
234
);
235
236
generate_forum_nav($forum_data);
237
238
// Start output of page
239
page_header($page_title);
240
241
$template->set_filenames(array(
242
        'body' => 'report_body.html')
243
);
244
245
page_footer();
246
247
?>