Subs-ReportedContent.php 20 KB

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