SendTopic.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. // You can't use this if it's off or you are not allowed to do it.
  239. isAllowedTo('report_any');
  240. // If they're posting, it should be processed by ReportToModerator2.
  241. if ((isset($_POST[$context['session_var']]) || isset($_POST['save'])) && empty($context['post_errors']))
  242. ReportToModerator2();
  243. // We need a message ID to check!
  244. if (empty($_REQUEST['msg']) && empty($_REQUEST['mid']))
  245. fatal_lang_error('no_access', false);
  246. // For compatibility, accept mid, but we should be using msg. (not the flavor kind!)
  247. $_REQUEST['msg'] = empty($_REQUEST['msg']) ? (int) $_REQUEST['mid'] : (int) $_REQUEST['msg'];
  248. // Check the message's ID - don't want anyone reporting a post they can't even see!
  249. $result = $smcFunc['db_query']('', '
  250. SELECT m.id_msg, m.id_member, t.id_member_started
  251. FROM {db_prefix}messages AS m
  252. INNER JOIN {db_prefix}topics AS t ON (t.id_topic = {int:current_topic})
  253. WHERE m.id_msg = {int:id_msg}
  254. AND m.id_topic = {int:current_topic}
  255. LIMIT 1',
  256. array(
  257. 'current_topic' => $topic,
  258. 'id_msg' => $_REQUEST['msg'],
  259. )
  260. );
  261. if ($smcFunc['db_num_rows']($result) == 0)
  262. fatal_lang_error('no_board', false);
  263. list ($_REQUEST['msg'], $member, $starter) = $smcFunc['db_fetch_row']($result);
  264. $smcFunc['db_free_result']($result);
  265. // Do we need to show the visual verification image?
  266. $context['require_verification'] = $user_info['is_guest'] && !empty($modSettings['guests_report_require_captcha']);
  267. if ($context['require_verification'])
  268. {
  269. require_once($sourcedir . '/Subs-Editor.php');
  270. $verificationOptions = array(
  271. 'id' => 'report',
  272. );
  273. $context['require_verification'] = create_control_verification($verificationOptions);
  274. $context['visual_verification_id'] = $verificationOptions['id'];
  275. }
  276. // Show the inputs for the comment, etc.
  277. loadLanguage('Post');
  278. loadTemplate('SendTopic');
  279. addInlineJavascript('
  280. var error_box = $("#error_box");
  281. $("#report_comment").keyup(function() {
  282. var post_too_long = $("#error_post_too_long");
  283. if ($(this).val().length > 254)
  284. {
  285. if (post_too_long.length == 0)
  286. {
  287. error_box.show();
  288. if ($.trim(error_box.html()) == \'\')
  289. error_box.append("<ul id=\'error_list\'></ul>");
  290. $("#error_list").append("<li id=\'error_post_too_long\' class=\'error\'>" + ' . JavaScriptEscape($txt['post_too_long']) . ' + "</li>");
  291. }
  292. }
  293. else
  294. {
  295. post_too_long.remove();
  296. if ($("#error_list li").length == 0)
  297. error_box.hide();
  298. }
  299. });', true);
  300. $context['comment_body'] = !isset($_POST['comment']) ? '' : trim($_POST['comment']);
  301. $context['email_address'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
  302. // This is here so that the user could, in theory, be redirected back to the topic.
  303. $context['start'] = $_REQUEST['start'];
  304. $context['message_id'] = $_REQUEST['msg'];
  305. $context['page_title'] = $txt['report_to_mod'];
  306. $context['sub_template'] = 'report';
  307. }
  308. /**
  309. * Send the emails.
  310. * Sends off emails to all the moderators.
  311. * Sends to administrators and global moderators. (1 and 2)
  312. * Called by ReportToModerator(), and thus has the same permission and setting requirements as it does.
  313. * Accessed through ?action=reporttm when posting.
  314. */
  315. function ReportToModerator2()
  316. {
  317. global $txt, $scripturl, $topic, $board, $user_info, $modSettings, $sourcedir, $language, $context, $smcFunc;
  318. // You must have the proper permissions!
  319. isAllowedTo('report_any');
  320. // Make sure they aren't spamming.
  321. spamProtection('reporttm');
  322. require_once($sourcedir . '/Subs-Post.php');
  323. // No errors, yet.
  324. $post_errors = array();
  325. // Check their session.
  326. if (checkSession('post', '', false) != '')
  327. $post_errors[] = 'session_timeout';
  328. // Make sure we have a comment and it's clean.
  329. if (!isset($_POST['comment']) || $smcFunc['htmltrim']($_POST['comment']) === '')
  330. $post_errors[] = 'no_comment';
  331. $poster_comment = strtr($smcFunc['htmlspecialchars']($_POST['comment']), array("\r" => '', "\t" => ''));
  332. if ($smcFunc['strlen']($poster_comment) > 254)
  333. $post_errors[] = 'post_too_long';
  334. // Guests need to provide their address!
  335. if ($user_info['is_guest'])
  336. {
  337. $_POST['email'] = !isset($_POST['email']) ? '' : trim($_POST['email']);
  338. if ($_POST['email'] === '')
  339. $post_errors[] = 'no_email';
  340. elseif (preg_match('~^[0-9A-Za-z=_+\-/][0-9A-Za-z=_\'+\-/\.]*@[\w\-]+(\.[\w\-]+)*(\.[\w]{2,6})$~', $_POST['email']) == 0)
  341. $post_errors[] = 'bad_email';
  342. isBannedEmail($_POST['email'], 'cannot_post', sprintf($txt['you_are_post_banned'], $txt['guest_title']));
  343. $user_info['email'] = htmlspecialchars($_POST['email']);
  344. }
  345. // Could they get the right verification code?
  346. if ($user_info['is_guest'] && !empty($modSettings['guests_report_require_captcha']))
  347. {
  348. require_once($sourcedir . '/Subs-Editor.php');
  349. $verificationOptions = array(
  350. 'id' => 'report',
  351. );
  352. $context['require_verification'] = create_control_verification($verificationOptions, true);
  353. if (is_array($context['require_verification']))
  354. $post_errors = array_merge($post_errors, $context['require_verification']);
  355. }
  356. // Any errors?
  357. if (!empty($post_errors))
  358. {
  359. loadLanguage('Errors');
  360. $context['post_errors'] = array();
  361. foreach ($post_errors as $post_error)
  362. $context['post_errors'][$post_error] = $txt['error_' . $post_error];
  363. return ReportToModerator();
  364. }
  365. // Get the basic topic information, and make sure they can see it.
  366. $_POST['msg'] = (int) $_POST['msg'];
  367. $request = $smcFunc['db_query']('', '
  368. SELECT m.id_topic, m.id_board, m.subject, m.body, m.id_member AS id_poster, m.poster_name, mem.real_name
  369. FROM {db_prefix}messages AS m
  370. LEFT JOIN {db_prefix}members AS mem ON (m.id_member = mem.id_member)
  371. WHERE m.id_msg = {int:id_msg}
  372. AND m.id_topic = {int:current_topic}
  373. LIMIT 1',
  374. array(
  375. 'current_topic' => $topic,
  376. 'id_msg' => $_POST['msg'],
  377. )
  378. );
  379. if ($smcFunc['db_num_rows']($request) == 0)
  380. fatal_lang_error('no_board', false);
  381. $message = $smcFunc['db_fetch_assoc']($request);
  382. $smcFunc['db_free_result']($request);
  383. $poster_name = un_htmlspecialchars($message['real_name']) . ($message['real_name'] != $message['poster_name'] ? ' (' . $message['poster_name'] . ')' : '');
  384. $reporterName = un_htmlspecialchars($user_info['name']) . ($user_info['name'] != $user_info['username'] && $user_info['username'] != '' ? ' (' . $user_info['username'] . ')' : '');
  385. $subject = un_htmlspecialchars($message['subject']);
  386. // Get a list of members with the moderate_board permission.
  387. require_once($sourcedir . '/Subs-Members.php');
  388. $moderators = membersAllowedTo('moderate_board', $board);
  389. $request = $smcFunc['db_query']('', '
  390. SELECT id_member, email_address, lngfile, mod_prefs
  391. FROM {db_prefix}members
  392. WHERE id_member IN ({array_int:moderator_list})
  393. AND notify_types != {int:notify_types}
  394. ORDER BY lngfile',
  395. array(
  396. 'moderator_list' => $moderators,
  397. 'notify_types' => 4,
  398. )
  399. );
  400. // Check that moderators do exist!
  401. if ($smcFunc['db_num_rows']($request) == 0)
  402. fatal_lang_error('no_mods', false);
  403. // If we get here, I believe we should make a record of this, for historical significance, yabber.
  404. if (empty($modSettings['disable_log_report']))
  405. {
  406. $request2 = $smcFunc['db_query']('', '
  407. SELECT id_report, ignore_all
  408. FROM {db_prefix}log_reported
  409. WHERE id_msg = {int:id_msg}
  410. AND (closed = {int:not_closed} OR ignore_all = {int:ignored})
  411. ORDER BY ignore_all DESC',
  412. array(
  413. 'id_msg' => $_POST['msg'],
  414. 'not_closed' => 0,
  415. 'ignored' => 1,
  416. )
  417. );
  418. if ($smcFunc['db_num_rows']($request2) != 0)
  419. list ($id_report, $ignore) = $smcFunc['db_fetch_row']($request2);
  420. $smcFunc['db_free_result']($request2);
  421. // If we're just going to ignore these, then who gives a monkeys...
  422. if (!empty($ignore))
  423. redirectexit('topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']);
  424. // Already reported? My god, we could be dealing with a real rogue here...
  425. if (!empty($id_report))
  426. $smcFunc['db_query']('', '
  427. UPDATE {db_prefix}log_reported
  428. SET num_reports = num_reports + 1, time_updated = {int:current_time}
  429. WHERE id_report = {int:id_report}',
  430. array(
  431. 'current_time' => time(),
  432. 'id_report' => $id_report,
  433. )
  434. );
  435. // Otherwise, we shall make one!
  436. else
  437. {
  438. if (empty($message['real_name']))
  439. $message['real_name'] = $message['poster_name'];
  440. $smcFunc['db_insert']('',
  441. '{db_prefix}log_reported',
  442. array(
  443. 'id_msg' => 'int', 'id_topic' => 'int', 'id_board' => 'int', 'id_member' => 'int', 'membername' => 'string',
  444. 'subject' => 'string', 'body' => 'string', 'time_started' => 'int', 'time_updated' => 'int',
  445. 'num_reports' => 'int', 'closed' => 'int',
  446. ),
  447. array(
  448. $_POST['msg'], $message['id_topic'], $message['id_board'], $message['id_poster'], $message['real_name'],
  449. $message['subject'], $message['body'] , time(), time(), 1, 0,
  450. ),
  451. array('id_report')
  452. );
  453. $id_report = $smcFunc['db_insert_id']('{db_prefix}log_reported', 'id_report');
  454. }
  455. // Now just add our report...
  456. if ($id_report)
  457. {
  458. $smcFunc['db_insert']('',
  459. '{db_prefix}log_reported_comments',
  460. array(
  461. 'id_report' => 'int', 'id_member' => 'int', 'membername' => 'string', 'email_address' => 'string',
  462. 'member_ip' => 'string', 'comment' => 'string', 'time_sent' => 'int',
  463. ),
  464. array(
  465. $id_report, $user_info['id'], $user_info['name'], $user_info['email'],
  466. $user_info['ip'], $poster_comment, time(),
  467. ),
  468. array('id_comment')
  469. );
  470. }
  471. }
  472. // Find out who the real moderators are - for mod preferences.
  473. $request2 = $smcFunc['db_query']('', '
  474. SELECT id_member
  475. FROM {db_prefix}moderators
  476. WHERE id_board = {int:current_board}',
  477. array(
  478. 'current_board' => $board,
  479. )
  480. );
  481. $real_mods = array();
  482. while ($row = $smcFunc['db_fetch_assoc']($request2))
  483. $real_mods[] = $row['id_member'];
  484. $smcFunc['db_free_result']($request2);
  485. // Get any additional members who are in groups assigned to moderate this board
  486. $request3 = $smcFunc['db_query']('', '
  487. SELECT mem.id_member
  488. FROM {db_prefix}members AS mem, {db_prefix}moderator_groups AS bm
  489. WHERE bm.id_board = {int:current_board}
  490. AND(
  491. mem.id_group = bm.id_group
  492. OR FIND_IN_SET(bm.id_group, mem.additional_groups) != 0
  493. )',
  494. array(
  495. 'current_board' => $board,
  496. )
  497. );
  498. while ($row = $smcFunc['db_fetch_assoc']($request3))
  499. $real_mods[] = $row['id_member'];
  500. $smcFunc['db_free_result']($request3);
  501. // Make sure we don't have any duplicates
  502. $real_mods = array_unique($real_mods);
  503. // Send every moderator an email.
  504. while ($row = $smcFunc['db_fetch_assoc']($request))
  505. {
  506. // Maybe they don't want to know?!
  507. if (!empty($row['mod_prefs']))
  508. {
  509. list(,, $pref_binary) = explode('|', $row['mod_prefs']);
  510. if (!($pref_binary & 1) && (!($pref_binary & 2) || !in_array($row['id_member'], $real_mods)))
  511. continue;
  512. }
  513. $replacements = array(
  514. 'TOPICSUBJECT' => $subject,
  515. 'POSTERNAME' => $poster_name,
  516. 'REPORTERNAME' => $reporterName,
  517. 'TOPICLINK' => $scripturl . '?topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg'],
  518. 'REPORTLINK' => !empty($id_report) ? $scripturl . '?action=moderate;area=reports;report=' . $id_report : '',
  519. 'COMMENT' => $_POST['comment'],
  520. );
  521. $emaildata = loadEmailTemplate('report_to_moderator', $replacements, empty($row['lngfile']) || empty($modSettings['userLanguage']) ? $language : $row['lngfile']);
  522. // Send it to the moderator.
  523. sendmail($row['email_address'], $emaildata['subject'], $emaildata['body'], $user_info['email'], null, false, 2);
  524. }
  525. $smcFunc['db_free_result']($request);
  526. // Keep track of when the mod reports get updated, that way we know when we need to look again.
  527. updateSettings(array('last_mod_report_action' => time()));
  528. // Back to the post we reported!
  529. redirectexit('reportsent;topic=' . $topic . '.msg' . $_POST['msg'] . '#msg' . $_POST['msg']);
  530. }
  531. ?>