ModerationCenter.php 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848
  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. $context['can_moderate_users'] = allowedTo('moderate_forum');
  31. // Everyone using this area must be allowed here!
  32. if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'] && !$context['can_moderate_users'])
  33. isAllowedTo('access_mod_center');
  34. // We're gonna want a menu of some kind.
  35. require_once($sourcedir . '/Subs-Menu.php');
  36. // Load the language, and the template.
  37. loadLanguage('ModerationCenter');
  38. loadTemplate(false, 'admin');
  39. $context['admin_preferences'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array();
  40. $context['robot_no_index'] = true;
  41. // This is the menu structure - refer to Subs-Menu.php for the details.
  42. $moderation_areas = array(
  43. 'main' => array(
  44. 'title' => $txt['mc_main'],
  45. 'areas' => array(
  46. 'index' => array(
  47. 'label' => $txt['moderation_center'],
  48. 'function' => 'ModerationHome',
  49. 'icon' => 'administration.png',
  50. ),
  51. 'settings' => array(
  52. 'label' => $txt['mc_settings'],
  53. 'function' => 'ModerationSettings',
  54. 'icon' => 'features.png',
  55. ),
  56. 'modlogoff' => array(
  57. 'label' => $txt['mc_logoff'],
  58. 'function' => 'ModEndSession',
  59. 'enabled' => empty($modSettings['securityDisable_moderate']),
  60. 'icon' => 'exit.png',
  61. ),
  62. 'notice' => array(
  63. 'file' => 'ModerationCenter.php',
  64. 'function' => 'ShowNotice',
  65. 'select' => 'index'
  66. ),
  67. ),
  68. ),
  69. 'logs' => array(
  70. 'title' => $txt['mc_logs'],
  71. 'areas' => array(
  72. 'modlog' => array(
  73. 'label' => $txt['modlog_view'],
  74. 'enabled' => !empty($modSettings['modlog_enabled']) && $context['can_moderate_boards'],
  75. 'file' => 'Modlog.php',
  76. 'function' => 'ViewModlog',
  77. 'icon' => 'logs.png',
  78. ),
  79. 'warnings' => array(
  80. 'label' => $txt['mc_warnings'],
  81. 'enabled' => $modSettings['warning_settings'][0] == 1 && $context['can_moderate_boards'],
  82. 'function' => 'ViewWarnings',
  83. 'icon' => 'warning.png',
  84. 'subsections' => array(
  85. 'log' => array($txt['mc_warning_log']),
  86. 'templates' => array($txt['mc_warning_templates'], 'issue_warning'),
  87. ),
  88. ),
  89. ),
  90. ),
  91. 'posts' => array(
  92. 'title' => $txt['mc_posts'],
  93. 'enabled' => $context['can_moderate_boards'] || $context['can_moderate_approvals'],
  94. 'areas' => array(
  95. 'postmod' => array(
  96. 'label' => $txt['mc_unapproved_posts'],
  97. 'enabled' => $context['can_moderate_approvals'],
  98. 'file' => 'PostModeration.php',
  99. 'function' => 'PostModerationMain',
  100. 'icon' => 'posts.png',
  101. 'custom_url' => $scripturl . '?action=moderate;area=postmod',
  102. 'subsections' => array(
  103. 'posts' => array($txt['mc_unapproved_replies']),
  104. 'topics' => array($txt['mc_unapproved_topics']),
  105. ),
  106. ),
  107. 'attachmod' => array(
  108. 'label' => $txt['mc_unapproved_attachments'],
  109. 'enabled' => $context['can_moderate_approvals'],
  110. 'file' => 'PostModeration.php',
  111. 'function' => 'PostModerationMain',
  112. 'icon' => 'post_moderation_attach.png',
  113. 'custom_url' => $scripturl . '?action=moderate;area=attachmod;sa=attachments',
  114. ),
  115. 'reports' => array(
  116. 'label' => $txt['mc_reported_posts'],
  117. 'enabled' => $context['can_moderate_boards'],
  118. 'file' => 'ModerationCenter.php',
  119. 'function' => 'ReportedPosts',
  120. 'icon' => 'reports.png',
  121. 'subsections' => array(
  122. 'open' => array($txt['mc_reportedp_active']),
  123. 'closed' => array($txt['mc_reportedp_closed']),
  124. ),
  125. ),
  126. ),
  127. ),
  128. 'groups' => array(
  129. 'title' => $txt['mc_groups'],
  130. 'enabled' => $context['can_moderate_groups'],
  131. 'areas' => array(
  132. 'groups' => array(
  133. 'label' => $txt['mc_group_requests'],
  134. 'file' => 'Groups.php',
  135. 'function' => 'Groups',
  136. 'icon' => 'members_request.png',
  137. 'custom_url' => $scripturl . '?action=moderate;area=groups;sa=requests',
  138. ),
  139. 'viewgroups' => array(
  140. 'label' => $txt['mc_view_groups'],
  141. 'file' => 'Groups.php',
  142. 'function' => 'Groups',
  143. 'icon' => 'membergroups.png',
  144. ),
  145. ),
  146. ),
  147. 'members' => array(
  148. 'title' => $txt['mc_members'],
  149. 'enabled' => $context['can_moderate_users'] || ($modSettings['warning_settings'][0] == 1 && $context['can_moderate_boards']),
  150. 'areas' => array(
  151. 'userwatch' => array(
  152. 'label' => $txt['mc_watched_users_title'],
  153. 'enabled' => $modSettings['warning_settings'][0] == 1 && $context['can_moderate_boards'],
  154. 'function' => 'ViewWatchedUsers',
  155. 'icon' => 'members_watched.png',
  156. 'subsections' => array(
  157. 'member' => array($txt['mc_watched_users_member']),
  158. 'post' => array($txt['mc_watched_users_post']),
  159. ),
  160. ),
  161. 'memberreports' => array(
  162. 'label' => $txt['mc_reported_members_title'],
  163. 'enabled' => $context['can_moderate_users'],
  164. 'function' => 'ReportedMembers',
  165. 'icon' => 'members_watched.png',
  166. 'subsections' => array(
  167. 'open' => array($txt['mc_reportedp_active']),
  168. 'closed' => array($txt['mc_reportedp_closed']),
  169. ),
  170. ),
  171. ),
  172. )
  173. );
  174. // Make sure the administrator has a valid session...
  175. validateSession('moderate');
  176. // I don't know where we're going - I don't know where we've been...
  177. $menuOptions = array(
  178. 'action' => 'moderate',
  179. 'disable_url_session_check' => true,
  180. );
  181. $mod_include_data = createMenu($moderation_areas, $menuOptions);
  182. unset($moderation_areas);
  183. // We got something - didn't we? DIDN'T WE!
  184. if ($mod_include_data == false)
  185. fatal_lang_error('no_access', false);
  186. // Retain the ID information in case required by a subaction.
  187. $context['moderation_menu_id'] = $context['max_menu_id'];
  188. $context['moderation_menu_name'] = 'menu_data_' . $context['moderation_menu_id'];
  189. // @todo: html in here is not good
  190. $context[$context['moderation_menu_name']]['tab_data'] = array(
  191. 'title' => $txt['moderation_center'],
  192. 'help' => '',
  193. 'description' => '
  194. <strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong>
  195. <br><br>
  196. ' . $txt['mc_description']);
  197. // What a pleasant shortcut - even tho we're not *really* on the admin screen who cares...
  198. $context['admin_area'] = $mod_include_data['current_area'];
  199. // Build the link tree.
  200. $context['linktree'][] = array(
  201. 'url' => $scripturl . '?action=moderate',
  202. 'name' => $txt['moderation_center'],
  203. );
  204. if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index')
  205. $context['linktree'][] = array(
  206. 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'],
  207. 'name' => $mod_include_data['label'],
  208. );
  209. if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label'])
  210. $context['linktree'][] = array(
  211. 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'] . ';sa=' . $mod_include_data['current_subsection'],
  212. 'name' => $mod_include_data['subsections'][$mod_include_data['current_subsection']][0],
  213. );
  214. // Now - finally - the bit before the encore - the main performance of course!
  215. if (!$dont_call)
  216. {
  217. if (isset($mod_include_data['file']))
  218. require_once($sourcedir . '/' . $mod_include_data['file']);
  219. $mod_include_data['function']();
  220. }
  221. }
  222. /**
  223. * This function basically is the home page of the moderation center.
  224. */
  225. function ModerationHome()
  226. {
  227. global $txt, $context, $scripturl, $user_settings, $options;
  228. loadTemplate('ModerationCenter');
  229. loadJavascriptFile('admin.js', array('default_theme' => true), 'admin.js');
  230. $context['page_title'] = $txt['moderation_center'];
  231. $context['sub_template'] = 'moderation_center';
  232. // Handle moderators notes.
  233. ModBlockNotes();
  234. // Load what blocks the user actually can see...
  235. $valid_blocks = array();
  236. if ($context['can_moderate_groups'])
  237. $valid_blocks['g'] = 'GroupRequests';
  238. if ($context['can_moderate_boards'])
  239. {
  240. $valid_blocks['r'] = 'ReportedPosts';
  241. $valid_blocks['w'] = 'WatchedUsers';
  242. }
  243. if ($context['can_moderate_users'])
  244. {
  245. // This falls under the category of moderating users as well...
  246. if (!$context['can_moderate_boards'])
  247. $valid_blocks['w'] = 'WatchedUsers';
  248. $valid_blocks['ru'] = 'ReportedUsers';
  249. }
  250. call_integration_hook('integrate_mod_centre_blocks', array(&$valid_blocks));
  251. $context['mod_blocks'] = array();
  252. foreach ($valid_blocks as $k => $block)
  253. {
  254. $block = 'ModBlock' . $block;
  255. if (function_exists($block))
  256. $context['mod_blocks'][] = $block();
  257. }
  258. $context['admin_prefs'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array();
  259. }
  260. /**
  261. * Show a list of the most active watched users.
  262. */
  263. function ModBlockWatchedUsers()
  264. {
  265. global $context, $smcFunc, $scripturl, $modSettings;
  266. if (($watched_users = cache_get_data('recent_user_watches', 240)) === null)
  267. {
  268. $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch'];
  269. $request = $smcFunc['db_query']('', '
  270. SELECT id_member, real_name, last_login
  271. FROM {db_prefix}members
  272. WHERE warning >= {int:warning_watch}
  273. ORDER BY last_login DESC
  274. LIMIT 10',
  275. array(
  276. 'warning_watch' => $modSettings['warning_watch'],
  277. )
  278. );
  279. $watched_users = array();
  280. while ($row = $smcFunc['db_fetch_assoc']($request))
  281. $watched_users[] = $row;
  282. $smcFunc['db_free_result']($request);
  283. cache_put_data('recent_user_watches', $watched_users, 240);
  284. }
  285. $context['watched_users'] = array();
  286. foreach ($watched_users as $user)
  287. {
  288. $context['watched_users'][] = array(
  289. 'id' => $user['id_member'],
  290. 'name' => $user['real_name'],
  291. 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $user['id_member'] . '">' . $user['real_name'] . '</a>',
  292. 'href' => $scripturl . '?action=profile;u=' . $user['id_member'],
  293. 'last_login' => !empty($user['last_login']) ? timeformat($user['last_login']) : '',
  294. );
  295. }
  296. return 'watched_users';
  297. }
  298. /**
  299. * Show an area for the moderator to type into.
  300. */
  301. function ModBlockNotes()
  302. {
  303. global $context, $smcFunc, $scripturl, $txt, $user_info;
  304. // Are we saving a note?
  305. if (isset($_GET['modnote']) && isset($_POST['makenote']) && isset($_POST['new_note']))
  306. {
  307. checkSession();
  308. $_POST['new_note'] = $smcFunc['htmlspecialchars'](trim($_POST['new_note']));
  309. // Make sure they actually entered something.
  310. if (!empty($_POST['new_note']) && $_POST['new_note'] !== $txt['mc_click_add_note'])
  311. {
  312. // Insert it into the database then!
  313. $smcFunc['db_insert']('',
  314. '{db_prefix}log_comments',
  315. array(
  316. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string',
  317. 'body' => 'string', 'log_time' => 'int',
  318. ),
  319. array(
  320. $user_info['id'], $user_info['name'], 'modnote', '', $_POST['new_note'], time(),
  321. ),
  322. array('id_comment')
  323. );
  324. // Clear the cache.
  325. cache_put_data('moderator_notes', null, 240);
  326. cache_put_data('moderator_notes_total', null, 240);
  327. }
  328. // Redirect otherwise people can resubmit.
  329. redirectexit('action=moderate');
  330. }
  331. // Bye... bye...
  332. if (isset($_GET['notes']) && isset($_GET['delete']) && is_numeric($_GET['delete']))
  333. {
  334. checkSession('get');
  335. // Lets delete it.
  336. $smcFunc['db_query']('', '
  337. DELETE FROM {db_prefix}log_comments
  338. WHERE id_comment = {int:note}
  339. AND comment_type = {string:type}',
  340. array(
  341. 'note' => $_GET['delete'],
  342. 'type' => 'modnote',
  343. )
  344. );
  345. // Clear the cache.
  346. cache_put_data('moderator_notes', null, 240);
  347. cache_put_data('moderator_notes_total', null, 240);
  348. redirectexit('action=moderate');
  349. }
  350. // How many notes in total?
  351. if (($moderator_notes_total = cache_get_data('moderator_notes_total', 240)) === null)
  352. {
  353. $request = $smcFunc['db_query']('', '
  354. SELECT COUNT(*)
  355. FROM {db_prefix}log_comments AS lc
  356. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  357. WHERE lc.comment_type = {string:modnote}',
  358. array(
  359. 'modnote' => 'modnote',
  360. )
  361. );
  362. list ($moderator_notes_total) = $smcFunc['db_fetch_row']($request);
  363. $smcFunc['db_free_result']($request);
  364. cache_put_data('moderator_notes_total', $moderator_notes_total, 240);
  365. }
  366. // Grab the current notes. We can only use the cache for the first page of notes.
  367. $offset = isset($_GET['notes']) && isset($_GET['start']) ? $_GET['start'] : 0;
  368. if ($offset != 0 || ($moderator_notes = cache_get_data('moderator_notes', 240)) === null)
  369. {
  370. $request = $smcFunc['db_query']('', '
  371. SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name,
  372. lc.log_time, lc.body, lc.id_comment AS id_note
  373. FROM {db_prefix}log_comments AS lc
  374. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  375. WHERE lc.comment_type = {string:modnote}
  376. ORDER BY id_comment DESC
  377. LIMIT {int:offset}, 10',
  378. array(
  379. 'modnote' => 'modnote',
  380. 'offset' => $offset,
  381. )
  382. );
  383. $moderator_notes = array();
  384. while ($row = $smcFunc['db_fetch_assoc']($request))
  385. $moderator_notes[] = $row;
  386. $smcFunc['db_free_result']($request);
  387. if ($offset == 0)
  388. cache_put_data('moderator_notes', $moderator_notes, 240);
  389. }
  390. // Lets construct a page index.
  391. $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=index;notes', $_GET['start'], $moderator_notes_total, 10);
  392. $context['start'] = $_GET['start'];
  393. $context['notes'] = array();
  394. foreach ($moderator_notes as $note)
  395. {
  396. $context['notes'][] = array(
  397. 'author' => array(
  398. 'id' => $note['id_member'],
  399. 'link' => $note['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $note['id_member'] . '">' . $note['member_name'] . '</a>') : $note['member_name'],
  400. ),
  401. 'time' => timeformat($note['log_time']),
  402. 'text' => parse_bbc($note['body']),
  403. 'delete_href' => $scripturl . '?action=moderate;area=index;notes;delete=' . $note['id_note'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  404. );
  405. }
  406. return 'notes';
  407. }
  408. /**
  409. * Show a list of the most recent reported posts.
  410. */
  411. function ModBlockReportedPosts()
  412. {
  413. global $context, $user_info, $scripturl, $smcFunc;
  414. // Got the info already?
  415. $cachekey = md5(serialize($user_info['mod_cache']['bq']));
  416. $context['reported_posts'] = array();
  417. if ($user_info['mod_cache']['bq'] == '0=1')
  418. return 'reported_posts_block';
  419. if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null)
  420. {
  421. // By George, that means we in a position to get the reports, jolly good.
  422. $request = $smcFunc['db_query']('', '
  423. SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject,
  424. lr.num_reports, IFNULL(mem.real_name, lr.membername) AS author_name,
  425. IFNULL(mem.id_member, 0) AS id_author
  426. FROM {db_prefix}log_reported AS lr
  427. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  428. 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']) . '
  429. AND lr.id_board != {int:not_a_reported_post}
  430. AND lr.closed = {int:not_closed}
  431. AND lr.ignore_all = {int:not_ignored}
  432. ORDER BY lr.time_updated DESC
  433. LIMIT 10',
  434. array(
  435. 'not_a_reported_post' => 0,
  436. 'not_closed' => 0,
  437. 'not_ignored' => 0,
  438. )
  439. );
  440. $reported_posts = array();
  441. while ($row = $smcFunc['db_fetch_assoc']($request))
  442. $reported_posts[] = $row;
  443. $smcFunc['db_free_result']($request);
  444. // Cache it.
  445. cache_put_data('reported_posts_' . $cachekey, $reported_posts, 90);
  446. }
  447. $context['reported_posts'] = array();
  448. foreach ($reported_posts as $i => $row)
  449. {
  450. $context['reported_posts'][] = array(
  451. 'id' => $row['id_report'],
  452. 'alternate' => $i % 2,
  453. 'topic_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
  454. 'report_href' => $scripturl . '?action=moderate;area=reports;report=' . $row['id_report'],
  455. 'author' => array(
  456. 'id' => $row['id_author'],
  457. 'name' => $row['author_name'],
  458. 'link' => $row['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_author'] . '">' . $row['author_name'] . '</a>' : $row['author_name'],
  459. 'href' => $scripturl . '?action=profile;u=' . $row['id_author'],
  460. ),
  461. 'comments' => array(),
  462. 'subject' => $row['subject'],
  463. 'num_reports' => $row['num_reports'],
  464. );
  465. }
  466. return 'reported_posts_block';
  467. }
  468. /**
  469. * Show a list of all the group requests they can see.
  470. */
  471. function ModBlockGroupRequests()
  472. {
  473. global $context, $user_info, $scripturl, $smcFunc;
  474. $context['group_requests'] = array();
  475. // Make sure they can even moderate someone!
  476. if ($user_info['mod_cache']['gq'] == '0=1')
  477. return 'group_requests_block';
  478. // What requests are outstanding?
  479. $request = $smcFunc['db_query']('', '
  480. SELECT lgr.id_request, lgr.id_member, lgr.id_group, lgr.time_applied, mem.member_name, mg.group_name, mem.real_name
  481. FROM {db_prefix}log_group_requests AS lgr
  482. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = lgr.id_member)
  483. INNER JOIN {db_prefix}membergroups AS mg ON (mg.id_group = lgr.id_group)
  484. 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']) . '
  485. AND lgr.status = {int:status_open}
  486. ORDER BY lgr.id_request DESC
  487. LIMIT 10',
  488. array(
  489. 'status_open' => 0,
  490. )
  491. );
  492. for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i ++)
  493. {
  494. $context['group_requests'][] = array(
  495. 'id' => $row['id_request'],
  496. 'alternate' => $i % 2,
  497. 'request_href' => $scripturl . '?action=groups;sa=requests;gid=' . $row['id_group'],
  498. 'member' => array(
  499. 'id' => $row['id_member'],
  500. 'name' => $row['real_name'],
  501. 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
  502. 'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
  503. ),
  504. 'group' => array(
  505. 'id' => $row['id_group'],
  506. 'name' => $row['group_name'],
  507. ),
  508. 'time_submitted' => timeformat($row['time_applied']),
  509. );
  510. }
  511. $smcFunc['db_free_result']($request);
  512. return 'group_requests_block';
  513. }
  514. /**
  515. * Show a list of the most recent reported posts.
  516. */
  517. function ModBlockReportedMembers()
  518. {
  519. global $context, $user_info, $scripturl, $smcFunc;
  520. // Got the info already?
  521. $cache_key = md5(serialize((int) allowedTo('moderate_forum')));
  522. $context['reported_users'] = array();
  523. if (!allowedTo('moderate_forum'))
  524. return 'reported_users_block';
  525. if (($reported_posts = cache_get_data('reported_users_' . $cache_key, 90)) === null)
  526. {
  527. // By George, that means we in a position to get the reports, jolly good.
  528. $request = $smcFunc['db_query']('', '
  529. SELECT lr.id_report, lr.id_member,
  530. lr.num_reports, IFNULL(mem.real_name, lr.membername) AS user_name,
  531. IFNULL(mem.id_member, 0) AS id_user
  532. FROM {db_prefix}log_reported AS lr
  533. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  534. WHERE lr.id_board = {int:not_a_reported_post}
  535. AND lr.closed = {int:not_closed}
  536. AND lr.ignore_all = {int:not_ignored}
  537. ORDER BY lr.time_updated DESC
  538. LIMIT 10',
  539. array(
  540. 'not_a_reported_post' => 0,
  541. 'not_closed' => 0,
  542. 'not_ignored' => 0,
  543. )
  544. );
  545. $reported_users = array();
  546. while ($row = $smcFunc['db_fetch_assoc']($request))
  547. $reported_users[] = $row;
  548. $smcFunc['db_free_result']($request);
  549. // Cache it.
  550. cache_put_data('reported_users_' . $cachekey, $reported_posts, 90);
  551. }
  552. $context['reported_users'] = array();
  553. foreach ($reported_users as $i => $row)
  554. {
  555. $context['reported_users'][] = array(
  556. 'id' => $row['id_report'],
  557. 'alternate' => $i % 2,
  558. 'report_href' => $scripturl . '?action=moderate;area=memberreports;report=' . $row['id_report'],
  559. 'user' => array(
  560. 'id' => $row['id_user'],
  561. 'name' => $row['user_name'],
  562. 'link' => $row['id_user'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_user'] . '">' . $row['user_name'] . '</a>' : $row['user_name'],
  563. 'href' => $scripturl . '?action=profile;u=' . $row['id_author'],
  564. ),
  565. 'comments' => array(),
  566. 'num_reports' => $row['num_reports'],
  567. );
  568. }
  569. return 'reported_users_block';
  570. }
  571. /**
  572. * Browse all the reported posts...
  573. * @todo this needs to be given its own file?
  574. */
  575. function ReportedPosts()
  576. {
  577. global $txt, $context, $scripturl, $user_info, $smcFunc;
  578. loadTemplate('ModerationCenter');
  579. // Set an empty var for the server response.
  580. $context['report_post_action'] = '';
  581. // Put the open and closed options into tabs, because we can...
  582. $context[$context['moderation_menu_name']]['tab_data'] = array(
  583. 'title' => $txt['mc_reported_posts'],
  584. 'help' => '',
  585. 'description' => $txt['mc_reported_posts_desc'],
  586. );
  587. // This comes under the umbrella of moderating posts.
  588. if ($user_info['mod_cache']['bq'] == '0=1')
  589. isAllowedTo('moderate_forum');
  590. // Are they wanting to view a particular report?
  591. if (!empty($_REQUEST['report']))
  592. return ModReport();
  593. // Set up the comforting bits...
  594. $context['page_title'] = $txt['mc_reported_posts'];
  595. $context['sub_template'] = 'reported_posts';
  596. // Are we viewing open or closed reports?
  597. $context['view_closed'] = isset($_GET['sa']) && $_GET['sa'] == 'closed' ? 1 : 0;
  598. // Are we doing any work?
  599. if ((isset($_GET['ignore']) || isset($_GET['close'])) && isset($_GET['rid']))
  600. {
  601. checkSession('get');
  602. $_GET['rid'] = (int) $_GET['rid'];
  603. // Update the report...
  604. $smcFunc['db_query']('', '
  605. UPDATE {db_prefix}log_reported
  606. SET ' . (isset($_GET['ignore']) ? 'ignore_all = {int:ignore_all}' : 'closed = {int:closed}') . '
  607. WHERE id_report = {int:id_report}
  608. AND ' . $user_info['mod_cache']['bq'],
  609. array(
  610. 'ignore_all' => isset($_GET['ignore']) ? (int) $_GET['ignore'] : 0,
  611. 'closed' => isset($_GET['close']) ? (int) $_GET['close'] : 0,
  612. 'id_report' => $_GET['rid'],
  613. )
  614. );
  615. // Get the board, topic and message for this report
  616. $request = $smcFunc['db_query']('', '
  617. SELECT id_board, id_topic, id_msg
  618. FROM {db_prefix}log_reported
  619. WHERE id_report = {int:id_report}',
  620. array(
  621. 'id_report' => $_GET['rid'],
  622. )
  623. );
  624. // Set up the data for the log...
  625. $extra = array('report' => $_GET['rid']);
  626. list ($extra['board'], $extra['topic'], $extra['message']) = $smcFunc['db_fetch_row']($request);
  627. $smcFunc['db_free_result']($request);
  628. // Tell the user about it.
  629. $context['report_post_action'] = isset($_GET['ignore']) ? (!empty($_GET['ignore']) ? 'ignore' : 'unignore') : (!empty($_GET['close']) ? 'close' : 'open');
  630. // Log this action
  631. logAction($context['report_post_action'] . '_report', $extra);
  632. // Time to update.
  633. updateSettings(array('last_mod_report_action' => time()));
  634. recountOpenReports();
  635. }
  636. elseif (isset($_POST['close']) && isset($_POST['close_selected']))
  637. {
  638. checkSession();
  639. // All the ones to update...
  640. $toClose = array();
  641. foreach ($_POST['close'] as $rid)
  642. $toClose[] = (int) $rid;
  643. if (!empty($toClose))
  644. {
  645. // Get the data for each of these reports
  646. $request = $smcFunc['db_query']('', '
  647. SELECT id_report, id_board, id_topic, id_msg
  648. FROM {db_prefix}log_reported
  649. WHERE id_report IN ({array_int:report_list})
  650. AND ' . $user_inf['mod_cache']['bq'],
  651. array(
  652. 'id_report' => $_GET['rid'],
  653. )
  654. );
  655. while ($reports = $smcFunc['db_fetch_assoc']($request))
  656. {
  657. $report_data = array(
  658. 'report' => $row['id_report'],
  659. 'board' => $row['id_board'],
  660. 'topic' => $row['id_topic'],
  661. 'message' => $row['id_msg'],
  662. );
  663. // Log that this report was closed
  664. logAction('close_report', $report_data);
  665. }
  666. $smcFunc['db_free_result']($request);
  667. $smcFunc['db_query']('', '
  668. UPDATE {db_prefix}log_reported
  669. SET closed = {int:is_closed}
  670. WHERE id_report IN ({array_int:report_list})
  671. AND ' . $user_info['mod_cache']['bq'],
  672. array(
  673. 'report_list' => $toClose,
  674. 'is_closed' => 1,
  675. )
  676. );
  677. // Time to update.
  678. updateSettings(array('last_mod_report_action' => time()));
  679. recountOpenReports();
  680. }
  681. // Go on and tell the result.
  682. $context['report_post_action'] = 'close_all';
  683. }
  684. // How many entries are we viewing?
  685. $request = $smcFunc['db_query']('', '
  686. SELECT COUNT(*)
  687. FROM {db_prefix}log_reported AS lr
  688. WHERE lr.closed = {int:view_closed}
  689. AND ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . '
  690. AND lr.id_board != {int:not_a_reported_post}',
  691. array(
  692. 'view_closed' => $context['view_closed'],
  693. 'not_a_reported_post' => 0,
  694. )
  695. );
  696. list ($context['total_reports']) = $smcFunc['db_fetch_row']($request);
  697. $smcFunc['db_free_result']($request);
  698. // So, that means we can page index, yes?
  699. $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=reports' . ($context['view_closed'] ? ';sa=closed' : ''), $_GET['start'], $context['total_reports'], 10);
  700. $context['start'] = $_GET['start'];
  701. // By George, that means we in a position to get the reports, golly good.
  702. $request = $smcFunc['db_query']('', '
  703. SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body,
  704. lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all,
  705. IFNULL(mem.real_name, lr.membername) AS author_name, IFNULL(mem.id_member, 0) AS id_author
  706. FROM {db_prefix}log_reported AS lr
  707. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  708. WHERE lr.closed = {int:view_closed}
  709. AND ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . '
  710. AND lr.id_board != {int:not_a_reported_post}
  711. ORDER BY lr.time_updated DESC
  712. LIMIT ' . $context['start'] . ', 10',
  713. array(
  714. 'view_closed' => $context['view_closed'],
  715. 'not_a_reported_post' => 0,
  716. )
  717. );
  718. $context['reports'] = array();
  719. $report_ids = array();
  720. $report_boards_ids = array();
  721. for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i++)
  722. {
  723. $report_ids[] = $row['id_report'];
  724. $report_boards_ids[] = $row['id_board'];
  725. $context['reports'][$row['id_report']] = array(
  726. 'id' => $row['id_report'],
  727. 'alternate' => $i % 2,
  728. 'topic' => array(
  729. 'id' => $row['id_topic'],
  730. 'id_msg' => $row['id_msg'],
  731. 'id_board' => $row['id_board'],
  732. 'href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
  733. ),
  734. 'report_href' => $scripturl . '?action=moderate;area=reports;report=' . $row['id_report'],
  735. 'author' => array(
  736. 'id' => $row['id_author'],
  737. 'name' => $row['author_name'],
  738. 'link' => $row['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_author'] . '">' . $row['author_name'] . '</a>' : $row['author_name'],
  739. 'href' => $scripturl . '?action=profile;u=' . $row['id_author'],
  740. ),
  741. 'comments' => array(),
  742. 'time_started' => timeformat($row['time_started']),
  743. 'last_updated' => timeformat($row['time_updated']),
  744. 'subject' => $row['subject'],
  745. 'body' => parse_bbc($row['body']),
  746. 'num_reports' => $row['num_reports'],
  747. 'closed' => $row['closed'],
  748. 'ignore' => $row['ignore_all']
  749. );
  750. }
  751. $smcFunc['db_free_result']($request);
  752. // Get the names of boards those topics are in. Slightly faster this way.
  753. if (!empty($report_boards_ids))
  754. {
  755. $report_boards_ids = array_unique($report_boards_ids);
  756. $board_names = array();
  757. $request = $smcFunc['db_query']('', '
  758. SELECT id_board, name
  759. FROM {db_prefix}boards
  760. WHERE id_board IN ({array_int:boards})',
  761. array(
  762. 'boards' => $report_boards_ids,
  763. )
  764. );
  765. while ($row = $smcFunc['db_fetch_assoc']($request))
  766. $board_names[$row['id_board']] = $row['name'];
  767. $smcFunc['db_free_result']($request);
  768. foreach ($context['reports'] as $id_report => $report)
  769. if (!empty($board_names[$report['topic']['id_board']]))
  770. $context['reports'][$id_report]['topic']['board_name'] = $board_names[$report['topic']['id_board']];
  771. }
  772. // Now get all the people who reported it.
  773. if (!empty($report_ids))
  774. {
  775. $request = $smcFunc['db_query']('', '
  776. SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment,
  777. IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lrc.membername) AS reporter
  778. FROM {db_prefix}log_reported_comments AS lrc
  779. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member)
  780. WHERE lrc.id_report IN ({array_int:report_list})',
  781. array(
  782. 'report_list' => $report_ids,
  783. )
  784. );
  785. while ($row = $smcFunc['db_fetch_assoc']($request))
  786. {
  787. $context['reports'][$row['id_report']]['comments'][] = array(
  788. 'id' => $row['id_comment'],
  789. 'message' => $row['comment'],
  790. 'time' => timeformat($row['time_sent']),
  791. 'member' => array(
  792. 'id' => $row['id_member'],
  793. 'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'],
  794. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']),
  795. 'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
  796. ),
  797. );
  798. }
  799. $smcFunc['db_free_result']($request);
  800. }
  801. // Get the boards where the current user can remove any message.
  802. $context['report_remove_any_boards'] = $user_info['is_admin'] ? $report_boards_ids : array_intersect($report_boards_ids, boardsAllowedTo('remove_any'));
  803. $context['report_manage_bans'] = allowedTo('manage_bans');
  804. // Do we deleted a message?
  805. if (isset($_REQUEST['done']))
  806. $context['report_post_action'] = 'message_deleted';
  807. }
  808. /**
  809. * Browse all the reported users...
  810. */
  811. function ReportedMembers()
  812. {
  813. global $txt, $context, $scripturl, $user_info, $smcFunc;
  814. loadTemplate('ModerationCenter');
  815. // Set an empty var for the server response.
  816. $context['report_member_action'] = '';
  817. // Put the open and closed options into tabs, because we can...
  818. $context[$context['moderation_menu_name']]['tab_data'] = array(
  819. 'title' => $txt['mc_reported_members'],
  820. 'help' => '',
  821. 'description' => $txt['mc_reported_members_desc'],
  822. );
  823. isAllowedTo('moderate_forum');
  824. // Are they wanting to view a particular report?
  825. if (!empty($_REQUEST['report']))
  826. return MemberReport();
  827. // Set up the comforting bits...
  828. $context['page_title'] = $txt['mc_reported_members'];
  829. $context['sub_template'] = 'reported_members';
  830. // Are we viewing open or closed reports?
  831. $context['view_closed'] = isset($_GET['sa']) && $_GET['sa'] == 'closed' ? 1 : 0;
  832. // Are we doing any work?
  833. if ((isset($_GET['ignore']) || isset($_GET['close'])) && isset($_GET['rid']))
  834. {
  835. checkSession('get');
  836. $_GET['rid'] = (int) $_GET['rid'];
  837. // Update the report...
  838. $smcFunc['db_query']('', '
  839. UPDATE {db_prefix}log_reported
  840. SET ' . (isset($_GET['ignore']) ? 'ignore_all = {int:ignore_all}' : 'closed = {int:closed}') . '
  841. WHERE id_report = {int:id_report}',
  842. array(
  843. 'ignore_all' => isset($_GET['ignore']) ? (int) $_GET['ignore'] : 0,
  844. 'closed' => isset($_GET['close']) ? (int) $_GET['close'] : 0,
  845. 'id_report' => $_GET['rid'],
  846. )
  847. );
  848. // Get the board, topic and message for this report
  849. $request = $smcFunc['db_query']('', '
  850. SELECT id_member, membername
  851. FROM {db_prefix}log_reported
  852. WHERE id_report = {int:id_report}',
  853. array(
  854. 'id_report' => $_GET['rid'],
  855. )
  856. );
  857. // Set up the data for the log...
  858. $extra = array('report' => $_GET['rid']);
  859. list($extra['member'], $extra['membername']) = $smcFunc['db_fetch_row']($request);
  860. $smcFunc['db_free_result']($request);
  861. // Stick this in string format for consistency
  862. $extra['member'] = (string)$extra['member'];
  863. // Tell the user about it.
  864. $context['report_member_action'] = isset($_GET['ignore']) ? (!empty($_GET['ignore']) ? 'ignore' : 'unignore') : (!empty($_GET['close']) ? 'close' : 'open');
  865. // Log this action
  866. logAction($context['report_member_action'] . '_user_report', $extra);
  867. // Time to update.
  868. updateSettings(array('last_mod_report_action' => time()));
  869. recountOpenMemberReports();
  870. }
  871. elseif (isset($_POST['close']) && isset($_POST['close_selected']))
  872. {
  873. checkSession();
  874. // All the ones to update...
  875. $toClose = array();
  876. foreach ($_POST['close'] as $rid)
  877. $toClose[] = (int) $rid;
  878. if (!empty($toClose))
  879. {
  880. // Get the data for each of these reports
  881. $request = $smcFunc['db_query']('', '
  882. SELECT id_report, id_member, membername
  883. FROM {db_prefix}log_reported
  884. WHERE id_report IN ({array_int:report_list})',
  885. array(
  886. 'id_report' => $_GET['rid'],
  887. )
  888. );
  889. while ($reports = $smcFunc['db_fetch_assoc']($request))
  890. {
  891. $report_data = array(
  892. 'report' => $row['id_report'],
  893. 'member' => (string)$row['id_member'],
  894. 'membername' => $row['membername'],
  895. );
  896. // Log that this report was closed
  897. logAction('close_user_report', $report_data);
  898. }
  899. $smcFunc['db_free_result']($request);
  900. $smcFunc['db_query']('', '
  901. UPDATE {db_prefix}log_reported
  902. SET closed = {int:is_closed}
  903. WHERE id_report IN ({array_int:report_list})',
  904. array(
  905. 'report_list' => $toClose,
  906. 'is_closed' => 1,
  907. )
  908. );
  909. // Time to update.
  910. updateSettings(array('last_mod_report_action' => time()));
  911. recountOpenMemberReports();
  912. }
  913. // Go on and tell the result.
  914. $context['report_member_action'] = 'close_all';
  915. }
  916. // How many entries are we viewing?
  917. $request = $smcFunc['db_query']('', '
  918. SELECT COUNT(*)
  919. FROM {db_prefix}log_reported AS lr
  920. WHERE lr.closed = {int:view_closed}
  921. AND lr.id_board = {int:not_a_reported_post}',
  922. array(
  923. 'view_closed' => $context['view_closed'],
  924. 'not_a_reported_post' => 0,
  925. )
  926. );
  927. list ($context['total_reports']) = $smcFunc['db_fetch_row']($request);
  928. $smcFunc['db_free_result']($request);
  929. // So, that means we can page index, yes?
  930. $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=memberreports' . ($context['view_closed'] ? ';sa=closed' : ''), $_GET['start'], $context['total_reports'], 10);
  931. $context['start'] = $_GET['start'];
  932. // By George, that means we in a position to get the reports, golly good.
  933. $request = $smcFunc['db_query']('', '
  934. SELECT lr.id_report, lr.id_member, lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all,
  935. IFNULL(mem.real_name, lr.membername) AS user_name, IFNULL(mem.id_member, 0) AS id_user
  936. FROM {db_prefix}log_reported AS lr
  937. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  938. WHERE lr.closed = {int:view_closed}
  939. AND lr.id_board = {int:not_a_reported_post}
  940. ORDER BY lr.time_updated DESC
  941. LIMIT ' . $context['start'] . ', 10',
  942. array(
  943. 'view_closed' => $context['view_closed'],
  944. 'not_a_reported_post' => 0,
  945. )
  946. );
  947. $context['reports'] = array();
  948. $report_ids = array();
  949. for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i++)
  950. {
  951. $report_ids[] = $row['id_report'];
  952. $context['reports'][$row['id_report']] = array(
  953. 'id' => $row['id_report'],
  954. 'alternate' => $i % 2,
  955. 'report_href' => $scripturl . '?action=moderate;area=memberreports;report=' . $row['id_report'],
  956. 'user' => array(
  957. 'id' => $row['id_user'],
  958. 'name' => $row['user_name'],
  959. 'link' => $row['id_user'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_user'] . '">' . $row['user_name'] . '</a>' : $row['user_name'],
  960. 'href' => $scripturl . '?action=profile;u=' . $row['id_user'],
  961. ),
  962. 'comments' => array(),
  963. 'time_started' => timeformat($row['time_started']),
  964. 'last_updated' => timeformat($row['time_updated']),
  965. 'num_reports' => $row['num_reports'],
  966. 'closed' => $row['closed'],
  967. 'ignore' => $row['ignore_all']
  968. );
  969. }
  970. $smcFunc['db_free_result']($request);
  971. // Now get all the people who reported it.
  972. if (!empty($report_ids))
  973. {
  974. $request = $smcFunc['db_query']('', '
  975. SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment,
  976. IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lrc.membername) AS reporter
  977. FROM {db_prefix}log_reported_comments AS lrc
  978. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member)
  979. WHERE lrc.id_report IN ({array_int:report_list})',
  980. array(
  981. 'report_list' => $report_ids,
  982. )
  983. );
  984. while ($row = $smcFunc['db_fetch_assoc']($request))
  985. {
  986. $context['reports'][$row['id_report']]['comments'][] = array(
  987. 'id' => $row['id_comment'],
  988. 'message' => $row['comment'],
  989. 'time' => timeformat($row['time_sent']),
  990. 'member' => array(
  991. 'id' => $row['id_member'],
  992. 'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'],
  993. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']),
  994. 'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
  995. ),
  996. );
  997. }
  998. $smcFunc['db_free_result']($request);
  999. }
  1000. $context['report_manage_bans'] = allowedTo('manage_bans');
  1001. }
  1002. /**
  1003. * Act as an entrace for all group related activity.
  1004. * @todo As for most things in this file, this needs to be moved somewhere appropriate?
  1005. */
  1006. function ModerateGroups()
  1007. {
  1008. global $txt, $context, $scripturl, $user_info;
  1009. // You need to be allowed to moderate groups...
  1010. if ($user_info['mod_cache']['gq'] == '0=1')
  1011. isAllowedTo('manage_membergroups');
  1012. // Load the group templates.
  1013. loadTemplate('ModerationCenter');
  1014. // Setup the subactions...
  1015. $subactions = array(
  1016. 'requests' => 'GroupRequests',
  1017. 'view' => 'ViewGroups',
  1018. );
  1019. if (!isset($_GET['sa']) || !isset($subactions[$_GET['sa']]))
  1020. $_GET['sa'] = 'view';
  1021. $context['sub_action'] = $_GET['sa'];
  1022. // Call the relevant function.
  1023. $subactions[$context['sub_action']]();
  1024. }
  1025. /**
  1026. * How many open reports do we have?
  1027. */
  1028. function recountOpenReports()
  1029. {
  1030. global $user_info, $context, $smcFunc;
  1031. $request = $smcFunc['db_query']('', '
  1032. SELECT COUNT(*)
  1033. FROM {db_prefix}log_reported
  1034. WHERE ' . $user_info['mod_cache']['bq'] . '
  1035. AND closed = {int:not_closed}
  1036. AND ignore_all = {int:not_ignored}
  1037. AND id_board != {int:not_a_reported_post}',
  1038. array(
  1039. 'not_closed' => 0,
  1040. 'not_ignored' => 0,
  1041. 'not_a_reported_post' => 0,
  1042. )
  1043. );
  1044. list ($open_reports) = $smcFunc['db_fetch_row']($request);
  1045. $smcFunc['db_free_result']($request);
  1046. $_SESSION['rc'] = array(
  1047. 'id' => $user_info['id'],
  1048. 'time' => time(),
  1049. 'reports' => $open_reports,
  1050. );
  1051. $context['open_mod_reports'] = $open_reports;
  1052. }
  1053. /**
  1054. * How many open reports do we have?
  1055. */
  1056. function recountOpenMemberReports()
  1057. {
  1058. global $user_info, $context, $smcFunc;
  1059. $request = $smcFunc['db_query']('', '
  1060. SELECT COUNT(*)
  1061. FROM {db_prefix}log_reported
  1062. WHERE closed = {int:not_closed}
  1063. AND ignore_all = {int:not_ignored}
  1064. AND id_board = {int:not_a_reported_post}',
  1065. array(
  1066. 'not_closed' => 0,
  1067. 'not_ignored' => 0,
  1068. 'not_a_reported_post' => 0,
  1069. )
  1070. );
  1071. list ($open_reports) = $smcFunc['db_fetch_row']($request);
  1072. $smcFunc['db_free_result']($request);
  1073. $_SESSION['rmc'] = array(
  1074. 'id' => $user_info['id'],
  1075. 'time' => time(),
  1076. 'reports' => $open_reports,
  1077. );
  1078. $context['open_member_reports'] = $open_reports;
  1079. }
  1080. /**
  1081. * Get details about the moderation report... specified in
  1082. * $_REQUEST['report'].
  1083. */
  1084. function ModReport()
  1085. {
  1086. global $user_info, $context, $sourcedir, $scripturl, $txt, $smcFunc;
  1087. // Have to at least give us something
  1088. if (empty($_REQUEST['report']))
  1089. fatal_lang_error('mc_no_modreport_specified');
  1090. // Integers only please
  1091. $_REQUEST['report'] = (int) $_REQUEST['report'];
  1092. // Get the report details, need this so we can limit access to a particular board
  1093. $request = $smcFunc['db_query']('', '
  1094. SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject, lr.body,
  1095. lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all,
  1096. IFNULL(mem.real_name, lr.membername) AS author_name, IFNULL(mem.id_member, 0) AS id_author
  1097. FROM {db_prefix}log_reported AS lr
  1098. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  1099. WHERE lr.id_report = {int:id_report}
  1100. AND ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . '
  1101. AND lr.id_board != {int:not_a_reported_post}
  1102. LIMIT 1',
  1103. array(
  1104. 'id_report' => $_REQUEST['report'],
  1105. 'not_a_reported_post' => 0,
  1106. )
  1107. );
  1108. // So did we find anything?
  1109. if (!$smcFunc['db_num_rows']($request))
  1110. fatal_lang_error('mc_no_modreport_found');
  1111. // Woohoo we found a report and they can see it! Bad news is we have more work to do
  1112. $row = $smcFunc['db_fetch_assoc']($request);
  1113. $smcFunc['db_free_result']($request);
  1114. // If they are adding a comment then... add a comment.
  1115. if (isset($_POST['add_comment']) && !empty($_POST['mod_comment']))
  1116. {
  1117. checkSession();
  1118. $newComment = trim($smcFunc['htmlspecialchars']($_POST['mod_comment']));
  1119. // In it goes.
  1120. if (!empty($newComment))
  1121. {
  1122. $smcFunc['db_insert']('',
  1123. '{db_prefix}log_comments',
  1124. array(
  1125. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string',
  1126. 'id_notice' => 'int', 'body' => 'string', 'log_time' => 'int',
  1127. ),
  1128. array(
  1129. $user_info['id'], $user_info['name'], 'reportc', '',
  1130. $_REQUEST['report'], $newComment, time(),
  1131. ),
  1132. array('id_comment')
  1133. );
  1134. $last_comment = $smcFunc['db_insert_id']('{db_prefix}log_comments', 'id_comment');
  1135. // And get ready to notify people.
  1136. $smcFunc['db_insert']('insert',
  1137. '{db_prefix}background_tasks',
  1138. array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
  1139. array('$sourcedir/tasks/MsgReportReply-Notify.php', 'MsgReportReply_Notify_Background', serialize(array(
  1140. 'report_id' => $_REQUEST['report'],
  1141. 'comment_id' => $last_comment,
  1142. 'msg_id' => $row['id_msg'],
  1143. 'topic_id' => $row['id_topic'],
  1144. 'board_id' => $row['id_board'],
  1145. 'sender_id' => $user_info['id'],
  1146. 'sender_name' => $user_info['name'],
  1147. 'time' => time(),
  1148. )), 0),
  1149. array('id_task')
  1150. );
  1151. // Redirect to prevent double submittion.
  1152. redirectexit($scripturl . '?action=moderate;area=reports;report=' . $_REQUEST['report']);
  1153. }
  1154. }
  1155. $context['report'] = array(
  1156. 'id' => $row['id_report'],
  1157. 'topic_id' => $row['id_topic'],
  1158. 'board_id' => $row['id_board'],
  1159. 'message_id' => $row['id_msg'],
  1160. 'message_href' => $scripturl . '?msg=' . $row['id_msg'],
  1161. 'message_link' => '<a href="' . $scripturl . '?msg=' . $row['id_msg'] . '">' . $row['subject'] . '</a>',
  1162. 'report_href' => $scripturl . '?action=moderate;area=reports;report=' . $row['id_report'],
  1163. 'author' => array(
  1164. 'id' => $row['id_author'],
  1165. 'name' => $row['author_name'],
  1166. 'link' => $row['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_author'] . '">' . $row['author_name'] . '</a>' : $row['author_name'],
  1167. 'href' => $scripturl . '?action=profile;u=' . $row['id_author'],
  1168. ),
  1169. 'comments' => array(),
  1170. 'mod_comments' => array(),
  1171. 'time_started' => timeformat($row['time_started']),
  1172. 'last_updated' => timeformat($row['time_updated']),
  1173. 'subject' => $row['subject'],
  1174. 'body' => parse_bbc($row['body']),
  1175. 'num_reports' => $row['num_reports'],
  1176. 'closed' => $row['closed'],
  1177. 'ignore' => $row['ignore_all']
  1178. );
  1179. // So what bad things do the reporters have to say about it?
  1180. $request = $smcFunc['db_query']('', '
  1181. SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment, lrc.member_ip,
  1182. IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lrc.membername) AS reporter
  1183. FROM {db_prefix}log_reported_comments AS lrc
  1184. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member)
  1185. WHERE lrc.id_report = {int:id_report}',
  1186. array(
  1187. 'id_report' => $context['report']['id'],
  1188. )
  1189. );
  1190. while ($row = $smcFunc['db_fetch_assoc']($request))
  1191. {
  1192. $context['report']['comments'][] = array(
  1193. 'id' => $row['id_comment'],
  1194. 'message' => strtr($row['comment'], array("\n" => '<br>')),
  1195. 'time' => timeformat($row['time_sent']),
  1196. 'member' => array(
  1197. 'id' => $row['id_member'],
  1198. 'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'],
  1199. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']),
  1200. 'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
  1201. 'ip' => !empty($row['member_ip']) && allowedTo('moderate_forum') ? '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['member_ip'] . '">' . $row['member_ip'] . '</a>' : '',
  1202. ),
  1203. );
  1204. }
  1205. $smcFunc['db_free_result']($request);
  1206. // Hang about old chap, any comments from moderators on this one?
  1207. $request = $smcFunc['db_query']('', '
  1208. SELECT lc.id_comment, lc.id_notice, lc.log_time, lc.body,
  1209. IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS moderator
  1210. FROM {db_prefix}log_comments AS lc
  1211. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  1212. WHERE lc.id_notice = {int:id_report}
  1213. AND lc.comment_type = {literal:reportc}',
  1214. array(
  1215. 'id_report' => $context['report']['id'],
  1216. )
  1217. );
  1218. while ($row = $smcFunc['db_fetch_assoc']($request))
  1219. {
  1220. $context['report']['mod_comments'][] = array(
  1221. 'id' => $row['id_comment'],
  1222. 'message' => parse_bbc($row['body']),
  1223. 'time' => timeformat($row['log_time']),
  1224. 'member' => array(
  1225. 'id' => $row['id_member'],
  1226. 'name' => $row['moderator'],
  1227. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['moderator'] . '</a>' : $row['moderator'],
  1228. 'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
  1229. ),
  1230. );
  1231. }
  1232. $smcFunc['db_free_result']($request);
  1233. // What have the other moderators done to this message?
  1234. require_once($sourcedir . '/Modlog.php');
  1235. require_once($sourcedir . '/Subs-List.php');
  1236. loadLanguage('Modlog');
  1237. // This is all the information from the moderation log.
  1238. $listOptions = array(
  1239. 'id' => 'moderation_actions_list',
  1240. 'title' => $txt['mc_modreport_modactions'],
  1241. 'items_per_page' => 15,
  1242. 'no_items_label' => $txt['modlog_no_entries_found'],
  1243. 'base_href' => $scripturl . '?action=moderate;area=reports;report=' . $context['report']['id'],
  1244. 'default_sort_col' => 'time',
  1245. 'get_items' => array(
  1246. 'function' => 'list_getModLogEntries',
  1247. 'params' => array(
  1248. 'lm.id_topic = {int:id_topic}',
  1249. array('id_topic' => $context['report']['topic_id']),
  1250. 1,
  1251. ),
  1252. ),
  1253. 'get_count' => array(
  1254. 'function' => 'list_getModLogEntryCount',
  1255. 'params' => array(
  1256. 'lm.id_topic = {int:id_topic}',
  1257. array('id_topic' => $context['report']['topic_id']),
  1258. 1,
  1259. ),
  1260. ),
  1261. // This assumes we are viewing by user.
  1262. 'columns' => array(
  1263. 'action' => array(
  1264. 'header' => array(
  1265. 'value' => $txt['modlog_action'],
  1266. ),
  1267. 'data' => array(
  1268. 'db' => 'action_text',
  1269. 'class' => 'smalltext',
  1270. ),
  1271. 'sort' => array(
  1272. 'default' => 'lm.action',
  1273. 'reverse' => 'lm.action DESC',
  1274. ),
  1275. ),
  1276. 'time' => array(
  1277. 'header' => array(
  1278. 'value' => $txt['modlog_date'],
  1279. ),
  1280. 'data' => array(
  1281. 'db' => 'time',
  1282. 'class' => 'smalltext',
  1283. ),
  1284. 'sort' => array(
  1285. 'default' => 'lm.log_time',
  1286. 'reverse' => 'lm.log_time DESC',
  1287. ),
  1288. ),
  1289. 'moderator' => array(
  1290. 'header' => array(
  1291. 'value' => $txt['modlog_member'],
  1292. ),
  1293. 'data' => array(
  1294. 'db' => 'moderator_link',
  1295. 'class' => 'smalltext',
  1296. ),
  1297. 'sort' => array(
  1298. 'default' => 'mem.real_name',
  1299. 'reverse' => 'mem.real_name DESC',
  1300. ),
  1301. ),
  1302. 'position' => array(
  1303. 'header' => array(
  1304. 'value' => $txt['modlog_position'],
  1305. ),
  1306. 'data' => array(
  1307. 'db' => 'position',
  1308. 'class' => 'smalltext',
  1309. ),
  1310. 'sort' => array(
  1311. 'default' => 'mg.group_name',
  1312. 'reverse' => 'mg.group_name DESC',
  1313. ),
  1314. ),
  1315. 'ip' => array(
  1316. 'header' => array(
  1317. 'value' => $txt['modlog_ip'],
  1318. ),
  1319. 'data' => array(
  1320. 'db' => 'ip',
  1321. 'class' => 'smalltext',
  1322. ),
  1323. 'sort' => array(
  1324. 'default' => 'lm.ip',
  1325. 'reverse' => 'lm.ip DESC',
  1326. ),
  1327. ),
  1328. ),
  1329. );
  1330. // Create the watched user list.
  1331. createList($listOptions);
  1332. // Make sure to get the correct tab selected.
  1333. if ($context['report']['closed'])
  1334. $context[$context['moderation_menu_name']]['current_subsection'] = 'closed';
  1335. // Finally we are done :P
  1336. loadTemplate('ModerationCenter');
  1337. $context['page_title'] = sprintf($txt['mc_viewmodreport'], $context['report']['subject'], $context['report']['author']['name']);
  1338. $context['sub_template'] = 'viewmodreport';
  1339. }
  1340. function MemberReport()
  1341. {
  1342. global $user_info, $context, $sourcedir, $scripturl, $txt, $smcFunc;
  1343. // Have to at least give us something
  1344. if (empty($_REQUEST['report']))
  1345. fatal_lang_error('mc_no_modreport_specified');
  1346. // Integers only please
  1347. $_REQUEST['report'] = (int) $_REQUEST['report'];
  1348. // Get the report details, need this so we can limit access to a particular board
  1349. $request = $smcFunc['db_query']('', '
  1350. SELECT lr.id_report, lr.id_member,
  1351. lr.time_started, lr.time_updated, lr.num_reports, lr.closed, lr.ignore_all,
  1352. IFNULL(mem.real_name, lr.membername) AS user_name, IFNULL(mem.id_member, 0) AS id_user
  1353. FROM {db_prefix}log_reported AS lr
  1354. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  1355. WHERE lr.id_report = {int:id_report}
  1356. AND lr.id_board = {int:not_a_reported_post}
  1357. LIMIT 1',
  1358. array(
  1359. 'id_report' => $_REQUEST['report'],
  1360. 'not_a_reported_post' => 0,
  1361. )
  1362. );
  1363. // So did we find anything?
  1364. if (!$smcFunc['db_num_rows']($request))
  1365. fatal_lang_error('mc_no_modreport_found');
  1366. // Woohoo we found a report and they can see it! Bad news is we have more work to do
  1367. $row = $smcFunc['db_fetch_assoc']($request);
  1368. $smcFunc['db_free_result']($request);
  1369. // If they are adding a comment then... add a comment.
  1370. if (isset($_POST['add_comment']) && !empty($_POST['mod_comment']))
  1371. {
  1372. checkSession();
  1373. $newComment = trim($smcFunc['htmlspecialchars']($_POST['mod_comment']));
  1374. // In it goes.
  1375. if (!empty($newComment))
  1376. {
  1377. $smcFunc['db_insert']('',
  1378. '{db_prefix}log_comments',
  1379. array(
  1380. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string',
  1381. 'id_notice' => 'int', 'body' => 'string', 'log_time' => 'int',
  1382. ),
  1383. array(
  1384. $user_info['id'], $user_info['name'], 'reportc', '',
  1385. $_REQUEST['report'], $newComment, time(),
  1386. ),
  1387. array('id_comment')
  1388. );
  1389. $last_comment = $smcFunc['db_insert_id']('{db_prefix}log_comments', 'id_comment');
  1390. // And get ready to notify people.
  1391. $smcFunc['db_insert']('insert',
  1392. '{db_prefix}background_tasks',
  1393. array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
  1394. array('$sourcedir/tasks/MemberReportReply-Notify.php', 'MemberReportReply_Notify_Background', serialize(array(
  1395. 'report_id' => $_REQUEST['report'],
  1396. 'comment_id' => $last_comment,
  1397. 'sender_name' => $user_info['name'],
  1398. 'time' => time(),
  1399. )), 0),
  1400. array('id_task')
  1401. );
  1402. // Redirect to prevent double submittion.
  1403. redirectexit($scripturl . '?action=moderate;area=memberreports;report=' . $_REQUEST['report']);
  1404. }
  1405. }
  1406. $context['report'] = array(
  1407. 'id' => $row['id_report'],
  1408. 'report_href' => $scripturl . '?action=moderate;area=memberreports;report=' . $row['id_report'],
  1409. 'user' => array(
  1410. 'id' => $row['id_user'],
  1411. 'name' => $row['user_name'],
  1412. 'link' => $row['id_user'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_user'] . '">' . $row['user_name'] . '</a>' : $row['user_name'],
  1413. 'href' => $scripturl . '?action=profile;u=' . $row['id_user'],
  1414. ),
  1415. 'comments' => array(),
  1416. 'mod_comments' => array(),
  1417. 'time_started' => timeformat($row['time_started']),
  1418. 'last_updated' => timeformat($row['time_updated']),
  1419. 'num_reports' => $row['num_reports'],
  1420. 'closed' => $row['closed'],
  1421. 'ignore' => $row['ignore_all']
  1422. );
  1423. // So what bad things do the reporters have to say about it?
  1424. $request = $smcFunc['db_query']('', '
  1425. SELECT lrc.id_comment, lrc.id_report, lrc.time_sent, lrc.comment, lrc.member_ip,
  1426. IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lrc.membername) AS reporter
  1427. FROM {db_prefix}log_reported_comments AS lrc
  1428. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lrc.id_member)
  1429. WHERE lrc.id_report = {int:id_report}',
  1430. array(
  1431. 'id_report' => $context['report']['id'],
  1432. )
  1433. );
  1434. while ($row = $smcFunc['db_fetch_assoc']($request))
  1435. {
  1436. $context['report']['comments'][] = array(
  1437. 'id' => $row['id_comment'],
  1438. 'message' => strtr($row['comment'], array("\n" => '<br>')),
  1439. 'time' => timeformat($row['time_sent']),
  1440. 'member' => array(
  1441. 'id' => $row['id_member'],
  1442. 'name' => empty($row['reporter']) ? $txt['guest'] : $row['reporter'],
  1443. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['reporter'] . '</a>' : (empty($row['reporter']) ? $txt['guest'] : $row['reporter']),
  1444. 'href' => $row['id_member'] ? $scripturl . '?action=profile;u=' . $row['id_member'] : '',
  1445. 'ip' => !empty($row['member_ip']) && allowedTo('moderate_forum') ? '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['member_ip'] . '">' . $row['member_ip'] . '</a>' : '',
  1446. ),
  1447. );
  1448. }
  1449. $smcFunc['db_free_result']($request);
  1450. // Hang about old chap, any comments from moderators on this one?
  1451. $request = $smcFunc['db_query']('', '
  1452. SELECT lc.id_comment, lc.id_notice, lc.log_time, lc.body,
  1453. IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS moderator
  1454. FROM {db_prefix}log_comments AS lc
  1455. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  1456. WHERE lc.id_notice = {int:id_report}
  1457. AND lc.comment_type = {literal:reportc}',
  1458. array(
  1459. 'id_report' => $context['report']['id'],
  1460. )
  1461. );
  1462. while ($row = $smcFunc['db_fetch_assoc']($request))
  1463. {
  1464. $context['report']['mod_comments'][] = array(
  1465. 'id' => $row['id_comment'],
  1466. 'message' => parse_bbc($row['body']),
  1467. 'time' => timeformat($row['log_time']),
  1468. 'member' => array(
  1469. 'id' => $row['id_member'],
  1470. 'name' => $row['moderator'],
  1471. 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['moderator'] . '</a>' : $row['moderator'],
  1472. 'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
  1473. ),
  1474. );
  1475. }
  1476. $smcFunc['db_free_result']($request);
  1477. // What have the other moderators done to this message?
  1478. require_once($sourcedir . '/Modlog.php');
  1479. require_once($sourcedir . '/Subs-List.php');
  1480. loadLanguage('Modlog');
  1481. // Serilaize the member id so we can find the member later
  1482. $member = serialize(array('member' => (string)$context['report']['user']['id']));
  1483. // This is all the information from the moderation log.
  1484. $listOptions = array(
  1485. 'id' => 'user_moderation_actions_list',
  1486. 'title' => $txt['mc_modreport_modactions'],
  1487. 'items_per_page' => 15,
  1488. 'no_items_label' => $txt['modlog_no_entries_found'],
  1489. 'base_href' => $scripturl . '?action=moderate;area=reports;report=' . $context['report']['id'],
  1490. 'default_sort_col' => 'time',
  1491. 'get_items' => array(
  1492. 'function' => 'list_getModLogEntries',
  1493. 'params' => array(
  1494. 'lm.extra LIKE {string:member}
  1495. AND lm.action LIKE {string:report}',
  1496. array('member' => '%' . $member . '%', 'report' => '%_user_report'),
  1497. 1,
  1498. true,
  1499. ),
  1500. ),
  1501. 'get_count' => array(
  1502. 'function' => 'list_getModLogEntryCount',
  1503. 'params' => array(
  1504. 'lm.extra LIKE {string:member}
  1505. AND lm.action LIKE {string:report}',
  1506. array('member' => '%' . $member . '%', 'report' => '%_user_report'),
  1507. 1,
  1508. true,
  1509. ),
  1510. ),
  1511. // This assumes we are viewing by user.
  1512. 'columns' => array(
  1513. 'action' => array(
  1514. 'header' => array(
  1515. 'value' => $txt['modlog_action'],
  1516. ),
  1517. 'data' => array(
  1518. 'db' => 'action_text',
  1519. 'class' => 'smalltext',
  1520. ),
  1521. 'sort' => array(
  1522. 'default' => 'lm.action',
  1523. 'reverse' => 'lm.action DESC',
  1524. ),
  1525. ),
  1526. 'time' => array(
  1527. 'header' => array(
  1528. 'value' => $txt['modlog_date'],
  1529. ),
  1530. 'data' => array(
  1531. 'db' => 'time',
  1532. 'class' => 'smalltext',
  1533. ),
  1534. 'sort' => array(
  1535. 'default' => 'lm.log_time',
  1536. 'reverse' => 'lm.log_time DESC',
  1537. ),
  1538. ),
  1539. 'moderator' => array(
  1540. 'header' => array(
  1541. 'value' => $txt['modlog_member'],
  1542. ),
  1543. 'data' => array(
  1544. 'db' => 'moderator_link',
  1545. 'class' => 'smalltext',
  1546. ),
  1547. 'sort' => array(
  1548. 'default' => 'mem.real_name',
  1549. 'reverse' => 'mem.real_name DESC',
  1550. ),
  1551. ),
  1552. 'position' => array(
  1553. 'header' => array(
  1554. 'value' => $txt['modlog_position'],
  1555. ),
  1556. 'data' => array(
  1557. 'db' => 'position',
  1558. 'class' => 'smalltext',
  1559. ),
  1560. 'sort' => array(
  1561. 'default' => 'mg.group_name',
  1562. 'reverse' => 'mg.group_name DESC',
  1563. ),
  1564. ),
  1565. 'ip' => array(
  1566. 'header' => array(
  1567. 'value' => $txt['modlog_ip'],
  1568. ),
  1569. 'data' => array(
  1570. 'db' => 'ip',
  1571. 'class' => 'smalltext',
  1572. ),
  1573. 'sort' => array(
  1574. 'default' => 'lm.ip',
  1575. 'reverse' => 'lm.ip DESC',
  1576. ),
  1577. ),
  1578. ),
  1579. );
  1580. // Create the watched user list.
  1581. createList($listOptions);
  1582. // Make sure to get the correct tab selected.
  1583. if ($context['report']['closed'])
  1584. $context[$context['moderation_menu_name']]['current_subsection'] = 'closed';
  1585. // Finally we are done :P
  1586. loadTemplate('ModerationCenter');
  1587. $context['page_title'] = sprintf($txt['mc_viewmemberreport'], $context['report']['user']['name']);
  1588. $context['sub_template'] = 'viewmemberreport';
  1589. }
  1590. /**
  1591. * Show a notice sent to a user.
  1592. */
  1593. function ShowNotice()
  1594. {
  1595. global $smcFunc, $txt, $context;
  1596. $context['page_title'] = $txt['show_notice'];
  1597. $context['sub_template'] = 'show_notice';
  1598. $context['template_layers'] = array();
  1599. loadTemplate('ModerationCenter');
  1600. // @todo Assumes nothing needs permission more than accessing moderation center!
  1601. $id_notice = (int) $_GET['nid'];
  1602. $request = $smcFunc['db_query']('', '
  1603. SELECT body, subject
  1604. FROM {db_prefix}log_member_notices
  1605. WHERE id_notice = {int:id_notice}',
  1606. array(
  1607. 'id_notice' => $id_notice,
  1608. )
  1609. );
  1610. if ($smcFunc['db_num_rows']($request) == 0)
  1611. fatal_lang_error('no_access', false);
  1612. list ($context['notice_body'], $context['notice_subject']) = $smcFunc['db_fetch_row']($request);
  1613. $smcFunc['db_free_result']($request);
  1614. $context['notice_body'] = parse_bbc($context['notice_body'], false);
  1615. }
  1616. /**
  1617. * View watched users.
  1618. */
  1619. function ViewWatchedUsers()
  1620. {
  1621. global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir;
  1622. // Some important context!
  1623. $context['page_title'] = $txt['mc_watched_users_title'];
  1624. $context['view_posts'] = isset($_GET['sa']) && $_GET['sa'] == 'post';
  1625. $context['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
  1626. loadTemplate('ModerationCenter');
  1627. // Get some key settings!
  1628. $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch'];
  1629. // Put some pretty tabs on cause we're gonna be doing hot stuff here...
  1630. $context[$context['moderation_menu_name']]['tab_data'] = array(
  1631. 'title' => $txt['mc_watched_users_title'],
  1632. 'help' => '',
  1633. 'description' => $txt['mc_watched_users_desc'],
  1634. );
  1635. // First off - are we deleting?
  1636. if (!empty($_REQUEST['delete']))
  1637. {
  1638. checkSession(!is_array($_REQUEST['delete']) ? 'get' : 'post');
  1639. $toDelete = array();
  1640. if (!is_array($_REQUEST['delete']))
  1641. $toDelete[] = (int) $_REQUEST['delete'];
  1642. else
  1643. foreach ($_REQUEST['delete'] as $did)
  1644. $toDelete[] = (int) $did;
  1645. if (!empty($toDelete))
  1646. {
  1647. require_once($sourcedir . '/RemoveTopic.php');
  1648. // If they don't have permission we'll let it error - either way no chance of a security slip here!
  1649. foreach ($toDelete as $did)
  1650. removeMessage($did);
  1651. }
  1652. }
  1653. // Start preparing the list by grabbing relevant permissions.
  1654. if (!$context['view_posts'])
  1655. {
  1656. $approve_query = '';
  1657. $delete_boards = array();
  1658. }
  1659. else
  1660. {
  1661. // Still obey permissions!
  1662. $approve_boards = boardsAllowedTo('approve_posts');
  1663. $delete_boards = boardsAllowedTo('delete_any');
  1664. if ($approve_boards == array(0))
  1665. $approve_query = '';
  1666. elseif (!empty($approve_boards))
  1667. $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
  1668. // Nada, zip, etc...
  1669. else
  1670. $approve_query = ' AND 1=0';
  1671. }
  1672. require_once($sourcedir . '/Subs-List.php');
  1673. // This is all the information required for a watched user listing.
  1674. $listOptions = array(
  1675. 'id' => 'watch_user_list',
  1676. 'title' => $txt['mc_watched_users_title'] . ' - ' . ($context['view_posts'] ? $txt['mc_watched_users_post'] : $txt['mc_watched_users_member']),
  1677. 'width' => '100%',
  1678. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1679. 'no_items_label' => $context['view_posts'] ? $txt['mc_watched_users_no_posts'] : $txt['mc_watched_users_none'],
  1680. 'base_href' => $scripturl . '?action=moderate;area=userwatch;sa=' . ($context['view_posts'] ? 'post' : 'member'),
  1681. 'default_sort_col' => $context['view_posts'] ? '' : 'member',
  1682. 'get_items' => array(
  1683. 'function' => $context['view_posts'] ? 'list_getWatchedUserPosts' : 'list_getWatchedUsers',
  1684. 'params' => array(
  1685. $approve_query,
  1686. $delete_boards,
  1687. ),
  1688. ),
  1689. 'get_count' => array(
  1690. 'function' => $context['view_posts'] ? 'list_getWatchedUserPostsCount' : 'list_getWatchedUserCount',
  1691. 'params' => array(
  1692. $approve_query,
  1693. ),
  1694. ),
  1695. // This assumes we are viewing by user.
  1696. 'columns' => array(
  1697. 'member' => array(
  1698. 'header' => array(
  1699. 'value' => $txt['mc_watched_users_member'],
  1700. ),
  1701. 'data' => array(
  1702. 'sprintf' => array(
  1703. 'format' => '<a href="' . $scripturl . '?action=profile;u=%1$d">%2$s</a>',
  1704. 'params' => array(
  1705. 'id' => false,
  1706. 'name' => false,
  1707. ),
  1708. ),
  1709. ),
  1710. 'sort' => array(
  1711. 'default' => 'real_name',
  1712. 'reverse' => 'real_name DESC',
  1713. ),
  1714. ),
  1715. 'warning' => array(
  1716. 'header' => array(
  1717. 'value' => $txt['mc_watched_users_warning'],
  1718. ),
  1719. 'data' => array(
  1720. 'function' => create_function('$member', '
  1721. global $scripturl;
  1722. return allowedTo(\'issue_warning\') ? \'<a href="\' . $scripturl . \'?action=profile;area=issuewarning;u=\' . $member[\'id\'] . \'">\' . $member[\'warning\'] . \'%</a>\' : $member[\'warning\'] . \'%\';
  1723. '),
  1724. ),
  1725. 'sort' => array(
  1726. 'default' => 'warning',
  1727. 'reverse' => 'warning DESC',
  1728. ),
  1729. ),
  1730. 'posts' => array(
  1731. 'header' => array(
  1732. 'value' => $txt['posts'],
  1733. ),
  1734. 'data' => array(
  1735. 'sprintf' => array(
  1736. 'format' => '<a href="' . $scripturl . '?action=profile;u=%1$d;area=showposts;sa=messages">%2$s</a>',
  1737. 'params' => array(
  1738. 'id' => false,
  1739. 'posts' => false,
  1740. ),
  1741. ),
  1742. ),
  1743. 'sort' => array(
  1744. 'default' => 'posts',
  1745. 'reverse' => 'posts DESC',
  1746. ),
  1747. ),
  1748. 'last_login' => array(
  1749. 'header' => array(
  1750. 'value' => $txt['mc_watched_users_last_login'],
  1751. ),
  1752. 'data' => array(
  1753. 'db' => 'last_login',
  1754. ),
  1755. 'sort' => array(
  1756. 'default' => 'last_login',
  1757. 'reverse' => 'last_login DESC',
  1758. ),
  1759. ),
  1760. 'last_post' => array(
  1761. 'header' => array(
  1762. 'value' => $txt['mc_watched_users_last_post'],
  1763. ),
  1764. 'data' => array(
  1765. 'function' => create_function('$member', '
  1766. global $scripturl;
  1767. if ($member[\'last_post_id\'])
  1768. return \'<a href="\' . $scripturl . \'?msg=\' . $member[\'last_post_id\'] . \'">\' . $member[\'last_post\'] . \'</a>\';
  1769. else
  1770. return $member[\'last_post\'];
  1771. '),
  1772. ),
  1773. ),
  1774. ),
  1775. 'form' => array(
  1776. 'href' => $scripturl . '?action=moderate;area=userwatch;sa=post',
  1777. 'include_sort' => true,
  1778. 'include_start' => true,
  1779. 'hidden_fields' => array(
  1780. $context['session_var'] => $context['session_id'],
  1781. ),
  1782. ),
  1783. 'additional_rows' => array(
  1784. $context['view_posts'] ?
  1785. array(
  1786. 'position' => 'bottom_of_list',
  1787. 'value' => '
  1788. <input type="submit" name="delete_selected" value="' . $txt['quickmod_delete_selected'] . '" class="button_submit">',
  1789. 'align' => 'right',
  1790. ) : array(),
  1791. ),
  1792. );
  1793. // If this is being viewed by posts we actually change the columns to call a template each time.
  1794. if ($context['view_posts'])
  1795. {
  1796. $listOptions['columns'] = array(
  1797. 'posts' => array(
  1798. 'data' => array(
  1799. 'function' => create_function('$post', '
  1800. return template_user_watch_post_callback($post);
  1801. '),
  1802. ),
  1803. ),
  1804. );
  1805. }
  1806. // Create the watched user list.
  1807. createList($listOptions);
  1808. $context['sub_template'] = 'show_list';
  1809. $context['default_list'] = 'watch_user_list';
  1810. }
  1811. /**
  1812. * Callback for createList().
  1813. * @param $approve_query
  1814. */
  1815. function list_getWatchedUserCount($approve_query)
  1816. {
  1817. global $smcFunc, $modSettings;
  1818. $request = $smcFunc['db_query']('', '
  1819. SELECT COUNT(*)
  1820. FROM {db_prefix}members
  1821. WHERE warning >= {int:warning_watch}',
  1822. array(
  1823. 'warning_watch' => $modSettings['warning_watch'],
  1824. )
  1825. );
  1826. list ($totalMembers) = $smcFunc['db_fetch_row']($request);
  1827. $smcFunc['db_free_result']($request);
  1828. return $totalMembers;
  1829. }
  1830. /**
  1831. * Callback for createList().
  1832. *
  1833. * @param $start
  1834. * @param $items_per_page
  1835. * @param $sort
  1836. * @param $approve_query
  1837. * @param $dummy
  1838. */
  1839. function list_getWatchedUsers($start, $items_per_page, $sort, $approve_query, $dummy)
  1840. {
  1841. global $smcFunc, $txt, $scripturl, $modSettings, $user_info, $context;
  1842. $request = $smcFunc['db_query']('', '
  1843. SELECT id_member, real_name, last_login, posts, warning
  1844. FROM {db_prefix}members
  1845. WHERE warning >= {int:warning_watch}
  1846. ORDER BY {raw:sort}
  1847. LIMIT ' . $start . ', ' . $items_per_page,
  1848. array(
  1849. 'warning_watch' => $modSettings['warning_watch'],
  1850. 'sort' => $sort,
  1851. )
  1852. );
  1853. $watched_users = array();
  1854. $members = array();
  1855. while ($row = $smcFunc['db_fetch_assoc']($request))
  1856. {
  1857. $watched_users[$row['id_member']] = array(
  1858. 'id' => $row['id_member'],
  1859. 'name' => $row['real_name'],
  1860. 'last_login' => $row['last_login'] ? timeformat($row['last_login']) : $txt['never'],
  1861. 'last_post' => $txt['not_applicable'],
  1862. 'last_post_id' => 0,
  1863. 'warning' => $row['warning'],
  1864. 'posts' => $row['posts'],
  1865. );
  1866. $members[] = $row['id_member'];
  1867. }
  1868. $smcFunc['db_free_result']($request);
  1869. if (!empty($members))
  1870. {
  1871. // First get the latest messages from these users.
  1872. $request = $smcFunc['db_query']('', '
  1873. SELECT m.id_member, MAX(m.id_msg) AS last_post_id
  1874. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  1875. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  1876. WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  1877. AND m.approved = {int:is_approved}') . '
  1878. GROUP BY m.id_member',
  1879. array(
  1880. 'member_list' => $members,
  1881. 'is_approved' => 1,
  1882. )
  1883. );
  1884. $latest_posts = array();
  1885. while ($row = $smcFunc['db_fetch_assoc']($request))
  1886. $latest_posts[$row['id_member']] = $row['last_post_id'];
  1887. if (!empty($latest_posts))
  1888. {
  1889. // Now get the time those messages were posted.
  1890. $request = $smcFunc['db_query']('', '
  1891. SELECT id_member, poster_time
  1892. FROM {db_prefix}messages
  1893. WHERE id_msg IN ({array_int:message_list})',
  1894. array(
  1895. 'message_list' => $latest_posts,
  1896. )
  1897. );
  1898. while ($row = $smcFunc['db_fetch_assoc']($request))
  1899. {
  1900. $watched_users[$row['id_member']]['last_post'] = timeformat($row['poster_time']);
  1901. $watched_users[$row['id_member']]['last_post_id'] = $latest_posts[$row['id_member']];
  1902. }
  1903. $smcFunc['db_free_result']($request);
  1904. }
  1905. $request = $smcFunc['db_query']('', '
  1906. SELECT MAX(m.poster_time) AS last_post, MAX(m.id_msg) AS last_post_id, m.id_member
  1907. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  1908. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  1909. WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  1910. AND m.approved = {int:is_approved}') . '
  1911. GROUP BY m.id_member',
  1912. array(
  1913. 'member_list' => $members,
  1914. 'is_approved' => 1,
  1915. )
  1916. );
  1917. while ($row = $smcFunc['db_fetch_assoc']($request))
  1918. {
  1919. $watched_users[$row['id_member']]['last_post'] = timeformat($row['last_post']);
  1920. $watched_users[$row['id_member']]['last_post_id'] = $row['last_post_id'];
  1921. }
  1922. $smcFunc['db_free_result']($request);
  1923. }
  1924. return $watched_users;
  1925. }
  1926. /**
  1927. * Callback for createList().
  1928. *
  1929. * @param $approve_query
  1930. */
  1931. function list_getWatchedUserPostsCount($approve_query)
  1932. {
  1933. global $smcFunc, $modSettings;
  1934. $request = $smcFunc['db_query']('', '
  1935. SELECT COUNT(*)
  1936. FROM {db_prefix}messages AS m
  1937. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1938. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1939. WHERE mem.warning >= {int:warning_watch}
  1940. AND {query_see_board}
  1941. ' . $approve_query,
  1942. array(
  1943. 'warning_watch' => $modSettings['warning_watch'],
  1944. )
  1945. );
  1946. list ($totalMemberPosts) = $smcFunc['db_fetch_row']($request);
  1947. $smcFunc['db_free_result']($request);
  1948. return $totalMemberPosts;
  1949. }
  1950. /**
  1951. * Callback for createList().
  1952. *
  1953. * @param $start
  1954. * @param $items_per_page
  1955. * @param $sort
  1956. * @param $approve_query
  1957. * @param $delete_boards
  1958. */
  1959. function list_getWatchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards)
  1960. {
  1961. global $smcFunc, $txt, $scripturl, $modSettings;
  1962. $request = $smcFunc['db_query']('', '
  1963. SELECT m.id_msg, m.id_topic, m.id_board, m.id_member, m.subject, m.body, m.poster_time,
  1964. m.approved, mem.real_name, m.smileys_enabled
  1965. FROM {db_prefix}messages AS m
  1966. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1967. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1968. WHERE mem.warning >= {int:warning_watch}
  1969. AND {query_see_board}
  1970. ' . $approve_query . '
  1971. ORDER BY m.id_msg DESC
  1972. LIMIT ' . $start . ', ' . $items_per_page,
  1973. array(
  1974. 'warning_watch' => $modSettings['warning_watch'],
  1975. )
  1976. );
  1977. $member_posts = array();
  1978. while ($row = $smcFunc['db_fetch_assoc']($request))
  1979. {
  1980. $row['subject'] = censorText($row['subject']);
  1981. $row['body'] = censorText($row['body']);
  1982. $member_posts[$row['id_msg']] = array(
  1983. 'id' => $row['id_msg'],
  1984. 'id_topic' => $row['id_topic'],
  1985. 'author_link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
  1986. 'subject' => $row['subject'],
  1987. 'body' => parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']),
  1988. 'poster_time' => timeformat($row['poster_time']),
  1989. 'approved' => $row['approved'],
  1990. 'can_delete' => $delete_boards == array(0) || in_array($row['id_board'], $delete_boards),
  1991. );
  1992. }
  1993. $smcFunc['db_free_result']($request);
  1994. return $member_posts;
  1995. }
  1996. /**
  1997. * Entry point for viewing warning related stuff.
  1998. */
  1999. function ViewWarnings()
  2000. {
  2001. global $context, $txt;
  2002. $subActions = array(
  2003. 'log' => array('ViewWarningLog'),
  2004. 'templateedit' => array('ModifyWarningTemplate', 'issue_warning'),
  2005. 'templates' => array('ViewWarningTemplates', 'issue_warning'),
  2006. );
  2007. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) && (empty($subActions[$_REQUEST['sa']][1]) || allowedTo($subActions[$_REQUEST['sa']]))? $_REQUEST['sa'] : 'log';
  2008. // Some of this stuff is overseas, so to speak.
  2009. loadTemplate('ModerationCenter');
  2010. loadLanguage('Profile');
  2011. // Setup the admin tabs.
  2012. $context[$context['moderation_menu_name']]['tab_data'] = array(
  2013. 'title' => $txt['mc_warnings'],
  2014. 'description' => $txt['mc_warnings_description'],
  2015. );
  2016. // Call the right function.
  2017. $subActions[$_REQUEST['sa']][0]();
  2018. }
  2019. /**
  2020. * Simply put, look at the warning log!
  2021. */
  2022. function ViewWarningLog()
  2023. {
  2024. global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir;
  2025. // Setup context as always.
  2026. $context['page_title'] = $txt['mc_warning_log_title'];
  2027. require_once($sourcedir . '/Subs-List.php');
  2028. // This is all the information required for a watched user listing.
  2029. $listOptions = array(
  2030. 'id' => 'warning_list',
  2031. 'title' => $txt['mc_warning_log_title'],
  2032. 'items_per_page' => $modSettings['defaultMaxMessages'],
  2033. 'no_items_label' => $txt['mc_warnings_none'],
  2034. 'base_href' => $scripturl . '?action=moderate;area=warnings;sa=log;' . $context['session_var'] . '=' . $context['session_id'],
  2035. 'default_sort_col' => 'time',
  2036. 'get_items' => array(
  2037. 'function' => 'list_getWarnings',
  2038. ),
  2039. 'get_count' => array(
  2040. 'function' => 'list_getWarningCount',
  2041. ),
  2042. // This assumes we are viewing by user.
  2043. 'columns' => array(
  2044. 'issuer' => array(
  2045. 'header' => array(
  2046. 'value' => $txt['profile_warning_previous_issued'],
  2047. ),
  2048. 'data' => array(
  2049. 'db' => 'issuer_link',
  2050. ),
  2051. 'sort' => array(
  2052. 'default' => 'member_name_col',
  2053. 'reverse' => 'member_name_col DESC',
  2054. ),
  2055. ),
  2056. 'recipient' => array(
  2057. 'header' => array(
  2058. 'value' => $txt['mc_warnings_recipient'],
  2059. ),
  2060. 'data' => array(
  2061. 'db' => 'recipient_link',
  2062. ),
  2063. 'sort' => array(
  2064. 'default' => 'recipient_name',
  2065. 'reverse' => 'recipient_name DESC',
  2066. ),
  2067. ),
  2068. 'time' => array(
  2069. 'header' => array(
  2070. 'value' => $txt['profile_warning_previous_time'],
  2071. ),
  2072. 'data' => array(
  2073. 'db' => 'time',
  2074. ),
  2075. 'sort' => array(
  2076. 'default' => 'lc.log_time DESC',
  2077. 'reverse' => 'lc.log_time',
  2078. ),
  2079. ),
  2080. 'reason' => array(
  2081. 'header' => array(
  2082. 'value' => $txt['profile_warning_previous_reason'],
  2083. ),
  2084. 'data' => array(
  2085. 'function' => create_function('$warning', '
  2086. global $scripturl, $txt;
  2087. $output = \'
  2088. <div class="floatleft">
  2089. \' . $warning[\'reason\'] . \'
  2090. </div>\';
  2091. if (!empty($warning[\'id_notice\']))
  2092. $output .= \'
  2093. &nbsp;<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\'] . \'"><span class="generic_icons filter centericon"></span></a>\';
  2094. return $output;
  2095. '),
  2096. ),
  2097. ),
  2098. 'points' => array(
  2099. 'header' => array(
  2100. 'value' => $txt['profile_warning_previous_level'],
  2101. ),
  2102. 'data' => array(
  2103. 'db' => 'counter',
  2104. ),
  2105. ),
  2106. ),
  2107. );
  2108. // Create the watched user list.
  2109. createList($listOptions);
  2110. $context['sub_template'] = 'show_list';
  2111. $context['default_list'] = 'warning_list';
  2112. }
  2113. /**
  2114. * Callback for createList().
  2115. */
  2116. function list_getWarningCount()
  2117. {
  2118. global $smcFunc;
  2119. $request = $smcFunc['db_query']('', '
  2120. SELECT COUNT(*)
  2121. FROM {db_prefix}log_comments
  2122. WHERE comment_type = {string:warning}',
  2123. array(
  2124. 'warning' => 'warning',
  2125. )
  2126. );
  2127. list ($totalWarns) = $smcFunc['db_fetch_row']($request);
  2128. $smcFunc['db_free_result']($request);
  2129. return $totalWarns;
  2130. }
  2131. /**
  2132. * Callback for createList().
  2133. *
  2134. * @param $start
  2135. * @param $items_per_page
  2136. * @param $sort
  2137. */
  2138. function list_getWarnings($start, $items_per_page, $sort)
  2139. {
  2140. global $smcFunc, $txt, $scripturl;
  2141. $request = $smcFunc['db_query']('', '
  2142. SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name_col,
  2143. IFNULL(mem2.id_member, 0) AS id_recipient, IFNULL(mem2.real_name, lc.recipient_name) AS recipient_name,
  2144. lc.log_time, lc.body, lc.id_notice, lc.counter
  2145. FROM {db_prefix}log_comments AS lc
  2146. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  2147. LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = lc.id_recipient)
  2148. WHERE lc.comment_type = {string:warning}
  2149. ORDER BY ' . $sort . '
  2150. LIMIT ' . $start . ', ' . $items_per_page,
  2151. array(
  2152. 'warning' => 'warning',
  2153. )
  2154. );
  2155. $warnings = array();
  2156. while ($row = $smcFunc['db_fetch_assoc']($request))
  2157. {
  2158. $warnings[] = array(
  2159. 'issuer_link' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['member_name_col'] . '</a>') : $row['member_name_col'],
  2160. 'recipient_link' => $row['id_recipient'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_recipient'] . '">' . $row['recipient_name'] . '</a>') : $row['recipient_name'],
  2161. 'time' => timeformat($row['log_time']),
  2162. 'reason' => $row['body'],
  2163. 'counter' => $row['counter'] > 0 ? '+' . $row['counter'] : $row['counter'],
  2164. 'id_notice' => $row['id_notice'],
  2165. );
  2166. }
  2167. $smcFunc['db_free_result']($request);
  2168. return $warnings;
  2169. }
  2170. /**
  2171. * Load all the warning templates.
  2172. */
  2173. function ViewWarningTemplates()
  2174. {
  2175. global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir, $user_info;
  2176. // Submitting a new one?
  2177. if (isset($_POST['add']))
  2178. return ModifyWarningTemplate();
  2179. elseif (isset($_POST['delete']) && !empty($_POST['deltpl']))
  2180. {
  2181. checkSession();
  2182. validateToken('mod-wt');
  2183. // Log the actions.
  2184. $request = $smcFunc['db_query']('', '
  2185. SELECT recipient_name
  2186. FROM {db_prefix}log_comments
  2187. WHERE id_comment IN ({array_int:delete_ids})
  2188. AND comment_type = {string:warntpl}
  2189. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  2190. array(
  2191. 'delete_ids' => $_POST['deltpl'],
  2192. 'warntpl' => 'warntpl',
  2193. 'generic' => 0,
  2194. 'current_member' => $user_info['id'],
  2195. )
  2196. );
  2197. while ($row = $smcFunc['db_fetch_assoc']($request))
  2198. logAction('delete_warn_template', array('template' => $row['recipient_name']));
  2199. $smcFunc['db_free_result']($request);
  2200. // Do the deletes.
  2201. $smcFunc['db_query']('', '
  2202. DELETE FROM {db_prefix}log_comments
  2203. WHERE id_comment IN ({array_int:delete_ids})
  2204. AND comment_type = {string:warntpl}
  2205. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  2206. array(
  2207. 'delete_ids' => $_POST['deltpl'],
  2208. 'warntpl' => 'warntpl',
  2209. 'generic' => 0,
  2210. 'current_member' => $user_info['id'],
  2211. )
  2212. );
  2213. }
  2214. // Setup context as always.
  2215. $context['page_title'] = $txt['mc_warning_templates_title'];
  2216. require_once($sourcedir . '/Subs-List.php');
  2217. // This is all the information required for a watched user listing.
  2218. $listOptions = array(
  2219. 'id' => 'warning_template_list',
  2220. 'title' => $txt['mc_warning_templates_title'],
  2221. 'items_per_page' => $modSettings['defaultMaxMessages'],
  2222. 'no_items_label' => $txt['mc_warning_templates_none'],
  2223. 'base_href' => $scripturl . '?action=moderate;area=warnings;sa=templates;' . $context['session_var'] . '=' . $context['session_id'],
  2224. 'default_sort_col' => 'title',
  2225. 'get_items' => array(
  2226. 'function' => 'list_getWarningTemplates',
  2227. ),
  2228. 'get_count' => array(
  2229. 'function' => 'list_getWarningTemplateCount',
  2230. ),
  2231. // This assumes we are viewing by user.
  2232. 'columns' => array(
  2233. 'title' => array(
  2234. 'header' => array(
  2235. 'value' => $txt['mc_warning_templates_name'],
  2236. ),
  2237. 'data' => array(
  2238. 'sprintf' => array(
  2239. 'format' => '<a href="' . $scripturl . '?action=moderate;area=warnings;sa=templateedit;tid=%1$d">%2$s</a>',
  2240. 'params' => array(
  2241. 'id_comment' => false,
  2242. 'title' => false,
  2243. 'body' => false,
  2244. ),
  2245. ),
  2246. ),
  2247. 'sort' => array(
  2248. 'default' => 'template_title',
  2249. 'reverse' => 'template_title DESC',
  2250. ),
  2251. ),
  2252. 'creator' => array(
  2253. 'header' => array(
  2254. 'value' => $txt['mc_warning_templates_creator'],
  2255. ),
  2256. 'data' => array(
  2257. 'db' => 'creator',
  2258. ),
  2259. 'sort' => array(
  2260. 'default' => 'creator_name',
  2261. 'reverse' => 'creator_name DESC',
  2262. ),
  2263. ),
  2264. 'time' => array(
  2265. 'header' => array(
  2266. 'value' => $txt['mc_warning_templates_time'],
  2267. ),
  2268. 'data' => array(
  2269. 'db' => 'time',
  2270. ),
  2271. 'sort' => array(
  2272. 'default' => 'lc.log_time DESC',
  2273. 'reverse' => 'lc.log_time',
  2274. ),
  2275. ),
  2276. 'delete' => array(
  2277. 'header' => array(
  2278. 'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);">',
  2279. 'style' => 'width: 4%;',
  2280. 'class' => 'centercol',
  2281. ),
  2282. 'data' => array(
  2283. 'function' => create_function('$rowData', '
  2284. global $context, $txt, $scripturl;
  2285. return \'<input type="checkbox" name="deltpl[]" value="\' . $rowData[\'id_comment\'] . \'" class="input_check">\';
  2286. '),
  2287. 'class' => 'centercol',
  2288. ),
  2289. ),
  2290. ),
  2291. 'form' => array(
  2292. 'href' => $scripturl . '?action=moderate;area=warnings;sa=templates',
  2293. 'token' => 'mod-wt',
  2294. ),
  2295. 'additional_rows' => array(
  2296. array(
  2297. 'position' => 'below_table_data',
  2298. '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">',
  2299. ),
  2300. array(
  2301. 'position' => 'bottom_of_list',
  2302. 'value' => '<input type="submit" name="add" value="' . $txt['mc_warning_template_add'] . '" class="button_submit">',
  2303. ),
  2304. ),
  2305. );
  2306. // Create the watched user list.
  2307. createToken('mod-wt');
  2308. createList($listOptions);
  2309. $context['sub_template'] = 'show_list';
  2310. $context['default_list'] = 'warning_template_list';
  2311. }
  2312. /**
  2313. * Callback for createList().
  2314. */
  2315. function list_getWarningTemplateCount()
  2316. {
  2317. global $smcFunc, $user_info;
  2318. $request = $smcFunc['db_query']('', '
  2319. SELECT COUNT(*)
  2320. FROM {db_prefix}log_comments
  2321. WHERE comment_type = {string:warntpl}
  2322. AND (id_recipient = {string:generic} OR id_recipient = {int:current_member})',
  2323. array(
  2324. 'warntpl' => 'warntpl',
  2325. 'generic' => 0,
  2326. 'current_member' => $user_info['id'],
  2327. )
  2328. );
  2329. list ($totalWarns) = $smcFunc['db_fetch_row']($request);
  2330. $smcFunc['db_free_result']($request);
  2331. return $totalWarns;
  2332. }
  2333. /**
  2334. * Callback for createList().
  2335. *
  2336. * @param $start
  2337. * @param $items_per_page
  2338. * @param $sort
  2339. */
  2340. function list_getWarningTemplates($start, $items_per_page, $sort)
  2341. {
  2342. global $smcFunc, $txt, $scripturl, $user_info;
  2343. $request = $smcFunc['db_query']('', '
  2344. SELECT lc.id_comment, IFNULL(mem.id_member, 0) AS id_member,
  2345. IFNULL(mem.real_name, lc.member_name) AS creator_name, recipient_name AS template_title,
  2346. lc.log_time, lc.body
  2347. FROM {db_prefix}log_comments AS lc
  2348. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  2349. WHERE lc.comment_type = {string:warntpl}
  2350. AND (id_recipient = {string:generic} OR id_recipient = {int:current_member})
  2351. ORDER BY ' . $sort . '
  2352. LIMIT ' . $start . ', ' . $items_per_page,
  2353. array(
  2354. 'warntpl' => 'warntpl',
  2355. 'generic' => 0,
  2356. 'current_member' => $user_info['id'],
  2357. )
  2358. );
  2359. $templates = array();
  2360. while ($row = $smcFunc['db_fetch_assoc']($request))
  2361. {
  2362. $templates[] = array(
  2363. 'id_comment' => $row['id_comment'],
  2364. 'creator' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['creator_name'] . '</a>') : $row['creator_name'],
  2365. 'time' => timeformat($row['log_time']),
  2366. 'title' => $row['template_title'],
  2367. 'body' => $smcFunc['htmlspecialchars']($row['body']),
  2368. );
  2369. }
  2370. $smcFunc['db_free_result']($request);
  2371. return $templates;
  2372. }
  2373. /**
  2374. * Edit a warning template.
  2375. */
  2376. function ModifyWarningTemplate()
  2377. {
  2378. global $smcFunc, $context, $txt, $user_info, $sourcedir;
  2379. $context['id_template'] = isset($_REQUEST['tid']) ? (int) $_REQUEST['tid'] : 0;
  2380. $context['is_edit'] = $context['id_template'];
  2381. // Standard template things.
  2382. $context['page_title'] = $context['is_edit'] ? $txt['mc_warning_template_modify'] : $txt['mc_warning_template_add'];
  2383. $context['sub_template'] = 'warn_template';
  2384. $context[$context['moderation_menu_name']]['current_subsection'] = 'templates';
  2385. // Defaults.
  2386. $context['template_data'] = array(
  2387. 'title' => '',
  2388. 'body' => $txt['mc_warning_template_body_default'],
  2389. 'personal' => false,
  2390. 'can_edit_personal' => true,
  2391. );
  2392. // If it's an edit load it.
  2393. if ($context['is_edit'])
  2394. {
  2395. $request = $smcFunc['db_query']('', '
  2396. SELECT id_member, id_recipient, recipient_name AS template_title, body
  2397. FROM {db_prefix}log_comments
  2398. WHERE id_comment = {int:id}
  2399. AND comment_type = {string:warntpl}
  2400. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  2401. array(
  2402. 'id' => $context['id_template'],
  2403. 'warntpl' => 'warntpl',
  2404. 'generic' => 0,
  2405. 'current_member' => $user_info['id'],
  2406. )
  2407. );
  2408. while ($row = $smcFunc['db_fetch_assoc']($request))
  2409. {
  2410. $context['template_data'] = array(
  2411. 'title' => $row['template_title'],
  2412. 'body' => $smcFunc['htmlspecialchars']($row['body']),
  2413. 'personal' => $row['id_recipient'],
  2414. 'can_edit_personal' => $row['id_member'] == $user_info['id'],
  2415. );
  2416. }
  2417. $smcFunc['db_free_result']($request);
  2418. }
  2419. // Wait, we are saving?
  2420. if (isset($_POST['save']))
  2421. {
  2422. checkSession();
  2423. validateToken('mod-wt');
  2424. // To check the BBC is pretty good...
  2425. require_once($sourcedir . '/Subs-Post.php');
  2426. // Bit of cleaning!
  2427. $_POST['template_body'] = trim($_POST['template_body']);
  2428. $_POST['template_title'] = trim($_POST['template_title']);
  2429. // Need something in both boxes.
  2430. if (!empty($_POST['template_body']) && !empty($_POST['template_title']))
  2431. {
  2432. // Safety first.
  2433. $_POST['template_title'] = $smcFunc['htmlspecialchars']($_POST['template_title']);
  2434. // Clean up BBC.
  2435. preparsecode($_POST['template_body']);
  2436. // But put line breaks back!
  2437. $_POST['template_body'] = strtr($_POST['template_body'], array('<br>' => "\n"));
  2438. // Is this personal?
  2439. $recipient_id = !empty($_POST['make_personal']) ? $user_info['id'] : 0;
  2440. // If we are this far it's save time.
  2441. if ($context['is_edit'])
  2442. {
  2443. // Simple update...
  2444. $smcFunc['db_query']('', '
  2445. UPDATE {db_prefix}log_comments
  2446. SET id_recipient = {int:personal}, recipient_name = {string:title}, body = {string:body}
  2447. WHERE id_comment = {int:id}
  2448. AND comment_type = {string:warntpl}
  2449. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})'.
  2450. ($recipient_id ? ' AND id_member = {int:current_member}' : ''),
  2451. array(
  2452. 'personal' => $recipient_id,
  2453. 'title' => $_POST['template_title'],
  2454. 'body' => $_POST['template_body'],
  2455. 'id' => $context['id_template'],
  2456. 'warntpl' => 'warntpl',
  2457. 'generic' => 0,
  2458. 'current_member' => $user_info['id'],
  2459. )
  2460. );
  2461. // If it wasn't visible and now is they've effectively added it.
  2462. if ($context['template_data']['personal'] && !$recipient_id)
  2463. logAction('add_warn_template', array('template' => $_POST['template_title']));
  2464. // Conversely if they made it personal it's a delete.
  2465. elseif (!$context['template_data']['personal'] && $recipient_id)
  2466. logAction('delete_warn_template', array('template' => $_POST['template_title']));
  2467. // Otherwise just an edit.
  2468. else
  2469. logAction('modify_warn_template', array('template' => $_POST['template_title']));
  2470. }
  2471. else
  2472. {
  2473. $smcFunc['db_insert']('',
  2474. '{db_prefix}log_comments',
  2475. array(
  2476. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int',
  2477. 'recipient_name' => 'string-255', 'body' => 'string-65535', 'log_time' => 'int',
  2478. ),
  2479. array(
  2480. $user_info['id'], $user_info['name'], 'warntpl', $recipient_id,
  2481. $_POST['template_title'], $_POST['template_body'], time(),
  2482. ),
  2483. array('id_comment')
  2484. );
  2485. logAction('add_warn_template', array('template' => $_POST['template_title']));
  2486. }
  2487. // Get out of town...
  2488. redirectexit('action=moderate;area=warnings;sa=templates');
  2489. }
  2490. else
  2491. {
  2492. $context['warning_errors'] = array();
  2493. $context['template_data']['title'] = !empty($_POST['template_title']) ? $_POST['template_title'] : '';
  2494. $context['template_data']['body'] = !empty($_POST['template_body']) ? $_POST['template_body'] : $txt['mc_warning_template_body_default'];
  2495. $context['template_data']['personal'] = !empty($_POST['make_personal']);
  2496. if (empty($_POST['template_title']))
  2497. $context['warning_errors'][] = $txt['mc_warning_template_error_no_title'];
  2498. if (empty($_POST['template_body']))
  2499. $context['warning_errors'][] = $txt['mc_warning_template_error_no_body'];
  2500. }
  2501. }
  2502. createToken('mod-wt');
  2503. }
  2504. /**
  2505. * Change moderation preferences.
  2506. */
  2507. function ModerationSettings()
  2508. {
  2509. global $context, $smcFunc, $txt, $sourcedir, $scripturl, $user_settings, $user_info;
  2510. // Some useful context stuff.
  2511. loadTemplate('ModerationCenter');
  2512. $context['page_title'] = $txt['mc_settings'];
  2513. $context['sub_template'] = 'moderation_settings';
  2514. $context[$context['moderation_menu_name']]['tab_data'] = array(
  2515. 'title' => $txt['mc_prefs_title'],
  2516. 'help' => '',
  2517. 'description' => $txt['mc_prefs_desc']
  2518. );
  2519. $mod_blocks = '';
  2520. $pref_binary = 5;
  2521. $show_reports = 0;
  2522. // Are we saving?
  2523. if (isset($_POST['save']))
  2524. {
  2525. checkSession();
  2526. validateToken('mod-set');
  2527. /* Current format of mod_prefs is:
  2528. x|ABCD|yyy
  2529. WHERE:
  2530. x = Show report count on forum header.
  2531. ABCD = Block indexes to show on moderation main page.
  2532. yyy = Integer with the following bit status:
  2533. - yyy & 4 = Notify about posts awaiting approval.
  2534. */
  2535. // Now check other options!
  2536. $pref_binary = 0;
  2537. if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval']))
  2538. $pref_binary |= 4;
  2539. // Put it all together.
  2540. $mod_prefs = '0||' . $pref_binary;
  2541. updateMemberData($user_info['id'], array('mod_prefs' => $mod_prefs));
  2542. }
  2543. // What blocks does the user currently have selected?
  2544. $context['mod_settings'] = array(
  2545. 'notify_approval' => $pref_binary & 4,
  2546. );
  2547. createToken('mod-set');
  2548. }
  2549. /**
  2550. * This ends a moderator session, requiring authentication to access the MCP again.
  2551. */
  2552. function ModEndSession()
  2553. {
  2554. // This is so easy!
  2555. unset($_SESSION['moderate_time']);
  2556. // Clean any moderator tokens as well.
  2557. foreach ($_SESSION['token'] as $key => $token)
  2558. if (strpos($key, '-mod') !== false)
  2559. unset($_SESSION['token'][$key]);
  2560. redirectexit();
  2561. }
  2562. ?>