ModerationCenter.php 67 KB

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