ModerationCenter.php 69 KB

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