ModerationCenter.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  1. <?php
  2. /**
  3. * Moderation Center.
  4. *
  5. * Simple Machines Forum (SMF)
  6. *
  7. * @package SMF
  8. * @author Simple Machines http://www.simplemachines.org
  9. * @copyright 2014 Simple Machines and individual contributors
  10. * @license http://www.simplemachines.org/about/smf/license.php BSD
  11. *
  12. * @version 2.1 Alpha 1
  13. */
  14. if (!defined('SMF'))
  15. die('No direct access...');
  16. /**
  17. * Entry point for the moderation center.
  18. *
  19. * @param bool $dont_call = false
  20. */
  21. function ModerationMain($dont_call = false)
  22. {
  23. global $txt, $context, $scripturl, $sc, $modSettings, $user_info, $sourcedir, $options, $smcFunc;
  24. // Don't run this twice... and don't conflict with the admin bar.
  25. if (isset($context['admin_area']))
  26. return;
  27. $context['can_moderate_boards'] = $user_info['mod_cache']['bq'] != '0=1';
  28. $context['can_moderate_groups'] = $user_info['mod_cache']['gq'] != '0=1';
  29. $context['can_moderate_approvals'] = $modSettings['postmod_active'] && !empty($user_info['mod_cache']['ap']);
  30. // Everyone using this area must be allowed here!
  31. if (!$context['can_moderate_boards'] && !$context['can_moderate_groups'] && !$context['can_moderate_approvals'])
  32. isAllowedTo('access_mod_center');
  33. // We're gonna want a menu of some kind.
  34. require_once($sourcedir . '/Subs-Menu.php');
  35. // Load the language, and the template.
  36. loadLanguage('ModerationCenter');
  37. loadTemplate(false, 'admin');
  38. $context['admin_preferences'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array();
  39. $context['robot_no_index'] = true;
  40. // This is the menu structure - refer to Subs-Menu.php for the details.
  41. $moderation_areas = array(
  42. 'main' => array(
  43. 'title' => $txt['mc_main'],
  44. 'areas' => array(
  45. 'index' => array(
  46. 'label' => $txt['moderation_center'],
  47. 'function' => 'ModerationHome',
  48. 'icon' => 'administration.png',
  49. ),
  50. 'settings' => array(
  51. 'label' => $txt['mc_settings'],
  52. 'function' => 'ModerationSettings',
  53. 'icon' => 'features.png',
  54. ),
  55. 'modlogoff' => array(
  56. 'label' => $txt['mc_logoff'],
  57. 'function' => 'ModEndSession',
  58. 'enabled' => empty($modSettings['securityDisable_moderate']),
  59. 'icon' => 'exit.png',
  60. ),
  61. 'notice' => array(
  62. 'file' => 'ModerationCenter.php',
  63. 'function' => 'ShowNotice',
  64. 'select' => 'index'
  65. ),
  66. ),
  67. ),
  68. 'logs' => array(
  69. 'title' => $txt['mc_logs'],
  70. 'areas' => array(
  71. 'modlog' => array(
  72. 'label' => $txt['modlog_view'],
  73. 'enabled' => !empty($modSettings['modlog_enabled']) && $context['can_moderate_boards'],
  74. 'file' => 'Modlog.php',
  75. 'function' => 'ViewModlog',
  76. 'icon' => 'logs.png',
  77. ),
  78. 'warnings' => array(
  79. 'label' => $txt['mc_warnings'],
  80. 'enabled' => $modSettings['warning_settings'][0] == 1 && $context['can_moderate_boards'],
  81. 'function' => 'ViewWarnings',
  82. 'icon' => 'warning.png',
  83. 'subsections' => array(
  84. 'log' => array($txt['mc_warning_log']),
  85. 'templates' => array($txt['mc_warning_templates'], 'issue_warning'),
  86. ),
  87. ),
  88. ),
  89. ),
  90. 'posts' => array(
  91. 'title' => $txt['mc_posts'],
  92. 'enabled' => $context['can_moderate_boards'] || $context['can_moderate_approvals'],
  93. 'areas' => array(
  94. 'postmod' => array(
  95. 'label' => $txt['mc_unapproved_posts'],
  96. 'enabled' => $context['can_moderate_approvals'],
  97. 'file' => 'PostModeration.php',
  98. 'function' => 'PostModerationMain',
  99. 'icon' => 'posts.png',
  100. 'custom_url' => $scripturl . '?action=moderate;area=postmod',
  101. 'subsections' => array(
  102. 'posts' => array($txt['mc_unapproved_replies']),
  103. 'topics' => array($txt['mc_unapproved_topics']),
  104. ),
  105. ),
  106. 'attachmod' => array(
  107. 'label' => $txt['mc_unapproved_attachments'],
  108. 'enabled' => $context['can_moderate_approvals'],
  109. 'file' => 'PostModeration.php',
  110. 'function' => 'PostModerationMain',
  111. 'icon' => 'post_moderation_attach.png',
  112. 'custom_url' => $scripturl . '?action=moderate;area=attachmod;sa=attachments',
  113. ),
  114. 'reports' => array(
  115. 'label' => $txt['mc_reported_posts'],
  116. 'enabled' => $context['can_moderate_boards'],
  117. 'file' => 'ReportedPosts.php',
  118. 'function' => 'ReportedPosts',
  119. 'icon' => 'reports.png',
  120. 'subsections' => array(
  121. 'open' => array($txt['mc_reportedp_active']),
  122. 'closed' => array($txt['mc_reportedp_closed']),
  123. ),
  124. ),
  125. ),
  126. ),
  127. 'groups' => array(
  128. 'title' => $txt['mc_groups'],
  129. 'enabled' => $context['can_moderate_groups'],
  130. 'areas' => array(
  131. 'userwatch' => array(
  132. 'label' => $txt['mc_watched_users_title'],
  133. 'enabled' => $modSettings['warning_settings'][0] == 1 && $context['can_moderate_boards'],
  134. 'function' => 'ViewWatchedUsers',
  135. 'icon' => 'members_watched.png',
  136. 'subsections' => array(
  137. 'member' => array($txt['mc_watched_users_member']),
  138. 'post' => array($txt['mc_watched_users_post']),
  139. ),
  140. ),
  141. 'groups' => array(
  142. 'label' => $txt['mc_group_requests'],
  143. 'file' => 'Groups.php',
  144. 'function' => 'Groups',
  145. 'icon' => 'members_request.png',
  146. 'custom_url' => $scripturl . '?action=moderate;area=groups;sa=requests',
  147. ),
  148. 'viewgroups' => array(
  149. 'label' => $txt['mc_view_groups'],
  150. 'file' => 'Groups.php',
  151. 'function' => 'Groups',
  152. 'icon' => 'membergroups.png',
  153. ),
  154. ),
  155. ),
  156. );
  157. // Make sure the administrator has a valid session...
  158. validateSession('moderate');
  159. // I don't know where we're going - I don't know where we've been...
  160. $menuOptions = array(
  161. 'action' => 'moderate',
  162. 'disable_url_session_check' => true,
  163. );
  164. $mod_include_data = createMenu($moderation_areas, $menuOptions);
  165. unset($moderation_areas);
  166. // We got something - didn't we? DIDN'T WE!
  167. if ($mod_include_data == false)
  168. fatal_lang_error('no_access', false);
  169. // Retain the ID information in case required by a subaction.
  170. $context['moderation_menu_id'] = $context['max_menu_id'];
  171. $context['moderation_menu_name'] = 'menu_data_' . $context['moderation_menu_id'];
  172. // @todo: html in here is not good
  173. $context[$context['moderation_menu_name']]['tab_data'] = array(
  174. 'title' => $txt['moderation_center'],
  175. 'help' => '',
  176. 'description' => '
  177. <strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong>
  178. <br><br>
  179. ' . $txt['mc_description']);
  180. // What a pleasant shortcut - even tho we're not *really* on the admin screen who cares...
  181. $context['admin_area'] = $mod_include_data['current_area'];
  182. // Build the link tree.
  183. $context['linktree'][] = array(
  184. 'url' => $scripturl . '?action=moderate',
  185. 'name' => $txt['moderation_center'],
  186. );
  187. if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index')
  188. $context['linktree'][] = array(
  189. 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'],
  190. 'name' => $mod_include_data['label'],
  191. );
  192. if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label'])
  193. $context['linktree'][] = array(
  194. 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'] . ';sa=' . $mod_include_data['current_subsection'],
  195. 'name' => $mod_include_data['subsections'][$mod_include_data['current_subsection']][0],
  196. );
  197. // Now - finally - the bit before the encore - the main performance of course!
  198. if (!$dont_call)
  199. {
  200. if (isset($mod_include_data['file']))
  201. require_once($sourcedir . '/' . $mod_include_data['file']);
  202. $mod_include_data['function']();
  203. }
  204. }
  205. /**
  206. * This function basically is the home page of the moderation center.
  207. */
  208. function ModerationHome()
  209. {
  210. global $txt, $context, $scripturl, $user_info, $user_settings, $options;
  211. loadTemplate('ModerationCenter');
  212. loadJavascriptFile('admin.js', array('default_theme' => true), 'admin.js');
  213. $context['page_title'] = $txt['moderation_center'];
  214. $context['sub_template'] = 'moderation_center';
  215. // Handle moderators notes.
  216. ModBlockNotes();
  217. // Load what blocks the user actually can see...
  218. $valid_blocks = array();
  219. if ($context['can_moderate_groups'])
  220. $valid_blocks['g'] = 'GroupRequests';
  221. if ($context['can_moderate_boards'])
  222. {
  223. $valid_blocks['r'] = 'ReportedPosts';
  224. $valid_blocks['w'] = 'WatchedUsers';
  225. }
  226. call_integration_hook('integrate_mod_centre_blocks', array(&$valid_blocks));
  227. $context['mod_blocks'] = array();
  228. foreach ($valid_blocks as $k => $block)
  229. {
  230. $block = 'ModBlock' . $block;
  231. if (function_exists($block))
  232. $context['mod_blocks'][] = $block();
  233. }
  234. $context['admin_prefs'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array();
  235. }
  236. /**
  237. * Show a list of the most active watched users.
  238. */
  239. function ModBlockWatchedUsers()
  240. {
  241. global $context, $smcFunc, $scripturl, $modSettings;
  242. if (($watched_users = cache_get_data('recent_user_watches', 240)) === null)
  243. {
  244. $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch'];
  245. $request = $smcFunc['db_query']('', '
  246. SELECT id_member, real_name, last_login
  247. FROM {db_prefix}members
  248. WHERE warning >= {int:warning_watch}
  249. ORDER BY last_login DESC
  250. LIMIT 10',
  251. array(
  252. 'warning_watch' => $modSettings['warning_watch'],
  253. )
  254. );
  255. $watched_users = array();
  256. while ($row = $smcFunc['db_fetch_assoc']($request))
  257. $watched_users[] = $row;
  258. $smcFunc['db_free_result']($request);
  259. cache_put_data('recent_user_watches', $watched_users, 240);
  260. }
  261. $context['watched_users'] = array();
  262. foreach ($watched_users as $user)
  263. {
  264. $context['watched_users'][] = array(
  265. 'id' => $user['id_member'],
  266. 'name' => $user['real_name'],
  267. 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $user['id_member'] . '">' . $user['real_name'] . '</a>',
  268. 'href' => $scripturl . '?action=profile;u=' . $user['id_member'],
  269. 'last_login' => !empty($user['last_login']) ? timeformat($user['last_login']) : '',
  270. );
  271. }
  272. return 'watched_users';
  273. }
  274. /**
  275. * Show an area for the moderator to type into.
  276. */
  277. function ModBlockNotes()
  278. {
  279. global $context, $smcFunc, $scripturl, $txt, $user_info;
  280. // Are we saving a note?
  281. if (isset($_GET['modnote']) && isset($_POST['makenote']) && isset($_POST['new_note']))
  282. {
  283. checkSession();
  284. $_POST['new_note'] = $smcFunc['htmlspecialchars'](trim($_POST['new_note']));
  285. // Make sure they actually entered something.
  286. if (!empty($_POST['new_note']) && $_POST['new_note'] !== $txt['mc_click_add_note'])
  287. {
  288. // Insert it into the database then!
  289. $smcFunc['db_insert']('',
  290. '{db_prefix}log_comments',
  291. array(
  292. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string',
  293. 'body' => 'string', 'log_time' => 'int',
  294. ),
  295. array(
  296. $user_info['id'], $user_info['name'], 'modnote', '', $_POST['new_note'], time(),
  297. ),
  298. array('id_comment')
  299. );
  300. // Clear the cache.
  301. cache_put_data('moderator_notes', null, 240);
  302. cache_put_data('moderator_notes_total', null, 240);
  303. }
  304. // Redirect otherwise people can resubmit.
  305. redirectexit('action=moderate');
  306. }
  307. // Bye... bye...
  308. if (isset($_GET['notes']) && isset($_GET['delete']) && is_numeric($_GET['delete']))
  309. {
  310. checkSession('get');
  311. // Lets delete it.
  312. $smcFunc['db_query']('', '
  313. DELETE FROM {db_prefix}log_comments
  314. WHERE id_comment = {int:note}
  315. AND comment_type = {string:type}',
  316. array(
  317. 'note' => $_GET['delete'],
  318. 'type' => 'modnote',
  319. )
  320. );
  321. // Clear the cache.
  322. cache_put_data('moderator_notes', null, 240);
  323. cache_put_data('moderator_notes_total', null, 240);
  324. redirectexit('action=moderate');
  325. }
  326. // How many notes in total?
  327. if (($moderator_notes_total = cache_get_data('moderator_notes_total', 240)) === null)
  328. {
  329. $request = $smcFunc['db_query']('', '
  330. SELECT COUNT(*)
  331. FROM {db_prefix}log_comments AS lc
  332. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  333. WHERE lc.comment_type = {string:modnote}',
  334. array(
  335. 'modnote' => 'modnote',
  336. )
  337. );
  338. list ($moderator_notes_total) = $smcFunc['db_fetch_row']($request);
  339. $smcFunc['db_free_result']($request);
  340. cache_put_data('moderator_notes_total', $moderator_notes_total, 240);
  341. }
  342. // Grab the current notes. We can only use the cache for the first page of notes.
  343. $offset = isset($_GET['notes']) && isset($_GET['start']) ? $_GET['start'] : 0;
  344. if ($offset != 0 || ($moderator_notes = cache_get_data('moderator_notes', 240)) === null)
  345. {
  346. $request = $smcFunc['db_query']('', '
  347. SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name,
  348. lc.log_time, lc.body, lc.id_comment AS id_note
  349. FROM {db_prefix}log_comments AS lc
  350. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  351. WHERE lc.comment_type = {string:modnote}
  352. ORDER BY id_comment DESC
  353. LIMIT {int:offset}, 10',
  354. array(
  355. 'modnote' => 'modnote',
  356. 'offset' => $offset,
  357. )
  358. );
  359. $moderator_notes = array();
  360. while ($row = $smcFunc['db_fetch_assoc']($request))
  361. $moderator_notes[] = $row;
  362. $smcFunc['db_free_result']($request);
  363. if ($offset == 0)
  364. cache_put_data('moderator_notes', $moderator_notes, 240);
  365. }
  366. // Lets construct a page index.
  367. $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=index;notes', $_GET['start'], $moderator_notes_total, 10);
  368. $context['start'] = $_GET['start'];
  369. $context['notes'] = array();
  370. foreach ($moderator_notes as $note)
  371. {
  372. $context['notes'][] = array(
  373. 'author' => array(
  374. 'id' => $note['id_member'],
  375. 'link' => $note['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $note['id_member'] . '">' . $note['member_name'] . '</a>') : $note['member_name'],
  376. ),
  377. 'time' => timeformat($note['log_time']),
  378. 'text' => parse_bbc($note['body']),
  379. 'delete_href' => $scripturl . '?action=moderate;area=index;notes;delete=' . $note['id_note'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  380. );
  381. }
  382. return 'notes';
  383. }
  384. /**
  385. * Show a list of the most recent reported posts.
  386. */
  387. function ModBlockReportedPosts()
  388. {
  389. global $context, $user_info, $scripturl, $smcFunc;
  390. // Got the info already?
  391. $cachekey = md5(serialize($user_info['mod_cache']['bq']));
  392. $context['reported_posts'] = array();
  393. if ($user_info['mod_cache']['bq'] == '0=1')
  394. return 'reported_posts_block';
  395. if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null)
  396. {
  397. // By George, that means we in a position to get the reports, jolly good.
  398. $request = $smcFunc['db_query']('', '
  399. SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject,
  400. lr.num_reports, IFNULL(mem.real_name, lr.membername) AS author_name,
  401. IFNULL(mem.id_member, 0) AS id_author
  402. FROM {db_prefix}log_reported AS lr
  403. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  404. WHERE ' . ($user_info['mod_cache']['bq'] == '1=1' || $user_info['mod_cache']['bq'] == '0=1' ? $user_info['mod_cache']['bq'] : 'lr.' . $user_info['mod_cache']['bq']) . '
  405. AND lr.closed = {int:not_closed}
  406. AND lr.ignore_all = {int:not_ignored}
  407. ORDER BY lr.time_updated DESC
  408. LIMIT 10',
  409. array(
  410. 'not_closed' => 0,
  411. 'not_ignored' => 0,
  412. )
  413. );
  414. $reported_posts = array();
  415. while ($row = $smcFunc['db_fetch_assoc']($request))
  416. $reported_posts[] = $row;
  417. $smcFunc['db_free_result']($request);
  418. // Cache it.
  419. cache_put_data('reported_posts_' . $cachekey, $reported_posts, 90);
  420. }
  421. $context['reported_posts'] = array();
  422. foreach ($reported_posts as $i => $row)
  423. {
  424. $context['reported_posts'][] = array(
  425. 'id' => $row['id_report'],
  426. 'alternate' => $i % 2,
  427. 'topic_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
  428. 'report_href' => $scripturl . '?action=moderate;area=reports;report=' . $row['id_report'],
  429. 'author' => array(
  430. 'id' => $row['id_author'],
  431. 'name' => $row['author_name'],
  432. 'link' => $row['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_author'] . '">' . $row['author_name'] . '</a>' : $row['author_name'],
  433. 'href' => $scripturl . '?action=profile;u=' . $row['id_author'],
  434. ),
  435. 'comments' => array(),
  436. 'subject' => $row['subject'],
  437. 'num_reports' => $row['num_reports'],
  438. );
  439. }
  440. return 'reported_posts_block';
  441. }
  442. /**
  443. * Show a list of all the group requests they can see.
  444. */
  445. function ModBlockGroupRequests()
  446. {
  447. global $context, $user_info, $scripturl, $smcFunc;
  448. $context['group_requests'] = array();
  449. // Make sure they can even moderate someone!
  450. if ($user_info['mod_cache']['gq'] == '0=1')
  451. return 'group_requests_block';
  452. // What requests are outstanding?
  453. $request = $smcFunc['db_query']('', '
  454. SELECT lgr.id_request, lgr.id_member, lgr.id_group, lgr.time_applied, mem.member_name, mg.group_name, mem.real_name
  455. FROM {db_prefix}log_group_requests AS lgr
  456. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = lgr.id_member)
  457. INNER JOIN {db_prefix}membergroups AS mg ON (mg.id_group = lgr.id_group)
  458. WHERE ' . ($user_info['mod_cache']['gq'] == '1=1' || $user_info['mod_cache']['gq'] == '0=1' ? $user_info['mod_cache']['gq'] : 'lgr.' . $user_info['mod_cache']['gq']) . '
  459. AND lgr.status = {int:status_open}
  460. ORDER BY lgr.id_request DESC
  461. LIMIT 10',
  462. array(
  463. 'status_open' => 0,
  464. )
  465. );
  466. for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i ++)
  467. {
  468. $context['group_requests'][] = array(
  469. 'id' => $row['id_request'],
  470. 'alternate' => $i % 2,
  471. 'request_href' => $scripturl . '?action=groups;sa=requests;gid=' . $row['id_group'],
  472. 'member' => array(
  473. 'id' => $row['id_member'],
  474. 'name' => $row['real_name'],
  475. 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
  476. 'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
  477. ),
  478. 'group' => array(
  479. 'id' => $row['id_group'],
  480. 'name' => $row['group_name'],
  481. ),
  482. 'time_submitted' => timeformat($row['time_applied']),
  483. );
  484. }
  485. $smcFunc['db_free_result']($request);
  486. return 'group_requests_block';
  487. }
  488. /**
  489. * Act as an entrace for all group related activity.
  490. * @todo As for most things in this file, this needs to be moved somewhere appropriate?
  491. */
  492. function ModerateGroups()
  493. {
  494. global $txt, $context, $scripturl, $user_info;
  495. // You need to be allowed to moderate groups...
  496. if ($user_info['mod_cache']['gq'] == '0=1')
  497. isAllowedTo('manage_membergroups');
  498. // Load the group templates.
  499. loadTemplate('ModerationCenter');
  500. // Setup the subactions...
  501. $subactions = array(
  502. 'requests' => 'GroupRequests',
  503. 'view' => 'ViewGroups',
  504. );
  505. if (!isset($_GET['sa']) || !isset($subactions[$_GET['sa']]))
  506. $_GET['sa'] = 'view';
  507. $context['sub_action'] = $_GET['sa'];
  508. // Call the relevant function.
  509. $subactions[$context['sub_action']]();
  510. }
  511. /**
  512. * Show a notice sent to a user.
  513. */
  514. function ShowNotice()
  515. {
  516. global $smcFunc, $txt, $context;
  517. $context['page_title'] = $txt['show_notice'];
  518. $context['sub_template'] = 'show_notice';
  519. $context['template_layers'] = array();
  520. loadTemplate('ModerationCenter');
  521. // @todo Assumes nothing needs permission more than accessing moderation center!
  522. $id_notice = (int) $_GET['nid'];
  523. $request = $smcFunc['db_query']('', '
  524. SELECT body, subject
  525. FROM {db_prefix}log_member_notices
  526. WHERE id_notice = {int:id_notice}',
  527. array(
  528. 'id_notice' => $id_notice,
  529. )
  530. );
  531. if ($smcFunc['db_num_rows']($request) == 0)
  532. fatal_lang_error('no_access', false);
  533. list ($context['notice_body'], $context['notice_subject']) = $smcFunc['db_fetch_row']($request);
  534. $smcFunc['db_free_result']($request);
  535. $context['notice_body'] = parse_bbc($context['notice_body'], false);
  536. }
  537. /**
  538. * View watched users.
  539. */
  540. function ViewWatchedUsers()
  541. {
  542. global $smcFunc, $modSettings, $context, $txt, $scripturl, $user_info, $sourcedir;
  543. // Some important context!
  544. $context['page_title'] = $txt['mc_watched_users_title'];
  545. $context['view_posts'] = isset($_GET['sa']) && $_GET['sa'] == 'post';
  546. $context['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
  547. loadTemplate('ModerationCenter');
  548. // Get some key settings!
  549. $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch'];
  550. // Put some pretty tabs on cause we're gonna be doing hot stuff here...
  551. $context[$context['moderation_menu_name']]['tab_data'] = array(
  552. 'title' => $txt['mc_watched_users_title'],
  553. 'help' => '',
  554. 'description' => $txt['mc_watched_users_desc'],
  555. );
  556. // First off - are we deleting?
  557. if (!empty($_REQUEST['delete']))
  558. {
  559. checkSession(!is_array($_REQUEST['delete']) ? 'get' : 'post');
  560. $toDelete = array();
  561. if (!is_array($_REQUEST['delete']))
  562. $toDelete[] = (int) $_REQUEST['delete'];
  563. else
  564. foreach ($_REQUEST['delete'] as $did)
  565. $toDelete[] = (int) $did;
  566. if (!empty($toDelete))
  567. {
  568. require_once($sourcedir . '/RemoveTopic.php');
  569. // If they don't have permission we'll let it error - either way no chance of a security slip here!
  570. foreach ($toDelete as $did)
  571. removeMessage($did);
  572. }
  573. }
  574. // Start preparing the list by grabbing relevant permissions.
  575. if (!$context['view_posts'])
  576. {
  577. $approve_query = '';
  578. $delete_boards = array();
  579. }
  580. else
  581. {
  582. // Still obey permissions!
  583. $approve_boards = boardsAllowedTo('approve_posts');
  584. $delete_boards = boardsAllowedTo('delete_any');
  585. if ($approve_boards == array(0))
  586. $approve_query = '';
  587. elseif (!empty($approve_boards))
  588. $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
  589. // Nada, zip, etc...
  590. else
  591. $approve_query = ' AND 1=0';
  592. }
  593. require_once($sourcedir . '/Subs-List.php');
  594. // This is all the information required for a watched user listing.
  595. $listOptions = array(
  596. 'id' => 'watch_user_list',
  597. 'title' => $txt['mc_watched_users_title'] . ' - ' . ($context['view_posts'] ? $txt['mc_watched_users_post'] : $txt['mc_watched_users_member']),
  598. 'width' => '100%',
  599. 'items_per_page' => $modSettings['defaultMaxMessages'],
  600. 'no_items_label' => $context['view_posts'] ? $txt['mc_watched_users_no_posts'] : $txt['mc_watched_users_none'],
  601. 'base_href' => $scripturl . '?action=moderate;area=userwatch;sa=' . ($context['view_posts'] ? 'post' : 'member'),
  602. 'default_sort_col' => $context['view_posts'] ? '' : 'member',
  603. 'get_items' => array(
  604. 'function' => $context['view_posts'] ? 'list_getWatchedUserPosts' : 'list_getWatchedUsers',
  605. 'params' => array(
  606. $approve_query,
  607. $delete_boards,
  608. ),
  609. ),
  610. 'get_count' => array(
  611. 'function' => $context['view_posts'] ? 'list_getWatchedUserPostsCount' : 'list_getWatchedUserCount',
  612. 'params' => array(
  613. $approve_query,
  614. ),
  615. ),
  616. // This assumes we are viewing by user.
  617. 'columns' => array(
  618. 'member' => array(
  619. 'header' => array(
  620. 'value' => $txt['mc_watched_users_member'],
  621. ),
  622. 'data' => array(
  623. 'sprintf' => array(
  624. 'format' => '<a href="' . $scripturl . '?action=profile;u=%1$d">%2$s</a>',
  625. 'params' => array(
  626. 'id' => false,
  627. 'name' => false,
  628. ),
  629. ),
  630. ),
  631. 'sort' => array(
  632. 'default' => 'real_name',
  633. 'reverse' => 'real_name DESC',
  634. ),
  635. ),
  636. 'warning' => array(
  637. 'header' => array(
  638. 'value' => $txt['mc_watched_users_warning'],
  639. ),
  640. 'data' => array(
  641. 'function' => create_function('$member', '
  642. global $scripturl;
  643. return allowedTo(\'issue_warning\') ? \'<a href="\' . $scripturl . \'?action=profile;area=issuewarning;u=\' . $member[\'id\'] . \'">\' . $member[\'warning\'] . \'%</a>\' : $member[\'warning\'] . \'%\';
  644. '),
  645. ),
  646. 'sort' => array(
  647. 'default' => 'warning',
  648. 'reverse' => 'warning DESC',
  649. ),
  650. ),
  651. 'posts' => array(
  652. 'header' => array(
  653. 'value' => $txt['posts'],
  654. ),
  655. 'data' => array(
  656. 'sprintf' => array(
  657. 'format' => '<a href="' . $scripturl . '?action=profile;u=%1$d;area=showposts;sa=messages">%2$s</a>',
  658. 'params' => array(
  659. 'id' => false,
  660. 'posts' => false,
  661. ),
  662. ),
  663. ),
  664. 'sort' => array(
  665. 'default' => 'posts',
  666. 'reverse' => 'posts DESC',
  667. ),
  668. ),
  669. 'last_login' => array(
  670. 'header' => array(
  671. 'value' => $txt['mc_watched_users_last_login'],
  672. ),
  673. 'data' => array(
  674. 'db' => 'last_login',
  675. ),
  676. 'sort' => array(
  677. 'default' => 'last_login',
  678. 'reverse' => 'last_login DESC',
  679. ),
  680. ),
  681. 'last_post' => array(
  682. 'header' => array(
  683. 'value' => $txt['mc_watched_users_last_post'],
  684. ),
  685. 'data' => array(
  686. 'function' => create_function('$member', '
  687. global $scripturl;
  688. if ($member[\'last_post_id\'])
  689. return \'<a href="\' . $scripturl . \'?msg=\' . $member[\'last_post_id\'] . \'">\' . $member[\'last_post\'] . \'</a>\';
  690. else
  691. return $member[\'last_post\'];
  692. '),
  693. ),
  694. ),
  695. ),
  696. 'form' => array(
  697. 'href' => $scripturl . '?action=moderate;area=userwatch;sa=post',
  698. 'include_sort' => true,
  699. 'include_start' => true,
  700. 'hidden_fields' => array(
  701. $context['session_var'] => $context['session_id'],
  702. ),
  703. ),
  704. 'additional_rows' => array(
  705. $context['view_posts'] ?
  706. array(
  707. 'position' => 'bottom_of_list',
  708. 'value' => '
  709. <input type="submit" name="delete_selected" value="' . $txt['quickmod_delete_selected'] . '" class="button_submit">',
  710. 'align' => 'right',
  711. ) : array(),
  712. ),
  713. );
  714. // If this is being viewed by posts we actually change the columns to call a template each time.
  715. if ($context['view_posts'])
  716. {
  717. $listOptions['columns'] = array(
  718. 'posts' => array(
  719. 'data' => array(
  720. 'function' => create_function('$post', '
  721. return template_user_watch_post_callback($post);
  722. '),
  723. ),
  724. ),
  725. );
  726. }
  727. // Create the watched user list.
  728. createList($listOptions);
  729. $context['sub_template'] = 'show_list';
  730. $context['default_list'] = 'watch_user_list';
  731. }
  732. /**
  733. * Callback for createList().
  734. * @param $approve_query
  735. */
  736. function list_getWatchedUserCount($approve_query)
  737. {
  738. global $smcFunc, $modSettings;
  739. $request = $smcFunc['db_query']('', '
  740. SELECT COUNT(*)
  741. FROM {db_prefix}members
  742. WHERE warning >= {int:warning_watch}',
  743. array(
  744. 'warning_watch' => $modSettings['warning_watch'],
  745. )
  746. );
  747. list ($totalMembers) = $smcFunc['db_fetch_row']($request);
  748. $smcFunc['db_free_result']($request);
  749. return $totalMembers;
  750. }
  751. /**
  752. * Callback for createList().
  753. *
  754. * @param $start
  755. * @param $items_per_page
  756. * @param $sort
  757. * @param $approve_query
  758. * @param $dummy
  759. */
  760. function list_getWatchedUsers($start, $items_per_page, $sort, $approve_query, $dummy)
  761. {
  762. global $smcFunc, $txt, $scripturl, $modSettings, $user_info, $context;
  763. $request = $smcFunc['db_query']('', '
  764. SELECT id_member, real_name, last_login, posts, warning
  765. FROM {db_prefix}members
  766. WHERE warning >= {int:warning_watch}
  767. ORDER BY {raw:sort}
  768. LIMIT ' . $start . ', ' . $items_per_page,
  769. array(
  770. 'warning_watch' => $modSettings['warning_watch'],
  771. 'sort' => $sort,
  772. )
  773. );
  774. $watched_users = array();
  775. $members = array();
  776. while ($row = $smcFunc['db_fetch_assoc']($request))
  777. {
  778. $watched_users[$row['id_member']] = array(
  779. 'id' => $row['id_member'],
  780. 'name' => $row['real_name'],
  781. 'last_login' => $row['last_login'] ? timeformat($row['last_login']) : $txt['never'],
  782. 'last_post' => $txt['not_applicable'],
  783. 'last_post_id' => 0,
  784. 'warning' => $row['warning'],
  785. 'posts' => $row['posts'],
  786. );
  787. $members[] = $row['id_member'];
  788. }
  789. $smcFunc['db_free_result']($request);
  790. if (!empty($members))
  791. {
  792. // First get the latest messages from these users.
  793. $request = $smcFunc['db_query']('', '
  794. SELECT m.id_member, MAX(m.id_msg) AS last_post_id
  795. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  796. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  797. WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  798. AND m.approved = {int:is_approved}') . '
  799. GROUP BY m.id_member',
  800. array(
  801. 'member_list' => $members,
  802. 'is_approved' => 1,
  803. )
  804. );
  805. $latest_posts = array();
  806. while ($row = $smcFunc['db_fetch_assoc']($request))
  807. $latest_posts[$row['id_member']] = $row['last_post_id'];
  808. if (!empty($latest_posts))
  809. {
  810. // Now get the time those messages were posted.
  811. $request = $smcFunc['db_query']('', '
  812. SELECT id_member, poster_time
  813. FROM {db_prefix}messages
  814. WHERE id_msg IN ({array_int:message_list})',
  815. array(
  816. 'message_list' => $latest_posts,
  817. )
  818. );
  819. while ($row = $smcFunc['db_fetch_assoc']($request))
  820. {
  821. $watched_users[$row['id_member']]['last_post'] = timeformat($row['poster_time']);
  822. $watched_users[$row['id_member']]['last_post_id'] = $latest_posts[$row['id_member']];
  823. }
  824. $smcFunc['db_free_result']($request);
  825. }
  826. $request = $smcFunc['db_query']('', '
  827. SELECT MAX(m.poster_time) AS last_post, MAX(m.id_msg) AS last_post_id, m.id_member
  828. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  829. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  830. WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  831. AND m.approved = {int:is_approved}') . '
  832. GROUP BY m.id_member',
  833. array(
  834. 'member_list' => $members,
  835. 'is_approved' => 1,
  836. )
  837. );
  838. while ($row = $smcFunc['db_fetch_assoc']($request))
  839. {
  840. $watched_users[$row['id_member']]['last_post'] = timeformat($row['last_post']);
  841. $watched_users[$row['id_member']]['last_post_id'] = $row['last_post_id'];
  842. }
  843. $smcFunc['db_free_result']($request);
  844. }
  845. return $watched_users;
  846. }
  847. /**
  848. * Callback for createList().
  849. *
  850. * @param $approve_query
  851. */
  852. function list_getWatchedUserPostsCount($approve_query)
  853. {
  854. global $smcFunc, $modSettings, $user_info;
  855. $request = $smcFunc['db_query']('', '
  856. SELECT COUNT(*)
  857. FROM {db_prefix}messages AS m
  858. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  859. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  860. WHERE mem.warning >= {int:warning_watch}
  861. AND {query_see_board}
  862. ' . $approve_query,
  863. array(
  864. 'warning_watch' => $modSettings['warning_watch'],
  865. )
  866. );
  867. list ($totalMemberPosts) = $smcFunc['db_fetch_row']($request);
  868. $smcFunc['db_free_result']($request);
  869. return $totalMemberPosts;
  870. }
  871. /**
  872. * Callback for createList().
  873. *
  874. * @param $start
  875. * @param $items_per_page
  876. * @param $sort
  877. * @param $approve_query
  878. * @param $delete_boards
  879. */
  880. function list_getWatchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards)
  881. {
  882. global $smcFunc, $txt, $scripturl, $modSettings, $user_info;
  883. $request = $smcFunc['db_query']('', '
  884. SELECT m.id_msg, m.id_topic, m.id_board, m.id_member, m.subject, m.body, m.poster_time,
  885. m.approved, mem.real_name, m.smileys_enabled
  886. FROM {db_prefix}messages AS m
  887. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  888. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  889. WHERE mem.warning >= {int:warning_watch}
  890. AND {query_see_board}
  891. ' . $approve_query . '
  892. ORDER BY m.id_msg DESC
  893. LIMIT ' . $start . ', ' . $items_per_page,
  894. array(
  895. 'warning_watch' => $modSettings['warning_watch'],
  896. )
  897. );
  898. $member_posts = array();
  899. while ($row = $smcFunc['db_fetch_assoc']($request))
  900. {
  901. $row['subject'] = censorText($row['subject']);
  902. $row['body'] = censorText($row['body']);
  903. $member_posts[$row['id_msg']] = array(
  904. 'id' => $row['id_msg'],
  905. 'id_topic' => $row['id_topic'],
  906. 'author_link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
  907. 'subject' => $row['subject'],
  908. 'body' => parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']),
  909. 'poster_time' => timeformat($row['poster_time']),
  910. 'approved' => $row['approved'],
  911. 'can_delete' => $delete_boards == array(0) || in_array($row['id_board'], $delete_boards),
  912. );
  913. }
  914. $smcFunc['db_free_result']($request);
  915. return $member_posts;
  916. }
  917. /**
  918. * Entry point for viewing warning related stuff.
  919. */
  920. function ViewWarnings()
  921. {
  922. global $context, $txt;
  923. $subActions = array(
  924. 'log' => array('ViewWarningLog'),
  925. 'templateedit' => array('ModifyWarningTemplate', 'issue_warning'),
  926. 'templates' => array('ViewWarningTemplates', 'issue_warning'),
  927. );
  928. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) && (empty($subActions[$_REQUEST['sa']][1]) || allowedTo($subActions[$_REQUEST['sa']]))? $_REQUEST['sa'] : 'log';
  929. // Some of this stuff is overseas, so to speak.
  930. loadTemplate('ModerationCenter');
  931. loadLanguage('Profile');
  932. // Setup the admin tabs.
  933. $context[$context['moderation_menu_name']]['tab_data'] = array(
  934. 'title' => $txt['mc_warnings'],
  935. 'description' => $txt['mc_warnings_description'],
  936. );
  937. // Call the right function.
  938. $subActions[$_REQUEST['sa']][0]();
  939. }
  940. /**
  941. * Simply put, look at the warning log!
  942. */
  943. function ViewWarningLog()
  944. {
  945. global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir;
  946. // Setup context as always.
  947. $context['page_title'] = $txt['mc_warning_log_title'];
  948. require_once($sourcedir . '/Subs-List.php');
  949. // This is all the information required for a watched user listing.
  950. $listOptions = array(
  951. 'id' => 'warning_list',
  952. 'title' => $txt['mc_warning_log_title'],
  953. 'items_per_page' => $modSettings['defaultMaxMessages'],
  954. 'no_items_label' => $txt['mc_warnings_none'],
  955. 'base_href' => $scripturl . '?action=moderate;area=warnings;sa=log;' . $context['session_var'] . '=' . $context['session_id'],
  956. 'default_sort_col' => 'time',
  957. 'get_items' => array(
  958. 'function' => 'list_getWarnings',
  959. ),
  960. 'get_count' => array(
  961. 'function' => 'list_getWarningCount',
  962. ),
  963. // This assumes we are viewing by user.
  964. 'columns' => array(
  965. 'issuer' => array(
  966. 'header' => array(
  967. 'value' => $txt['profile_warning_previous_issued'],
  968. ),
  969. 'data' => array(
  970. 'db' => 'issuer_link',
  971. ),
  972. 'sort' => array(
  973. 'default' => 'member_name_col',
  974. 'reverse' => 'member_name_col DESC',
  975. ),
  976. ),
  977. 'recipient' => array(
  978. 'header' => array(
  979. 'value' => $txt['mc_warnings_recipient'],
  980. ),
  981. 'data' => array(
  982. 'db' => 'recipient_link',
  983. ),
  984. 'sort' => array(
  985. 'default' => 'recipient_name',
  986. 'reverse' => 'recipient_name DESC',
  987. ),
  988. ),
  989. 'time' => array(
  990. 'header' => array(
  991. 'value' => $txt['profile_warning_previous_time'],
  992. ),
  993. 'data' => array(
  994. 'db' => 'time',
  995. ),
  996. 'sort' => array(
  997. 'default' => 'lc.log_time DESC',
  998. 'reverse' => 'lc.log_time',
  999. ),
  1000. ),
  1001. 'reason' => array(
  1002. 'header' => array(
  1003. 'value' => $txt['profile_warning_previous_reason'],
  1004. ),
  1005. 'data' => array(
  1006. 'function' => create_function('$warning', '
  1007. global $scripturl, $settings, $txt;
  1008. $output = \'
  1009. <div class="floatleft">
  1010. \' . $warning[\'reason\'] . \'
  1011. </div>\';
  1012. if (!empty($warning[\'id_notice\']))
  1013. $output .= \'
  1014. <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>\';
  1015. return $output;
  1016. '),
  1017. ),
  1018. ),
  1019. 'points' => array(
  1020. 'header' => array(
  1021. 'value' => $txt['profile_warning_previous_level'],
  1022. ),
  1023. 'data' => array(
  1024. 'db' => 'counter',
  1025. ),
  1026. ),
  1027. ),
  1028. );
  1029. // Create the watched user list.
  1030. createList($listOptions);
  1031. $context['sub_template'] = 'show_list';
  1032. $context['default_list'] = 'warning_list';
  1033. }
  1034. /**
  1035. * Callback for createList().
  1036. */
  1037. function list_getWarningCount()
  1038. {
  1039. global $smcFunc;
  1040. $request = $smcFunc['db_query']('', '
  1041. SELECT COUNT(*)
  1042. FROM {db_prefix}log_comments
  1043. WHERE comment_type = {string:warning}',
  1044. array(
  1045. 'warning' => 'warning',
  1046. )
  1047. );
  1048. list ($totalWarns) = $smcFunc['db_fetch_row']($request);
  1049. $smcFunc['db_free_result']($request);
  1050. return $totalWarns;
  1051. }
  1052. /**
  1053. * Callback for createList().
  1054. *
  1055. * @param $start
  1056. * @param $items_per_page
  1057. * @param $sort
  1058. */
  1059. function list_getWarnings($start, $items_per_page, $sort)
  1060. {
  1061. global $smcFunc, $txt, $scripturl, $user_info;
  1062. $request = $smcFunc['db_query']('', '
  1063. SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name_col,
  1064. IFNULL(mem2.id_member, 0) AS id_recipient, IFNULL(mem2.real_name, lc.recipient_name) AS recipient_name,
  1065. lc.log_time, lc.body, lc.id_notice, lc.counter
  1066. FROM {db_prefix}log_comments AS lc
  1067. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  1068. LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = lc.id_recipient)
  1069. WHERE lc.comment_type = {string:warning}
  1070. ORDER BY ' . $sort . '
  1071. LIMIT ' . $start . ', ' . $items_per_page,
  1072. array(
  1073. 'warning' => 'warning',
  1074. )
  1075. );
  1076. $warnings = array();
  1077. while ($row = $smcFunc['db_fetch_assoc']($request))
  1078. {
  1079. $warnings[] = array(
  1080. 'issuer_link' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['member_name_col'] . '</a>') : $row['member_name_col'],
  1081. 'recipient_link' => $row['id_recipient'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_recipient'] . '">' . $row['recipient_name'] . '</a>') : $row['recipient_name'],
  1082. 'time' => timeformat($row['log_time']),
  1083. 'reason' => $row['body'],
  1084. 'counter' => $row['counter'] > 0 ? '+' . $row['counter'] : $row['counter'],
  1085. 'id_notice' => $row['id_notice'],
  1086. );
  1087. }
  1088. $smcFunc['db_free_result']($request);
  1089. return $warnings;
  1090. }
  1091. /**
  1092. * Load all the warning templates.
  1093. */
  1094. function ViewWarningTemplates()
  1095. {
  1096. global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir, $user_info;
  1097. // Submitting a new one?
  1098. if (isset($_POST['add']))
  1099. return ModifyWarningTemplate();
  1100. elseif (isset($_POST['delete']) && !empty($_POST['deltpl']))
  1101. {
  1102. checkSession();
  1103. validateToken('mod-wt');
  1104. // Log the actions.
  1105. $request = $smcFunc['db_query']('', '
  1106. SELECT recipient_name
  1107. FROM {db_prefix}log_comments
  1108. WHERE id_comment IN ({array_int:delete_ids})
  1109. AND comment_type = {string:warntpl}
  1110. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  1111. array(
  1112. 'delete_ids' => $_POST['deltpl'],
  1113. 'warntpl' => 'warntpl',
  1114. 'generic' => 0,
  1115. 'current_member' => $user_info['id'],
  1116. )
  1117. );
  1118. while ($row = $smcFunc['db_fetch_assoc']($request))
  1119. logAction('delete_warn_template', array('template' => $row['recipient_name']));
  1120. $smcFunc['db_free_result']($request);
  1121. // Do the deletes.
  1122. $smcFunc['db_query']('', '
  1123. DELETE FROM {db_prefix}log_comments
  1124. WHERE id_comment IN ({array_int:delete_ids})
  1125. AND comment_type = {string:warntpl}
  1126. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  1127. array(
  1128. 'delete_ids' => $_POST['deltpl'],
  1129. 'warntpl' => 'warntpl',
  1130. 'generic' => 0,
  1131. 'current_member' => $user_info['id'],
  1132. )
  1133. );
  1134. }
  1135. // Setup context as always.
  1136. $context['page_title'] = $txt['mc_warning_templates_title'];
  1137. require_once($sourcedir . '/Subs-List.php');
  1138. // This is all the information required for a watched user listing.
  1139. $listOptions = array(
  1140. 'id' => 'warning_template_list',
  1141. 'title' => $txt['mc_warning_templates_title'],
  1142. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1143. 'no_items_label' => $txt['mc_warning_templates_none'],
  1144. 'base_href' => $scripturl . '?action=moderate;area=warnings;sa=templates;' . $context['session_var'] . '=' . $context['session_id'],
  1145. 'default_sort_col' => 'title',
  1146. 'get_items' => array(
  1147. 'function' => 'list_getWarningTemplates',
  1148. ),
  1149. 'get_count' => array(
  1150. 'function' => 'list_getWarningTemplateCount',
  1151. ),
  1152. // This assumes we are viewing by user.
  1153. 'columns' => array(
  1154. 'title' => array(
  1155. 'header' => array(
  1156. 'value' => $txt['mc_warning_templates_name'],
  1157. ),
  1158. 'data' => array(
  1159. 'sprintf' => array(
  1160. 'format' => '<a href="' . $scripturl . '?action=moderate;area=warnings;sa=templateedit;tid=%1$d">%2$s</a>',
  1161. 'params' => array(
  1162. 'id_comment' => false,
  1163. 'title' => false,
  1164. 'body' => false,
  1165. ),
  1166. ),
  1167. ),
  1168. 'sort' => array(
  1169. 'default' => 'template_title',
  1170. 'reverse' => 'template_title DESC',
  1171. ),
  1172. ),
  1173. 'creator' => array(
  1174. 'header' => array(
  1175. 'value' => $txt['mc_warning_templates_creator'],
  1176. ),
  1177. 'data' => array(
  1178. 'db' => 'creator',
  1179. ),
  1180. 'sort' => array(
  1181. 'default' => 'creator_name',
  1182. 'reverse' => 'creator_name DESC',
  1183. ),
  1184. ),
  1185. 'time' => array(
  1186. 'header' => array(
  1187. 'value' => $txt['mc_warning_templates_time'],
  1188. ),
  1189. 'data' => array(
  1190. 'db' => 'time',
  1191. ),
  1192. 'sort' => array(
  1193. 'default' => 'lc.log_time DESC',
  1194. 'reverse' => 'lc.log_time',
  1195. ),
  1196. ),
  1197. 'delete' => array(
  1198. 'header' => array(
  1199. 'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);">',
  1200. 'style' => 'width: 4%;',
  1201. 'class' => 'centercol',
  1202. ),
  1203. 'data' => array(
  1204. 'function' => create_function('$rowData', '
  1205. global $context, $txt, $scripturl;
  1206. return \'<input type="checkbox" name="deltpl[]" value="\' . $rowData[\'id_comment\'] . \'" class="input_check">\';
  1207. '),
  1208. 'class' => 'centercol',
  1209. ),
  1210. ),
  1211. ),
  1212. 'form' => array(
  1213. 'href' => $scripturl . '?action=moderate;area=warnings;sa=templates',
  1214. 'token' => 'mod-wt',
  1215. ),
  1216. 'additional_rows' => array(
  1217. array(
  1218. 'position' => 'below_table_data',
  1219. '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">',
  1220. ),
  1221. array(
  1222. 'position' => 'bottom_of_list',
  1223. 'value' => '<input type="submit" name="add" value="' . $txt['mc_warning_template_add'] . '" class="button_submit">',
  1224. ),
  1225. ),
  1226. );
  1227. // Create the watched user list.
  1228. createToken('mod-wt');
  1229. createList($listOptions);
  1230. $context['sub_template'] = 'show_list';
  1231. $context['default_list'] = 'warning_template_list';
  1232. }
  1233. /**
  1234. * Callback for createList().
  1235. */
  1236. function list_getWarningTemplateCount()
  1237. {
  1238. global $smcFunc, $user_info;
  1239. $request = $smcFunc['db_query']('', '
  1240. SELECT COUNT(*)
  1241. FROM {db_prefix}log_comments
  1242. WHERE comment_type = {string:warntpl}
  1243. AND (id_recipient = {string:generic} OR id_recipient = {int:current_member})',
  1244. array(
  1245. 'warntpl' => 'warntpl',
  1246. 'generic' => 0,
  1247. 'current_member' => $user_info['id'],
  1248. )
  1249. );
  1250. list ($totalWarns) = $smcFunc['db_fetch_row']($request);
  1251. $smcFunc['db_free_result']($request);
  1252. return $totalWarns;
  1253. }
  1254. /**
  1255. * Callback for createList().
  1256. *
  1257. * @param $start
  1258. * @param $items_per_page
  1259. * @param $sort
  1260. */
  1261. function list_getWarningTemplates($start, $items_per_page, $sort)
  1262. {
  1263. global $smcFunc, $txt, $scripturl, $user_info;
  1264. $request = $smcFunc['db_query']('', '
  1265. SELECT lc.id_comment, IFNULL(mem.id_member, 0) AS id_member,
  1266. IFNULL(mem.real_name, lc.member_name) AS creator_name, recipient_name AS template_title,
  1267. lc.log_time, lc.body
  1268. FROM {db_prefix}log_comments AS lc
  1269. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  1270. WHERE lc.comment_type = {string:warntpl}
  1271. AND (id_recipient = {string:generic} OR id_recipient = {int:current_member})
  1272. ORDER BY ' . $sort . '
  1273. LIMIT ' . $start . ', ' . $items_per_page,
  1274. array(
  1275. 'warntpl' => 'warntpl',
  1276. 'generic' => 0,
  1277. 'current_member' => $user_info['id'],
  1278. )
  1279. );
  1280. $templates = array();
  1281. while ($row = $smcFunc['db_fetch_assoc']($request))
  1282. {
  1283. $templates[] = array(
  1284. 'id_comment' => $row['id_comment'],
  1285. 'creator' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['creator_name'] . '</a>') : $row['creator_name'],
  1286. 'time' => timeformat($row['log_time']),
  1287. 'title' => $row['template_title'],
  1288. 'body' => $smcFunc['htmlspecialchars']($row['body']),
  1289. );
  1290. }
  1291. $smcFunc['db_free_result']($request);
  1292. return $templates;
  1293. }
  1294. /**
  1295. * Edit a warning template.
  1296. */
  1297. function ModifyWarningTemplate()
  1298. {
  1299. global $smcFunc, $context, $txt, $user_info, $sourcedir;
  1300. $context['id_template'] = isset($_REQUEST['tid']) ? (int) $_REQUEST['tid'] : 0;
  1301. $context['is_edit'] = $context['id_template'];
  1302. // Standard template things.
  1303. $context['page_title'] = $context['is_edit'] ? $txt['mc_warning_template_modify'] : $txt['mc_warning_template_add'];
  1304. $context['sub_template'] = 'warn_template';
  1305. $context[$context['moderation_menu_name']]['current_subsection'] = 'templates';
  1306. // Defaults.
  1307. $context['template_data'] = array(
  1308. 'title' => '',
  1309. 'body' => $txt['mc_warning_template_body_default'],
  1310. 'personal' => false,
  1311. 'can_edit_personal' => true,
  1312. );
  1313. // If it's an edit load it.
  1314. if ($context['is_edit'])
  1315. {
  1316. $request = $smcFunc['db_query']('', '
  1317. SELECT id_member, id_recipient, recipient_name AS template_title, body
  1318. FROM {db_prefix}log_comments
  1319. WHERE id_comment = {int:id}
  1320. AND comment_type = {string:warntpl}
  1321. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  1322. array(
  1323. 'id' => $context['id_template'],
  1324. 'warntpl' => 'warntpl',
  1325. 'generic' => 0,
  1326. 'current_member' => $user_info['id'],
  1327. )
  1328. );
  1329. while ($row = $smcFunc['db_fetch_assoc']($request))
  1330. {
  1331. $context['template_data'] = array(
  1332. 'title' => $row['template_title'],
  1333. 'body' => $smcFunc['htmlspecialchars']($row['body']),
  1334. 'personal' => $row['id_recipient'],
  1335. 'can_edit_personal' => $row['id_member'] == $user_info['id'],
  1336. );
  1337. }
  1338. $smcFunc['db_free_result']($request);
  1339. }
  1340. // Wait, we are saving?
  1341. if (isset($_POST['save']))
  1342. {
  1343. checkSession();
  1344. validateToken('mod-wt');
  1345. // To check the BBC is pretty good...
  1346. require_once($sourcedir . '/Subs-Post.php');
  1347. // Bit of cleaning!
  1348. $_POST['template_body'] = trim($_POST['template_body']);
  1349. $_POST['template_title'] = trim($_POST['template_title']);
  1350. // Need something in both boxes.
  1351. if (!empty($_POST['template_body']) && !empty($_POST['template_title']))
  1352. {
  1353. // Safety first.
  1354. $_POST['template_title'] = $smcFunc['htmlspecialchars']($_POST['template_title']);
  1355. // Clean up BBC.
  1356. preparsecode($_POST['template_body']);
  1357. // But put line breaks back!
  1358. $_POST['template_body'] = strtr($_POST['template_body'], array('<br>' => "\n"));
  1359. // Is this personal?
  1360. $recipient_id = !empty($_POST['make_personal']) ? $user_info['id'] : 0;
  1361. // If we are this far it's save time.
  1362. if ($context['is_edit'])
  1363. {
  1364. // Simple update...
  1365. $smcFunc['db_query']('', '
  1366. UPDATE {db_prefix}log_comments
  1367. SET id_recipient = {int:personal}, recipient_name = {string:title}, body = {string:body}
  1368. WHERE id_comment = {int:id}
  1369. AND comment_type = {string:warntpl}
  1370. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})'.
  1371. ($recipient_id ? ' AND id_member = {int:current_member}' : ''),
  1372. array(
  1373. 'personal' => $recipient_id,
  1374. 'title' => $_POST['template_title'],
  1375. 'body' => $_POST['template_body'],
  1376. 'id' => $context['id_template'],
  1377. 'warntpl' => 'warntpl',
  1378. 'generic' => 0,
  1379. 'current_member' => $user_info['id'],
  1380. )
  1381. );
  1382. // If it wasn't visible and now is they've effectively added it.
  1383. if ($context['template_data']['personal'] && !$recipient_id)
  1384. logAction('add_warn_template', array('template' => $_POST['template_title']));
  1385. // Conversely if they made it personal it's a delete.
  1386. elseif (!$context['template_data']['personal'] && $recipient_id)
  1387. logAction('delete_warn_template', array('template' => $_POST['template_title']));
  1388. // Otherwise just an edit.
  1389. else
  1390. logAction('modify_warn_template', array('template' => $_POST['template_title']));
  1391. }
  1392. else
  1393. {
  1394. $smcFunc['db_insert']('',
  1395. '{db_prefix}log_comments',
  1396. array(
  1397. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int',
  1398. 'recipient_name' => 'string-255', 'body' => 'string-65535', 'log_time' => 'int',
  1399. ),
  1400. array(
  1401. $user_info['id'], $user_info['name'], 'warntpl', $recipient_id,
  1402. $_POST['template_title'], $_POST['template_body'], time(),
  1403. ),
  1404. array('id_comment')
  1405. );
  1406. logAction('add_warn_template', array('template' => $_POST['template_title']));
  1407. }
  1408. // Get out of town...
  1409. redirectexit('action=moderate;area=warnings;sa=templates');
  1410. }
  1411. else
  1412. {
  1413. $context['warning_errors'] = array();
  1414. $context['template_data']['title'] = !empty($_POST['template_title']) ? $_POST['template_title'] : '';
  1415. $context['template_data']['body'] = !empty($_POST['template_body']) ? $_POST['template_body'] : $txt['mc_warning_template_body_default'];
  1416. $context['template_data']['personal'] = !empty($_POST['make_personal']);
  1417. if (empty($_POST['template_title']))
  1418. $context['warning_errors'][] = $txt['mc_warning_template_error_no_title'];
  1419. if (empty($_POST['template_body']))
  1420. $context['warning_errors'][] = $txt['mc_warning_template_error_no_body'];
  1421. }
  1422. }
  1423. createToken('mod-wt');
  1424. }
  1425. /**
  1426. * Change moderation preferences.
  1427. */
  1428. function ModerationSettings()
  1429. {
  1430. global $context, $smcFunc, $txt, $sourcedir, $scripturl, $user_settings, $user_info;
  1431. // Some useful context stuff.
  1432. loadTemplate('ModerationCenter');
  1433. $context['page_title'] = $txt['mc_settings'];
  1434. $context['sub_template'] = 'moderation_settings';
  1435. $context[$context['moderation_menu_name']]['tab_data'] = array(
  1436. 'title' => $txt['mc_prefs_title'],
  1437. 'help' => '',
  1438. 'description' => $txt['mc_prefs_desc']
  1439. );
  1440. $mod_blocks = '';
  1441. $pref_binary = 5;
  1442. $show_reports = 0;
  1443. // Are we saving?
  1444. if (isset($_POST['save']))
  1445. {
  1446. checkSession();
  1447. validateToken('mod-set');
  1448. /* Current format of mod_prefs is:
  1449. x|ABCD|yyy
  1450. WHERE:
  1451. x = Show report count on forum header.
  1452. ABCD = Block indexes to show on moderation main page.
  1453. yyy = Integer with the following bit status:
  1454. - yyy & 4 = Notify about posts awaiting approval.
  1455. */
  1456. // Now check other options!
  1457. $pref_binary = 0;
  1458. if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval']))
  1459. $pref_binary |= 4;
  1460. // Put it all together.
  1461. $mod_prefs = '0||' . $pref_binary;
  1462. updateMemberData($user_info['id'], array('mod_prefs' => $mod_prefs));
  1463. }
  1464. // What blocks does the user currently have selected?
  1465. $context['mod_settings'] = array(
  1466. 'notify_approval' => $pref_binary & 4,
  1467. );
  1468. createToken('mod-set');
  1469. }
  1470. /**
  1471. * This ends a moderator session, requiring authentication to access the MCP again.
  1472. */
  1473. function ModEndSession()
  1474. {
  1475. // This is so easy!
  1476. unset($_SESSION['moderate_time']);
  1477. // Clean any moderator tokens as well.
  1478. foreach ($_SESSION['token'] as $key => $token)
  1479. if (strpos($key, '-mod') !== false)
  1480. unset($_SESSION['token'][$key]);
  1481. redirectexit();
  1482. }
  1483. ?>