ModerationCenter.php 66 KB

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