ModerationCenter.php 66 KB

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