SendTopic.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  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 2013 Simple Machines and individual contributors
  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('No direct access...');
  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('sendtopic');
  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;topicsent');
  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. isAllowedTo('send_email_to_members');
  130. // Are we sending to a user?
  131. $context['form_hidden_vars'] = array();
  132. if (isset($_REQUEST['uid']))
  133. {
  134. $request = $smcFunc['db_query']('', '
  135. SELECT email_address AS email, real_name AS name, id_member, hide_email
  136. FROM {db_prefix}members
  137. WHERE id_member = {int:id_member}',
  138. array(
  139. 'id_member' => (int) $_REQUEST['uid'],
  140. )
  141. );
  142. $context['form_hidden_vars']['uid'] = (int) $_REQUEST['uid'];
  143. }
  144. elseif (isset($_REQUEST['msg']))
  145. {
  146. $request = $smcFunc['db_query']('', '
  147. 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
  148. FROM {db_prefix}messages AS m
  149. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  150. WHERE m.id_msg = {int:id_msg}',
  151. array(
  152. 'id_msg' => (int) $_REQUEST['msg'],
  153. )
  154. );
  155. $context['form_hidden_vars']['msg'] = (int) $_REQUEST['msg'];
  156. }
  157. if (empty($request) || $smcFunc['db_num_rows']($request) == 0)
  158. fatal_lang_error('cant_find_user_email');
  159. $row = $smcFunc['db_fetch_assoc']($request);
  160. $smcFunc['db_free_result']($request);
  161. // Are you sure you got the address?
  162. if (empty($row['email']))
  163. fatal_lang_error('cant_find_user_email');
  164. // Can they actually do this?
  165. $context['show_email_address'] = showEmailAddress(!empty($row['hide_email']), $row['id_member']);
  166. if ($context['show_email_address'] === 'no')
  167. fatal_lang_error('no_access', false);
  168. // Setup the context!
  169. $context['recipient'] = array(
  170. 'id' => $row['id_member'],
  171. 'name' => $row['name'],
  172. 'email' => $row['email'],
  173. '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>' : ''),
  174. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['name'] . '</a>' : $row['name'],
  175. );
  176. // Can we see this person's email address?
  177. $context['can_view_receipient_email'] = $context['show_email_address'] == 'yes' || $context['show_email_address'] == 'yes_permission_override';
  178. // Are we actually sending it?
  179. if (isset($_POST['send']) && isset($_POST['email_body']))
  180. {
  181. require_once($sourcedir . '/Subs-Post.php');
  182. checkSession();
  183. // If it's a guest sort out their names.
  184. if ($user_info['is_guest'])
  185. {
  186. if (empty($_POST['y_name']) || $_POST['y_name'] == '_' || trim($_POST['y_name']) == '')
  187. fatal_lang_error('no_name', false);
  188. if (empty($_POST['y_email']))
  189. fatal_lang_error('no_email', false);
  190. if (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['y_email']) == 0)
  191. fatal_lang_error('email_invalid_character', false);
  192. $from_name = trim($_POST['y_name']);
  193. $from_email = trim($_POST['y_email']);
  194. }
  195. else
  196. {
  197. $from_name = $user_info['name'];
  198. $from_email = $user_info['email'];
  199. }
  200. // Check we have a body (etc).
  201. if (trim($_POST['email_body']) == '' || trim($_POST['email_subject']) == '')
  202. fatal_lang_error('email_missing_data');
  203. // We use a template in case they want to customise!
  204. $replacements = array(
  205. 'EMAILSUBJECT' => $_POST['email_subject'],
  206. 'EMAILBODY' => $_POST['email_body'],
  207. 'SENDERNAME' => $from_name,
  208. 'RECPNAME' => $context['recipient']['name'],
  209. );
  210. // Don't let them send too many!
  211. spamProtection('sendmail');
  212. // Get the template and get out!
  213. $emaildata = loadEmailTemplate('send_email', $replacements);
  214. sendmail($context['recipient']['email'], $emaildata['subject'], $emaildata['body'], $from_email, null, false, 1, null, true);
  215. // Now work out where to go!
  216. if (isset($_REQUEST['uid']))
  217. redirectexit('action=profile;u=' . (int) $_REQUEST['uid']);
  218. elseif (isset($_REQUEST['msg']))
  219. redirectexit('msg=' . (int) $_REQUEST['msg']);
  220. else
  221. redirectexit();
  222. }
  223. $context['sub_template'] = 'custom_email';
  224. $context['page_title'] = $txt['send_email'];
  225. }
  226. /**
  227. * Report a post to the moderator... ask for a comment.
  228. * Gathers data from the user to report abuse to the moderator(s).
  229. * Uses the ReportToModerator template, main sub template.
  230. * Requires the report_any permission.
  231. * Uses ReportToModerator2() if post data was sent.
  232. * Accessed through ?action=reporttm.
  233. */
  234. function ReportToModerator()
  235. {
  236. global $txt, $topic, $sourcedir, $modSettings, $user_info, $context, $smcFunc;
  237. $context['robot_no_index'] = true;
  238. // No guests!
  239. is_not_guest();
  240. // You can't use this if it's off or you are not allowed to do it.
  241. isAllowedTo('report_any');
  242. // If they're posting, it should be processed by ReportToModerator2.
  243. if ((isset($_POST[$context['session_var']]) || isset($_POST['save'])) && empty($context['post_errors']))
  244. ReportToModerator2();
  245. // We need a message ID to check!
  246. if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']))
  247. fatal_lang_error('no_access', false);
  248. // For compatibility, accept mid, but we should be using msg. (not the flavor kind!)
  249. $_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg'];
  250. // Check the message's ID - don't want anyone reporting a post they can't even see!
  251. $result = $smcFunc['db_query']('', '
  252. SELECT m.id_msg, m.id_member, t.id_member_started
  253. FROM {db_prefix}messages AS m
  254. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
  255. WHERE m.id_msg = {int:id_msg}
  256. AND m.id_topic = {int:current_topic}
  257. LIMIT 1',
  258. array(
  259. 'current_topic' => $topic,
  260. 'id_msg' => $_REQUEST['msg'],
  261. )
  262. );
  263. if ($smcFunc['db_num_rows']($result) == 0)
  264. fatal_lang_error('no_board', false);
  265. list ($_REQUEST['msg'], $member, $starter) = $smcFunc['db_fetch_row']($result);
  266. $smcFunc['db_free_result']($result);
  267. // Show the inputs for the comment, etc.
  268. loadLanguage('Post');
  269. loadTemplate('SendTopic');
  270. addInlineJavascript('
  271. var error_box = $("#error_box");
  272. $("#report_comment").keyup(function() {
  273. var post_too_long = $("#error_post_too_long");
  274. if ($(this).val().length > 254)
  275. {
  276. if (post_too_long.length == 0)
  277. {
  278. error_box.show();
  279. if ($.trim(error_box.html()) == \'\')
  280. error_box.append("<ul id=\'error_list\'></ul>");
  281. $("#error_list").append("<li id=\'error_post_too_long\' class=\'error\'>" + ' . JavaScriptEscape($txt['post_too_long']) . ' + "</li>");
  282. }
  283. }
  284. else
  285. {
  286. post_too_long.remove();
  287. if ($("#error_list li").length == 0)
  288. error_box.hide();
  289. }
  290. });', true);
  291. $context['comment_body'] = !isset($_POST['comment']) ? '' : trim($_POST['comment']);
  292. // This is here so that the user could, in theory, be redirected back to the topic.
  293. $context['start'] = $_REQUEST['start'];
  294. $context['message_id'] = $_REQUEST['msg'];
  295. $context['page_title'] = $txt['report_to_mod'];
  296. $context['sub_template'] = 'report';
  297. }
  298. /**
  299. * Send the emails.
  300. * Sends off emails to all the moderators.
  301. * Sends to administrators and global moderators. (1 and 2)
  302. * Called by ReportToModerator(), and thus has the same permission and setting requirements as it does.
  303. * Accessed through ?action=reporttm when posting.
  304. */
  305. function ReportToModerator2()
  306. {
  307. global $txt, $scripturl, $topic, $board, $user_info, $modSettings, $sourcedir, $language, $context, $smcFunc;
  308. // Sorry, no guests allowed... Probably just trying to spam us anyway
  309. is_not_guest();
  310. // You must have the proper permissions!
  311. isAllowedTo('report_any');
  312. // Make sure they aren't spamming.
  313. spamProtection('reporttm');
  314. require_once($sourcedir . '/Subs-Post.php');
  315. // No errors, yet.
  316. $post_errors = array();
  317. // Check their session.
  318. if (checkSession('post', '', false) != '')
  319. $post_errors[] = 'session_timeout';
  320. // Make sure we have a comment and it's clean.
  321. if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '')
  322. $post_errors[] = 'no_comment';
  323. $poster_comment = strtr($smcFunc['htmlspecialchars']($_POST['comment']), array("\r" => '', "\t" => ''));
  324. if ($smcFunc['strlen']($poster_comment) > 254)
  325. $post_errors[] = 'post_too_long';
  326. // Guests need to provide their address!
  327. if ($user_info['is_guest'])
  328. {
  329. $_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
  330. if ($_POST['email'] === '')
  331. $post_errors[] = 'no_email';
  332. elseif (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['email']) == 0)
  333. $post_errors[] = 'bad_email';
  334. isBannedEmail($_POST['email'], 'cannot_post', sprintf($txt['you_are_post_banned'], $txt['guest_title']));
  335. $user_info['email'] = htmlspecialchars($_POST['email']);
  336. }
  337. // Could they get the right verification code?
  338. if ($user_info['is_guest'] && !empty($modSettings['guests_report_require_captcha']))
  339. {
  340. require_once($sourcedir . '/Subs-Editor.php');
  341. $verificationOptions = array(
  342. 'id' => 'report',
  343. );
  344. $context['require_verification'] = create_control_verification($verificationOptions, true);
  345. if (is_array($context['require_verification']))
  346. $post_errors = array_merge($post_errors, $context['require_verification']);
  347. }
  348. // Any errors?
  349. if (!empty($post_errors))
  350. {
  351. loadLanguage('Errors');
  352. $context['post_errors'] = array();
  353. foreach ($post_errors as $post_error)
  354. $context['post_errors'][$post_error] = $txt['error_' . $post_error];
  355. return ReportToModerator();
  356. }
  357. // Get the basic topic information, and make sure they can see it.
  358. $_POST['msg'] = (int) $_POST['msg'];
  359. $request = $smcFunc['db_query']('', '
  360. SELECT m.id_topic, m.id_board, m.subject, m.body, m.id_member AS id_poster, m.poster_name, mem.real_name
  361. FROM {db_prefix}messages AS m
  362. LEFT JOIN {db_prefix}members AS mem ON (m.id_member = mem.id_member)
  363. WHERE m.id_msg = {int:id_msg}
  364. AND m.id_topic = {int:current_topic}
  365. LIMIT 1',
  366. array(
  367. 'current_topic' => $topic,
  368. 'id_msg' => $_POST['msg'],
  369. )
  370. );
  371. if ($smcFunc['db_num_rows']($request) == 0)
  372. fatal_lang_error('no_board', false);
  373. $message = $smcFunc['db_fetch_assoc']($request);
  374. $smcFunc['db_free_result']($request);
  375. $poster_name = un_htmlspecialchars($message['real_name']) . ($message['real_name'] != $message['poster_name'] ? ' (' . $message['poster_name'] . ')' : '');
  376. $reporterName = un_htmlspecialchars($user_info['name']) . ($user_info['name'] != $user_info['username'] && $user_info['username'] != '' ? ' (' . $user_info['username'] . ')' : '');
  377. $subject = un_htmlspecialchars($message['subject']);
  378. // Get a list of members with the moderate_board permission.
  379. require_once($sourcedir . '/Subs-Members.php');
  380. $moderators = membersAllowedTo('moderate_board', $board);
  381. $request = $smcFunc['db_query']('', '
  382. SELECT id_report, ignore_all
  383. FROM {db_prefix}log_reported
  384. WHERE id_msg = {int:id_msg}
  385. AND (closed = {int:not_closed} OR ignore_all = {int:ignored})
  386. ORDER BY ignore_all DESC',
  387. array(
  388. 'id_msg' => $_POST['msg'],
  389. 'not_closed' => 0,
  390. 'ignored' => 1,
  391. )
  392. );
  393. if ($smcFunc['db_num_rows']($request) != 0)
  394. list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request);
  395. $smcFunc['db_free_result']($request);
  396. // If we're just going to ignore these, then who gives a monkeys...
  397. if (!empty($ignore))
  398. redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']);
  399. // Already reported? My god, we could be dealing with a real rogue here...
  400. if (!empty($id_report))
  401. $smcFunc['db_query']('', '
  402. UPDATE {db_prefix}log_reported
  403. SET num_reports = num_reports + 1, time_updated = {int:current_time}
  404. WHERE id_report = {int:id_report}',
  405. array(
  406. 'current_time' => time(),
  407. 'id_report' => $id_report,
  408. )
  409. );
  410. // Otherwise, we shall make one!
  411. else
  412. {
  413. if (empty($message['real_name']))
  414. $message['real_name'] = $message['poster_name'];
  415. $smcFunc['db_insert']('',
  416. '{db_prefix}log_reported',
  417. array(
  418. 'id_msg' => 'int', 'id_topic' => 'int', 'id_board' => 'int', 'id_member' => 'int', 'membername' => 'string',
  419. 'subject' => 'string', 'body' => 'string', 'time_started' => 'int', 'time_updated' => 'int',
  420. 'num_reports' => 'int', 'closed' => 'int',
  421. ),
  422. array(
  423. $_POST['msg'], $message['id_topic'], $message['id_board'], $message['id_poster'], $message['real_name'],
  424. $message['subject'], $message['body'] , time(), time(), 1, 0,
  425. ),
  426. array('id_report')
  427. );
  428. $id_report = $smcFunc['db_insert_id']('{db_prefix}log_reported', 'id_report');
  429. }
  430. // Now just add our report...
  431. if ($id_report)
  432. {
  433. $smcFunc['db_insert']('',
  434. '{db_prefix}log_reported_comments',
  435. array(
  436. 'id_report' => 'int', 'id_member' => 'int', 'membername' => 'string',
  437. 'member_ip' => 'string', 'comment' => 'string', 'time_sent' => 'int',
  438. ),
  439. array(
  440. $id_report, $user_info['id'], $user_info['name'],
  441. $user_info['ip'], $poster_comment, time(),
  442. ),
  443. array('id_comment')
  444. );
  445. }
  446. // Find out who the real moderators are - for mod preferences.
  447. $request = $smcFunc['db_query']('', '
  448. SELECT id_member
  449. FROM {db_prefix}moderators
  450. WHERE id_board = {int:current_board}',
  451. array(
  452. 'current_board' => $board,
  453. )
  454. );
  455. $real_mods = array();
  456. while ($row = $smcFunc['db_fetch_assoc']($request))
  457. $real_mods[] = $row['id_member'];
  458. $smcFunc['db_free_result']($request);
  459. // Get any additional members who are in groups assigned to moderate this board
  460. $request = $smcFunc['db_query']('', '
  461. SELECT mem.id_member
  462. FROM {db_prefix}members AS mem, {db_prefix}moderator_groups AS bm
  463. WHERE bm.id_board = {int:current_board}
  464. AND(
  465. mem.id_group = bm.id_group
  466. OR FIND_IN_SET(bm.id_group, mem.additional_groups) != 0
  467. )',
  468. array(
  469. 'current_board' => $board,
  470. )
  471. );
  472. while ($row = $smcFunc['db_fetch_assoc']($request))
  473. $real_mods[] = $row['id_member'];
  474. $smcFunc['db_free_result']($request);
  475. // Make sure we don't have any duplicates
  476. $real_mods = array_unique($real_mods);
  477. // Get the mods who want to be notified of stuff...
  478. $request = $smcFunc['db_query']('', '
  479. SELECT id_member, email_address, lngfile, mod_prefs
  480. FROM {db_prefix}members
  481. WHERE id_member IN ({array_int:moderator_list})
  482. AND notify_types != {int:notify_types}
  483. ORDER BY lngfile',
  484. array(
  485. 'moderator_list' => $moderators,
  486. 'notify_types' => 4,
  487. )
  488. );
  489. // Send every moderator an email.
  490. while ($row = $smcFunc['db_fetch_assoc']($request))
  491. {
  492. // Maybe they don't want to know?!
  493. if (!empty($row['mod_prefs']))
  494. {
  495. list(,, $pref_binary) = explode('|', $row['mod_prefs']);
  496. if (!($pref_binary & 1) && (!($pref_binary & 2) || !in_array($row['id_member'], $real_mods)))
  497. continue;
  498. }
  499. $replacements = array(
  500. 'TOPICSUBJECT' => $subject,
  501. 'POSTERNAME' => $poster_name,
  502. 'REPORTERNAME' => $reporterName,
  503. 'TOPICLINK' => $scripturl . '?topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg'],
  504. 'REPORTLINK' => !empty($id_report) ? $scripturl . '?action=moderate;area=reports;report=' . $id_report : '',
  505. 'COMMENT' => $_POST['comment'],
  506. );
  507. $emaildata = loadEmailTemplate('report_to_moderator', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
  508. // Send it to the moderator.
  509. sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], null, null, false, 2);
  510. }
  511. $smcFunc['db_free_result']($request);
  512. // Keep track of when the mod reports get updated, that way we know when we need to look again.
  513. updateSettings(array('last_mod_report_action' => time()));
  514. // Back to the post we reported!
  515. redirectexit('reportsent;topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']);
  516. }
  517. ?>