ModerationCenter.php 67 KB

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