2
0

ModerationCenter.php 68 KB

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