ModerationCenter.php 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796
  1. <?php
  2. /**
  3. * Moderation Center.
  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. * Entry point for the moderation center.
  18. *
  19. * @param bool $dont_call = false
  20. */
  21. function ModerationMain($dont_call = false)
  22. {
  23. global $txt, $context, $scripturl, $sc, $modSettings, $user_info, $sourcedir, $options, $smcFunc;
  24. // Don't run this twice... and don't conflict with the admin bar.
  25. if (isset($context['admin_area']))
  26. return;
  27. $context['can_moderate_boards'] = $user_info['mod_cache']['bq'] != '0=1';
  28. $context['can_moderate_groups'] = $user_info['mod_cache']['gq'] != '0=1';
  29. $context['can_moderate_approvals'] = $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']);
  30. // Everyone using this area must be allowed here!
  31. if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'])
  32. isAllowedTo('access_mod_center');
  33. // We're gonna want a menu of some kind.
  34. require_once($sourcedir . '/Subs-Menu.php');
  35. // Load the language, and the template.
  36. loadLanguage('ModerationCenter');
  37. loadTemplate(false, 'admin');
  38. $context['admin_preferences'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array();
  39. $context['robot_no_index'] = true;
  40. // This is the menu structure - refer to Subs-Menu.php for the details.
  41. $moderation_areas = array(
  42. 'main' => array(
  43. 'title' => $txt['mc_main'],
  44. 'areas' => array(
  45. 'index' => array(
  46. 'label' => $txt['moderation_center'],
  47. 'function' => 'ModerationHome',
  48. 'icon' => 'administration.png',
  49. ),
  50. 'settings' => array(
  51. 'label' => $txt['mc_settings'],
  52. 'function' => 'ModerationSettings',
  53. 'icon' => 'features.png',
  54. ),
  55. 'modlogoff' => array(
  56. 'label' => $txt['mc_logoff'],
  57. 'function' => 'ModEndSession',
  58. 'enabled' => empty($modSettings['securityDisable_moderate']),
  59. 'icon' => 'exit.png',
  60. ),
  61. 'notice' => array(
  62. 'file' => 'ModerationCenter.php',
  63. 'function' => 'ShowNotice',
  64. 'select' => 'index'
  65. ),
  66. ),
  67. ),
  68. 'logs' => array(
  69. 'title' => $txt['mc_logs'],
  70. 'areas' => array(
  71. 'modlog' => array(
  72. 'label' => $txt['modlog_view'],
  73. 'enabled' => !empty($modSettings['modlog_enabled']) && $context['can_moderate_boards'],
  74. 'file' => 'Modlog.php',
  75. 'function' => 'ViewModlog',
  76. 'icon' => 'logs.png',
  77. ),
  78. 'warnings' => array(
  79. 'label' => $txt['mc_warnings'],
  80. 'enabled' => $modSettings['warning_settings'][0] == 1 && $context['can_moderate_boards'],
  81. 'function' => 'ViewWarnings',
  82. 'icon' => 'warning.png',
  83. 'subsections' => array(
  84. 'log' => array($txt['mc_warning_log']),
  85. 'templates' => array($txt['mc_warning_templates'], 'issue_warning'),
  86. ),
  87. ),
  88. ),
  89. ),
  90. 'posts' => array(
  91. 'title' => $txt['mc_posts'],
  92. 'enabled' => $context['can_moderate_boards'] || $context['can_moderate_approvals'],
  93. 'areas' => array(
  94. 'postmod' => array(
  95. 'label' => $txt['mc_unapproved_posts'],
  96. 'enabled' => $context['can_moderate_approvals'],
  97. 'file' => 'PostModeration.php',
  98. 'function' => 'PostModerationMain',
  99. 'icon' => 'posts.png',
  100. 'custom_url' => $scripturl . '?action=moderate;area=postmod',
  101. 'subsections' => array(
  102. 'posts' => array($txt['mc_unapproved_replies']),
  103. 'topics' => array($txt['mc_unapproved_topics']),
  104. ),
  105. ),
  106. 'attachmod' => array(
  107. 'label' => $txt['mc_unapproved_attachments'],
  108. 'enabled' => $context['can_moderate_approvals'],
  109. 'file' => 'PostModeration.php',
  110. 'function' => 'PostModerationMain',
  111. 'icon' => 'post_moderation_attach.png',
  112. 'custom_url' => $scripturl . '?action=moderate;area=attachmod;sa=attachments',
  113. ),
  114. 'reports' => array(
  115. 'label' => $txt['mc_reported_posts'],
  116. 'enabled' => $context['can_moderate_boards'],
  117. 'file' => 'ModerationCenter.php',
  118. 'function' => 'ReportedPosts',
  119. 'icon' => 'reports.png',
  120. 'subsections' => array(
  121. 'open' => array($txt['mc_reportedp_active']),
  122. 'closed' => array($txt['mc_reportedp_closed']),
  123. ),
  124. ),
  125. ),
  126. ),
  127. 'groups' => array(
  128. 'title' => $txt['mc_groups'],
  129. 'enabled' => $context['can_moderate_groups'],
  130. 'areas' => array(
  131. 'userwatch' => array(
  132. 'label' => $txt['mc_watched_users_title'],
  133. 'enabled' => $modSettings['warning_settings'][0] == 1 && $context['can_moderate_boards'],
  134. 'function' => 'ViewWatchedUsers',
  135. 'icon' => 'members_watched.png',
  136. 'subsections' => array(
  137. 'member' => array($txt['mc_watched_users_member']),
  138. 'post' => array($txt['mc_watched_users_post']),
  139. ),
  140. ),
  141. 'groups' => array(
  142. 'label' => $txt['mc_group_requests'],
  143. 'file' => 'Groups.php',
  144. 'function' => 'Groups',
  145. 'icon' => 'members_request.png',
  146. 'custom_url' => $scripturl . '?action=moderate;area=groups;sa=requests',
  147. ),
  148. 'viewgroups' => array(
  149. 'label' => $txt['mc_view_groups'],
  150. 'file' => 'Groups.php',
  151. 'function' => 'Groups',
  152. 'icon' => 'membergroups.png',
  153. ),
  154. ),
  155. ),
  156. );
  157. // Make sure the administrator has a valid session...
  158. validateSession('moderate');
  159. // I don't know where we're going - I don't know where we've been...
  160. $menuOptions = array(
  161. 'action' => 'moderate',
  162. 'disable_url_session_check' => true,
  163. );
  164. $mod_include_data = createMenu($moderation_areas, $menuOptions);
  165. unset($moderation_areas);
  166. // We got something - didn't we? DIDN'T WE!
  167. if ($mod_include_data == false)
  168. fatal_lang_error('no_access', false);
  169. // Retain the ID information in case required by a subaction.
  170. $context['moderation_menu_id'] = $context['max_menu_id'];
  171. $context['moderation_menu_name'] = 'menu_data_' . $context['moderation_menu_id'];
  172. // @todo: html in here is not good
  173. $context[$context['moderation_menu_name']]['tab_data'] = array(
  174. 'title' => $txt['moderation_center'],
  175. 'help' => '',
  176. 'description' => '
  177. <strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong>
  178. <br><br>
  179. ' . $txt['mc_description']);
  180. // What a pleasant shortcut - even tho we're not *really* on the admin screen who cares...
  181. $context['admin_area'] = $mod_include_data['current_area'];
  182. // Build the link tree.
  183. $context['linktree'][] = array(
  184. 'url' => $scripturl . '?action=moderate',
  185. 'name' => $txt['moderation_center'],
  186. );
  187. if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index')
  188. $context['linktree'][] = array(
  189. 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'],
  190. 'name' => $mod_include_data['label'],
  191. );
  192. if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label'])
  193. $context['linktree'][] = array(
  194. 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'] . ';sa=' . $mod_include_data['current_subsection'],
  195. 'name' => $mod_include_data['subsections'][$mod_include_data['current_subsection']][0],
  196. );
  197. // Now - finally - the bit before the encore - the main performance of course!
  198. if (!$dont_call)
  199. {
  200. if (isset($mod_include_data['file']))
  201. require_once($sourcedir . '/' . $mod_include_data['file']);
  202. $mod_include_data['function']();
  203. }
  204. }
  205. /**
  206. * This function basically is the home page of the moderation center.
  207. */
  208. function ModerationHome()
  209. {
  210. global $txt, $context, $scripturl, $user_info, $user_settings, $options;
  211. loadTemplate('ModerationCenter');
  212. loadJavascriptFile('admin.js', array('default_theme' => true), 'admin.js');
  213. $context['page_title'] = $txt['moderation_center'];
  214. $context['sub_template'] = 'moderation_center';
  215. // Handle moderators notes.
  216. ModBlockNotes();
  217. // Load what blocks the user actually can see...
  218. $valid_blocks = array();
  219. if ($context['can_moderate_groups'])
  220. $valid_blocks['g'] = 'GroupRequests';
  221. if ($context['can_moderate_boards'])
  222. {
  223. $valid_blocks['r'] = 'ReportedPosts';
  224. $valid_blocks['w'] = 'WatchedUsers';
  225. }
  226. call_integration_hook('integrate_mod_centre_blocks', array(&$valid_blocks));
  227. $context['mod_blocks'] = array();
  228. foreach ($valid_blocks as $k => $block)
  229. {
  230. $block = 'ModBlock' . $block;
  231. if (function_exists($block))
  232. $context['mod_blocks'][] = $block();
  233. }
  234. $context['admin_prefs'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array();
  235. }
  236. /**
  237. * Show a list of the most active watched users.
  238. */
  239. function ModBlockWatchedUsers()
  240. {
  241. global $context, $smcFunc, $scripturl, $modSettings;
  242. if (($watched_users = cache_get_data('recent_user_watches', 240)) === null)
  243. {
  244. $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch'];
  245. $request = $smcFunc['db_query']('', '
  246. SELECT id_member, real_name, last_login
  247. FROM {db_prefix}members
  248. WHERE warning >= {int:warning_watch}
  249. ORDER BY last_login DESC
  250. LIMIT 10',
  251. array(
  252. 'warning_watch' => $modSettings['warning_watch'],
  253. )
  254. );
  255. $watched_users = array();
  256. while ($row = $smcFunc['db_fetch_assoc']($request))
  257. $watched_users[] = $row;
  258. $smcFunc['db_free_result']($request);
  259. cache_put_data('recent_user_watches', $watched_users, 240);
  260. }
  261. $context['watched_users'] = array();
  262. foreach ($watched_users as $user)
  263. {
  264. $context['watched_users'][] = array(
  265. 'id' => $user['id_member'],
  266. 'name' => $user['real_name'],
  267. 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $user['id_member'] . '">' . $user['real_name'] . '</a>',
  268. 'href' => $scripturl . '?action=profile;u=' . $user['id_member'],
  269. 'last_login' => !empty($user['last_login']) ? timeformat($user['last_login']) : '',
  270. );
  271. }
  272. return 'watched_users';
  273. }
  274. /**
  275. * Show an area for the moderator to type into.
  276. */
  277. function ModBlockNotes()
  278. {
  279. global $context, $smcFunc, $scripturl, $txt, $user_info;
  280. // Are we saving a note?
  281. if (isset($_GET['modnote']) && isset($_POST['makenote']) && isset($_POST['new_note']))
  282. {
  283. checkSession();
  284. $_POST['new_note'] = $smcFunc['htmlspecialchars'](trim($_POST['new_note']));
  285. // Make sure they actually entered something.
  286. if (!empty($_POST['new_note']) && $_POST['new_note'] !== $txt['mc_click_add_note'])
  287. {
  288. // Insert it into the database then!
  289. $smcFunc['db_insert']('',
  290. '{db_prefix}log_comments',
  291. array(
  292. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string',
  293. 'body' => 'string', 'log_time' => 'int',
  294. ),
  295. array(
  296. $user_info['id'], $user_info['name'], 'modnote', '', $_POST['new_note'], time(),
  297. ),
  298. array('id_comment')
  299. );
  300. // Clear the cache.
  301. cache_put_data('moderator_notes', null, 240);
  302. cache_put_data('moderator_notes_total', null, 240);
  303. }
  304. // Redirect otherwise people can resubmit.
  305. redirectexit('action=moderate');
  306. }
  307. // Bye... bye...
  308. if (isset($_GET['notes']) && isset($_GET['delete']) && is_numeric($_GET['delete']))
  309. {
  310. checkSession('get');
  311. // Lets delete it.
  312. $smcFunc['db_query']('', '
  313. DELETE FROM {db_prefix}log_comments
  314. WHERE id_comment = {int:note}
  315. AND comment_type = {string:type}',
  316. array(
  317. 'note' => $_GET['delete'],
  318. 'type' => 'modnote',
  319. )
  320. );
  321. // Clear the cache.
  322. cache_put_data('moderator_notes', null, 240);
  323. cache_put_data('moderator_notes_total', null, 240);
  324. redirectexit('action=moderate');
  325. }
  326. // How many notes in total?
  327. if (($moderator_notes_total = cache_get_data('moderator_notes_total', 240)) === null)
  328. {
  329. $request = $smcFunc['db_query']('', '
  330. SELECT COUNT(*)
  331. FROM {db_prefix}log_comments AS lc
  332. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  333. WHERE lc.comment_type = {string:modnote}',
  334. array(
  335. 'modnote' => 'modnote',
  336. )
  337. );
  338. list ($moderator_notes_total) = $smcFunc['db_fetch_row']($request);
  339. $smcFunc['db_free_result']($request);
  340. cache_put_data('moderator_notes_total', $moderator_notes_total, 240);
  341. }
  342. // Grab the current notes. We can only use the cache for the first page of notes.
  343. $offset = isset($_GET['notes']) && isset($_GET['start']) ? $_GET['start'] : 0;
  344. if ($offset != 0 || ($moderator_notes = cache_get_data('moderator_notes', 240)) === null)
  345. {
  346. $request = $smcFunc['db_query']('', '
  347. SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name,
  348. lc.log_time, lc.body, lc.id_comment AS id_note
  349. FROM {db_prefix}log_comments AS lc
  350. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  351. WHERE lc.comment_type = {string:modnote}
  352. ORDER BY id_comment DESC
  353. LIMIT {int:offset}, 10',
  354. array(
  355. 'modnote' => 'modnote',
  356. 'offset' => $offset,
  357. )
  358. );
  359. $moderator_notes = array();
  360. while ($row = $smcFunc['db_fetch_assoc']($request))
  361. $moderator_notes[] = $row;
  362. $smcFunc['db_free_result']($request);
  363. if ($offset == 0)
  364. cache_put_data('moderator_notes', $moderator_notes, 240);
  365. }
  366. // Lets construct a page index.
  367. $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=index;notes', $_GET['start'], $moderator_notes_total, 10);
  368. $context['start'] = $_GET['start'];
  369. $context['notes'] = array();
  370. foreach ($moderator_notes as $note)
  371. {
  372. $context['notes'][] = array(
  373. 'author' => array(
  374. 'id' => $note['id_member'],
  375. 'link' => $note['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $note['id_member'] . '">' . $note['member_name'] . '</a>') : $note['member_name'],
  376. ),
  377. 'time' => timeformat($note['log_time']),
  378. 'text' => parse_bbc($note['body']),
  379. 'delete_href' => $scripturl . '?action=moderate;area=index;notes;delete=' . $note['id_note'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  380. );
  381. }
  382. return 'notes';
  383. }
  384. /**
  385. * Show a list of the most recent reported posts.
  386. */
  387. function ModBlockReportedPosts()
  388. {
  389. global $context, $user_info, $scripturl, $smcFunc;
  390. // Got the info already?
  391. $cachekey = md5(serialize($user_info['mod_cache']['bq']));
  392. $context['reported_posts'] = array();
  393. if ($user_info['mod_cache']['bq'] == '0=1')
  394. return 'reported_posts_block';
  395. if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null)
  396. {
  397. // By George, that means we in a position to get the reports, jolly good.
  398. $request = $smcFunc['db_query']('', '
  399. SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject,
  400. lr.num_reports, IFNULL(mem.real_name, lr.membername) AS author_name,
  401. IFNULL(mem.id_member, 0) AS id_author
  402. FROM {db_prefix}log_reported AS lr
  403. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  404. WHERE ' . ($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']) . '
  405. AND lr.closed = {int:not_closed}
  406. AND lr.ignore_all = {int:not_ignored}
  407. ORDER BY lr.time_updated DESC
  408. LIMIT 10',
  409. array(
  410. 'not_closed' => 0,
  411. 'not_ignored' => 0,
  412. )
  413. );
  414. $reported_posts = array();
  415. while ($row = $smcFunc['db_fetch_assoc']($request))
  416. $reported_posts[] = $row;
  417. $smcFunc['db_free_result']($request);
  418. // Cache it.
  419. cache_put_data('reported_posts_' . $cachekey, $reported_posts, 90);
  420. }
  421. $context['reported_posts'] = array();
  422. foreach ($reported_posts as $i => $row)
  423. {
  424. $context['reported_posts'][] = array(
  425. 'id' => $row['id_report'],
  426. 'alternate' => $i % 2,
  427. 'topic_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
  428. 'report_href' => $scripturl . '?action=moderate;area=reports;report=' . $row['id_report'],
  429. 'author' => array(
  430. 'id' => $row['id_author'],
  431. 'name' => $row['author_name'],
  432. 'link' => $row['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_author'] . '">' . $row['author_name'] . '</a>' : $row['author_name'],
  433. 'href' => $scripturl . '?action=profile;u=' . $row['id_author'],
  434. ),
  435. 'comments' => array(),
  436. 'subject' => $row['subject'],
  437. 'num_reports' => $row['num_reports'],
  438. );
  439. }
  440. return 'reported_posts_block';
  441. }
  442. /**
  443. * Show a list of all the group requests they can see.
  444. */
  445. function ModBlockGroupRequests()
  446. {
  447. global $context, $user_info, $scripturl, $smcFunc;
  448. $context['group_requests'] = array();
  449. // Make sure they can even moderate someone!
  450. if ($user_info['mod_cache']['gq'] == '0=1')
  451. return 'group_requests_block';
  452. // What requests are outstanding?
  453. $request = $smcFunc['db_query']('', '
  454. SELECT lgr.id_request, lgr.id_member, lgr.id_group, lgr.time_applied, mem.member_name, mg.group_name, mem.real_name
  455. FROM {db_prefix}log_group_requests AS lgr
  456. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = lgr.id_member)
  457. INNER JOIN {db_prefix}membergroups AS mg ON (mg.id_group = lgr.id_group)
  458. WHERE ' . ($user_info['mod_cache']['gq'] == '1=1' || $user_info['mod_cache']['gq'] == '0=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']) . '
  459. AND lgr.status = {int:status_open}
  460. ORDER BY lgr.id_request DESC
  461. LIMIT 10',
  462. array(
  463. 'status_open' => 0,
  464. )
  465. );
  466. for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i ++)
  467. {
  468. $context['group_requests'][] = array(
  469. 'id' => $row['id_request'],
  470. 'alternate' => $i % 2,
  471. 'request_href' => $scripturl . '?action=groups;sa=requests;gid=' . $row['id_group'],
  472. 'member' => array(
  473. 'id' => $row['id_member'],
  474. 'name' => $row['real_name'],
  475. 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
  476. 'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
  477. ),
  478. 'group' => array(
  479. 'id' => $row['id_group'],
  480. 'name' => $row['group_name'],
  481. ),
  482. 'time_submitted' => timeformat($row['time_applied']),
  483. );
  484. }
  485. $smcFunc['db_free_result']($request);
  486. return 'group_requests_block';
  487. }
  488. /**
  489. * Browse all the reported posts...
  490. * @todo this needs to be given its own file?
  491. */
  492. function ReportedPosts()
  493. {
  494. global $txt, $context, $scripturl, $user_info, $smcFunc;
  495. loadTemplate('ModerationCenter');
  496. // Set an empty var for the server response.
  497. $context['report_post_action'] = '';
  498. // Put the open and closed options into tabs, because we can...
  499. $context[$context['moderation_menu_name']]['tab_data'] = array(
  500. 'title' => $txt['mc_reported_posts'],
  501. 'help' => '',
  502. 'description' => $txt['mc_reported_posts_desc'],
  503. );
  504. // This comes under the umbrella of moderating posts.
  505. if ($user_info['mod_cache']['bq'] == '0=1')
  506. isAllowedTo('moderate_forum');
  507. // Are they wanting to view a particular report?
  508. if (!empty($_REQUEST['report']))
  509. return ModReport();
  510. // Set up the comforting bits...
  511. $context['page_title'] = $txt['mc_reported_posts'];
  512. $context['sub_template'] = 'reported_posts';
  513. // Are we viewing open or closed reports?
  514. $context['view_closed'] = isset($_GET['sa']) && $_GET['sa'] == 'closed' ? 1 : 0;
  515. // Are we doing any work?
  516. if ((isset($_GET['ignore']) || isset($_GET['close'])) && isset($_GET['rid']))
  517. {
  518. checkSession('get');
  519. $_GET['rid'] = (int) $_GET['rid'];
  520. // Update the report...
  521. $smcFunc['db_query']('', '
  522. UPDATE {db_prefix}log_reported
  523. SET ' . (isset($_GET['ignore']) ? 'ignore_all = {int:ignore_all}' : 'closed = {int:closed}') . '
  524. WHERE id_report = {int:id_report}
  525. AND ' . $user_info['mod_cache']['bq'],
  526. array(
  527. 'ignore_all' => isset($_GET['ignore']) ? (int) $_GET['ignore'] : 0,
  528. 'closed' => isset($_GET['close']) ? (int) $_GET['close'] : 0,
  529. 'id_report' => $_GET['rid'],
  530. )
  531. );
  532. // Get the board, topic and message for this report
  533. $request = $smcFunc['db_query']('', '
  534. SELECT id_board, id_topic, id_msg
  535. FROM {db_prefix}log_reported
  536. WHERE id_report = {int:id_report}',
  537. array(
  538. 'id_report' => $_GET['rid'],
  539. )
  540. );
  541. // Set up the data for the log...
  542. $extra = array('report' => $_GET['rid']);
  543. list ($extra['board'], $extra['topic'], $extra['message']) = $smcFunc['db_fetch_row']($request);
  544. $smcFunc['db_free_result']($request);
  545. // Tell the user about it.
  546. $context['report_post_action'] = isset($_GET['ignore']) ? (!empty($_GET['ignore']) ? 'ignore' : 'unignore') : (!empty($_GET['close']) ? 'close' : 'open');
  547. // Log this action
  548. logAction($context['report_post_action'] . '_report', $extra);
  549. // Time to update.
  550. updateSettings(array('last_mod_report_action' => time()));
  551. recountOpenReports();
  552. }
  553. elseif (isset($_POST['close']) && isset($_POST['close_selected']))
  554. {
  555. checkSession();
  556. // All the ones to update...
  557. $toClose = array();
  558. foreach ($_POST['close'] as $rid)
  559. $toClose[] = (int) $rid;
  560. if (!empty($toClose))
  561. {
  562. // Get the data for each of these reports
  563. $request = $smcFunc['db_query']('', '
  564. SELECT id_report, id_board, id_topic, id_msg
  565. FROM {db_prefix}log_reported
  566. WHERE id_report IN ({array_int:report_list})
  567. AND ' . $user_inf['mod_cache']['bq'],
  568. array(
  569. 'id_report' => $_GET['rid'],
  570. )
  571. );
  572. while ($reports = $smcFunc['db_fetch_assoc']($request))
  573. {
  574. $report_data = array(
  575. 'report' => $row['id_report'],
  576. 'board' => $row['id_board'],
  577. 'topic' => $row['id_topic'],
  578. 'message' => $row['id_msg'],
  579. );
  580. // Log that this report was closed
  581. logAction('close_report', $report_data);
  582. }
  583. $smcFunc['db_free_result']($request);
  584. $smcFunc['db_query']('', '
  585. UPDATE {db_prefix}log_reported
  586. SET closed = {int:is_closed}
  587. WHERE id_report IN ({array_int:report_list})
  588. AND ' . $user_info['mod_cache']['bq'],
  589. array(
  590. 'report_list' => $toClose,
  591. 'is_closed' => 1,
  592. )
  593. );
  594. // Time to update.
  595. updateSettings(array('last_mod_report_action' => time()));
  596. recountOpenReports();
  597. }
  598. // Go on and tell the result.
  599. $context['report_post_action'] = 'close_all';
  600. }
  601. // Do we deleted a message?
  602. if (isset($_REQUEST['done']))
  603. $context['report_post_action'] = 'message_deleted';
  604. }
  605. /**
  606. * Act as an entrace for all group related activity.
  607. * @todo As for most things in this file, this needs to be moved somewhere appropriate?
  608. */
  609. function ModerateGroups()
  610. {
  611. global $txt, $context, $scripturl, $user_info;
  612. // You need to be allowed to moderate groups...
  613. if ($user_info['mod_cache']['gq'] == '0=1')
  614. isAllowedTo('manage_membergroups');
  615. // Load the group templates.
  616. loadTemplate('ModerationCenter');
  617. // Setup the subactions...
  618. $subactions = array(
  619. 'requests' => 'GroupRequests',
  620. 'view' => 'ViewGroups',
  621. );
  622. if (!isset($_GET['sa']) || !isset($subactions[$_GET['sa']]))
  623. $_GET['sa'] = 'view';
  624. $context['sub_action'] = $_GET['sa'];
  625. // Call the relevant function.
  626. $subactions[$context['sub_action']]();
  627. }
  628. /**
  629. * Show a notice sent to a user.
  630. */
  631. function ShowNotice()
  632. {
  633. global $smcFunc, $txt, $context;
  634. $context['page_title'] = $txt['show_notice'];
  635. $context['sub_template'] = 'show_notice';
  636. $context['template_layers'] = array();
  637. loadTemplate('ModerationCenter');
  638. // @todo Assumes nothing needs permission more than accessing moderation center!
  639. $id_notice = (int) $_GET['nid'];
  640. $request = $smcFunc['db_query']('', '
  641. SELECT body, subject
  642. FROM {db_prefix}log_member_notices
  643. WHERE id_notice = {int:id_notice}',
  644. array(
  645. 'id_notice' => $id_notice,
  646. )
  647. );
  648. if ($smcFunc['db_num_rows']($request) == 0)
  649. fatal_lang_error('no_access', false);
  650. list ($context['notice_body'], $context['notice_subject']) = $smcFunc['db_fetch_row']($request);
  651. $smcFunc['db_free_result']($request);
  652. $context['notice_body'] = parse_bbc($context['notice_body'], false);
  653. }
  654. /**
  655. * View watched users.
  656. */
  657. function ViewWatchedUsers()
  658. {
  659. global $smcFunc, $modSettings, $context, $txt, $scripturl, $user_info, $sourcedir;
  660. // Some important context!
  661. $context['page_title'] = $txt['mc_watched_users_title'];
  662. $context['view_posts'] = isset($_GET['sa']) && $_GET['sa'] == 'post';
  663. $context['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
  664. loadTemplate('ModerationCenter');
  665. // Get some key settings!
  666. $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch'];
  667. // Put some pretty tabs on cause we're gonna be doing hot stuff here...
  668. $context[$context['moderation_menu_name']]['tab_data'] = array(
  669. 'title' => $txt['mc_watched_users_title'],
  670. 'help' => '',
  671. 'description' => $txt['mc_watched_users_desc'],
  672. );
  673. // First off - are we deleting?
  674. if (!empty($_REQUEST['delete']))
  675. {
  676. checkSession(!is_array($_REQUEST['delete']) ? 'get' : 'post');
  677. $toDelete = array();
  678. if (!is_array($_REQUEST['delete']))
  679. $toDelete[] = (int) $_REQUEST['delete'];
  680. else
  681. foreach ($_REQUEST['delete'] as $did)
  682. $toDelete[] = (int) $did;
  683. if (!empty($toDelete))
  684. {
  685. require_once($sourcedir . '/RemoveTopic.php');
  686. // If they don't have permission we'll let it error - either way no chance of a security slip here!
  687. foreach ($toDelete as $did)
  688. removeMessage($did);
  689. }
  690. }
  691. // Start preparing the list by grabbing relevant permissions.
  692. if (!$context['view_posts'])
  693. {
  694. $approve_query = '';
  695. $delete_boards = array();
  696. }
  697. else
  698. {
  699. // Still obey permissions!
  700. $approve_boards = boardsAllowedTo('approve_posts');
  701. $delete_boards = boardsAllowedTo('delete_any');
  702. if ($approve_boards == array(0))
  703. $approve_query = '';
  704. elseif (!empty($approve_boards))
  705. $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
  706. // Nada, zip, etc...
  707. else
  708. $approve_query = ' AND 1=0';
  709. }
  710. require_once($sourcedir . '/Subs-List.php');
  711. // This is all the information required for a watched user listing.
  712. $listOptions = array(
  713. 'id' => 'watch_user_list',
  714. 'title' => $txt['mc_watched_users_title'] . ' - ' . ($context['view_posts'] ? $txt['mc_watched_users_post'] : $txt['mc_watched_users_member']),
  715. 'width' => '100%',
  716. 'items_per_page' => $modSettings['defaultMaxMessages'],
  717. 'no_items_label' => $context['view_posts'] ? $txt['mc_watched_users_no_posts'] : $txt['mc_watched_users_none'],
  718. 'base_href' => $scripturl . '?action=moderate;area=userwatch;sa=' . ($context['view_posts'] ? 'post' : 'member'),
  719. 'default_sort_col' => $context['view_posts'] ? '' : 'member',
  720. 'get_items' => array(
  721. 'function' => $context['view_posts'] ? 'list_getWatchedUserPosts' : 'list_getWatchedUsers',
  722. 'params' => array(
  723. $approve_query,
  724. $delete_boards,
  725. ),
  726. ),
  727. 'get_count' => array(
  728. 'function' => $context['view_posts'] ? 'list_getWatchedUserPostsCount' : 'list_getWatchedUserCount',
  729. 'params' => array(
  730. $approve_query,
  731. ),
  732. ),
  733. // This assumes we are viewing by user.
  734. 'columns' => array(
  735. 'member' => array(
  736. 'header' => array(
  737. 'value' => $txt['mc_watched_users_member'],
  738. ),
  739. 'data' => array(
  740. 'sprintf' => array(
  741. 'format' => '<a href="' . $scripturl . '?action=profile;u=%1$d">%2$s</a>',
  742. 'params' => array(
  743. 'id' => false,
  744. 'name' => false,
  745. ),
  746. ),
  747. ),
  748. 'sort' => array(
  749. 'default' => 'real_name',
  750. 'reverse' => 'real_name DESC',
  751. ),
  752. ),
  753. 'warning' => array(
  754. 'header' => array(
  755. 'value' => $txt['mc_watched_users_warning'],
  756. ),
  757. 'data' => array(
  758. 'function' => create_function('$member', '
  759. global $scripturl;
  760. return allowedTo(\'issue_warning\') ? \'<a href="\' . $scripturl . \'?action=profile;area=issuewarning;u=\' . $member[\'id\'] . \'">\' . $member[\'warning\'] . \'%</a>\' : $member[\'warning\'] . \'%\';
  761. '),
  762. ),
  763. 'sort' => array(
  764. 'default' => 'warning',
  765. 'reverse' => 'warning DESC',
  766. ),
  767. ),
  768. 'posts' => array(
  769. 'header' => array(
  770. 'value' => $txt['posts'],
  771. ),
  772. 'data' => array(
  773. 'sprintf' => array(
  774. 'format' => '<a href="' . $scripturl . '?action=profile;u=%1$d;area=showposts;sa=messages">%2$s</a>',
  775. 'params' => array(
  776. 'id' => false,
  777. 'posts' => false,
  778. ),
  779. ),
  780. ),
  781. 'sort' => array(
  782. 'default' => 'posts',
  783. 'reverse' => 'posts DESC',
  784. ),
  785. ),
  786. 'last_login' => array(
  787. 'header' => array(
  788. 'value' => $txt['mc_watched_users_last_login'],
  789. ),
  790. 'data' => array(
  791. 'db' => 'last_login',
  792. ),
  793. 'sort' => array(
  794. 'default' => 'last_login',
  795. 'reverse' => 'last_login DESC',
  796. ),
  797. ),
  798. 'last_post' => array(
  799. 'header' => array(
  800. 'value' => $txt['mc_watched_users_last_post'],
  801. ),
  802. 'data' => array(
  803. 'function' => create_function('$member', '
  804. global $scripturl;
  805. if ($member[\'last_post_id\'])
  806. return \'<a href="\' . $scripturl . \'?msg=\' . $member[\'last_post_id\'] . \'">\' . $member[\'last_post\'] . \'</a>\';
  807. else
  808. return $member[\'last_post\'];
  809. '),
  810. ),
  811. ),
  812. ),
  813. 'form' => array(
  814. 'href' => $scripturl . '?action=moderate;area=userwatch;sa=post',
  815. 'include_sort' => true,
  816. 'include_start' => true,
  817. 'hidden_fields' => array(
  818. $context['session_var'] => $context['session_id'],
  819. ),
  820. ),
  821. 'additional_rows' => array(
  822. $context['view_posts'] ?
  823. array(
  824. 'position' => 'bottom_of_list',
  825. 'value' => '
  826. <input type="submit" name="delete_selected" value="' . $txt['quickmod_delete_selected'] . '" class="button_submit">',
  827. 'align' => 'right',
  828. ) : array(),
  829. ),
  830. );
  831. // If this is being viewed by posts we actually change the columns to call a template each time.
  832. if ($context['view_posts'])
  833. {
  834. $listOptions['columns'] = array(
  835. 'posts' => array(
  836. 'data' => array(
  837. 'function' => create_function('$post', '
  838. return template_user_watch_post_callback($post);
  839. '),
  840. ),
  841. ),
  842. );
  843. }
  844. // Create the watched user list.
  845. createList($listOptions);
  846. $context['sub_template'] = 'show_list';
  847. $context['default_list'] = 'watch_user_list';
  848. }
  849. /**
  850. * Callback for createList().
  851. * @param $approve_query
  852. */
  853. function list_getWatchedUserCount($approve_query)
  854. {
  855. global $smcFunc, $modSettings;
  856. $request = $smcFunc['db_query']('', '
  857. SELECT COUNT(*)
  858. FROM {db_prefix}members
  859. WHERE warning >= {int:warning_watch}',
  860. array(
  861. 'warning_watch' => $modSettings['warning_watch'],
  862. )
  863. );
  864. list ($totalMembers) = $smcFunc['db_fetch_row']($request);
  865. $smcFunc['db_free_result']($request);
  866. return $totalMembers;
  867. }
  868. /**
  869. * Callback for createList().
  870. *
  871. * @param $start
  872. * @param $items_per_page
  873. * @param $sort
  874. * @param $approve_query
  875. * @param $dummy
  876. */
  877. function list_getWatchedUsers($start, $items_per_page, $sort, $approve_query, $dummy)
  878. {
  879. global $smcFunc, $txt, $scripturl, $modSettings, $user_info, $context;
  880. $request = $smcFunc['db_query']('', '
  881. SELECT id_member, real_name, last_login, posts, warning
  882. FROM {db_prefix}members
  883. WHERE warning >= {int:warning_watch}
  884. ORDER BY {raw:sort}
  885. LIMIT ' . $start . ', ' . $items_per_page,
  886. array(
  887. 'warning_watch' => $modSettings['warning_watch'],
  888. 'sort' => $sort,
  889. )
  890. );
  891. $watched_users = array();
  892. $members = array();
  893. while ($row = $smcFunc['db_fetch_assoc']($request))
  894. {
  895. $watched_users[$row['id_member']] = array(
  896. 'id' => $row['id_member'],
  897. 'name' => $row['real_name'],
  898. 'last_login' => $row['last_login'] ? timeformat($row['last_login']) : $txt['never'],
  899. 'last_post' => $txt['not_applicable'],
  900. 'last_post_id' => 0,
  901. 'warning' => $row['warning'],
  902. 'posts' => $row['posts'],
  903. );
  904. $members[] = $row['id_member'];
  905. }
  906. $smcFunc['db_free_result']($request);
  907. if (!empty($members))
  908. {
  909. // First get the latest messages from these users.
  910. $request = $smcFunc['db_query']('', '
  911. SELECT m.id_member, MAX(m.id_msg) AS last_post_id
  912. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  913. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  914. WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  915. AND m.approved = {int:is_approved}') . '
  916. GROUP BY m.id_member',
  917. array(
  918. 'member_list' => $members,
  919. 'is_approved' => 1,
  920. )
  921. );
  922. $latest_posts = array();
  923. while ($row = $smcFunc['db_fetch_assoc']($request))
  924. $latest_posts[$row['id_member']] = $row['last_post_id'];
  925. if (!empty($latest_posts))
  926. {
  927. // Now get the time those messages were posted.
  928. $request = $smcFunc['db_query']('', '
  929. SELECT id_member, poster_time
  930. FROM {db_prefix}messages
  931. WHERE id_msg IN ({array_int:message_list})',
  932. array(
  933. 'message_list' => $latest_posts,
  934. )
  935. );
  936. while ($row = $smcFunc['db_fetch_assoc']($request))
  937. {
  938. $watched_users[$row['id_member']]['last_post'] = timeformat($row['poster_time']);
  939. $watched_users[$row['id_member']]['last_post_id'] = $latest_posts[$row['id_member']];
  940. }
  941. $smcFunc['db_free_result']($request);
  942. }
  943. $request = $smcFunc['db_query']('', '
  944. SELECT MAX(m.poster_time) AS last_post, MAX(m.id_msg) AS last_post_id, m.id_member
  945. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  946. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  947. WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  948. AND m.approved = {int:is_approved}') . '
  949. GROUP BY m.id_member',
  950. array(
  951. 'member_list' => $members,
  952. 'is_approved' => 1,
  953. )
  954. );
  955. while ($row = $smcFunc['db_fetch_assoc']($request))
  956. {
  957. $watched_users[$row['id_member']]['last_post'] = timeformat($row['last_post']);
  958. $watched_users[$row['id_member']]['last_post_id'] = $row['last_post_id'];
  959. }
  960. $smcFunc['db_free_result']($request);
  961. }
  962. return $watched_users;
  963. }
  964. /**
  965. * Callback for createList().
  966. *
  967. * @param $approve_query
  968. */
  969. function list_getWatchedUserPostsCount($approve_query)
  970. {
  971. global $smcFunc, $modSettings, $user_info;
  972. $request = $smcFunc['db_query']('', '
  973. SELECT COUNT(*)
  974. FROM {db_prefix}messages AS m
  975. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  976. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  977. WHERE mem.warning >= {int:warning_watch}
  978. AND {query_see_board}
  979. ' . $approve_query,
  980. array(
  981. 'warning_watch' => $modSettings['warning_watch'],
  982. )
  983. );
  984. list ($totalMemberPosts) = $smcFunc['db_fetch_row']($request);
  985. $smcFunc['db_free_result']($request);
  986. return $totalMemberPosts;
  987. }
  988. /**
  989. * Callback for createList().
  990. *
  991. * @param $start
  992. * @param $items_per_page
  993. * @param $sort
  994. * @param $approve_query
  995. * @param $delete_boards
  996. */
  997. function list_getWatchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards)
  998. {
  999. global $smcFunc, $txt, $scripturl, $modSettings, $user_info;
  1000. $request = $smcFunc['db_query']('', '
  1001. SELECT m.id_msg, m.id_topic, m.id_board, m.id_member, m.subject, m.body, m.poster_time,
  1002. m.approved, mem.real_name, m.smileys_enabled
  1003. FROM {db_prefix}messages AS m
  1004. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1005. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1006. WHERE mem.warning >= {int:warning_watch}
  1007. AND {query_see_board}
  1008. ' . $approve_query . '
  1009. ORDER BY m.id_msg DESC
  1010. LIMIT ' . $start . ', ' . $items_per_page,
  1011. array(
  1012. 'warning_watch' => $modSettings['warning_watch'],
  1013. )
  1014. );
  1015. $member_posts = array();
  1016. while ($row = $smcFunc['db_fetch_assoc']($request))
  1017. {
  1018. $row['subject'] = censorText($row['subject']);
  1019. $row['body'] = censorText($row['body']);
  1020. $member_posts[$row['id_msg']] = array(
  1021. 'id' => $row['id_msg'],
  1022. 'id_topic' => $row['id_topic'],
  1023. 'author_link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
  1024. 'subject' => $row['subject'],
  1025. 'body' => parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']),
  1026. 'poster_time' => timeformat($row['poster_time']),
  1027. 'approved' => $row['approved'],
  1028. 'can_delete' => $delete_boards == array(0) || in_array($row['id_board'], $delete_boards),
  1029. );
  1030. }
  1031. $smcFunc['db_free_result']($request);
  1032. return $member_posts;
  1033. }
  1034. /**
  1035. * Entry point for viewing warning related stuff.
  1036. */
  1037. function ViewWarnings()
  1038. {
  1039. global $context, $txt;
  1040. $subActions = array(
  1041. 'log' => array('ViewWarningLog'),
  1042. 'templateedit' => array('ModifyWarningTemplate', 'issue_warning'),
  1043. 'templates' => array('ViewWarningTemplates', 'issue_warning'),
  1044. );
  1045. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) && (empty($subActions[$_REQUEST['sa']][1]) || allowedTo($subActions[$_REQUEST['sa']]))? $_REQUEST['sa'] : 'log';
  1046. // Some of this stuff is overseas, so to speak.
  1047. loadTemplate('ModerationCenter');
  1048. loadLanguage('Profile');
  1049. // Setup the admin tabs.
  1050. $context[$context['moderation_menu_name']]['tab_data'] = array(
  1051. 'title' => $txt['mc_warnings'],
  1052. 'description' => $txt['mc_warnings_description'],
  1053. );
  1054. // Call the right function.
  1055. $subActions[$_REQUEST['sa']][0]();
  1056. }
  1057. /**
  1058. * Simply put, look at the warning log!
  1059. */
  1060. function ViewWarningLog()
  1061. {
  1062. global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir;
  1063. // Setup context as always.
  1064. $context['page_title'] = $txt['mc_warning_log_title'];
  1065. require_once($sourcedir . '/Subs-List.php');
  1066. // This is all the information required for a watched user listing.
  1067. $listOptions = array(
  1068. 'id' => 'warning_list',
  1069. 'title' => $txt['mc_warning_log_title'],
  1070. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1071. 'no_items_label' => $txt['mc_warnings_none'],
  1072. 'base_href' => $scripturl . '?action=moderate;area=warnings;sa=log;' . $context['session_var'] . '=' . $context['session_id'],
  1073. 'default_sort_col' => 'time',
  1074. 'get_items' => array(
  1075. 'function' => 'list_getWarnings',
  1076. ),
  1077. 'get_count' => array(
  1078. 'function' => 'list_getWarningCount',
  1079. ),
  1080. // This assumes we are viewing by user.
  1081. 'columns' => array(
  1082. 'issuer' => array(
  1083. 'header' => array(
  1084. 'value' => $txt['profile_warning_previous_issued'],
  1085. ),
  1086. 'data' => array(
  1087. 'db' => 'issuer_link',
  1088. ),
  1089. 'sort' => array(
  1090. 'default' => 'member_name_col',
  1091. 'reverse' => 'member_name_col DESC',
  1092. ),
  1093. ),
  1094. 'recipient' => array(
  1095. 'header' => array(
  1096. 'value' => $txt['mc_warnings_recipient'],
  1097. ),
  1098. 'data' => array(
  1099. 'db' => 'recipient_link',
  1100. ),
  1101. 'sort' => array(
  1102. 'default' => 'recipient_name',
  1103. 'reverse' => 'recipient_name DESC',
  1104. ),
  1105. ),
  1106. 'time' => array(
  1107. 'header' => array(
  1108. 'value' => $txt['profile_warning_previous_time'],
  1109. ),
  1110. 'data' => array(
  1111. 'db' => 'time',
  1112. ),
  1113. 'sort' => array(
  1114. 'default' => 'lc.log_time DESC',
  1115. 'reverse' => 'lc.log_time',
  1116. ),
  1117. ),
  1118. 'reason' => array(
  1119. 'header' => array(
  1120. 'value' => $txt['profile_warning_previous_reason'],
  1121. ),
  1122. 'data' => array(
  1123. 'function' => create_function('$warning', '
  1124. global $scripturl, $settings, $txt;
  1125. $output = \'
  1126. <div class="floatleft">
  1127. \' . $warning[\'reason\'] . \'
  1128. </div>\';
  1129. if (!empty($warning[\'id_notice\']))
  1130. $output .= \'
  1131. <a href="\' . $scripturl . \'?action=moderate;area=notice;nid=\' . $warning[\'id_notice\'] . \'" onclick="window.open(this.href, \\\'\\\', \\\'scrollbars=yes,resizable=yes,width=400,height=250\\\');return false;" target="_blank" class="new_win" title="\' . $txt[\'profile_warning_previous_notice\'] . \'"><img src="\' . $settings[\'default_images_url\'] . \'/filter.png" alt="\' . $txt[\'profile_warning_previous_notice\'] . \'"></a>\';
  1132. return $output;
  1133. '),
  1134. ),
  1135. ),
  1136. 'points' => array(
  1137. 'header' => array(
  1138. 'value' => $txt['profile_warning_previous_level'],
  1139. ),
  1140. 'data' => array(
  1141. 'db' => 'counter',
  1142. ),
  1143. ),
  1144. ),
  1145. );
  1146. // Create the watched user list.
  1147. createList($listOptions);
  1148. $context['sub_template'] = 'show_list';
  1149. $context['default_list'] = 'warning_list';
  1150. }
  1151. /**
  1152. * Callback for createList().
  1153. */
  1154. function list_getWarningCount()
  1155. {
  1156. global $smcFunc;
  1157. $request = $smcFunc['db_query']('', '
  1158. SELECT COUNT(*)
  1159. FROM {db_prefix}log_comments
  1160. WHERE comment_type = {string:warning}',
  1161. array(
  1162. 'warning' => 'warning',
  1163. )
  1164. );
  1165. list ($totalWarns) = $smcFunc['db_fetch_row']($request);
  1166. $smcFunc['db_free_result']($request);
  1167. return $totalWarns;
  1168. }
  1169. /**
  1170. * Callback for createList().
  1171. *
  1172. * @param $start
  1173. * @param $items_per_page
  1174. * @param $sort
  1175. */
  1176. function list_getWarnings($start, $items_per_page, $sort)
  1177. {
  1178. global $smcFunc, $txt, $scripturl, $user_info;
  1179. $request = $smcFunc['db_query']('', '
  1180. SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name_col,
  1181. IFNULL(mem2.id_member, 0) AS id_recipient, IFNULL(mem2.real_name, lc.recipient_name) AS recipient_name,
  1182. lc.log_time, lc.body, lc.id_notice, lc.counter
  1183. FROM {db_prefix}log_comments AS lc
  1184. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  1185. LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = lc.id_recipient)
  1186. WHERE lc.comment_type = {string:warning}
  1187. ORDER BY ' . $sort . '
  1188. LIMIT ' . $start . ', ' . $items_per_page,
  1189. array(
  1190. 'warning' => 'warning',
  1191. )
  1192. );
  1193. $warnings = array();
  1194. while ($row = $smcFunc['db_fetch_assoc']($request))
  1195. {
  1196. $warnings[] = array(
  1197. 'issuer_link' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['member_name_col'] . '</a>') : $row['member_name_col'],
  1198. 'recipient_link' => $row['id_recipient'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_recipient'] . '">' . $row['recipient_name'] . '</a>') : $row['recipient_name'],
  1199. 'time' => timeformat($row['log_time']),
  1200. 'reason' => $row['body'],
  1201. 'counter' => $row['counter'] > 0 ? '+' . $row['counter'] : $row['counter'],
  1202. 'id_notice' => $row['id_notice'],
  1203. );
  1204. }
  1205. $smcFunc['db_free_result']($request);
  1206. return $warnings;
  1207. }
  1208. /**
  1209. * Load all the warning templates.
  1210. */
  1211. function ViewWarningTemplates()
  1212. {
  1213. global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir, $user_info;
  1214. // Submitting a new one?
  1215. if (isset($_POST['add']))
  1216. return ModifyWarningTemplate();
  1217. elseif (isset($_POST['delete']) && !empty($_POST['deltpl']))
  1218. {
  1219. checkSession();
  1220. validateToken('mod-wt');
  1221. // Log the actions.
  1222. $request = $smcFunc['db_query']('', '
  1223. SELECT recipient_name
  1224. FROM {db_prefix}log_comments
  1225. WHERE id_comment IN ({array_int:delete_ids})
  1226. AND comment_type = {string:warntpl}
  1227. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  1228. array(
  1229. 'delete_ids' => $_POST['deltpl'],
  1230. 'warntpl' => 'warntpl',
  1231. 'generic' => 0,
  1232. 'current_member' => $user_info['id'],
  1233. )
  1234. );
  1235. while ($row = $smcFunc['db_fetch_assoc']($request))
  1236. logAction('delete_warn_template', array('template' => $row['recipient_name']));
  1237. $smcFunc['db_free_result']($request);
  1238. // Do the deletes.
  1239. $smcFunc['db_query']('', '
  1240. DELETE FROM {db_prefix}log_comments
  1241. WHERE id_comment IN ({array_int:delete_ids})
  1242. AND comment_type = {string:warntpl}
  1243. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  1244. array(
  1245. 'delete_ids' => $_POST['deltpl'],
  1246. 'warntpl' => 'warntpl',
  1247. 'generic' => 0,
  1248. 'current_member' => $user_info['id'],
  1249. )
  1250. );
  1251. }
  1252. // Setup context as always.
  1253. $context['page_title'] = $txt['mc_warning_templates_title'];
  1254. require_once($sourcedir . '/Subs-List.php');
  1255. // This is all the information required for a watched user listing.
  1256. $listOptions = array(
  1257. 'id' => 'warning_template_list',
  1258. 'title' => $txt['mc_warning_templates_title'],
  1259. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1260. 'no_items_label' => $txt['mc_warning_templates_none'],
  1261. 'base_href' => $scripturl . '?action=moderate;area=warnings;sa=templates;' . $context['session_var'] . '=' . $context['session_id'],
  1262. 'default_sort_col' => 'title',
  1263. 'get_items' => array(
  1264. 'function' => 'list_getWarningTemplates',
  1265. ),
  1266. 'get_count' => array(
  1267. 'function' => 'list_getWarningTemplateCount',
  1268. ),
  1269. // This assumes we are viewing by user.
  1270. 'columns' => array(
  1271. 'title' => array(
  1272. 'header' => array(
  1273. 'value' => $txt['mc_warning_templates_name'],
  1274. ),
  1275. 'data' => array(
  1276. 'sprintf' => array(
  1277. 'format' => '<a href="' . $scripturl . '?action=moderate;area=warnings;sa=templateedit;tid=%1$d">%2$s</a>',
  1278. 'params' => array(
  1279. 'id_comment' => false,
  1280. 'title' => false,
  1281. 'body' => false,
  1282. ),
  1283. ),
  1284. ),
  1285. 'sort' => array(
  1286. 'default' => 'template_title',
  1287. 'reverse' => 'template_title DESC',
  1288. ),
  1289. ),
  1290. 'creator' => array(
  1291. 'header' => array(
  1292. 'value' => $txt['mc_warning_templates_creator'],
  1293. ),
  1294. 'data' => array(
  1295. 'db' => 'creator',
  1296. ),
  1297. 'sort' => array(
  1298. 'default' => 'creator_name',
  1299. 'reverse' => 'creator_name DESC',
  1300. ),
  1301. ),
  1302. 'time' => array(
  1303. 'header' => array(
  1304. 'value' => $txt['mc_warning_templates_time'],
  1305. ),
  1306. 'data' => array(
  1307. 'db' => 'time',
  1308. ),
  1309. 'sort' => array(
  1310. 'default' => 'lc.log_time DESC',
  1311. 'reverse' => 'lc.log_time',
  1312. ),
  1313. ),
  1314. 'delete' => array(
  1315. 'header' => array(
  1316. 'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);">',
  1317. 'style' => 'width: 4%;',
  1318. 'class' => 'centercol',
  1319. ),
  1320. 'data' => array(
  1321. 'function' => create_function('$rowData', '
  1322. global $context, $txt, $scripturl;
  1323. return \'<input type="checkbox" name="deltpl[]" value="\' . $rowData[\'id_comment\'] . \'" class="input_check">\';
  1324. '),
  1325. 'class' => 'centercol',
  1326. ),
  1327. ),
  1328. ),
  1329. 'form' => array(
  1330. 'href' => $scripturl . '?action=moderate;area=warnings;sa=templates',
  1331. 'token' => 'mod-wt',
  1332. ),
  1333. 'additional_rows' => array(
  1334. array(
  1335. 'position' => 'below_table_data',
  1336. 'value' => '&nbsp;<input type="submit" name="delete" value="' . $txt['mc_warning_template_delete'] . '" onclick="return confirm(\'' . $txt['mc_warning_template_delete_confirm'] . '\');" class="button_submit">',
  1337. ),
  1338. array(
  1339. 'position' => 'bottom_of_list',
  1340. 'value' => '<input type="submit" name="add" value="' . $txt['mc_warning_template_add'] . '" class="button_submit">',
  1341. ),
  1342. ),
  1343. );
  1344. // Create the watched user list.
  1345. createToken('mod-wt');
  1346. createList($listOptions);
  1347. $context['sub_template'] = 'show_list';
  1348. $context['default_list'] = 'warning_template_list';
  1349. }
  1350. /**
  1351. * Callback for createList().
  1352. */
  1353. function list_getWarningTemplateCount()
  1354. {
  1355. global $smcFunc, $user_info;
  1356. $request = $smcFunc['db_query']('', '
  1357. SELECT COUNT(*)
  1358. FROM {db_prefix}log_comments
  1359. WHERE comment_type = {string:warntpl}
  1360. AND (id_recipient = {string:generic} OR id_recipient = {int:current_member})',
  1361. array(
  1362. 'warntpl' => 'warntpl',
  1363. 'generic' => 0,
  1364. 'current_member' => $user_info['id'],
  1365. )
  1366. );
  1367. list ($totalWarns) = $smcFunc['db_fetch_row']($request);
  1368. $smcFunc['db_free_result']($request);
  1369. return $totalWarns;
  1370. }
  1371. /**
  1372. * Callback for createList().
  1373. *
  1374. * @param $start
  1375. * @param $items_per_page
  1376. * @param $sort
  1377. */
  1378. function list_getWarningTemplates($start, $items_per_page, $sort)
  1379. {
  1380. global $smcFunc, $txt, $scripturl, $user_info;
  1381. $request = $smcFunc['db_query']('', '
  1382. SELECT lc.id_comment, IFNULL(mem.id_member, 0) AS id_member,
  1383. IFNULL(mem.real_name, lc.member_name) AS creator_name, recipient_name AS template_title,
  1384. lc.log_time, lc.body
  1385. FROM {db_prefix}log_comments AS lc
  1386. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  1387. WHERE lc.comment_type = {string:warntpl}
  1388. AND (id_recipient = {string:generic} OR id_recipient = {int:current_member})
  1389. ORDER BY ' . $sort . '
  1390. LIMIT ' . $start . ', ' . $items_per_page,
  1391. array(
  1392. 'warntpl' => 'warntpl',
  1393. 'generic' => 0,
  1394. 'current_member' => $user_info['id'],
  1395. )
  1396. );
  1397. $templates = array();
  1398. while ($row = $smcFunc['db_fetch_assoc']($request))
  1399. {
  1400. $templates[] = array(
  1401. 'id_comment' => $row['id_comment'],
  1402. 'creator' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['creator_name'] . '</a>') : $row['creator_name'],
  1403. 'time' => timeformat($row['log_time']),
  1404. 'title' => $row['template_title'],
  1405. 'body' => $smcFunc['htmlspecialchars']($row['body']),
  1406. );
  1407. }
  1408. $smcFunc['db_free_result']($request);
  1409. return $templates;
  1410. }
  1411. /**
  1412. * Edit a warning template.
  1413. */
  1414. function ModifyWarningTemplate()
  1415. {
  1416. global $smcFunc, $context, $txt, $user_info, $sourcedir;
  1417. $context['id_template'] = isset($_REQUEST['tid']) ? (int) $_REQUEST['tid'] : 0;
  1418. $context['is_edit'] = $context['id_template'];
  1419. // Standard template things.
  1420. $context['page_title'] = $context['is_edit'] ? $txt['mc_warning_template_modify'] : $txt['mc_warning_template_add'];
  1421. $context['sub_template'] = 'warn_template';
  1422. $context[$context['moderation_menu_name']]['current_subsection'] = 'templates';
  1423. // Defaults.
  1424. $context['template_data'] = array(
  1425. 'title' => '',
  1426. 'body' => $txt['mc_warning_template_body_default'],
  1427. 'personal' => false,
  1428. 'can_edit_personal' => true,
  1429. );
  1430. // If it's an edit load it.
  1431. if ($context['is_edit'])
  1432. {
  1433. $request = $smcFunc['db_query']('', '
  1434. SELECT id_member, id_recipient, recipient_name AS template_title, body
  1435. FROM {db_prefix}log_comments
  1436. WHERE id_comment = {int:id}
  1437. AND comment_type = {string:warntpl}
  1438. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  1439. array(
  1440. 'id' => $context['id_template'],
  1441. 'warntpl' => 'warntpl',
  1442. 'generic' => 0,
  1443. 'current_member' => $user_info['id'],
  1444. )
  1445. );
  1446. while ($row = $smcFunc['db_fetch_assoc']($request))
  1447. {
  1448. $context['template_data'] = array(
  1449. 'title' => $row['template_title'],
  1450. 'body' => $smcFunc['htmlspecialchars']($row['body']),
  1451. 'personal' => $row['id_recipient'],
  1452. 'can_edit_personal' => $row['id_member'] == $user_info['id'],
  1453. );
  1454. }
  1455. $smcFunc['db_free_result']($request);
  1456. }
  1457. // Wait, we are saving?
  1458. if (isset($_POST['save']))
  1459. {
  1460. checkSession();
  1461. validateToken('mod-wt');
  1462. // To check the BBC is pretty good...
  1463. require_once($sourcedir . '/Subs-Post.php');
  1464. // Bit of cleaning!
  1465. $_POST['template_body'] = trim($_POST['template_body']);
  1466. $_POST['template_title'] = trim($_POST['template_title']);
  1467. // Need something in both boxes.
  1468. if (!empty($_POST['template_body']) && !empty($_POST['template_title']))
  1469. {
  1470. // Safety first.
  1471. $_POST['template_title'] = $smcFunc['htmlspecialchars']($_POST['template_title']);
  1472. // Clean up BBC.
  1473. preparsecode($_POST['template_body']);
  1474. // But put line breaks back!
  1475. $_POST['template_body'] = strtr($_POST['template_body'], array('<br>' => "\n"));
  1476. // Is this personal?
  1477. $recipient_id = !empty($_POST['make_personal']) ? $user_info['id'] : 0;
  1478. // If we are this far it's save time.
  1479. if ($context['is_edit'])
  1480. {
  1481. // Simple update...
  1482. $smcFunc['db_query']('', '
  1483. UPDATE {db_prefix}log_comments
  1484. SET id_recipient = {int:personal}, recipient_name = {string:title}, body = {string:body}
  1485. WHERE id_comment = {int:id}
  1486. AND comment_type = {string:warntpl}
  1487. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})'.
  1488. ($recipient_id ? ' AND id_member = {int:current_member}' : ''),
  1489. array(
  1490. 'personal' => $recipient_id,
  1491. 'title' => $_POST['template_title'],
  1492. 'body' => $_POST['template_body'],
  1493. 'id' => $context['id_template'],
  1494. 'warntpl' => 'warntpl',
  1495. 'generic' => 0,
  1496. 'current_member' => $user_info['id'],
  1497. )
  1498. );
  1499. // If it wasn't visible and now is they've effectively added it.
  1500. if ($context['template_data']['personal'] && !$recipient_id)
  1501. logAction('add_warn_template', array('template' => $_POST['template_title']));
  1502. // Conversely if they made it personal it's a delete.
  1503. elseif (!$context['template_data']['personal'] && $recipient_id)
  1504. logAction('delete_warn_template', array('template' => $_POST['template_title']));
  1505. // Otherwise just an edit.
  1506. else
  1507. logAction('modify_warn_template', array('template' => $_POST['template_title']));
  1508. }
  1509. else
  1510. {
  1511. $smcFunc['db_insert']('',
  1512. '{db_prefix}log_comments',
  1513. array(
  1514. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int',
  1515. 'recipient_name' => 'string-255', 'body' => 'string-65535', 'log_time' => 'int',
  1516. ),
  1517. array(
  1518. $user_info['id'], $user_info['name'], 'warntpl', $recipient_id,
  1519. $_POST['template_title'], $_POST['template_body'], time(),
  1520. ),
  1521. array('id_comment')
  1522. );
  1523. logAction('add_warn_template', array('template' => $_POST['template_title']));
  1524. }
  1525. // Get out of town...
  1526. redirectexit('action=moderate;area=warnings;sa=templates');
  1527. }
  1528. else
  1529. {
  1530. $context['warning_errors'] = array();
  1531. $context['template_data']['title'] = !empty($_POST['template_title']) ? $_POST['template_title'] : '';
  1532. $context['template_data']['body'] = !empty($_POST['template_body']) ? $_POST['template_body'] : $txt['mc_warning_template_body_default'];
  1533. $context['template_data']['personal'] = !empty($_POST['make_personal']);
  1534. if (empty($_POST['template_title']))
  1535. $context['warning_errors'][] = $txt['mc_warning_template_error_no_title'];
  1536. if (empty($_POST['template_body']))
  1537. $context['warning_errors'][] = $txt['mc_warning_template_error_no_body'];
  1538. }
  1539. }
  1540. createToken('mod-wt');
  1541. }
  1542. /**
  1543. * Change moderation preferences.
  1544. */
  1545. function ModerationSettings()
  1546. {
  1547. global $context, $smcFunc, $txt, $sourcedir, $scripturl, $user_settings, $user_info;
  1548. // Some useful context stuff.
  1549. loadTemplate('ModerationCenter');
  1550. $context['page_title'] = $txt['mc_settings'];
  1551. $context['sub_template'] = 'moderation_settings';
  1552. $context[$context['moderation_menu_name']]['tab_data'] = array(
  1553. 'title' => $txt['mc_prefs_title'],
  1554. 'help' => '',
  1555. 'description' => $txt['mc_prefs_desc']
  1556. );
  1557. $mod_blocks = '';
  1558. $pref_binary = 5;
  1559. $show_reports = 0;
  1560. // Are we saving?
  1561. if (isset($_POST['save']))
  1562. {
  1563. checkSession();
  1564. validateToken('mod-set');
  1565. /* Current format of mod_prefs is:
  1566. x|ABCD|yyy
  1567. WHERE:
  1568. x = Show report count on forum header.
  1569. ABCD = Block indexes to show on moderation main page.
  1570. yyy = Integer with the following bit status:
  1571. - yyy & 4 = Notify about posts awaiting approval.
  1572. */
  1573. // Now check other options!
  1574. $pref_binary = 0;
  1575. if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval']))
  1576. $pref_binary |= 4;
  1577. // Put it all together.
  1578. $mod_prefs = '0||' . $pref_binary;
  1579. updateMemberData($user_info['id'], array('mod_prefs' => $mod_prefs));
  1580. }
  1581. // What blocks does the user currently have selected?
  1582. $context['mod_settings'] = array(
  1583. 'notify_approval' => $pref_binary & 4,
  1584. );
  1585. createToken('mod-set');
  1586. }
  1587. /**
  1588. * This ends a moderator session, requiring authentication to access the MCP again.
  1589. */
  1590. function ModEndSession()
  1591. {
  1592. // This is so easy!
  1593. unset($_SESSION['moderate_time']);
  1594. // Clean any moderator tokens as well.
  1595. foreach ($_SESSION['token'] as $key => $token)
  1596. if (strpos($key, '-mod') !== false)
  1597. unset($_SESSION['token'][$key]);
  1598. redirectexit();
  1599. }
  1600. ?>