ModerationCenter.php 69 KB

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