ModerationCenter.php 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850
  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['rm'] = 'ReportedMembers';
  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. $cachekey = 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_' . $cachekey, 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_info['mod_cache']['bq'],
  651. array(
  652. 'report_list' => $toClose,
  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. 'report_list' => $toClose,
  887. )
  888. );
  889. while ($reports = $smcFunc['db_fetch_assoc']($request))
  890. {
  891. $report_data = array(
  892. 'report' => $reports['id_report'],
  893. 'membername' => $reports['membername'],
  894. 'member' => (string)$reports['id_member'],
  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. // Find their ID in the serialized action string...
  1482. $user_id_length = strlen((string)$context['report']['user']['id']);
  1483. $member = 's:6:"member";s:' . $user_id_length . ':"' . $context['report']['user']['id'] . '";}';
  1484. // This is all the information from the moderation log.
  1485. // Note that we use "raw" here to prevent SMF from escaping things we don't want escaped
  1486. $listOptions = array(
  1487. 'id' => 'memreport_actions_list',
  1488. 'title' => $txt['mc_modreport_modactions'],
  1489. 'items_per_page' => 15,
  1490. 'no_items_label' => $txt['modlog_no_entries_found'],
  1491. 'base_href' => $scripturl . '?action=moderate;area=memberreports;report=' . $context['report']['id'],
  1492. 'default_sort_col' => 'time',
  1493. 'get_items' => array(
  1494. 'function' => 'list_getModLogEntries',
  1495. 'params' => array(
  1496. 'lm.extra LIKE {raw:member}
  1497. AND lm.action LIKE {raw:report}',
  1498. array('member' => '\'%' . $member . '\'', 'report' => '\'%_user_report\''),
  1499. 1,
  1500. true,
  1501. ),
  1502. ),
  1503. 'get_count' => array(
  1504. 'function' => 'list_getModLogEntryCount',
  1505. 'params' => array(
  1506. 'lm.extra LIKE {string:member}
  1507. AND lm.action LIKE {string:report}',
  1508. array('member' => '%' . $member . '%', 'report' => '%_user_report'),
  1509. 1,
  1510. true,
  1511. ),
  1512. ),
  1513. // This assumes we are viewing by user.
  1514. 'columns' => array(
  1515. 'action' => array(
  1516. 'header' => array(
  1517. 'value' => $txt['modlog_action'],
  1518. ),
  1519. 'data' => array(
  1520. 'db' => 'action_text',
  1521. 'class' => 'smalltext',
  1522. ),
  1523. 'sort' => array(
  1524. 'default' => 'lm.action',
  1525. 'reverse' => 'lm.action DESC',
  1526. ),
  1527. ),
  1528. 'time' => array(
  1529. 'header' => array(
  1530. 'value' => $txt['modlog_date'],
  1531. ),
  1532. 'data' => array(
  1533. 'db' => 'time',
  1534. 'class' => 'smalltext',
  1535. ),
  1536. 'sort' => array(
  1537. 'default' => 'lm.log_time',
  1538. 'reverse' => 'lm.log_time DESC',
  1539. ),
  1540. ),
  1541. 'moderator' => array(
  1542. 'header' => array(
  1543. 'value' => $txt['modlog_member'],
  1544. ),
  1545. 'data' => array(
  1546. 'db' => 'moderator_link',
  1547. 'class' => 'smalltext',
  1548. ),
  1549. 'sort' => array(
  1550. 'default' => 'mem.real_name',
  1551. 'reverse' => 'mem.real_name DESC',
  1552. ),
  1553. ),
  1554. 'position' => array(
  1555. 'header' => array(
  1556. 'value' => $txt['modlog_position'],
  1557. ),
  1558. 'data' => array(
  1559. 'db' => 'position',
  1560. 'class' => 'smalltext',
  1561. ),
  1562. 'sort' => array(
  1563. 'default' => 'mg.group_name',
  1564. 'reverse' => 'mg.group_name DESC',
  1565. ),
  1566. ),
  1567. 'ip' => array(
  1568. 'header' => array(
  1569. 'value' => $txt['modlog_ip'],
  1570. ),
  1571. 'data' => array(
  1572. 'db' => 'ip',
  1573. 'class' => 'smalltext',
  1574. ),
  1575. 'sort' => array(
  1576. 'default' => 'lm.ip',
  1577. 'reverse' => 'lm.ip DESC',
  1578. ),
  1579. ),
  1580. ),
  1581. );
  1582. // Create the watched user list.
  1583. createList($listOptions);
  1584. // Make sure to get the correct tab selected.
  1585. if ($context['report']['closed'])
  1586. $context[$context['moderation_menu_name']]['current_subsection'] = 'closed';
  1587. // Finally we are done :P
  1588. loadTemplate('ModerationCenter');
  1589. $context['page_title'] = sprintf($txt['mc_viewmemberreport'], $context['report']['user']['name']);
  1590. $context['sub_template'] = 'viewmemberreport';
  1591. }
  1592. /**
  1593. * Show a notice sent to a user.
  1594. */
  1595. function ShowNotice()
  1596. {
  1597. global $smcFunc, $txt, $context;
  1598. $context['page_title'] = $txt['show_notice'];
  1599. $context['sub_template'] = 'show_notice';
  1600. $context['template_layers'] = array();
  1601. loadTemplate('ModerationCenter');
  1602. // @todo Assumes nothing needs permission more than accessing moderation center!
  1603. $id_notice = (int) $_GET['nid'];
  1604. $request = $smcFunc['db_query']('', '
  1605. SELECT body, subject
  1606. FROM {db_prefix}log_member_notices
  1607. WHERE id_notice = {int:id_notice}',
  1608. array(
  1609. 'id_notice' => $id_notice,
  1610. )
  1611. );
  1612. if ($smcFunc['db_num_rows']($request) == 0)
  1613. fatal_lang_error('no_access', false);
  1614. list ($context['notice_body'], $context['notice_subject']) = $smcFunc['db_fetch_row']($request);
  1615. $smcFunc['db_free_result']($request);
  1616. $context['notice_body'] = parse_bbc($context['notice_body'], false);
  1617. }
  1618. /**
  1619. * View watched users.
  1620. */
  1621. function ViewWatchedUsers()
  1622. {
  1623. global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir;
  1624. // Some important context!
  1625. $context['page_title'] = $txt['mc_watched_users_title'];
  1626. $context['view_posts'] = isset($_GET['sa']) && $_GET['sa'] == 'post';
  1627. $context['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
  1628. loadTemplate('ModerationCenter');
  1629. // Get some key settings!
  1630. $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch'];
  1631. // Put some pretty tabs on cause we're gonna be doing hot stuff here...
  1632. $context[$context['moderation_menu_name']]['tab_data'] = array(
  1633. 'title' => $txt['mc_watched_users_title'],
  1634. 'help' => '',
  1635. 'description' => $txt['mc_watched_users_desc'],
  1636. );
  1637. // First off - are we deleting?
  1638. if (!empty($_REQUEST['delete']))
  1639. {
  1640. checkSession(!is_array($_REQUEST['delete']) ? 'get' : 'post');
  1641. $toDelete = array();
  1642. if (!is_array($_REQUEST['delete']))
  1643. $toDelete[] = (int) $_REQUEST['delete'];
  1644. else
  1645. foreach ($_REQUEST['delete'] as $did)
  1646. $toDelete[] = (int) $did;
  1647. if (!empty($toDelete))
  1648. {
  1649. require_once($sourcedir . '/RemoveTopic.php');
  1650. // If they don't have permission we'll let it error - either way no chance of a security slip here!
  1651. foreach ($toDelete as $did)
  1652. removeMessage($did);
  1653. }
  1654. }
  1655. // Start preparing the list by grabbing relevant permissions.
  1656. if (!$context['view_posts'])
  1657. {
  1658. $approve_query = '';
  1659. $delete_boards = array();
  1660. }
  1661. else
  1662. {
  1663. // Still obey permissions!
  1664. $approve_boards = boardsAllowedTo('approve_posts');
  1665. $delete_boards = boardsAllowedTo('delete_any');
  1666. if ($approve_boards == array(0))
  1667. $approve_query = '';
  1668. elseif (!empty($approve_boards))
  1669. $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
  1670. // Nada, zip, etc...
  1671. else
  1672. $approve_query = ' AND 1=0';
  1673. }
  1674. require_once($sourcedir . '/Subs-List.php');
  1675. // This is all the information required for a watched user listing.
  1676. $listOptions = array(
  1677. 'id' => 'watch_user_list',
  1678. 'title' => $txt['mc_watched_users_title'] . ' - ' . ($context['view_posts'] ? $txt['mc_watched_users_post'] : $txt['mc_watched_users_member']),
  1679. 'width' => '100%',
  1680. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1681. 'no_items_label' => $context['view_posts'] ? $txt['mc_watched_users_no_posts'] : $txt['mc_watched_users_none'],
  1682. 'base_href' => $scripturl . '?action=moderate;area=userwatch;sa=' . ($context['view_posts'] ? 'post' : 'member'),
  1683. 'default_sort_col' => $context['view_posts'] ? '' : 'member',
  1684. 'get_items' => array(
  1685. 'function' => $context['view_posts'] ? 'list_getWatchedUserPosts' : 'list_getWatchedUsers',
  1686. 'params' => array(
  1687. $approve_query,
  1688. $delete_boards,
  1689. ),
  1690. ),
  1691. 'get_count' => array(
  1692. 'function' => $context['view_posts'] ? 'list_getWatchedUserPostsCount' : 'list_getWatchedUserCount',
  1693. 'params' => array(
  1694. $approve_query,
  1695. ),
  1696. ),
  1697. // This assumes we are viewing by user.
  1698. 'columns' => array(
  1699. 'member' => array(
  1700. 'header' => array(
  1701. 'value' => $txt['mc_watched_users_member'],
  1702. ),
  1703. 'data' => array(
  1704. 'sprintf' => array(
  1705. 'format' => '<a href="' . $scripturl . '?action=profile;u=%1$d">%2$s</a>',
  1706. 'params' => array(
  1707. 'id' => false,
  1708. 'name' => false,
  1709. ),
  1710. ),
  1711. ),
  1712. 'sort' => array(
  1713. 'default' => 'real_name',
  1714. 'reverse' => 'real_name DESC',
  1715. ),
  1716. ),
  1717. 'warning' => array(
  1718. 'header' => array(
  1719. 'value' => $txt['mc_watched_users_warning'],
  1720. ),
  1721. 'data' => array(
  1722. 'function' => create_function('$member', '
  1723. global $scripturl;
  1724. return allowedTo(\'issue_warning\') ? \'<a href="\' . $scripturl . \'?action=profile;area=issuewarning;u=\' . $member[\'id\'] . \'">\' . $member[\'warning\'] . \'%</a>\' : $member[\'warning\'] . \'%\';
  1725. '),
  1726. ),
  1727. 'sort' => array(
  1728. 'default' => 'warning',
  1729. 'reverse' => 'warning DESC',
  1730. ),
  1731. ),
  1732. 'posts' => array(
  1733. 'header' => array(
  1734. 'value' => $txt['posts'],
  1735. ),
  1736. 'data' => array(
  1737. 'sprintf' => array(
  1738. 'format' => '<a href="' . $scripturl . '?action=profile;u=%1$d;area=showposts;sa=messages">%2$s</a>',
  1739. 'params' => array(
  1740. 'id' => false,
  1741. 'posts' => false,
  1742. ),
  1743. ),
  1744. ),
  1745. 'sort' => array(
  1746. 'default' => 'posts',
  1747. 'reverse' => 'posts DESC',
  1748. ),
  1749. ),
  1750. 'last_login' => array(
  1751. 'header' => array(
  1752. 'value' => $txt['mc_watched_users_last_login'],
  1753. ),
  1754. 'data' => array(
  1755. 'db' => 'last_login',
  1756. ),
  1757. 'sort' => array(
  1758. 'default' => 'last_login',
  1759. 'reverse' => 'last_login DESC',
  1760. ),
  1761. ),
  1762. 'last_post' => array(
  1763. 'header' => array(
  1764. 'value' => $txt['mc_watched_users_last_post'],
  1765. ),
  1766. 'data' => array(
  1767. 'function' => create_function('$member', '
  1768. global $scripturl;
  1769. if ($member[\'last_post_id\'])
  1770. return \'<a href="\' . $scripturl . \'?msg=\' . $member[\'last_post_id\'] . \'">\' . $member[\'last_post\'] . \'</a>\';
  1771. else
  1772. return $member[\'last_post\'];
  1773. '),
  1774. ),
  1775. ),
  1776. ),
  1777. 'form' => array(
  1778. 'href' => $scripturl . '?action=moderate;area=userwatch;sa=post',
  1779. 'include_sort' => true,
  1780. 'include_start' => true,
  1781. 'hidden_fields' => array(
  1782. $context['session_var'] => $context['session_id'],
  1783. ),
  1784. ),
  1785. 'additional_rows' => array(
  1786. $context['view_posts'] ?
  1787. array(
  1788. 'position' => 'bottom_of_list',
  1789. 'value' => '
  1790. <input type="submit" name="delete_selected" value="' . $txt['quickmod_delete_selected'] . '" class="button_submit">',
  1791. 'align' => 'right',
  1792. ) : array(),
  1793. ),
  1794. );
  1795. // If this is being viewed by posts we actually change the columns to call a template each time.
  1796. if ($context['view_posts'])
  1797. {
  1798. $listOptions['columns'] = array(
  1799. 'posts' => array(
  1800. 'data' => array(
  1801. 'function' => create_function('$post', '
  1802. return template_user_watch_post_callback($post);
  1803. '),
  1804. ),
  1805. ),
  1806. );
  1807. }
  1808. // Create the watched user list.
  1809. createList($listOptions);
  1810. $context['sub_template'] = 'show_list';
  1811. $context['default_list'] = 'watch_user_list';
  1812. }
  1813. /**
  1814. * Callback for createList().
  1815. * @param $approve_query
  1816. */
  1817. function list_getWatchedUserCount($approve_query)
  1818. {
  1819. global $smcFunc, $modSettings;
  1820. $request = $smcFunc['db_query']('', '
  1821. SELECT COUNT(*)
  1822. FROM {db_prefix}members
  1823. WHERE warning >= {int:warning_watch}',
  1824. array(
  1825. 'warning_watch' => $modSettings['warning_watch'],
  1826. )
  1827. );
  1828. list ($totalMembers) = $smcFunc['db_fetch_row']($request);
  1829. $smcFunc['db_free_result']($request);
  1830. return $totalMembers;
  1831. }
  1832. /**
  1833. * Callback for createList().
  1834. *
  1835. * @param $start
  1836. * @param $items_per_page
  1837. * @param $sort
  1838. * @param $approve_query
  1839. * @param $dummy
  1840. */
  1841. function list_getWatchedUsers($start, $items_per_page, $sort, $approve_query, $dummy)
  1842. {
  1843. global $smcFunc, $txt, $scripturl, $modSettings, $user_info, $context;
  1844. $request = $smcFunc['db_query']('', '
  1845. SELECT id_member, real_name, last_login, posts, warning
  1846. FROM {db_prefix}members
  1847. WHERE warning >= {int:warning_watch}
  1848. ORDER BY {raw:sort}
  1849. LIMIT ' . $start . ', ' . $items_per_page,
  1850. array(
  1851. 'warning_watch' => $modSettings['warning_watch'],
  1852. 'sort' => $sort,
  1853. )
  1854. );
  1855. $watched_users = array();
  1856. $members = array();
  1857. while ($row = $smcFunc['db_fetch_assoc']($request))
  1858. {
  1859. $watched_users[$row['id_member']] = array(
  1860. 'id' => $row['id_member'],
  1861. 'name' => $row['real_name'],
  1862. 'last_login' => $row['last_login'] ? timeformat($row['last_login']) : $txt['never'],
  1863. 'last_post' => $txt['not_applicable'],
  1864. 'last_post_id' => 0,
  1865. 'warning' => $row['warning'],
  1866. 'posts' => $row['posts'],
  1867. );
  1868. $members[] = $row['id_member'];
  1869. }
  1870. $smcFunc['db_free_result']($request);
  1871. if (!empty($members))
  1872. {
  1873. // First get the latest messages from these users.
  1874. $request = $smcFunc['db_query']('', '
  1875. SELECT m.id_member, MAX(m.id_msg) AS last_post_id
  1876. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  1877. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  1878. WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  1879. AND m.approved = {int:is_approved}') . '
  1880. GROUP BY m.id_member',
  1881. array(
  1882. 'member_list' => $members,
  1883. 'is_approved' => 1,
  1884. )
  1885. );
  1886. $latest_posts = array();
  1887. while ($row = $smcFunc['db_fetch_assoc']($request))
  1888. $latest_posts[$row['id_member']] = $row['last_post_id'];
  1889. if (!empty($latest_posts))
  1890. {
  1891. // Now get the time those messages were posted.
  1892. $request = $smcFunc['db_query']('', '
  1893. SELECT id_member, poster_time
  1894. FROM {db_prefix}messages
  1895. WHERE id_msg IN ({array_int:message_list})',
  1896. array(
  1897. 'message_list' => $latest_posts,
  1898. )
  1899. );
  1900. while ($row = $smcFunc['db_fetch_assoc']($request))
  1901. {
  1902. $watched_users[$row['id_member']]['last_post'] = timeformat($row['poster_time']);
  1903. $watched_users[$row['id_member']]['last_post_id'] = $latest_posts[$row['id_member']];
  1904. }
  1905. $smcFunc['db_free_result']($request);
  1906. }
  1907. $request = $smcFunc['db_query']('', '
  1908. SELECT MAX(m.poster_time) AS last_post, MAX(m.id_msg) AS last_post_id, m.id_member
  1909. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  1910. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  1911. WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  1912. AND m.approved = {int:is_approved}') . '
  1913. GROUP BY m.id_member',
  1914. array(
  1915. 'member_list' => $members,
  1916. 'is_approved' => 1,
  1917. )
  1918. );
  1919. while ($row = $smcFunc['db_fetch_assoc']($request))
  1920. {
  1921. $watched_users[$row['id_member']]['last_post'] = timeformat($row['last_post']);
  1922. $watched_users[$row['id_member']]['last_post_id'] = $row['last_post_id'];
  1923. }
  1924. $smcFunc['db_free_result']($request);
  1925. }
  1926. return $watched_users;
  1927. }
  1928. /**
  1929. * Callback for createList().
  1930. *
  1931. * @param $approve_query
  1932. */
  1933. function list_getWatchedUserPostsCount($approve_query)
  1934. {
  1935. global $smcFunc, $modSettings;
  1936. $request = $smcFunc['db_query']('', '
  1937. SELECT COUNT(*)
  1938. FROM {db_prefix}messages AS m
  1939. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1940. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1941. WHERE mem.warning >= {int:warning_watch}
  1942. AND {query_see_board}
  1943. ' . $approve_query,
  1944. array(
  1945. 'warning_watch' => $modSettings['warning_watch'],
  1946. )
  1947. );
  1948. list ($totalMemberPosts) = $smcFunc['db_fetch_row']($request);
  1949. $smcFunc['db_free_result']($request);
  1950. return $totalMemberPosts;
  1951. }
  1952. /**
  1953. * Callback for createList().
  1954. *
  1955. * @param $start
  1956. * @param $items_per_page
  1957. * @param $sort
  1958. * @param $approve_query
  1959. * @param $delete_boards
  1960. */
  1961. function list_getWatchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards)
  1962. {
  1963. global $smcFunc, $txt, $scripturl, $modSettings;
  1964. $request = $smcFunc['db_query']('', '
  1965. SELECT m.id_msg, m.id_topic, m.id_board, m.id_member, m.subject, m.body, m.poster_time,
  1966. m.approved, mem.real_name, m.smileys_enabled
  1967. FROM {db_prefix}messages AS m
  1968. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  1969. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  1970. WHERE mem.warning >= {int:warning_watch}
  1971. AND {query_see_board}
  1972. ' . $approve_query . '
  1973. ORDER BY m.id_msg DESC
  1974. LIMIT ' . $start . ', ' . $items_per_page,
  1975. array(
  1976. 'warning_watch' => $modSettings['warning_watch'],
  1977. )
  1978. );
  1979. $member_posts = array();
  1980. while ($row = $smcFunc['db_fetch_assoc']($request))
  1981. {
  1982. $row['subject'] = censorText($row['subject']);
  1983. $row['body'] = censorText($row['body']);
  1984. $member_posts[$row['id_msg']] = array(
  1985. 'id' => $row['id_msg'],
  1986. 'id_topic' => $row['id_topic'],
  1987. 'author_link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
  1988. 'subject' => $row['subject'],
  1989. 'body' => parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']),
  1990. 'poster_time' => timeformat($row['poster_time']),
  1991. 'approved' => $row['approved'],
  1992. 'can_delete' => $delete_boards == array(0) || in_array($row['id_board'], $delete_boards),
  1993. );
  1994. }
  1995. $smcFunc['db_free_result']($request);
  1996. return $member_posts;
  1997. }
  1998. /**
  1999. * Entry point for viewing warning related stuff.
  2000. */
  2001. function ViewWarnings()
  2002. {
  2003. global $context, $txt;
  2004. $subActions = array(
  2005. 'log' => array('ViewWarningLog'),
  2006. 'templateedit' => array('ModifyWarningTemplate', 'issue_warning'),
  2007. 'templates' => array('ViewWarningTemplates', 'issue_warning'),
  2008. );
  2009. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) && (empty($subActions[$_REQUEST['sa']][1]) || allowedTo($subActions[$_REQUEST['sa']]))? $_REQUEST['sa'] : 'log';
  2010. // Some of this stuff is overseas, so to speak.
  2011. loadTemplate('ModerationCenter');
  2012. loadLanguage('Profile');
  2013. // Setup the admin tabs.
  2014. $context[$context['moderation_menu_name']]['tab_data'] = array(
  2015. 'title' => $txt['mc_warnings'],
  2016. 'description' => $txt['mc_warnings_description'],
  2017. );
  2018. // Call the right function.
  2019. $subActions[$_REQUEST['sa']][0]();
  2020. }
  2021. /**
  2022. * Simply put, look at the warning log!
  2023. */
  2024. function ViewWarningLog()
  2025. {
  2026. global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir;
  2027. // Setup context as always.
  2028. $context['page_title'] = $txt['mc_warning_log_title'];
  2029. require_once($sourcedir . '/Subs-List.php');
  2030. // This is all the information required for a watched user listing.
  2031. $listOptions = array(
  2032. 'id' => 'warning_list',
  2033. 'title' => $txt['mc_warning_log_title'],
  2034. 'items_per_page' => $modSettings['defaultMaxMessages'],
  2035. 'no_items_label' => $txt['mc_warnings_none'],
  2036. 'base_href' => $scripturl . '?action=moderate;area=warnings;sa=log;' . $context['session_var'] . '=' . $context['session_id'],
  2037. 'default_sort_col' => 'time',
  2038. 'get_items' => array(
  2039. 'function' => 'list_getWarnings',
  2040. ),
  2041. 'get_count' => array(
  2042. 'function' => 'list_getWarningCount',
  2043. ),
  2044. // This assumes we are viewing by user.
  2045. 'columns' => array(
  2046. 'issuer' => array(
  2047. 'header' => array(
  2048. 'value' => $txt['profile_warning_previous_issued'],
  2049. ),
  2050. 'data' => array(
  2051. 'db' => 'issuer_link',
  2052. ),
  2053. 'sort' => array(
  2054. 'default' => 'member_name_col',
  2055. 'reverse' => 'member_name_col DESC',
  2056. ),
  2057. ),
  2058. 'recipient' => array(
  2059. 'header' => array(
  2060. 'value' => $txt['mc_warnings_recipient'],
  2061. ),
  2062. 'data' => array(
  2063. 'db' => 'recipient_link',
  2064. ),
  2065. 'sort' => array(
  2066. 'default' => 'recipient_name',
  2067. 'reverse' => 'recipient_name DESC',
  2068. ),
  2069. ),
  2070. 'time' => array(
  2071. 'header' => array(
  2072. 'value' => $txt['profile_warning_previous_time'],
  2073. ),
  2074. 'data' => array(
  2075. 'db' => 'time',
  2076. ),
  2077. 'sort' => array(
  2078. 'default' => 'lc.log_time DESC',
  2079. 'reverse' => 'lc.log_time',
  2080. ),
  2081. ),
  2082. 'reason' => array(
  2083. 'header' => array(
  2084. 'value' => $txt['profile_warning_previous_reason'],
  2085. ),
  2086. 'data' => array(
  2087. 'function' => create_function('$warning', '
  2088. global $scripturl, $txt;
  2089. $output = \'
  2090. <div class="floatleft">
  2091. \' . $warning[\'reason\'] . \'
  2092. </div>\';
  2093. if (!empty($warning[\'id_notice\']))
  2094. $output .= \'
  2095. &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>\';
  2096. return $output;
  2097. '),
  2098. ),
  2099. ),
  2100. 'points' => array(
  2101. 'header' => array(
  2102. 'value' => $txt['profile_warning_previous_level'],
  2103. ),
  2104. 'data' => array(
  2105. 'db' => 'counter',
  2106. ),
  2107. ),
  2108. ),
  2109. );
  2110. // Create the watched user list.
  2111. createList($listOptions);
  2112. $context['sub_template'] = 'show_list';
  2113. $context['default_list'] = 'warning_list';
  2114. }
  2115. /**
  2116. * Callback for createList().
  2117. */
  2118. function list_getWarningCount()
  2119. {
  2120. global $smcFunc;
  2121. $request = $smcFunc['db_query']('', '
  2122. SELECT COUNT(*)
  2123. FROM {db_prefix}log_comments
  2124. WHERE comment_type = {string:warning}',
  2125. array(
  2126. 'warning' => 'warning',
  2127. )
  2128. );
  2129. list ($totalWarns) = $smcFunc['db_fetch_row']($request);
  2130. $smcFunc['db_free_result']($request);
  2131. return $totalWarns;
  2132. }
  2133. /**
  2134. * Callback for createList().
  2135. *
  2136. * @param $start
  2137. * @param $items_per_page
  2138. * @param $sort
  2139. */
  2140. function list_getWarnings($start, $items_per_page, $sort)
  2141. {
  2142. global $smcFunc, $txt, $scripturl;
  2143. $request = $smcFunc['db_query']('', '
  2144. SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name_col,
  2145. IFNULL(mem2.id_member, 0) AS id_recipient, IFNULL(mem2.real_name, lc.recipient_name) AS recipient_name,
  2146. lc.log_time, lc.body, lc.id_notice, lc.counter
  2147. FROM {db_prefix}log_comments AS lc
  2148. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  2149. LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = lc.id_recipient)
  2150. WHERE lc.comment_type = {string:warning}
  2151. ORDER BY ' . $sort . '
  2152. LIMIT ' . $start . ', ' . $items_per_page,
  2153. array(
  2154. 'warning' => 'warning',
  2155. )
  2156. );
  2157. $warnings = array();
  2158. while ($row = $smcFunc['db_fetch_assoc']($request))
  2159. {
  2160. $warnings[] = array(
  2161. 'issuer_link' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['member_name_col'] . '</a>') : $row['member_name_col'],
  2162. 'recipient_link' => $row['id_recipient'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_recipient'] . '">' . $row['recipient_name'] . '</a>') : $row['recipient_name'],
  2163. 'time' => timeformat($row['log_time']),
  2164. 'reason' => $row['body'],
  2165. 'counter' => $row['counter'] > 0 ? '+' . $row['counter'] : $row['counter'],
  2166. 'id_notice' => $row['id_notice'],
  2167. );
  2168. }
  2169. $smcFunc['db_free_result']($request);
  2170. return $warnings;
  2171. }
  2172. /**
  2173. * Load all the warning templates.
  2174. */
  2175. function ViewWarningTemplates()
  2176. {
  2177. global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir, $user_info;
  2178. // Submitting a new one?
  2179. if (isset($_POST['add']))
  2180. return ModifyWarningTemplate();
  2181. elseif (isset($_POST['delete']) && !empty($_POST['deltpl']))
  2182. {
  2183. checkSession();
  2184. validateToken('mod-wt');
  2185. // Log the actions.
  2186. $request = $smcFunc['db_query']('', '
  2187. SELECT recipient_name
  2188. FROM {db_prefix}log_comments
  2189. WHERE id_comment IN ({array_int:delete_ids})
  2190. AND comment_type = {string:warntpl}
  2191. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  2192. array(
  2193. 'delete_ids' => $_POST['deltpl'],
  2194. 'warntpl' => 'warntpl',
  2195. 'generic' => 0,
  2196. 'current_member' => $user_info['id'],
  2197. )
  2198. );
  2199. while ($row = $smcFunc['db_fetch_assoc']($request))
  2200. logAction('delete_warn_template', array('template' => $row['recipient_name']));
  2201. $smcFunc['db_free_result']($request);
  2202. // Do the deletes.
  2203. $smcFunc['db_query']('', '
  2204. DELETE FROM {db_prefix}log_comments
  2205. WHERE id_comment IN ({array_int:delete_ids})
  2206. AND comment_type = {string:warntpl}
  2207. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  2208. array(
  2209. 'delete_ids' => $_POST['deltpl'],
  2210. 'warntpl' => 'warntpl',
  2211. 'generic' => 0,
  2212. 'current_member' => $user_info['id'],
  2213. )
  2214. );
  2215. }
  2216. // Setup context as always.
  2217. $context['page_title'] = $txt['mc_warning_templates_title'];
  2218. require_once($sourcedir . '/Subs-List.php');
  2219. // This is all the information required for a watched user listing.
  2220. $listOptions = array(
  2221. 'id' => 'warning_template_list',
  2222. 'title' => $txt['mc_warning_templates_title'],
  2223. 'items_per_page' => $modSettings['defaultMaxMessages'],
  2224. 'no_items_label' => $txt['mc_warning_templates_none'],
  2225. 'base_href' => $scripturl . '?action=moderate;area=warnings;sa=templates;' . $context['session_var'] . '=' . $context['session_id'],
  2226. 'default_sort_col' => 'title',
  2227. 'get_items' => array(
  2228. 'function' => 'list_getWarningTemplates',
  2229. ),
  2230. 'get_count' => array(
  2231. 'function' => 'list_getWarningTemplateCount',
  2232. ),
  2233. // This assumes we are viewing by user.
  2234. 'columns' => array(
  2235. 'title' => array(
  2236. 'header' => array(
  2237. 'value' => $txt['mc_warning_templates_name'],
  2238. ),
  2239. 'data' => array(
  2240. 'sprintf' => array(
  2241. 'format' => '<a href="' . $scripturl . '?action=moderate;area=warnings;sa=templateedit;tid=%1$d">%2$s</a>',
  2242. 'params' => array(
  2243. 'id_comment' => false,
  2244. 'title' => false,
  2245. 'body' => false,
  2246. ),
  2247. ),
  2248. ),
  2249. 'sort' => array(
  2250. 'default' => 'template_title',
  2251. 'reverse' => 'template_title DESC',
  2252. ),
  2253. ),
  2254. 'creator' => array(
  2255. 'header' => array(
  2256. 'value' => $txt['mc_warning_templates_creator'],
  2257. ),
  2258. 'data' => array(
  2259. 'db' => 'creator',
  2260. ),
  2261. 'sort' => array(
  2262. 'default' => 'creator_name',
  2263. 'reverse' => 'creator_name DESC',
  2264. ),
  2265. ),
  2266. 'time' => array(
  2267. 'header' => array(
  2268. 'value' => $txt['mc_warning_templates_time'],
  2269. ),
  2270. 'data' => array(
  2271. 'db' => 'time',
  2272. ),
  2273. 'sort' => array(
  2274. 'default' => 'lc.log_time DESC',
  2275. 'reverse' => 'lc.log_time',
  2276. ),
  2277. ),
  2278. 'delete' => array(
  2279. 'header' => array(
  2280. 'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);">',
  2281. 'style' => 'width: 4%;',
  2282. 'class' => 'centercol',
  2283. ),
  2284. 'data' => array(
  2285. 'function' => create_function('$rowData', '
  2286. global $context, $txt, $scripturl;
  2287. return \'<input type="checkbox" name="deltpl[]" value="\' . $rowData[\'id_comment\'] . \'" class="input_check">\';
  2288. '),
  2289. 'class' => 'centercol',
  2290. ),
  2291. ),
  2292. ),
  2293. 'form' => array(
  2294. 'href' => $scripturl . '?action=moderate;area=warnings;sa=templates',
  2295. 'token' => 'mod-wt',
  2296. ),
  2297. 'additional_rows' => array(
  2298. array(
  2299. 'position' => 'below_table_data',
  2300. '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">',
  2301. ),
  2302. array(
  2303. 'position' => 'bottom_of_list',
  2304. 'value' => '<input type="submit" name="add" value="' . $txt['mc_warning_template_add'] . '" class="button_submit">',
  2305. ),
  2306. ),
  2307. );
  2308. // Create the watched user list.
  2309. createToken('mod-wt');
  2310. createList($listOptions);
  2311. $context['sub_template'] = 'show_list';
  2312. $context['default_list'] = 'warning_template_list';
  2313. }
  2314. /**
  2315. * Callback for createList().
  2316. */
  2317. function list_getWarningTemplateCount()
  2318. {
  2319. global $smcFunc, $user_info;
  2320. $request = $smcFunc['db_query']('', '
  2321. SELECT COUNT(*)
  2322. FROM {db_prefix}log_comments
  2323. WHERE comment_type = {string:warntpl}
  2324. AND (id_recipient = {string:generic} OR id_recipient = {int:current_member})',
  2325. array(
  2326. 'warntpl' => 'warntpl',
  2327. 'generic' => 0,
  2328. 'current_member' => $user_info['id'],
  2329. )
  2330. );
  2331. list ($totalWarns) = $smcFunc['db_fetch_row']($request);
  2332. $smcFunc['db_free_result']($request);
  2333. return $totalWarns;
  2334. }
  2335. /**
  2336. * Callback for createList().
  2337. *
  2338. * @param $start
  2339. * @param $items_per_page
  2340. * @param $sort
  2341. */
  2342. function list_getWarningTemplates($start, $items_per_page, $sort)
  2343. {
  2344. global $smcFunc, $txt, $scripturl, $user_info;
  2345. $request = $smcFunc['db_query']('', '
  2346. SELECT lc.id_comment, IFNULL(mem.id_member, 0) AS id_member,
  2347. IFNULL(mem.real_name, lc.member_name) AS creator_name, recipient_name AS template_title,
  2348. lc.log_time, lc.body
  2349. FROM {db_prefix}log_comments AS lc
  2350. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  2351. WHERE lc.comment_type = {string:warntpl}
  2352. AND (id_recipient = {string:generic} OR id_recipient = {int:current_member})
  2353. ORDER BY ' . $sort . '
  2354. LIMIT ' . $start . ', ' . $items_per_page,
  2355. array(
  2356. 'warntpl' => 'warntpl',
  2357. 'generic' => 0,
  2358. 'current_member' => $user_info['id'],
  2359. )
  2360. );
  2361. $templates = array();
  2362. while ($row = $smcFunc['db_fetch_assoc']($request))
  2363. {
  2364. $templates[] = array(
  2365. 'id_comment' => $row['id_comment'],
  2366. 'creator' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['creator_name'] . '</a>') : $row['creator_name'],
  2367. 'time' => timeformat($row['log_time']),
  2368. 'title' => $row['template_title'],
  2369. 'body' => $smcFunc['htmlspecialchars']($row['body']),
  2370. );
  2371. }
  2372. $smcFunc['db_free_result']($request);
  2373. return $templates;
  2374. }
  2375. /**
  2376. * Edit a warning template.
  2377. */
  2378. function ModifyWarningTemplate()
  2379. {
  2380. global $smcFunc, $context, $txt, $user_info, $sourcedir;
  2381. $context['id_template'] = isset($_REQUEST['tid']) ? (int) $_REQUEST['tid'] : 0;
  2382. $context['is_edit'] = $context['id_template'];
  2383. // Standard template things.
  2384. $context['page_title'] = $context['is_edit'] ? $txt['mc_warning_template_modify'] : $txt['mc_warning_template_add'];
  2385. $context['sub_template'] = 'warn_template';
  2386. $context[$context['moderation_menu_name']]['current_subsection'] = 'templates';
  2387. // Defaults.
  2388. $context['template_data'] = array(
  2389. 'title' => '',
  2390. 'body' => $txt['mc_warning_template_body_default'],
  2391. 'personal' => false,
  2392. 'can_edit_personal' => true,
  2393. );
  2394. // If it's an edit load it.
  2395. if ($context['is_edit'])
  2396. {
  2397. $request = $smcFunc['db_query']('', '
  2398. SELECT id_member, id_recipient, recipient_name AS template_title, body
  2399. FROM {db_prefix}log_comments
  2400. WHERE id_comment = {int:id}
  2401. AND comment_type = {string:warntpl}
  2402. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  2403. array(
  2404. 'id' => $context['id_template'],
  2405. 'warntpl' => 'warntpl',
  2406. 'generic' => 0,
  2407. 'current_member' => $user_info['id'],
  2408. )
  2409. );
  2410. while ($row = $smcFunc['db_fetch_assoc']($request))
  2411. {
  2412. $context['template_data'] = array(
  2413. 'title' => $row['template_title'],
  2414. 'body' => $smcFunc['htmlspecialchars']($row['body']),
  2415. 'personal' => $row['id_recipient'],
  2416. 'can_edit_personal' => $row['id_member'] == $user_info['id'],
  2417. );
  2418. }
  2419. $smcFunc['db_free_result']($request);
  2420. }
  2421. // Wait, we are saving?
  2422. if (isset($_POST['save']))
  2423. {
  2424. checkSession();
  2425. validateToken('mod-wt');
  2426. // To check the BBC is pretty good...
  2427. require_once($sourcedir . '/Subs-Post.php');
  2428. // Bit of cleaning!
  2429. $_POST['template_body'] = trim($_POST['template_body']);
  2430. $_POST['template_title'] = trim($_POST['template_title']);
  2431. // Need something in both boxes.
  2432. if (!empty($_POST['template_body']) && !empty($_POST['template_title']))
  2433. {
  2434. // Safety first.
  2435. $_POST['template_title'] = $smcFunc['htmlspecialchars']($_POST['template_title']);
  2436. // Clean up BBC.
  2437. preparsecode($_POST['template_body']);
  2438. // But put line breaks back!
  2439. $_POST['template_body'] = strtr($_POST['template_body'], array('<br>' => "\n"));
  2440. // Is this personal?
  2441. $recipient_id = !empty($_POST['make_personal']) ? $user_info['id'] : 0;
  2442. // If we are this far it's save time.
  2443. if ($context['is_edit'])
  2444. {
  2445. // Simple update...
  2446. $smcFunc['db_query']('', '
  2447. UPDATE {db_prefix}log_comments
  2448. SET id_recipient = {int:personal}, recipient_name = {string:title}, body = {string:body}
  2449. WHERE id_comment = {int:id}
  2450. AND comment_type = {string:warntpl}
  2451. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})'.
  2452. ($recipient_id ? ' AND id_member = {int:current_member}' : ''),
  2453. array(
  2454. 'personal' => $recipient_id,
  2455. 'title' => $_POST['template_title'],
  2456. 'body' => $_POST['template_body'],
  2457. 'id' => $context['id_template'],
  2458. 'warntpl' => 'warntpl',
  2459. 'generic' => 0,
  2460. 'current_member' => $user_info['id'],
  2461. )
  2462. );
  2463. // If it wasn't visible and now is they've effectively added it.
  2464. if ($context['template_data']['personal'] && !$recipient_id)
  2465. logAction('add_warn_template', array('template' => $_POST['template_title']));
  2466. // Conversely if they made it personal it's a delete.
  2467. elseif (!$context['template_data']['personal'] && $recipient_id)
  2468. logAction('delete_warn_template', array('template' => $_POST['template_title']));
  2469. // Otherwise just an edit.
  2470. else
  2471. logAction('modify_warn_template', array('template' => $_POST['template_title']));
  2472. }
  2473. else
  2474. {
  2475. $smcFunc['db_insert']('',
  2476. '{db_prefix}log_comments',
  2477. array(
  2478. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int',
  2479. 'recipient_name' => 'string-255', 'body' => 'string-65535', 'log_time' => 'int',
  2480. ),
  2481. array(
  2482. $user_info['id'], $user_info['name'], 'warntpl', $recipient_id,
  2483. $_POST['template_title'], $_POST['template_body'], time(),
  2484. ),
  2485. array('id_comment')
  2486. );
  2487. logAction('add_warn_template', array('template' => $_POST['template_title']));
  2488. }
  2489. // Get out of town...
  2490. redirectexit('action=moderate;area=warnings;sa=templates');
  2491. }
  2492. else
  2493. {
  2494. $context['warning_errors'] = array();
  2495. $context['template_data']['title'] = !empty($_POST['template_title']) ? $_POST['template_title'] : '';
  2496. $context['template_data']['body'] = !empty($_POST['template_body']) ? $_POST['template_body'] : $txt['mc_warning_template_body_default'];
  2497. $context['template_data']['personal'] = !empty($_POST['make_personal']);
  2498. if (empty($_POST['template_title']))
  2499. $context['warning_errors'][] = $txt['mc_warning_template_error_no_title'];
  2500. if (empty($_POST['template_body']))
  2501. $context['warning_errors'][] = $txt['mc_warning_template_error_no_body'];
  2502. }
  2503. }
  2504. createToken('mod-wt');
  2505. }
  2506. /**
  2507. * Change moderation preferences.
  2508. */
  2509. function ModerationSettings()
  2510. {
  2511. global $context, $smcFunc, $txt, $sourcedir, $scripturl, $user_settings, $user_info;
  2512. // Some useful context stuff.
  2513. loadTemplate('ModerationCenter');
  2514. $context['page_title'] = $txt['mc_settings'];
  2515. $context['sub_template'] = 'moderation_settings';
  2516. $context[$context['moderation_menu_name']]['tab_data'] = array(
  2517. 'title' => $txt['mc_prefs_title'],
  2518. 'help' => '',
  2519. 'description' => $txt['mc_prefs_desc']
  2520. );
  2521. $mod_blocks = '';
  2522. $pref_binary = 5;
  2523. $show_reports = 0;
  2524. // Are we saving?
  2525. if (isset($_POST['save']))
  2526. {
  2527. checkSession();
  2528. validateToken('mod-set');
  2529. /* Current format of mod_prefs is:
  2530. x|ABCD|yyy
  2531. WHERE:
  2532. x = Show report count on forum header.
  2533. ABCD = Block indexes to show on moderation main page.
  2534. yyy = Integer with the following bit status:
  2535. - yyy & 4 = Notify about posts awaiting approval.
  2536. */
  2537. // Now check other options!
  2538. $pref_binary = 0;
  2539. if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval']))
  2540. $pref_binary |= 4;
  2541. // Put it all together.
  2542. $mod_prefs = '0||' . $pref_binary;
  2543. updateMemberData($user_info['id'], array('mod_prefs' => $mod_prefs));
  2544. }
  2545. // What blocks does the user currently have selected?
  2546. $context['mod_settings'] = array(
  2547. 'notify_approval' => $pref_binary & 4,
  2548. );
  2549. createToken('mod-set');
  2550. }
  2551. /**
  2552. * This ends a moderator session, requiring authentication to access the MCP again.
  2553. */
  2554. function ModEndSession()
  2555. {
  2556. // This is so easy!
  2557. unset($_SESSION['moderate_time']);
  2558. // Clean any moderator tokens as well.
  2559. foreach ($_SESSION['token'] as $key => $token)
  2560. if (strpos($key, '-mod') !== false)
  2561. unset($_SESSION['token'][$key]);
  2562. redirectexit();
  2563. }
  2564. ?>