Subs-ReportedContent.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. <?php
  2. /**
  3. * Perform CRUD actions for reported posts and moderation comments.
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines http://www.simplemachines.org
  9. * @copyright 2014 Simple Machines and individual contributors
  10. * @license http://www.simplemachines.org/about/smf/license.php BSD
  11. *
  12. * @version 2.1 Alpha 1
  13. */
  14. if (!defined('SMF'))
  15. die('No direct access...');
  16. /**
  17. * Updates a report with the given parameters. Logs each action via logAction()
  18. *
  19. * @param string $action The action to perform. Accepts "closed" and "ignore".
  20. * @param integer $value The new value to update.
  21. * @params integer|array $report_id The affected report(s).
  22. */
  23. function updateReport($action, $value, $report_id)
  24. {
  25. global $smcFunc, $user_info, $context;
  26. // Don't bother.
  27. if (empty($action) || empty($report_id))
  28. return false;
  29. // Add the "_all" thingy.
  30. if ($action == 'ignore')
  31. $action = 'ignore_all';
  32. // We don't need the board query for reported members
  33. if ($context['report_type'] == 'members')
  34. {
  35. $board_query = '';
  36. }
  37. else
  38. {
  39. $board_query = ' AND ' . $user_info['mod_cache']['bq'];
  40. }
  41. // Update the report...
  42. $smcFunc['db_query']('', '
  43. UPDATE {db_prefix}log_reported
  44. SET {raw:action} = {string:value}
  45. '. (is_array($report_id) ? 'WHERE id_report IN ({array_int:id_report})' : 'WHERE id_report = {int:id_report}') .'
  46. ' . $board_query,
  47. array(
  48. 'action' => $action,
  49. 'value' => $value,
  50. 'id_report' => $report_id,
  51. )
  52. );
  53. // From now on, lets work with arrays, makes life easier.
  54. $report_id = (array) $report_id;
  55. // Set up the data for the log...
  56. $extra = array();
  57. if ($context['report_type'] == 'posts')
  58. {
  59. // Get the board, topic and message for this report
  60. $request = $smcFunc['db_query']('', '
  61. SELECT id_board, id_topic, id_msg, id_report
  62. FROM {db_prefix}log_reported
  63. WHERE id_report IN ({array_int:id_report})',
  64. array(
  65. 'id_report' => $report_id,
  66. )
  67. );
  68. while ($row = $smcFunc['db_fetch_assoc']($request))
  69. $extra[$row['id_report']] = array(
  70. 'report' => $row['id_report'],
  71. 'board' => $row['id_board'],
  72. 'message' => $row['id_msg'],
  73. 'topic' => $row['id_topic'],
  74. );
  75. $smcFunc['db_free_result']($request);
  76. }
  77. else
  78. {
  79. $request = $smcFunc['db_query']('', '
  80. SELECT id_report, id_member, membername
  81. FROM {db_prefix}log_reported
  82. WHERE id_report IN ({array_int:id_report})',
  83. array(
  84. 'id_report' => $report_id,
  85. )
  86. );
  87. while($row = $smcFunc['db_fetch_assoc']($request))
  88. $extra[$row['id_report']] = array(
  89. 'report' => $row['id_report'],
  90. 'member' => $row['id_member'],
  91. 'membername' => $row['membername'],
  92. );
  93. $smcFunc['db_free_result']($request);
  94. }
  95. // Back to "ignore".
  96. if ($action == 'ignore_all')
  97. $action = 'ignore';
  98. $log_report = $action == 'ignore' ? (!empty($value) ? 'ignore' : 'unignore') : (!empty($value) ? 'close' : 'open');
  99. if ($context['report_type'] == 'members')
  100. $log_report .= '_user';
  101. // Log this action.
  102. if (!empty($extra))
  103. foreach ($extra as $report)
  104. logAction($log_report . '_report', $report);
  105. // Time to update.
  106. updateSettings(array('last_mod_report_action' => time()));
  107. recountOpenReports($context['report_type']);
  108. }
  109. /**
  110. * Counts how many reports are in total. Used for creating pagination.
  111. *
  112. * @param int $closed 1 for counting closed reports, 0 for open ones.
  113. * @return integer How many reports.
  114. */
  115. function countReports($closed = 0)
  116. {
  117. global $smcFunc, $user_info, $context;
  118. $total_reports = 0;
  119. // Skip entries with id_board = 0 if we're viewing member reports
  120. if ($context['report_type'] == 'members')
  121. {
  122. $and = 'lr.id_board = 0';
  123. }
  124. else
  125. {
  126. if ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1')
  127. {
  128. $bq = $user_info['mod_cache']['bq'];
  129. }
  130. else
  131. {
  132. $bq = 'lr.' . $user_info['mod_cache']['bq'];
  133. }
  134. $and = $bq . ' AND lr.id_board != 0';
  135. }
  136. // How many entries are we viewing?
  137. $request = $smcFunc['db_query']('', '
  138. SELECT COUNT(*)
  139. FROM {db_prefix}log_reported AS lr
  140. WHERE lr.closed = {int:view_closed}
  141. AND ' . $and,
  142. array(
  143. 'view_closed' => (int) $closed,
  144. )
  145. );
  146. list ($total_reports) = $smcFunc['db_fetch_row']($request);
  147. $smcFunc['db_free_result']($request);
  148. return $total_reports;
  149. }
  150. /**
  151. * Get all possible reports the current user can see.
  152. *
  153. * @param int $closed 1 for closed reports, 0 for open ones.
  154. * @return array the reports data with the report ID as key.
  155. */
  156. function getReports($closed = 0)
  157. {
  158. global $smcFunc, $context, $user_info, $scripturl;
  159. // Lonely, standalone var.
  160. $reports = array();
  161. // By George, that means we in a position to get the reports, golly good.
  162. if ($context['report_type'] == 'members')
  163. {
  164. $request = $smcFunc['db_query']('', '
  165. SELECT lr.id_report, lr.id_member,
  166. lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all,
  167. IFNULL(mem.real_name, lr.membername) AS user_name, IFNULL(mem.id_member, 0) AS id_user
  168. FROM {db_prefix}log_reported AS lr
  169. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  170. WHERE lr.closed = {int:view_closed}
  171. AND lr.id_board = 0
  172. ORDER BY lr.time_updated DESC
  173. LIMIT ' . $context['start'] . ', 10',
  174. array(
  175. 'view_closed' => (int) $closed,
  176. )
  177. );
  178. }
  179. else
  180. {
  181. $request = $smcFunc['db_query']('', '
  182. SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body,
  183. lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all,
  184. IFNULL(mem.real_name, lr.membername) AS author_name, IFNULL(mem.id_member, 0) AS id_author
  185. FROM {db_prefix}log_reported AS lr
  186. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  187. WHERE lr.closed = {int:view_closed}
  188. AND lr.id_board != 0
  189. AND ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . '
  190. ORDER BY lr.time_updated DESC
  191. LIMIT ' . $context['start'] . ', 10',
  192. array(
  193. 'view_closed' => (int) $closed,
  194. )
  195. );
  196. }
  197. $report_ids = array();
  198. $report_boards_ids = array();
  199. $i = 0;
  200. while ($row = $smcFunc['db_fetch_assoc']($request))
  201. {
  202. $report_ids[] = $row['id_report'];
  203. $reports[$row['id_report']] = array(
  204. 'id' => $row['id_report'],
  205. 'alternate' => $i % 2,
  206. 'report_href' => $scripturl . '?action=moderate;area=reported' . $context['report_type'] . ';sa=details;rid=' . $row['id_report'],
  207. 'comments' => array(),
  208. 'time_started' => timeformat($row['time_started']),
  209. 'last_updated' => timeformat($row['time_updated']),
  210. 'num_reports' => $row['num_reports'],
  211. 'closed' => $row['closed'],
  212. 'ignore' => $row['ignore_all']
  213. );
  214. if ($context['report_type'] == 'members')
  215. {
  216. $extraDetails = array(
  217. 'user' => array(
  218. 'id' => $row['id_user'],
  219. 'name' => $row['user_name'],
  220. 'link' => $row['id_user'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_user'] . '">' . $row['user_name'] . '</a>' : $row['user_name'],
  221. 'href' => $scripturl . '?action=profile;u=' . $row['id_user'],
  222. ),
  223. );
  224. }
  225. else
  226. {
  227. $report_boards_ids[] = $row['id_board'];
  228. $extraDetails = array(
  229. 'topic' => array(
  230. 'id' => $row['id_topic'],
  231. 'id_msg' => $row['id_msg'],
  232. 'id_board' => $row['id_board'],
  233. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
  234. ),
  235. 'author' => array(
  236. 'id' => $row['id_author'],
  237. 'name' => $row['author_name'],
  238. 'link' => $row['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_author'] . '">' . $row['author_name'] . '</a>' : $row['author_name'],
  239. 'href' => $scripturl . '?action=profile;u=' . $row['id_author'],
  240. ),
  241. 'subject' => $row['subject'],
  242. 'body' => parse_bbc($row['body']),
  243. );
  244. }
  245. $reports[$row['id_report']] = array_merge($reports[$row['id_report']], $extraDetails);
  246. $i++;
  247. }
  248. $smcFunc['db_free_result']($request);
  249. // Get the names of boards those topics are in. Slightly faster this way.
  250. if (!empty($report_boards_ids))
  251. {
  252. $report_boards_ids = array_unique($report_boards_ids);
  253. $board_names = array();
  254. $request = $smcFunc['db_query']('', '
  255. SELECT id_board, name
  256. FROM {db_prefix}boards
  257. WHERE id_board IN ({array_int:boards})',
  258. array(
  259. 'boards' => $report_boards_ids,
  260. )
  261. );
  262. while ($row = $smcFunc['db_fetch_assoc']($request))
  263. $board_names[$row['id_board']] = $row['name'];
  264. $smcFunc['db_free_result']($request);
  265. foreach ($reports as $id_report => $report)
  266. if (!empty($board_names[$report['topic']['id_board']]))
  267. $reports[$id_report]['topic']['board_name'] = $board_names[$report['topic']['id_board']];
  268. }
  269. // Now get all the people who reported it.
  270. if (!empty($report_ids))
  271. {
  272. $request = $smcFunc['db_query']('', '
  273. SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment,
  274. IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lrc.membername) AS reporter
  275. FROM {db_prefix}log_reported_comments AS lrc
  276. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member)
  277. WHERE lrc.id_report IN ({array_int:report_list})',
  278. array(
  279. 'report_list' => $report_ids,
  280. )
  281. );
  282. while ($row = $smcFunc['db_fetch_assoc']($request))
  283. {
  284. $reports[$row['id_report']]['comments'][] = array(
  285. 'id' => $row['id_comment'],
  286. 'message' => $row['comment'],
  287. 'time' => timeformat($row['time_sent']),
  288. 'member' => array(
  289. 'id' => $row['id_member'],
  290. 'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'],
  291. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']),
  292. 'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
  293. ),
  294. );
  295. }
  296. $smcFunc['db_free_result']($request);
  297. }
  298. // Get the boards where the current user can remove any message.
  299. $context['report_remove_any_boards'] = $user_info['is_admin'] ? $report_boards_ids : array_intersect($report_boards_ids, boardsAllowedTo('remove_any'));
  300. $context['report_manage_bans'] = allowedTo('manage_bans');
  301. return $reports;
  302. }
  303. /**
  304. * Recount all open reports. Sets a SESSION var with the updated info.
  305. *
  306. * @param string the type of reports to count
  307. * @return int the update open report count.
  308. */
  309. function recountOpenReports($type)
  310. {
  311. global $user_info, $smcFunc, $context;
  312. if ($type == 'members')
  313. $bq = '';
  314. else
  315. $bq = ' AND ' . $user_info['mod_cache']['bq'];
  316. $request = $smcFunc['db_query']('', '
  317. SELECT COUNT(*)
  318. FROM {db_prefix}log_reported
  319. WHERE closed = {int:not_closed}
  320. AND ignore_all = {int:not_ignored}
  321. AND id_board' . ($type == 'members' ? '' : '!') . '= {int:not_a_reported_post}'
  322. . $bq,
  323. array(
  324. 'not_closed' => 0,
  325. 'not_ignored' => 0,
  326. 'not_a_reported_post' => 0,
  327. )
  328. );
  329. list ($open_reports) = $smcFunc['db_fetch_row']($request);
  330. $smcFunc['db_free_result']($request);
  331. $_SESSION['rc'] = array(
  332. 'id' => $user_info['id'],
  333. 'time' => time(),
  334. 'reports' => $open_reports,
  335. );
  336. return $open_reports;
  337. }
  338. /**
  339. * Gets additional information for a specific report.
  340. *
  341. * @param int $report_id The report ID to get the info from.
  342. * @return array|bool the report data. Boolean false if no report_id was provided.
  343. */
  344. function getReportDetails($report_id)
  345. {
  346. global $smcFunc, $user_info, $context;
  347. if (empty($report_id))
  348. return false;
  349. // We don't need all this info if we're only getting user info
  350. if ($context['report_type'] == 'members')
  351. {
  352. $request = $smcFunc['db_query']('', '
  353. SELECT lr.id_report, lr.id_member,
  354. lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all,
  355. IFNULL(mem.real_name, lr.membername) AS user_name, IFNULL(mem.id_member, 0) AS id_user
  356. FROM {db_prefix}log_reported AS lr
  357. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  358. WHERE lr.id_report = {int:id_report}
  359. AND lr.id_board = 0
  360. LIMIT 1',
  361. array(
  362. 'id_report' => $report_id,
  363. )
  364. );
  365. }
  366. else
  367. {
  368. // Get the report details, need this so we can limit access to a particular board.
  369. $request = $smcFunc['db_query']('', '
  370. SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body,
  371. lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all,
  372. IFNULL(mem.real_name, lr.membername) AS author_name, IFNULL(mem.id_member, 0) AS id_author
  373. FROM {db_prefix}log_reported AS lr
  374. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  375. WHERE lr.id_report = {int:id_report}
  376. AND ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . '
  377. LIMIT 1',
  378. array(
  379. 'id_report' => $report_id,
  380. )
  381. );
  382. }
  383. // So did we find anything?
  384. if (!$smcFunc['db_num_rows']($request))
  385. return false;
  386. // Woohoo we found a report and they can see it!
  387. $row = $smcFunc['db_fetch_assoc']($request);
  388. $smcFunc['db_free_result']($request);
  389. return $row;
  390. }
  391. /**
  392. * Gets both report comments as well as any moderator comment.
  393. *
  394. * @param int $report_id The report ID to get the info from.
  395. * @return array|bool an associative array with 2 keys comments and mod_comments. Boolean false if no report_id was provided.
  396. */
  397. function getReportComments($report_id)
  398. {
  399. global $smcFunc, $scripturl;
  400. if (empty($report_id))
  401. return false;
  402. $report = array(
  403. 'comments' => array(),
  404. 'mod_comments' => array()
  405. );
  406. // So what bad things do the reporters have to say about it?
  407. $request = $smcFunc['db_query']('', '
  408. SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment, lrc.member_ip,
  409. IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lrc.membername) AS reporter
  410. FROM {db_prefix}log_reported_comments AS lrc
  411. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member)
  412. WHERE lrc.id_report = {int:id_report}',
  413. array(
  414. 'id_report' => $report_id,
  415. )
  416. );
  417. while ($row = $smcFunc['db_fetch_assoc']($request))
  418. {
  419. $report['comments'][] = array(
  420. 'id' => $row['id_comment'],
  421. 'message' => strtr($row['comment'], array("\n" => '<br>')),
  422. 'time' => timeformat($row['time_sent']),
  423. 'member' => array(
  424. 'id' => $row['id_member'],
  425. 'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'],
  426. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']),
  427. 'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
  428. 'ip' => !empty($row['member_ip']) && allowedTo('moderate_forum') ? '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['member_ip'] . '">' . $row['member_ip'] . '</a>' : '',
  429. ),
  430. );
  431. }
  432. $smcFunc['db_free_result']($request);
  433. // Hang about old chap, any comments from moderators on this one?
  434. $request = $smcFunc['db_query']('', '
  435. SELECT lc.id_comment, lc.id_notice, lc.log_time, lc.body,
  436. IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS moderator
  437. FROM {db_prefix}log_comments AS lc
  438. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  439. WHERE lc.id_notice = {int:id_report}
  440. AND lc.comment_type = {literal:reportc}',
  441. array(
  442. 'id_report' => $report_id,
  443. )
  444. );
  445. while ($row = $smcFunc['db_fetch_assoc']($request))
  446. {
  447. $report['mod_comments'][] = array(
  448. 'id' => $row['id_comment'],
  449. 'message' => parse_bbc($row['body']),
  450. 'time' => timeformat($row['log_time']),
  451. 'can_edit' => allowedTo('admin_forum') || (($user_info['id'] == $row['id_member']) && allowedTo('moderate_forum')),
  452. 'member' => array(
  453. 'id' => $row['id_member'],
  454. 'name' => $row['moderator'],
  455. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['moderator'] . '</a>' : $row['moderator'],
  456. 'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
  457. ),
  458. );
  459. }
  460. $smcFunc['db_free_result']($request);
  461. return $report;
  462. }
  463. /**
  464. * Gets specific details about a moderator comment. It also adds a permission for editing/deleting the comment,
  465. * by default only admins and the author of the comment can edit/delete it.
  466. *
  467. * @param int $comment_id The moderator comment ID to get the info from.
  468. * @return array|bool an array with the fetched data. Boolean false if no report_id was provided.
  469. */
  470. function getCommentModDetails($comment_id)
  471. {
  472. global $smcFunc, $user_info;
  473. $comment = array();
  474. if (empty($comment_id))
  475. return false;
  476. $request = $smcFunc['db_query']('', '
  477. SELECT id_comment, id_notice, log_time, body, id_member
  478. FROM {db_prefix}log_comments
  479. WHERE id_comment = {int:id_comment}
  480. AND comment_type = {literal:reportc}',
  481. array(
  482. 'id_comment' => $comment_id,
  483. )
  484. );
  485. $comment = $smcFunc['db_fetch_assoc']($request);
  486. $smcFunc['db_free_result']($request);
  487. // Add the permission
  488. if (!empty($comment))
  489. $comment['can_edit'] = allowedTo('admin_forum') || (($user_info['id'] == $comment['id_member']) && allowedTo('moderate_forum'));
  490. return $comment;
  491. }
  492. /**
  493. * Inserts a new moderator comment to the DB.
  494. *
  495. * @param int $report_id The report ID is used to fire a notification about the event.
  496. * @param array $data a formatted array of data to be inserted. Should be already properly sanitized.
  497. * @return bool Boolean false if no data was provided.
  498. */
  499. function saveModComment($report_id, $data)
  500. {
  501. global $smcFunc, $user_info;
  502. if (empty($data))
  503. return false;
  504. $data = array_merge(array($user_info['id'], $user_info['name'], 'reportc', ''), $data);
  505. $smcFunc['db_insert']('',
  506. '{db_prefix}log_comments',
  507. array(
  508. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string',
  509. 'id_notice' => 'int', 'body' => 'string', 'log_time' => 'int',
  510. ),
  511. $data,
  512. array('id_comment')
  513. );
  514. $last_comment = $smcFunc['db_insert_id']('{db_prefix}log_comments', 'id_comment');
  515. $report = getReportDetails($report_id);
  516. if ($context['report_type'] == 'members')
  517. {
  518. $prefix = 'Member';
  519. $data = array(
  520. 'report_id' => $id_report,
  521. 'user_id' => $user['id_member'],
  522. 'user_name' => $user_name,
  523. 'sender_id' => $context['user']['id'],
  524. 'sender_name' => $context['user']['name'],
  525. 'comment' => $reason,
  526. 'time' => time(),
  527. );
  528. }
  529. else
  530. {
  531. $prefix = 'Msg';
  532. $data = array(
  533. 'report_id' => $report_id,
  534. 'comment_id' => $last_comment,
  535. 'msg_id' => $report['id_msg'],
  536. 'topic_id' => $report['id_topic'],
  537. 'board_id' => $report['id_board'],
  538. 'sender_id' => $user_info['id'],
  539. 'sender_name' => $user_info['name'],
  540. 'time' => time(),
  541. );
  542. }
  543. // And get ready to notify people.
  544. if (!empty($report))
  545. $smcFunc['db_insert']('insert',
  546. '{db_prefix}background_tasks',
  547. array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
  548. array('$sourcedir/tasks/' . $prefix . 'ReportReply-Notify.php', $prefix . 'ReportReply_Notify_Background', serialize($data), 0),
  549. array('id_task')
  550. );
  551. }
  552. /**
  553. * Saves the new information whenever a moderator comment is edited.
  554. *
  555. * @param int $comment_id The edited moderator comment ID.
  556. * @param array $data The new data to de inserted. Should be already properly sanitized.
  557. * @return bool Boolean false if no data or no comment ID was provided.
  558. */
  559. function editModComment($comment_id, $edited_comment)
  560. {
  561. global $smcFunc;
  562. if (empty($comment_id) || empty($edited_comment))
  563. return false;
  564. $smcFunc['db_query']('', '
  565. UPDATE {db_prefix}log_comments
  566. SET body = {string:body}
  567. WHERE id_comment = {int:id_comment}',
  568. array(
  569. 'body' => $edited_comment,
  570. 'id_comment' => $comment_id,
  571. )
  572. );
  573. }
  574. /**
  575. * Deletes a moderator comment from the DB.
  576. *
  577. * @param int $comment_id The moderator comment ID used to identify which report will be deleted.
  578. * @return bool Boolean false if no data was provided.
  579. */
  580. function deleteModComment($comment_id)
  581. {
  582. global $smcFunc;
  583. if (empty($comment_id))
  584. return false;
  585. $smcFunc['db_query']('', '
  586. DELETE FROM {db_prefix}log_comments
  587. WHERE id_comment = {int:comment_id}',
  588. array(
  589. 'comment_id' => $comment_id,
  590. )
  591. );
  592. }
  593. ?>