SendTopic.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582
  1. <?php
  2. /**
  3. * The functions in this file deal with sending topics to a friend or moderator
  4. * Simple Machines Forum (SMF)
  5. *
  6. * @package SMF
  7. * @author Simple Machines http://www.simplemachines.org
  8. * @copyright 2011 Simple Machines
  9. * @license http://www.simplemachines.org/about/smf/license.php BSD
  10. *
  11. * @version 2.1 Alpha 1
  12. */
  13. if (!defined('SMF'))
  14. die('Hacking attempt...');
  15. /**
  16. * The main handling function for sending specialist (Or otherwise) emails to a user.
  17. */
  18. function EmailUser()
  19. {
  20. global $topic, $txt, $context, $scripturl, $sourcedir, $smcFunc;
  21. // Don't index anything here.
  22. $context['robot_no_index'] = true;
  23. // Load the template.
  24. loadTemplate('SendTopic');
  25. $sub_actions = array(
  26. 'email' => 'CustomEmail',
  27. 'sendtopic' => 'SendTopic',
  28. );
  29. if (!isset($_GET['sa']) || !isset($sub_actions[$_GET['sa']]))
  30. $_GET['sa'] = 'sendtopic';
  31. $sub_actions[$_GET['sa']]();
  32. }
  33. /**
  34. * Send a topic to a friend.
  35. * Uses the SendTopic template, with the main sub template.
  36. * Requires the send_topic permission.
  37. * Redirects back to the first page of the topic when done.
  38. * Is accessed via ?action=emailuser;sa=sendtopic.
  39. */
  40. function SendTopic()
  41. {
  42. global $topic, $txt, $context, $scripturl, $sourcedir, $smcFunc, $modSettings;
  43. // Check permissions...
  44. isAllowedTo('send_topic');
  45. // We need at least a topic... go away if you don't have one.
  46. if (empty($topic))
  47. fatal_lang_error('not_a_topic', false);
  48. // Get the topic's subject.
  49. $request = $smcFunc['db_query']('', '
  50. SELECT m.subject, t.approved
  51. FROM {db_prefix}topics AS t
  52. INNER JOIN {db_prefix}messages AS m ON (m.id_msg = t.id_first_msg)
  53. WHERE t.id_topic = {int:current_topic}
  54. LIMIT 1',
  55. array(
  56. 'current_topic' => $topic,
  57. )
  58. );
  59. if ($smcFunc['db_num_rows']($request) == 0)
  60. fatal_lang_error('not_a_topic', false);
  61. $row = $smcFunc['db_fetch_assoc']($request);
  62. $smcFunc['db_free_result']($request);
  63. // Can't send topic if its unapproved and using post moderation.
  64. if ($modSettings['postmod_active'] && !$row['approved'])
  65. fatal_lang_error('not_approved_topic', false);
  66. // Censor the subject....
  67. censorText($row['subject']);
  68. // Sending yet, or just getting prepped?
  69. if (empty($_POST['send']))
  70. {
  71. $context['page_title'] = sprintf($txt['sendtopic_title'], $row['subject']);
  72. $context['start'] = $_REQUEST['start'];
  73. return;
  74. }
  75. // Actually send the message...
  76. checkSession();
  77. spamProtection('sendtopc');
  78. // This is needed for sendmail().
  79. require_once($sourcedir . '/Subs-Post.php');
  80. // Trim the names..
  81. $_POST['y_name'] = trim($_POST['y_name']);
  82. $_POST['r_name'] = trim($_POST['r_name']);
  83. // Make sure they aren't playing "let's use a fake email".
  84. if ($_POST['y_name'] == '_' || !isset($_POST['y_name']) || $_POST['y_name'] == '')
  85. fatal_lang_error('no_name', false);
  86. if (!isset($_POST['y_email']) || $_POST['y_email'] == '')
  87. fatal_lang_error('no_email', false);
  88. if (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['y_email']) == 0)
  89. fatal_lang_error('email_invalid_character', false);
  90. // The receiver should be valid to.
  91. if ($_POST['r_name'] == '_' || !isset($_POST['r_name']) || $_POST['r_name'] == '')
  92. fatal_lang_error('no_name', false);
  93. if (!isset($_POST['r_email']) || $_POST['r_email'] == '')
  94. fatal_lang_error('no_email', false);
  95. if (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['r_email']) == 0)
  96. fatal_lang_error('email_invalid_character', false);
  97. // Emails don't like entities...
  98. $row['subject'] = un_htmlspecialchars($row['subject']);
  99. $replacements = array(
  100. 'TOPICSUBJECT' => $row['subject'],
  101. 'SENDERNAME' => $_POST['y_name'],
  102. 'RECPNAME' => $_POST['r_name'],
  103. 'TOPICLINK' => $scripturl . '?topic=' . $topic . '.0',
  104. );
  105. $emailtemplate = 'send_topic';
  106. if (!empty($_POST['comment']))
  107. {
  108. $emailtemplate .= '_comment';
  109. $replacements['COMMENT'] = $_POST['comment'];
  110. }
  111. $emaildata = loadEmailTemplate($emailtemplate, $replacements);
  112. // And off we go!
  113. sendmail($_POST['r_email'], $emaildata['subject'], $emaildata['body'], $_POST['y_email']);
  114. // Back to the topic!
  115. redirectexit('topic=' . $topic . '.0');
  116. }
  117. /**
  118. * Allow a user to send an email.
  119. * Send an email to the user - allow the sender to write the message.
  120. * Can either be passed a user ID as uid or a message id as msg.
  121. * Does not check permissions for a message ID as there is no information disclosed.
  122. */
  123. function CustomEmail()
  124. {
  125. global $context, $modSettings, $user_info, $smcFunc, $txt, $scripturl, $sourcedir;
  126. // Can the user even see this information?
  127. if ($user_info['is_guest'] && !empty($modSettings['guest_hideContacts']))
  128. fatal_lang_error('no_access', false);
  129. // Are we sending to a user?
  130. $context['form_hidden_vars'] = array();
  131. if (isset($_REQUEST['uid']))
  132. {
  133. $request = $smcFunc['db_query']('', '
  134. SELECT email_address AS email, real_name AS name, id_member, hide_email
  135. FROM {db_prefix}members
  136. WHERE id_member = {int:id_member}',
  137. array(
  138. 'id_member' => (int) $_REQUEST['uid'],
  139. )
  140. );
  141. $context['form_hidden_vars']['uid'] = (int) $_REQUEST['uid'];
  142. }
  143. elseif (isset($_REQUEST['msg']))
  144. {
  145. $request = $smcFunc['db_query']('', '
  146. SELECT IFNULL(mem.email_address, m.poster_email) AS email, IFNULL(mem.real_name, m.poster_name) AS name, IFNULL(mem.id_member, 0) AS id_member, hide_email
  147. FROM {db_prefix}messages AS m
  148. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  149. WHERE m.id_msg = {int:id_msg}',
  150. array(
  151. 'id_msg' => (int) $_REQUEST['msg'],
  152. )
  153. );
  154. $context['form_hidden_vars']['msg'] = (int) $_REQUEST['msg'];
  155. }
  156. if (empty($request) || $smcFunc['db_num_rows']($request) == 0)
  157. fatal_lang_error('cant_find_user_email');
  158. $row = $smcFunc['db_fetch_assoc']($request);
  159. $smcFunc['db_free_result']($request);
  160. // Are you sure you got the address?
  161. if (empty($row['email']))
  162. fatal_lang_error('cant_find_user_email');
  163. // Can they actually do this?
  164. $context['show_email_address'] = showEmailAddress(!empty($row['hide_email']), $row['id_member']);
  165. if ($context['show_email_address'] === 'no')
  166. fatal_lang_error('no_access', false);
  167. // Setup the context!
  168. $context['recipient'] = array(
  169. 'id' => $row['id_member'],
  170. 'name' => $row['name'],
  171. 'email' => $row['email'],
  172. 'email_link' => ($context['show_email_address'] == 'yes_permission_override' ? '<em>' : '') . '<a href="mailto:' . $row['email'] . '">' . $row['email'] . '</a>' . ($context['show_email_address'] == 'yes_permission_override' ? '</em>' : ''),
  173. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['name'] . '</a>' : $row['name'],
  174. );
  175. // Can we see this person's email address?
  176. $context['can_view_receipient_email'] = $context['show_email_address'] == 'yes' || $context['show_email_address'] == 'yes_permission_override';
  177. // Are we actually sending it?
  178. if (isset($_POST['send']) && isset($_POST['email_body']))
  179. {
  180. require_once($sourcedir . '/Subs-Post.php');
  181. checkSession();
  182. // If it's a guest sort out their names.
  183. if ($user_info['is_guest'])
  184. {
  185. if (empty($_POST['y_name']) || $_POST['y_name'] == '_' || trim($_POST['y_name']) == '')
  186. fatal_lang_error('no_name', false);
  187. if (empty($_POST['y_email']))
  188. fatal_lang_error('no_email', false);
  189. if (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['y_email']) == 0)
  190. fatal_lang_error('email_invalid_character', false);
  191. $from_name = trim($_POST['y_name']);
  192. $from_email = trim($_POST['y_email']);
  193. }
  194. else
  195. {
  196. $from_name = $user_info['name'];
  197. $from_email = $user_info['email'];
  198. }
  199. // Check we have a body (etc).
  200. if (trim($_POST['email_body']) == '' || trim($_POST['email_subject']) == '')
  201. fatal_lang_error('email_missing_data');
  202. // We use a template in case they want to customise!
  203. $replacements = array(
  204. 'EMAILSUBJECT' => $_POST['email_subject'],
  205. 'EMAILBODY' => $_POST['email_body'],
  206. 'SENDERNAME' => $from_name,
  207. 'RECPNAME' => $context['recipient']['name'],
  208. );
  209. // Don't let them send too many!
  210. spamProtection('sendmail');
  211. // Get the template and get out!
  212. $emaildata = loadEmailTemplate('send_email', $replacements);
  213. sendmail($context['recipient']['email'], $emaildata['subject'], $emaildata['body'], $from_email, null, false, 1, null, true);
  214. // Now work out where to go!
  215. if (isset($_REQUEST['uid']))
  216. redirectexit('action=profile;u=' . (int) $_REQUEST['uid']);
  217. elseif (isset($_REQUEST['msg']))
  218. redirectexit('msg=' . (int) $_REQUEST['msg']);
  219. else
  220. redirectexit();
  221. }
  222. $context['sub_template'] = 'custom_email';
  223. $context['page_title'] = $txt['send_email'];
  224. }
  225. /**
  226. * Report a post to the moderator... ask for a comment.
  227. * Gathers data from the user to report abuse to the moderator(s).
  228. * Uses the ReportToModerator template, main sub template.
  229. * Requires the report_any permission.
  230. * Uses ReportToModerator2() if post data was sent.
  231. * Accessed through ?action=reporttm.
  232. */
  233. function ReportToModerator()
  234. {
  235. global $txt, $topic, $sourcedir, $modSettings, $user_info, $context, $smcFunc;
  236. $context['robot_no_index'] = true;
  237. // You can't use this if it's off or you are not allowed to do it.
  238. isAllowedTo('report_any');
  239. // If they're posting, it should be processed by ReportToModerator2.
  240. if ((isset($_POST[$context['session_var']]) || isset($_POST['submit'])) && empty($context['post_errors']))
  241. ReportToModerator2();
  242. // We need a message ID to check!
  243. if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']))
  244. fatal_lang_error('no_access', false);
  245. // For compatibility, accept mid, but we should be using msg. (not the flavor kind!)
  246. $_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg'];
  247. // Check the message's ID - don't want anyone reporting a post they can't even see!
  248. $result = $smcFunc['db_query']('', '
  249. SELECT m.id_msg, m.id_member, t.id_member_started
  250. FROM {db_prefix}messages AS m
  251. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
  252. WHERE m.id_msg = {int:id_msg}
  253. AND m.id_topic = {int:current_topic}
  254. LIMIT 1',
  255. array(
  256. 'current_topic' => $topic,
  257. 'id_msg' => $_REQUEST['msg'],
  258. )
  259. );
  260. if ($smcFunc['db_num_rows']($result) == 0)
  261. fatal_lang_error('no_board', false);
  262. list ($_REQUEST['msg'], $member, $starter) = $smcFunc['db_fetch_row']($result);
  263. $smcFunc['db_free_result']($result);
  264. // Do we need to show the visual verification image?
  265. $context['require_verification'] = $user_info['is_guest'] && !empty($modSettings['guests_report_require_captcha']);
  266. if ($context['require_verification'])
  267. {
  268. require_once($sourcedir . '/Subs-Editor.php');
  269. $verificationOptions = array(
  270. 'id' => 'report',
  271. );
  272. $context['require_verification'] = create_control_verification($verificationOptions);
  273. $context['visual_verification_id'] = $verificationOptions['id'];
  274. }
  275. // Show the inputs for the comment, etc.
  276. loadLanguage('Post');
  277. loadTemplate('SendTopic');
  278. $context['comment_body'] = !isset($_POST['comment']) ? '' : trim($_POST['comment']);
  279. $context['email_address'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
  280. // This is here so that the user could, in theory, be redirected back to the topic.
  281. $context['start'] = $_REQUEST['start'];
  282. $context['message_id'] = $_REQUEST['msg'];
  283. $context['page_title'] = $txt['report_to_mod'];
  284. $context['sub_template'] = 'report';
  285. }
  286. /**
  287. * Send the emails.
  288. * Sends off emails to all the moderators.
  289. * Sends to administrators and global moderators. (1 and 2)
  290. * Called by ReportToModerator(), and thus has the same permission and setting requirements as it does.
  291. * Accessed through ?action=reporttm when posting.
  292. */
  293. function ReportToModerator2()
  294. {
  295. global $txt, $scripturl, $topic, $board, $user_info, $modSettings, $sourcedir, $language, $context, $smcFunc;
  296. // You must have the proper permissions!
  297. isAllowedTo('report_any');
  298. // Make sure they aren't spamming.
  299. spamProtection('reporttm');
  300. require_once($sourcedir . '/Subs-Post.php');
  301. // No errors, yet.
  302. $post_errors = array();
  303. // Check their session.
  304. if (checkSession('post', '', false) != '')
  305. $post_errors[] = 'session_timeout';
  306. // Make sure we have a comment and it's clean.
  307. if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '')
  308. $post_errors[] = 'no_comment';
  309. $poster_comment = strtr($smcFunc['htmlspecialchars']($_POST['comment']), array("\r" => '', "\n" => '', "\t" => ''));
  310. // Guests need to provide their address!
  311. if ($user_info['is_guest'])
  312. {
  313. $_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
  314. if ($_POST['email'] === '')
  315. $post_errors[] = 'no_email';
  316. elseif (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['email']) == 0)
  317. $post_errors[] = 'bad_email';
  318. isBannedEmail($_POST['email'], 'cannot_post', sprintf($txt['you_are_post_banned'], $txt['guest_title']));
  319. $user_info['email'] = htmlspecialchars($_POST['email']);
  320. }
  321. // Could they get the right verification code?
  322. if ($user_info['is_guest'] && !empty($modSettings['guests_report_require_captcha']))
  323. {
  324. require_once($sourcedir . '/Subs-Editor.php');
  325. $verificationOptions = array(
  326. 'id' => 'report',
  327. );
  328. $context['require_verification'] = create_control_verification($verificationOptions, true);
  329. if (is_array($context['require_verification']))
  330. $post_errors = array_merge($post_errors, $context['require_verification']);
  331. }
  332. // Any errors?
  333. if (!empty($post_errors))
  334. {
  335. loadLanguage('Errors');
  336. $context['post_errors'] = array();
  337. foreach ($post_errors as $post_error)
  338. $context['post_errors'][] = $txt['error_' . $post_error];
  339. return ReportToModerator();
  340. }
  341. // Get the basic topic information, and make sure they can see it.
  342. $_POST['msg'] = (int) $_POST['msg'];
  343. $request = $smcFunc['db_query']('', '
  344. SELECT m.id_topic, m.id_board, m.subject, m.body, m.id_member AS id_poster, m.poster_name, mem.real_name
  345. FROM {db_prefix}messages AS m
  346. LEFT JOIN {db_prefix}members AS mem ON (m.id_member = mem.id_member)
  347. WHERE m.id_msg = {int:id_msg}
  348. AND m.id_topic = {int:current_topic}
  349. LIMIT 1',
  350. array(
  351. 'current_topic' => $topic,
  352. 'id_msg' => $_POST['msg'],
  353. )
  354. );
  355. if ($smcFunc['db_num_rows']($request) == 0)
  356. fatal_lang_error('no_board', false);
  357. $message = $smcFunc['db_fetch_assoc']($request);
  358. $smcFunc['db_free_result']($request);
  359. $poster_name = un_htmlspecialchars($message['real_name']) . ($message['real_name'] != $message['poster_name'] ? ' (' . $message['poster_name'] . ')' : '');
  360. $reporterName = un_htmlspecialchars($user_info['name']) . ($user_info['name'] != $user_info['username'] && $user_info['username'] != '' ? ' (' . $user_info['username'] . ')' : '');
  361. $subject = un_htmlspecialchars($message['subject']);
  362. // Get a list of members with the moderate_board permission.
  363. require_once($sourcedir . '/Subs-Members.php');
  364. $moderators = membersAllowedTo('moderate_board', $board);
  365. $request = $smcFunc['db_query']('', '
  366. SELECT id_member, email_address, lngfile, mod_prefs
  367. FROM {db_prefix}members
  368. WHERE id_member IN ({array_int:moderator_list})
  369. AND notify_types != {int:notify_types}
  370. ORDER BY lngfile',
  371. array(
  372. 'moderator_list' => $moderators,
  373. 'notify_types' => 4,
  374. )
  375. );
  376. // Check that moderators do exist!
  377. if ($smcFunc['db_num_rows']($request) == 0)
  378. fatal_lang_error('no_mods', false);
  379. // If we get here, I believe we should make a record of this, for historical significance, yabber.
  380. if (empty($modSettings['disable_log_report']))
  381. {
  382. $request2 = $smcFunc['db_query']('', '
  383. SELECT id_report, ignore_all
  384. FROM {db_prefix}log_reported
  385. WHERE id_msg = {int:id_msg}
  386. AND (closed = {int:not_closed} OR ignore_all = {int:ignored})
  387. ORDER BY ignore_all DESC',
  388. array(
  389. 'id_msg' => $_POST['msg'],
  390. 'not_closed' => 0,
  391. 'ignored' => 1,
  392. )
  393. );
  394. if ($smcFunc['db_num_rows']($request2) != 0)
  395. list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request2);
  396. $smcFunc['db_free_result']($request2);
  397. // If we're just going to ignore these, then who gives a monkeys...
  398. if (!empty($ignore))
  399. redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']);
  400. // Already reported? My god, we could be dealing with a real rogue here...
  401. if (!empty($id_report))
  402. $smcFunc['db_query']('', '
  403. UPDATE {db_prefix}log_reported
  404. SET num_reports = num_reports + 1, time_updated = {int:current_time}
  405. WHERE id_report = {int:id_report}',
  406. array(
  407. 'current_time' => time(),
  408. 'id_report' => $id_report,
  409. )
  410. );
  411. // Otherwise, we shall make one!
  412. else
  413. {
  414. if (empty($message['real_name']))
  415. $message['real_name'] = $message['poster_name'];
  416. $smcFunc['db_insert']('',
  417. '{db_prefix}log_reported',
  418. array(
  419. 'id_msg' => 'int', 'id_topic' => 'int', 'id_board' => 'int', 'id_member' => 'int', 'membername' => 'string',
  420. 'subject' => 'string', 'body' => 'string', 'time_started' => 'int', 'time_updated' => 'int',
  421. 'num_reports' => 'int', 'closed' => 'int',
  422. ),
  423. array(
  424. $_POST['msg'], $message['id_topic'], $message['id_board'], $message['id_poster'], $message['real_name'],
  425. $message['subject'], $message['body'] , time(), time(), 1, 0,
  426. ),
  427. array('id_report')
  428. );
  429. $id_report = $smcFunc['db_insert_id']('{db_prefix}log_reported', 'id_report');
  430. }
  431. // Now just add our report...
  432. if ($id_report)
  433. {
  434. $smcFunc['db_insert']('',
  435. '{db_prefix}log_reported_comments',
  436. array(
  437. 'id_report' => 'int', 'id_member' => 'int', 'membername' => 'string', 'email_address' => 'string',
  438. 'member_ip' => 'string', 'comment' => 'string', 'time_sent' => 'int',
  439. ),
  440. array(
  441. $id_report, $user_info['id'], $user_info['name'], $user_info['email'],
  442. $user_info['ip'], $poster_comment, time(),
  443. ),
  444. array('id_comment')
  445. );
  446. }
  447. }
  448. // Find out who the real moderators are - for mod preferences.
  449. $request2 = $smcFunc['db_query']('', '
  450. SELECT id_member
  451. FROM {db_prefix}moderators
  452. WHERE id_board = {int:current_board}',
  453. array(
  454. 'current_board' => $board,
  455. )
  456. );
  457. $real_mods = array();
  458. while ($row = $smcFunc['db_fetch_assoc']($request2))
  459. $real_mods[] = $row['id_member'];
  460. $smcFunc['db_free_result']($request2);
  461. // Send every moderator an email.
  462. while ($row = $smcFunc['db_fetch_assoc']($request))
  463. {
  464. // Maybe they don't want to know?!
  465. if (!empty($row['mod_prefs']))
  466. {
  467. list(,, $pref_binary) = explode('|', $row['mod_prefs']);
  468. if (!($pref_binary & 1) && (!($pref_binary & 2) || !in_array($row['id_member'], $real_mods)))
  469. continue;
  470. }
  471. $replacements = array(
  472. 'TOPICSUBJECT' => $subject,
  473. 'POSTERNAME' => $poster_name,
  474. 'REPORTERNAME' => $reporterName,
  475. 'TOPICLINK' => $scripturl . '?topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg'],
  476. 'REPORTLINK' => !empty($id_report) ? $scripturl . '?action=moderate;area=reports;report=' . $id_report : '',
  477. 'COMMENT' => $_POST['comment'],
  478. );
  479. $emaildata = loadEmailTemplate('report_to_moderator', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
  480. // Send it to the moderator.
  481. sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], $user_info['email'], null, false, 2);
  482. }
  483. $smcFunc['db_free_result']($request);
  484. // Keep track of when the mod reports get updated, that way we know when we need to look again.
  485. updateSettings(array('last_mod_report_action' => time()));
  486. // Back to the post we reported!
  487. redirectexit('reportsent;topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']);
  488. }
  489. ?>