ModerationCenter.php 68 KB

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