PageRenderTime 58ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/includes/mcp/mcp_reports.php

https://bitbucket.org/jablonski/yebood
PHP | 728 lines | 583 code | 118 blank | 27 comment | 89 complexity | e10c1a24b87970c15b8a114bf7114feb MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package mcp
  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. * @ignore
  12. */
  13. if (!defined('IN_PHPBB'))
  14. {
  15. exit;
  16. }
  17. /**
  18. * mcp_reports
  19. * Handling the reports queue
  20. * @package mcp
  21. */
  22. class mcp_reports
  23. {
  24. var $p_master;
  25. var $u_action;
  26. function mcp_reports(&$p_master)
  27. {
  28. $this->p_master = &$p_master;
  29. }
  30. function main($id, $mode)
  31. {
  32. global $auth, $db, $user, $template, $cache;
  33. global $config, $phpbb_root_path, $phpEx, $action;
  34. include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
  35. $forum_id = request_var('f', 0);
  36. $start = request_var('start', 0);
  37. $this->page_title = 'MCP_REPORTS';
  38. switch ($action)
  39. {
  40. case 'close':
  41. case 'delete':
  42. include_once($phpbb_root_path . 'includes/functions_messenger.' . $phpEx);
  43. $report_id_list = request_var('report_id_list', array(0));
  44. if (!sizeof($report_id_list))
  45. {
  46. trigger_error('NO_REPORT_SELECTED');
  47. }
  48. close_report($report_id_list, $mode, $action);
  49. break;
  50. }
  51. switch ($mode)
  52. {
  53. case 'report_details':
  54. $user->add_lang(array('posting', 'viewforum', 'viewtopic'));
  55. $post_id = request_var('p', 0);
  56. // closed reports are accessed by report id
  57. $report_id = request_var('r', 0);
  58. $sql = 'SELECT r.post_id, r.user_id, r.report_id, r.report_closed, report_time, r.report_text, rr.reason_title, rr.reason_description, u.username, u.username_clean, u.user_colour
  59. FROM ' . REPORTS_TABLE . ' r, ' . REPORTS_REASONS_TABLE . ' rr, ' . USERS_TABLE . ' u
  60. WHERE ' . (($report_id) ? 'r.report_id = ' . $report_id : "r.post_id = $post_id") . '
  61. AND rr.reason_id = r.reason_id
  62. AND r.user_id = u.user_id
  63. AND r.pm_id = 0
  64. ORDER BY report_closed ASC';
  65. $result = $db->sql_query_limit($sql, 1);
  66. $report = $db->sql_fetchrow($result);
  67. $db->sql_freeresult($result);
  68. if (!$report)
  69. {
  70. trigger_error('NO_REPORT');
  71. }
  72. if (!$report_id && $report['report_closed'])
  73. {
  74. trigger_error('REPORT_CLOSED');
  75. }
  76. $post_id = $report['post_id'];
  77. $report_id = $report['report_id'];
  78. $post_info = get_post_data(array($post_id), 'm_report', true);
  79. if (!sizeof($post_info))
  80. {
  81. trigger_error('NO_REPORT_SELECTED');
  82. }
  83. $post_info = $post_info[$post_id];
  84. $reason = array('title' => $report['reason_title'], 'description' => $report['reason_description']);
  85. if (isset($user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])]) && isset($user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])]))
  86. {
  87. $reason['description'] = $user->lang['report_reasons']['DESCRIPTION'][strtoupper($reason['title'])];
  88. $reason['title'] = $user->lang['report_reasons']['TITLE'][strtoupper($reason['title'])];
  89. }
  90. if (topic_review($post_info['topic_id'], $post_info['forum_id'], 'topic_review', 0, false))
  91. {
  92. $template->assign_vars(array(
  93. 'S_TOPIC_REVIEW' => true,
  94. 'S_BBCODE_ALLOWED' => $post_info['enable_bbcode'],
  95. 'TOPIC_TITLE' => $post_info['topic_title'])
  96. );
  97. }
  98. $topic_tracking_info = $extensions = $attachments = array();
  99. // Get topic tracking info
  100. if ($config['load_db_lastread'])
  101. {
  102. $tmp_topic_data = array($post_info['topic_id'] => $post_info);
  103. $topic_tracking_info = get_topic_tracking($post_info['forum_id'], $post_info['topic_id'], $tmp_topic_data, array($post_info['forum_id'] => $post_info['forum_mark_time']));
  104. unset($tmp_topic_data);
  105. }
  106. else
  107. {
  108. $topic_tracking_info = get_complete_topic_tracking($post_info['forum_id'], $post_info['topic_id']);
  109. }
  110. $post_unread = (isset($topic_tracking_info[$post_info['topic_id']]) && $post_info['post_time'] > $topic_tracking_info[$post_info['topic_id']]) ? true : false;
  111. // Process message, leave it uncensored
  112. $message = $post_info['post_text'];
  113. if ($post_info['bbcode_bitfield'])
  114. {
  115. include_once($phpbb_root_path . 'includes/bbcode.' . $phpEx);
  116. $bbcode = new bbcode($post_info['bbcode_bitfield']);
  117. $bbcode->bbcode_second_pass($message, $post_info['bbcode_uid'], $post_info['bbcode_bitfield']);
  118. }
  119. $message = bbcode_nl2br($message);
  120. $message = smiley_text($message);
  121. $report['report_text'] = make_clickable(bbcode_nl2br($report['report_text']));
  122. if ($post_info['post_attachment'] && $auth->acl_get('u_download') && $auth->acl_get('f_download', $post_info['forum_id']))
  123. {
  124. $sql = 'SELECT *
  125. FROM ' . ATTACHMENTS_TABLE . '
  126. WHERE post_msg_id = ' . $post_id . '
  127. AND in_message = 0
  128. ORDER BY filetime DESC';
  129. $result = $db->sql_query($sql);
  130. while ($row = $db->sql_fetchrow($result))
  131. {
  132. $attachments[] = $row;
  133. }
  134. $db->sql_freeresult($result);
  135. if (sizeof($attachments))
  136. {
  137. $update_count = array();
  138. parse_attachments($post_info['forum_id'], $message, $attachments, $update_count);
  139. }
  140. // Display not already displayed Attachments for this post, we already parsed them. ;)
  141. if (!empty($attachments))
  142. {
  143. $template->assign_var('S_HAS_ATTACHMENTS', true);
  144. foreach ($attachments as $attachment)
  145. {
  146. $template->assign_block_vars('attachment', array(
  147. 'DISPLAY_ATTACHMENT' => $attachment)
  148. );
  149. }
  150. }
  151. }
  152. $template->assign_vars(array(
  153. 'S_MCP_REPORT' => true,
  154. 'S_CLOSE_ACTION' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id),
  155. 'S_CAN_VIEWIP' => $auth->acl_get('m_info', $post_info['forum_id']),
  156. 'S_POST_REPORTED' => $post_info['post_reported'],
  157. 'S_POST_UNAPPROVED' => !$post_info['post_approved'],
  158. 'S_POST_LOCKED' => $post_info['post_edit_locked'],
  159. 'S_USER_NOTES' => true,
  160. 'U_EDIT' => ($auth->acl_get('m_edit', $post_info['forum_id'])) ? append_sid("{$phpbb_root_path}posting.$phpEx", "mode=edit&amp;f={$post_info['forum_id']}&amp;p={$post_info['post_id']}") : '',
  161. 'U_MCP_APPROVE' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=queue&amp;mode=approve_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id),
  162. 'U_MCP_REPORT' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports&amp;mode=report_details&amp;f=' . $post_info['forum_id'] . '&amp;p=' . $post_id),
  163. 'U_MCP_REPORTER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $report['user_id']),
  164. 'U_MCP_USER_NOTES' => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=notes&amp;mode=user_notes&amp;u=' . $post_info['user_id']),
  165. 'U_MCP_WARN_REPORTER' => ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user&amp;u=' . $report['user_id']) : '',
  166. 'U_MCP_WARN_USER' => ($auth->acl_get('m_warn')) ? append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=warn&amp;mode=warn_user&amp;u=' . $post_info['user_id']) : '',
  167. 'U_VIEW_FORUM' => append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $post_info['forum_id']),
  168. 'U_VIEW_POST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;p=' . $post_info['post_id'] . '#p' . $post_info['post_id']),
  169. 'U_VIEW_TOPIC' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $post_info['forum_id'] . '&amp;t=' . $post_info['topic_id']),
  170. 'EDIT_IMG' => $user->img('icon_post_edit', $user->lang['EDIT_POST']),
  171. 'MINI_POST_IMG' => ($post_unread) ? $user->img('icon_post_target_unread', 'UNREAD_POST') : $user->img('icon_post_target', 'POST'),
  172. 'UNAPPROVED_IMG' => $user->img('icon_topic_unapproved', $user->lang['POST_UNAPPROVED']),
  173. 'RETURN_REPORTS' => sprintf($user->lang['RETURN_REPORTS'], '<a href="' . append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=reports' . (($post_info['post_reported']) ? '&amp;mode=reports' : '&amp;mode=reports_closed') . '&amp;start=' . $start . '&amp;f=' . $post_info['forum_id']) . '">', '</a>'),
  174. 'REPORTED_IMG' => $user->img('icon_topic_reported', $user->lang['POST_REPORTED']),
  175. 'REPORT_DATE' => $user->format_date($report['report_time']),
  176. 'REPORT_ID' => $report_id,
  177. 'REPORT_REASON_TITLE' => $reason['title'],
  178. 'REPORT_REASON_DESCRIPTION' => $reason['description'],
  179. 'REPORT_TEXT' => $report['report_text'],
  180. 'POST_AUTHOR_FULL' => get_username_string('full', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
  181. 'POST_AUTHOR_COLOUR' => get_username_string('colour', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
  182. 'POST_AUTHOR' => get_username_string('username', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
  183. 'U_POST_AUTHOR' => get_username_string('profile', $post_info['user_id'], $post_info['username'], $post_info['user_colour'], $post_info['post_username']),
  184. 'REPORTER_FULL' => get_username_string('full', $report['user_id'], $report['username'], $report['user_colour']),
  185. 'REPORTER_COLOUR' => get_username_string('colour', $report['user_id'], $report['username'], $report['user_colour']),
  186. 'REPORTER_NAME' => get_username_string('username', $report['user_id'], $report['username'], $report['user_colour']),
  187. 'U_VIEW_REPORTER_PROFILE' => get_username_string('profile', $report['user_id'], $report['username'], $report['user_colour']),
  188. 'POST_PREVIEW' => $message,
  189. 'POST_SUBJECT' => ($post_info['post_subject']) ? $post_info['post_subject'] : $user->lang['NO_SUBJECT'],
  190. 'POST_DATE' => $user->format_date($post_info['post_time']),
  191. 'POST_IP' => $post_info['poster_ip'],
  192. 'POST_IPADDR' => ($auth->acl_get('m_info', $post_info['forum_id']) && request_var('lookup', '')) ? @gethostbyaddr($post_info['poster_ip']) : '',
  193. 'POST_ID' => $post_info['post_id'],
  194. 'U_LOOKUP_IP' => ($auth->acl_get('m_info', $post_info['forum_id'])) ? $this->u_action . '&amp;r=' . $report_id . '&amp;p=' . $post_id . '&amp;f=' . $forum_id . '&amp;lookup=' . $post_info['poster_ip'] . '#ip' : '',
  195. ));
  196. $this->tpl_name = 'mcp_post';
  197. break;
  198. case 'reports':
  199. case 'reports_closed':
  200. $topic_id = request_var('t', 0);
  201. $forum_info = array();
  202. $forum_list_reports = get_forum_list('m_report', false, true);
  203. $forum_list_read = array_flip(get_forum_list('f_read', true, true)); // Flipped so we can isset() the forum IDs
  204. // Remove forums we cannot read
  205. foreach ($forum_list_reports as $k => $forum_data)
  206. {
  207. if (!isset($forum_list_read[$forum_data['forum_id']]))
  208. {
  209. unset($forum_list_reports[$k]);
  210. }
  211. }
  212. unset($forum_list_read);
  213. if ($topic_id)
  214. {
  215. $topic_info = get_topic_data(array($topic_id));
  216. if (!sizeof($topic_info))
  217. {
  218. trigger_error('TOPIC_NOT_EXIST');
  219. }
  220. if ($forum_id != $topic_info[$topic_id]['forum_id'])
  221. {
  222. $topic_id = 0;
  223. }
  224. else
  225. {
  226. $topic_info = $topic_info[$topic_id];
  227. $forum_id = (int) $topic_info['forum_id'];
  228. }
  229. }
  230. $forum_list = array();
  231. if (!$forum_id)
  232. {
  233. foreach ($forum_list_reports as $row)
  234. {
  235. $forum_list[] = $row['forum_id'];
  236. }
  237. if (!sizeof($forum_list))
  238. {
  239. trigger_error('NOT_MODERATOR');
  240. }
  241. $global_id = $forum_list[0];
  242. $sql = 'SELECT SUM(forum_topics) as sum_forum_topics
  243. FROM ' . FORUMS_TABLE . '
  244. WHERE ' . $db->sql_in_set('forum_id', $forum_list);
  245. $result = $db->sql_query($sql);
  246. $forum_info['forum_topics'] = (int) $db->sql_fetchfield('sum_forum_topics');
  247. $db->sql_freeresult($result);
  248. }
  249. else
  250. {
  251. $forum_info = get_forum_data(array($forum_id), 'm_report');
  252. if (!sizeof($forum_info))
  253. {
  254. trigger_error('NOT_MODERATOR');
  255. }
  256. $forum_info = $forum_info[$forum_id];
  257. $forum_list = array($forum_id);
  258. $global_id = $forum_id;
  259. }
  260. $forum_list[] = 0;
  261. $forum_data = array();
  262. $forum_options = '<option value="0"' . (($forum_id == 0) ? ' selected="selected"' : '') . '>' . $user->lang['ALL_FORUMS'] . '</option>';
  263. foreach ($forum_list_reports as $row)
  264. {
  265. $forum_options .= '<option value="' . $row['forum_id'] . '"' . (($forum_id == $row['forum_id']) ? ' selected="selected"' : '') . '>' . str_repeat('&nbsp; &nbsp;', $row['padding']) . $row['forum_name'] . '</option>';
  266. $forum_data[$row['forum_id']] = $row;
  267. }
  268. unset($forum_list_reports);
  269. $sort_days = $total = 0;
  270. $sort_key = $sort_dir = '';
  271. $sort_by_sql = $sort_order_sql = array();
  272. mcp_sorting($mode, $sort_days, $sort_key, $sort_dir, $sort_by_sql, $sort_order_sql, $total, $forum_id, $topic_id);
  273. $forum_topics = ($total == -1) ? $forum_info['forum_topics'] : $total;
  274. $limit_time_sql = ($sort_days) ? 'AND r.report_time >= ' . (time() - ($sort_days * 86400)) : '';
  275. if ($mode == 'reports')
  276. {
  277. $report_state = 'AND p.post_reported = 1 AND r.report_closed = 0';
  278. }
  279. else
  280. {
  281. $report_state = 'AND r.report_closed = 1';
  282. }
  283. $sql = 'SELECT r.report_id
  284. FROM ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . REPORTS_TABLE . ' r ' . (($sort_order_sql[0] == 'u') ? ', ' . USERS_TABLE . ' u' : '') . (($sort_order_sql[0] == 'r') ? ', ' . USERS_TABLE . ' ru' : '') . '
  285. WHERE ' . $db->sql_in_set('p.forum_id', $forum_list) . "
  286. $report_state
  287. AND r.post_id = p.post_id
  288. " . (($sort_order_sql[0] == 'u') ? 'AND u.user_id = p.poster_id' : '') . '
  289. ' . (($sort_order_sql[0] == 'r') ? 'AND ru.user_id = r.user_id' : '') . '
  290. ' . (($topic_id) ? 'AND p.topic_id = ' . $topic_id : '') . "
  291. AND t.topic_id = p.topic_id
  292. AND r.pm_id = 0
  293. $limit_time_sql
  294. ORDER BY $sort_order_sql";
  295. $result = $db->sql_query_limit($sql, $config['topics_per_page'], $start);
  296. $i = 0;
  297. $report_ids = array();
  298. while ($row = $db->sql_fetchrow($result))
  299. {
  300. $report_ids[] = $row['report_id'];
  301. $row_num[$row['report_id']] = $i++;
  302. }
  303. $db->sql_freeresult($result);
  304. if (sizeof($report_ids))
  305. {
  306. $sql = 'SELECT t.forum_id, t.topic_id, t.topic_title, p.post_id, p.post_subject, p.post_username, p.poster_id, p.post_time, u.username, u.username_clean, u.user_colour, r.user_id as reporter_id, ru.username as reporter_name, ru.user_colour as reporter_colour, r.report_time, r.report_id
  307. FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p, ' . TOPICS_TABLE . ' t, ' . USERS_TABLE . ' u, ' . USERS_TABLE . ' ru
  308. WHERE ' . $db->sql_in_set('r.report_id', $report_ids) . '
  309. AND t.topic_id = p.topic_id
  310. AND r.post_id = p.post_id
  311. AND u.user_id = p.poster_id
  312. AND ru.user_id = r.user_id
  313. AND r.pm_id = 0
  314. ORDER BY ' . $sort_order_sql;
  315. $result = $db->sql_query($sql);
  316. $report_data = $rowset = array();
  317. while ($row = $db->sql_fetchrow($result))
  318. {
  319. $global_topic = ($row['forum_id']) ? false : true;
  320. if ($global_topic)
  321. {
  322. $row['forum_id'] = $global_id;
  323. }
  324. $template->assign_block_vars('postrow', array(
  325. 'U_VIEWFORUM' => (!$global_topic) ? append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . $row['forum_id']) : '',
  326. 'U_VIEWPOST' => append_sid("{$phpbb_root_path}viewtopic.$phpEx", 'f=' . $row['forum_id'] . '&amp;p=' . $row['post_id']) . '#p' . $row['post_id'],
  327. 'U_VIEW_DETAILS' => append_sid("{$phpbb_root_path}mcp.$phpEx", "i=reports&amp;start=$start&amp;mode=report_details&amp;f={$row['forum_id']}&amp;r={$row['report_id']}"),
  328. 'POST_AUTHOR_FULL' => get_username_string('full', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
  329. 'POST_AUTHOR_COLOUR' => get_username_string('colour', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
  330. 'POST_AUTHOR' => get_username_string('username', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
  331. 'U_POST_AUTHOR' => get_username_string('profile', $row['poster_id'], $row['username'], $row['user_colour'], $row['post_username']),
  332. 'REPORTER_FULL' => get_username_string('full', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
  333. 'REPORTER_COLOUR' => get_username_string('colour', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
  334. 'REPORTER' => get_username_string('username', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
  335. 'U_REPORTER' => get_username_string('profile', $row['reporter_id'], $row['reporter_name'], $row['reporter_colour']),
  336. 'FORUM_NAME' => (!$global_topic) ? $forum_data[$row['forum_id']]['forum_name'] : $user->lang['GLOBAL_ANNOUNCEMENT'],
  337. 'POST_ID' => $row['post_id'],
  338. 'POST_SUBJECT' => ($row['post_subject']) ? $row['post_subject'] : $user->lang['NO_SUBJECT'],
  339. 'POST_TIME' => $user->format_date($row['post_time']),
  340. 'REPORT_ID' => $row['report_id'],
  341. 'REPORT_TIME' => $user->format_date($row['report_time']),
  342. 'TOPIC_TITLE' => $row['topic_title'])
  343. );
  344. }
  345. $db->sql_freeresult($result);
  346. unset($report_ids, $row);
  347. }
  348. // Now display the page
  349. $template->assign_vars(array(
  350. 'L_EXPLAIN' => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN_EXPLAIN'] : $user->lang['MCP_REPORTS_CLOSED_EXPLAIN'],
  351. 'L_TITLE' => ($mode == 'reports') ? $user->lang['MCP_REPORTS_OPEN'] : $user->lang['MCP_REPORTS_CLOSED'],
  352. 'L_ONLY_TOPIC' => ($topic_id) ? sprintf($user->lang['ONLY_TOPIC'], $topic_info['topic_title']) : '',
  353. 'S_MCP_ACTION' => $this->u_action,
  354. 'S_FORUM_OPTIONS' => $forum_options,
  355. 'S_CLOSED' => ($mode == 'reports_closed') ? true : false,
  356. 'PAGINATION' => generate_pagination($this->u_action . "&amp;f=$forum_id&amp;t=$topic_id&amp;st=$sort_days&amp;sk=$sort_key&amp;sd=$sort_dir", $total, $config['topics_per_page'], $start),
  357. 'PAGE_NUMBER' => on_page($total, $config['topics_per_page'], $start),
  358. 'TOPIC_ID' => $topic_id,
  359. 'TOTAL' => $total,
  360. 'TOTAL_REPORTS' => ($total == 1) ? $user->lang['LIST_REPORT'] : sprintf($user->lang['LIST_REPORTS'], $total),
  361. )
  362. );
  363. $this->tpl_name = 'mcp_reports';
  364. break;
  365. }
  366. }
  367. }
  368. /**
  369. * Closes a report
  370. */
  371. function close_report($report_id_list, $mode, $action, $pm = false)
  372. {
  373. global $db, $template, $user, $config, $auth;
  374. global $phpEx, $phpbb_root_path;
  375. $pm_where = ($pm) ? ' AND r.post_id = 0 ' : ' AND r.pm_id = 0 ';
  376. $id_column = ($pm) ? 'pm_id' : 'post_id';
  377. $module = ($pm) ? 'pm_reports' : 'reports';
  378. $pm_prefix = ($pm) ? 'PM_' : '';
  379. $sql = "SELECT r.$id_column
  380. FROM " . REPORTS_TABLE . ' r
  381. WHERE ' . $db->sql_in_set('r.report_id', $report_id_list) . $pm_where;
  382. $result = $db->sql_query($sql);
  383. $post_id_list = array();
  384. while ($row = $db->sql_fetchrow($result))
  385. {
  386. $post_id_list[] = $row[$id_column];
  387. }
  388. $post_id_list = array_unique($post_id_list);
  389. if ($pm)
  390. {
  391. if (!$auth->acl_getf_global('m_report'))
  392. {
  393. trigger_error('NOT_AUTHORISED');
  394. }
  395. }
  396. else
  397. {
  398. if (!check_ids($post_id_list, POSTS_TABLE, 'post_id', array('m_report')))
  399. {
  400. trigger_error('NOT_AUTHORISED');
  401. }
  402. }
  403. if ($action == 'delete' && strpos($user->data['session_page'], 'mode=report_details') !== false)
  404. {
  405. $redirect = request_var('redirect', build_url(array('mode', 'r', 'quickmod')) . '&amp;mode=reports');
  406. }
  407. elseif ($action == 'delete' && strpos($user->data['session_page'], 'mode=pm_report_details') !== false)
  408. {
  409. $redirect = request_var('redirect', build_url(array('mode', 'r', 'quickmod')) . '&amp;mode=pm_reports');
  410. }
  411. else if ($action == 'close' && !request_var('r', 0))
  412. {
  413. $redirect = request_var('redirect', build_url(array('mode', 'p', 'quickmod')) . '&amp;mode=' . $module);
  414. }
  415. else
  416. {
  417. $redirect = request_var('redirect', build_url(array('quickmod')));
  418. }
  419. $success_msg = '';
  420. $forum_ids = array();
  421. $topic_ids = array();
  422. $s_hidden_fields = build_hidden_fields(array(
  423. 'i' => $module,
  424. 'mode' => $mode,
  425. 'report_id_list' => $report_id_list,
  426. 'action' => $action,
  427. 'redirect' => $redirect)
  428. );
  429. if (confirm_box(true))
  430. {
  431. $post_info = ($pm) ? get_pm_data($post_id_list) : get_post_data($post_id_list, 'm_report');
  432. $sql = "SELECT r.report_id, r.$id_column, r.report_closed, r.user_id, r.user_notify, u.username, u.username_clean, u.user_email, u.user_jabber, u.user_lang, u.user_notify_type
  433. FROM " . REPORTS_TABLE . ' r, ' . USERS_TABLE . ' u
  434. WHERE ' . $db->sql_in_set('r.report_id', $report_id_list) . '
  435. ' . (($action == 'close') ? 'AND r.report_closed = 0' : '') . '
  436. AND r.user_id = u.user_id' . $pm_where;
  437. $result = $db->sql_query($sql);
  438. $reports = $close_report_posts = $close_report_topics = $notify_reporters = $report_id_list = array();
  439. while ($report = $db->sql_fetchrow($result))
  440. {
  441. $reports[$report['report_id']] = $report;
  442. $report_id_list[] = $report['report_id'];
  443. if (!$report['report_closed'])
  444. {
  445. $close_report_posts[] = $report[$id_column];
  446. if (!$pm)
  447. {
  448. $close_report_topics[] = $post_info[$report['post_id']]['topic_id'];
  449. }
  450. }
  451. if ($report['user_notify'] && !$report['report_closed'])
  452. {
  453. $notify_reporters[$report['report_id']] = &$reports[$report['report_id']];
  454. }
  455. }
  456. $db->sql_freeresult($result);
  457. if (sizeof($reports))
  458. {
  459. $close_report_posts = array_unique($close_report_posts);
  460. $close_report_topics = array_unique($close_report_topics);
  461. if (!$pm && sizeof($close_report_posts))
  462. {
  463. // Get a list of topics that still contain reported posts
  464. $sql = 'SELECT DISTINCT topic_id
  465. FROM ' . POSTS_TABLE . '
  466. WHERE ' . $db->sql_in_set('topic_id', $close_report_topics) . '
  467. AND post_reported = 1
  468. AND ' . $db->sql_in_set('post_id', $close_report_posts, true);
  469. $result = $db->sql_query($sql);
  470. $keep_report_topics = array();
  471. while ($row = $db->sql_fetchrow($result))
  472. {
  473. $keep_report_topics[] = $row['topic_id'];
  474. }
  475. $db->sql_freeresult($result);
  476. $close_report_topics = array_diff($close_report_topics, $keep_report_topics);
  477. unset($keep_report_topics);
  478. }
  479. $db->sql_transaction('begin');
  480. if ($action == 'close')
  481. {
  482. $sql = 'UPDATE ' . REPORTS_TABLE . '
  483. SET report_closed = 1
  484. WHERE ' . $db->sql_in_set('report_id', $report_id_list);
  485. }
  486. else
  487. {
  488. $sql = 'DELETE FROM ' . REPORTS_TABLE . '
  489. WHERE ' . $db->sql_in_set('report_id', $report_id_list);
  490. }
  491. $db->sql_query($sql);
  492. if (sizeof($close_report_posts))
  493. {
  494. if ($pm)
  495. {
  496. $sql = 'UPDATE ' . PRIVMSGS_TABLE . '
  497. SET message_reported = 0
  498. WHERE ' . $db->sql_in_set('msg_id', $close_report_posts);
  499. $db->sql_query($sql);
  500. if ($action == 'delete')
  501. {
  502. delete_pm(ANONYMOUS, $close_report_posts, PRIVMSGS_INBOX);
  503. }
  504. }
  505. else
  506. {
  507. $sql = 'UPDATE ' . POSTS_TABLE . '
  508. SET post_reported = 0
  509. WHERE ' . $db->sql_in_set('post_id', $close_report_posts);
  510. $db->sql_query($sql);
  511. if (sizeof($close_report_topics))
  512. {
  513. $sql = 'UPDATE ' . TOPICS_TABLE . '
  514. SET topic_reported = 0
  515. WHERE ' . $db->sql_in_set('topic_id', $close_report_topics) . '
  516. OR ' . $db->sql_in_set('topic_moved_id', $close_report_topics);
  517. $db->sql_query($sql);
  518. }
  519. }
  520. }
  521. $db->sql_transaction('commit');
  522. }
  523. unset($close_report_posts, $close_report_topics);
  524. foreach ($reports as $report)
  525. {
  526. if ($pm)
  527. {
  528. add_log('mod', 0, 0, 'LOG_PM_REPORT_' . strtoupper($action) . 'D', $post_info[$report['pm_id']]['message_subject']);
  529. }
  530. else
  531. {
  532. add_log('mod', $post_info[$report['post_id']]['forum_id'], $post_info[$report['post_id']]['topic_id'], 'LOG_REPORT_' . strtoupper($action) . 'D', $post_info[$report['post_id']]['post_subject']);
  533. }
  534. }
  535. $messenger = new messenger();
  536. // Notify reporters
  537. if (sizeof($notify_reporters))
  538. {
  539. foreach ($notify_reporters as $report_id => $reporter)
  540. {
  541. if ($reporter['user_id'] == ANONYMOUS)
  542. {
  543. continue;
  544. }
  545. $post_id = $reporter[$id_column];
  546. $messenger->template((($pm) ? 'pm_report_' : 'report_') . $action . 'd', $reporter['user_lang']);
  547. $messenger->to($reporter['user_email'], $reporter['username']);
  548. $messenger->im($reporter['user_jabber'], $reporter['username']);
  549. if ($pm)
  550. {
  551. $messenger->assign_vars(array(
  552. 'USERNAME' => htmlspecialchars_decode($reporter['username']),
  553. 'CLOSER_NAME' => htmlspecialchars_decode($user->data['username']),
  554. 'PM_SUBJECT' => htmlspecialchars_decode(censor_text($post_info[$post_id]['message_subject'])),
  555. ));
  556. }
  557. else
  558. {
  559. $messenger->assign_vars(array(
  560. 'USERNAME' => htmlspecialchars_decode($reporter['username']),
  561. 'CLOSER_NAME' => htmlspecialchars_decode($user->data['username']),
  562. 'POST_SUBJECT' => htmlspecialchars_decode(censor_text($post_info[$post_id]['post_subject'])),
  563. 'TOPIC_TITLE' => htmlspecialchars_decode(censor_text($post_info[$post_id]['topic_title'])))
  564. );
  565. }
  566. $messenger->send($reporter['user_notify_type']);
  567. }
  568. }
  569. if (!$pm)
  570. {
  571. foreach ($post_info as $post)
  572. {
  573. $forum_ids[$post['forum_id']] = $post['forum_id'];
  574. $topic_ids[$post['topic_id']] = $post['topic_id'];
  575. }
  576. }
  577. unset($notify_reporters, $post_info, $reports);
  578. $messenger->save_queue();
  579. $success_msg = (sizeof($report_id_list) == 1) ? "{$pm_prefix}REPORT_" . strtoupper($action) . 'D_SUCCESS' : "{$pm_prefix}REPORTS_" . strtoupper($action) . 'D_SUCCESS';
  580. }
  581. else
  582. {
  583. confirm_box(false, $user->lang[strtoupper($action) . "_{$pm_prefix}REPORT" . ((sizeof($report_id_list) == 1) ? '' : 'S') . '_CONFIRM'], $s_hidden_fields);
  584. }
  585. $redirect = request_var('redirect', "index.$phpEx");
  586. $redirect = reapply_sid($redirect);
  587. if (!$success_msg)
  588. {
  589. redirect($redirect);
  590. }
  591. else
  592. {
  593. meta_refresh(3, $redirect);
  594. $return_forum = '';
  595. $return_topic = '';
  596. if (!$pm)
  597. {
  598. if (sizeof($forum_ids) === 1)
  599. {
  600. $return_forum = sprintf($user->lang['RETURN_FORUM'], '<a href="' . append_sid("{$phpbb_root_path}viewforum.$phpEx", 'f=' . current($forum_ids)) . '">', '</a>') . '<br /><br />';
  601. }
  602. if (sizeof($topic_ids) === 1)
  603. {
  604. $return_topic = sprintf($user->lang['RETURN_TOPIC'], '<a href="' . append_sid("{$phpbb_root_path}viewtopic.$phpEx", 't=' . current($topic_ids) . '&amp;f=' . current($forum_ids)) . '">', '</a>') . '<br /><br />';
  605. }
  606. }
  607. trigger_error($user->lang[$success_msg] . '<br /><br />' . $return_forum . $return_topic . sprintf($user->lang['RETURN_PAGE'], "<a href=\"$redirect\">", '</a>'));
  608. }
  609. }
  610. ?>