do not display ban link for own profile
[phpbb.git] / phpBB / report.php
blob1997a55a15c3e12e0d49216fb41977c7a9b0556b
1 <?php
2 /**
4 * @package phpBB3
5 * @version $Id$
6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
9 */
11 /**
12 * @ignore
14 define('IN_PHPBB', true);
15 if (!defined('PHPBB_ROOT_PATH')) define('PHPBB_ROOT_PATH', './');
16 if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
17 include(PHPBB_ROOT_PATH . 'common.' . PHP_EXT);
18 include(PHPBB_ROOT_PATH . 'includes/functions_display.' . PHP_EXT);
20 // Start session management
21 $user->session_begin();
22 $auth->acl($user->data);
23 $user->setup('mcp');
25 $forum_id = request_var('f', 0);
26 $post_id = request_var('p', 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;
31 $submit = request::is_set_post('submit');
33 if (!$post_id)
35 trigger_error('NO_POST_SELECTED');
38 $redirect_url = append_sid('viewtopic', "f=$forum_id&amp;p=$post_id") . "#p$post_id";
40 // Has the report been cancelled?
41 if (request::is_set_post('cancel'))
43 redirect($redirect_url);
46 // Grab all relevant data
47 $sql = 'SELECT t.*, p.*
48 FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . " t
49 WHERE p.post_id = $post_id
50 AND p.topic_id = t.topic_id";
51 $result = $db->sql_query($sql);
52 $report_data = $db->sql_fetchrow($result);
53 $db->sql_freeresult($result);
55 if (!$report_data)
57 trigger_error('POST_NOT_EXIST');
60 $forum_id = (int) ($report_data['forum_id']) ? $report_data['forum_id'] : $forum_id;
61 $topic_id = (int) $report_data['topic_id'];
63 $sql = 'SELECT *
64 FROM ' . FORUMS_TABLE . '
65 WHERE forum_id = ' . $forum_id;
66 $result = $db->sql_query($sql);
67 $forum_data = $db->sql_fetchrow($result);
68 $db->sql_freeresult($result);
70 if (!$forum_data)
72 trigger_error('FORUM_NOT_EXIST');
75 // Check required permissions
76 $acl_check_ary = array('f_list' => 'POST_NOT_EXIST', 'f_read' => 'USER_CANNOT_READ', 'f_report' => 'USER_CANNOT_REPORT');
78 foreach ($acl_check_ary as $acl => $error)
80 if (!$auth->acl_get($acl, $forum_id))
82 trigger_error($error);
85 unset($acl_check_ary);
87 if ($report_data['post_reported'])
89 $message = $user->lang['ALREADY_REPORTED'];
90 $message .= '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
91 trigger_error($message);
94 // Submit report?
95 if ($submit && $reason_id)
97 $sql = 'SELECT *
98 FROM ' . REPORTS_REASONS_TABLE . "
99 WHERE reason_id = $reason_id";
100 $result = $db->sql_query($sql);
101 $row = $db->sql_fetchrow($result);
102 $db->sql_freeresult($result);
104 if (!$row || (!$report_text && strtolower($row['reason_title']) == 'other'))
106 trigger_error('EMPTY_REPORT');
109 $sql_ary = array(
110 'reason_id' => (int) $reason_id,
111 'post_id' => $post_id,
112 'user_id' => (int) $user->data['user_id'],
113 'user_notify' => (int) $user_notify,
114 'report_closed' => 0,
115 'report_time' => (int) time(),
116 'report_text' => (string) $report_text
119 $sql = 'INSERT INTO ' . REPORTS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary);
120 $db->sql_query($sql);
121 $report_id = $db->sql_nextid();
123 if (!$report_data['post_reported'])
125 $sql = 'UPDATE ' . POSTS_TABLE . '
126 SET post_reported = 1
127 WHERE post_id = ' . $post_id;
128 $db->sql_query($sql);
131 if (!$report_data['topic_reported'])
133 $sql = 'UPDATE ' . TOPICS_TABLE . '
134 SET topic_reported = 1
135 WHERE topic_id = ' . $report_data['topic_id'] . '
136 OR topic_moved_id = ' . $report_data['topic_id'];
137 $db->sql_query($sql);
140 meta_refresh(3, $redirect_url);
142 $message = $user->lang['POST_REPORTED_SUCCESS'] . '<br /><br />' . sprintf($user->lang['RETURN_TOPIC'], '<a href="' . $redirect_url . '">', '</a>');
143 trigger_error($message);
146 // Generate the reasons
147 display_reasons($reason_id);
149 $template->assign_vars(array(
150 'REPORT_TEXT' => $report_text,
151 'S_REPORT_ACTION' => append_sid('report', 'f=' . $forum_id . '&amp;p=' . $post_id),
153 'S_NOTIFY' => $user_notify,
154 'S_CAN_NOTIFY' => ($user->data['is_registered']) ? true : false)
157 generate_forum_nav($forum_data);
159 // Start output of page
160 page_header($user->lang['REPORT_POST']);
162 $template->set_filenames(array(
163 'body' => 'report_body.html')
166 page_footer();