ModerationCenter.php 66 KB

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