ModerationCenter.php 61 KB

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