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