ModerationCenter.php 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650
  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 2014 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, $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' => 'ReportedPosts.php',
  118. 'function' => 'ReportedPosts',
  119. 'icon' => 'reports.png',
  120. ),
  121. ),
  122. ),
  123. 'groups' => array(
  124. 'title' => $txt['mc_groups'],
  125. 'enabled' => $context['can_moderate_groups'],
  126. 'areas' => array(
  127. 'userwatch' => array(
  128. 'label' => $txt['mc_watched_users_title'],
  129. 'enabled' => $modSettings['warning_settings'][0] == 1 && $context['can_moderate_boards'],
  130. 'function' => 'ViewWatchedUsers',
  131. 'icon' => 'members_watched.png',
  132. 'subsections' => array(
  133. 'member' => array($txt['mc_watched_users_member']),
  134. 'post' => array($txt['mc_watched_users_post']),
  135. ),
  136. ),
  137. 'groups' => array(
  138. 'label' => $txt['mc_group_requests'],
  139. 'file' => 'Groups.php',
  140. 'function' => 'Groups',
  141. 'icon' => 'members_request.png',
  142. 'custom_url' => $scripturl . '?action=moderate;area=groups;sa=requests',
  143. ),
  144. 'viewgroups' => array(
  145. 'label' => $txt['mc_view_groups'],
  146. 'file' => 'Groups.php',
  147. 'function' => 'Groups',
  148. 'icon' => 'membergroups.png',
  149. ),
  150. ),
  151. ),
  152. );
  153. // Make sure the administrator has a valid session...
  154. validateSession('moderate');
  155. // I don't know where we're going - I don't know where we've been...
  156. $menuOptions = array(
  157. 'action' => 'moderate',
  158. 'disable_url_session_check' => true,
  159. );
  160. $mod_include_data = createMenu($moderation_areas, $menuOptions);
  161. unset($moderation_areas);
  162. // We got something - didn't we? DIDN'T WE!
  163. if ($mod_include_data == false)
  164. fatal_lang_error('no_access', false);
  165. // Retain the ID information in case required by a subaction.
  166. $context['moderation_menu_id'] = $context['max_menu_id'];
  167. $context['moderation_menu_name'] = 'menu_data_' . $context['moderation_menu_id'];
  168. // @todo: html in here is not good
  169. $context[$context['moderation_menu_name']]['tab_data'] = array(
  170. 'title' => $txt['moderation_center'],
  171. 'help' => '',
  172. 'description' => '
  173. <strong>' . $txt['hello_guest'] . ' ' . $context['user']['name'] . '!</strong>
  174. <br><br>
  175. ' . $txt['mc_description']);
  176. // What a pleasant shortcut - even tho we're not *really* on the admin screen who cares...
  177. $context['admin_area'] = $mod_include_data['current_area'];
  178. // Build the link tree.
  179. $context['linktree'][] = array(
  180. 'url' => $scripturl . '?action=moderate',
  181. 'name' => $txt['moderation_center'],
  182. );
  183. if (isset($mod_include_data['current_area']) && $mod_include_data['current_area'] != 'index')
  184. $context['linktree'][] = array(
  185. 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'],
  186. 'name' => $mod_include_data['label'],
  187. );
  188. if (!empty($mod_include_data['current_subsection']) && $mod_include_data['subsections'][$mod_include_data['current_subsection']][0] != $mod_include_data['label'])
  189. $context['linktree'][] = array(
  190. 'url' => $scripturl . '?action=moderate;area=' . $mod_include_data['current_area'] . ';sa=' . $mod_include_data['current_subsection'],
  191. 'name' => $mod_include_data['subsections'][$mod_include_data['current_subsection']][0],
  192. );
  193. // Now - finally - the bit before the encore - the main performance of course!
  194. if (!$dont_call)
  195. {
  196. if (isset($mod_include_data['file']))
  197. require_once($sourcedir . '/' . $mod_include_data['file']);
  198. $mod_include_data['function']();
  199. }
  200. }
  201. /**
  202. * This function basically is the home page of the moderation center.
  203. */
  204. function ModerationHome()
  205. {
  206. global $txt, $context, $scripturl, $user_info, $user_settings, $options;
  207. loadTemplate('ModerationCenter');
  208. loadJavascriptFile('admin.js', array('default_theme' => true), 'admin.js');
  209. $context['page_title'] = $txt['moderation_center'];
  210. $context['sub_template'] = 'moderation_center';
  211. // Handle moderators notes.
  212. ModBlockNotes();
  213. // Load what blocks the user actually can see...
  214. $valid_blocks = array();
  215. if ($context['can_moderate_groups'])
  216. $valid_blocks['g'] = 'GroupRequests';
  217. if ($context['can_moderate_boards'])
  218. {
  219. $valid_blocks['r'] = 'ReportedPosts';
  220. $valid_blocks['w'] = 'WatchedUsers';
  221. }
  222. call_integration_hook('integrate_mod_centre_blocks', array(&$valid_blocks));
  223. $context['mod_blocks'] = array();
  224. foreach ($valid_blocks as $k => $block)
  225. {
  226. $block = 'ModBlock' . $block;
  227. if (function_exists($block))
  228. $context['mod_blocks'][] = $block();
  229. }
  230. $context['admin_prefs'] = !empty($options['admin_preferences']) ? unserialize($options['admin_preferences']) : array();
  231. }
  232. /**
  233. * Show a list of the most active watched users.
  234. */
  235. function ModBlockWatchedUsers()
  236. {
  237. global $context, $smcFunc, $scripturl, $modSettings;
  238. if (($watched_users = cache_get_data('recent_user_watches', 240)) === null)
  239. {
  240. $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch'];
  241. $request = $smcFunc['db_query']('', '
  242. SELECT id_member, real_name, last_login
  243. FROM {db_prefix}members
  244. WHERE warning >= {int:warning_watch}
  245. ORDER BY last_login DESC
  246. LIMIT 10',
  247. array(
  248. 'warning_watch' => $modSettings['warning_watch'],
  249. )
  250. );
  251. $watched_users = array();
  252. while ($row = $smcFunc['db_fetch_assoc']($request))
  253. $watched_users[] = $row;
  254. $smcFunc['db_free_result']($request);
  255. cache_put_data('recent_user_watches', $watched_users, 240);
  256. }
  257. $context['watched_users'] = array();
  258. foreach ($watched_users as $user)
  259. {
  260. $context['watched_users'][] = array(
  261. 'id' => $user['id_member'],
  262. 'name' => $user['real_name'],
  263. 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $user['id_member'] . '">' . $user['real_name'] . '</a>',
  264. 'href' => $scripturl . '?action=profile;u=' . $user['id_member'],
  265. 'last_login' => !empty($user['last_login']) ? timeformat($user['last_login']) : '',
  266. );
  267. }
  268. return 'watched_users';
  269. }
  270. /**
  271. * Show an area for the moderator to type into.
  272. */
  273. function ModBlockNotes()
  274. {
  275. global $context, $smcFunc, $scripturl, $txt, $user_info;
  276. // Are we saving a note?
  277. if (isset($_GET['modnote']) && isset($_POST['makenote']) && isset($_POST['new_note']))
  278. {
  279. checkSession();
  280. $_POST['new_note'] = $smcFunc['htmlspecialchars'](trim($_POST['new_note']));
  281. // Make sure they actually entered something.
  282. if (!empty($_POST['new_note']) && $_POST['new_note'] !== $txt['mc_click_add_note'])
  283. {
  284. // Insert it into the database then!
  285. $smcFunc['db_insert']('',
  286. '{db_prefix}log_comments',
  287. array(
  288. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'recipient_name' => 'string',
  289. 'body' => 'string', 'log_time' => 'int',
  290. ),
  291. array(
  292. $user_info['id'], $user_info['name'], 'modnote', '', $_POST['new_note'], time(),
  293. ),
  294. array('id_comment')
  295. );
  296. // Clear the cache.
  297. cache_put_data('moderator_notes', null, 240);
  298. cache_put_data('moderator_notes_total', null, 240);
  299. }
  300. // Redirect otherwise people can resubmit.
  301. redirectexit('action=moderate');
  302. }
  303. // Bye... bye...
  304. if (isset($_GET['notes']) && isset($_GET['delete']) && is_numeric($_GET['delete']))
  305. {
  306. checkSession('get');
  307. // Lets delete it.
  308. $smcFunc['db_query']('', '
  309. DELETE FROM {db_prefix}log_comments
  310. WHERE id_comment = {int:note}
  311. AND comment_type = {string:type}',
  312. array(
  313. 'note' => $_GET['delete'],
  314. 'type' => 'modnote',
  315. )
  316. );
  317. // Clear the cache.
  318. cache_put_data('moderator_notes', null, 240);
  319. cache_put_data('moderator_notes_total', null, 240);
  320. redirectexit('action=moderate');
  321. }
  322. // How many notes in total?
  323. if (($moderator_notes_total = cache_get_data('moderator_notes_total', 240)) === null)
  324. {
  325. $request = $smcFunc['db_query']('', '
  326. SELECT COUNT(*)
  327. FROM {db_prefix}log_comments AS lc
  328. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  329. WHERE lc.comment_type = {string:modnote}',
  330. array(
  331. 'modnote' => 'modnote',
  332. )
  333. );
  334. list ($moderator_notes_total) = $smcFunc['db_fetch_row']($request);
  335. $smcFunc['db_free_result']($request);
  336. cache_put_data('moderator_notes_total', $moderator_notes_total, 240);
  337. }
  338. // Grab the current notes. We can only use the cache for the first page of notes.
  339. $offset = isset($_GET['notes']) && isset($_GET['start']) ? $_GET['start'] : 0;
  340. if ($offset != 0 || ($moderator_notes = cache_get_data('moderator_notes', 240)) === null)
  341. {
  342. $request = $smcFunc['db_query']('', '
  343. SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name,
  344. lc.log_time, lc.body, lc.id_comment AS id_note
  345. FROM {db_prefix}log_comments AS lc
  346. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  347. WHERE lc.comment_type = {string:modnote}
  348. ORDER BY id_comment DESC
  349. LIMIT {int:offset}, 10',
  350. array(
  351. 'modnote' => 'modnote',
  352. 'offset' => $offset,
  353. )
  354. );
  355. $moderator_notes = array();
  356. while ($row = $smcFunc['db_fetch_assoc']($request))
  357. $moderator_notes[] = $row;
  358. $smcFunc['db_free_result']($request);
  359. if ($offset == 0)
  360. cache_put_data('moderator_notes', $moderator_notes, 240);
  361. }
  362. // Lets construct a page index.
  363. $context['page_index'] = constructPageIndex($scripturl . '?action=moderate;area=index;notes', $_GET['start'], $moderator_notes_total, 10);
  364. $context['start'] = $_GET['start'];
  365. $context['notes'] = array();
  366. foreach ($moderator_notes as $note)
  367. {
  368. $context['notes'][] = array(
  369. 'author' => array(
  370. 'id' => $note['id_member'],
  371. 'link' => $note['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $note['id_member'] . '">' . $note['member_name'] . '</a>') : $note['member_name'],
  372. ),
  373. 'time' => timeformat($note['log_time']),
  374. 'text' => parse_bbc($note['body']),
  375. 'delete_href' => $scripturl . '?action=moderate;area=index;notes;delete=' . $note['id_note'] . ';' . $context['session_var'] . '=' . $context['session_id'],
  376. );
  377. }
  378. return 'notes';
  379. }
  380. /**
  381. * Show a list of the most recent reported posts.
  382. */
  383. function ModBlockReportedPosts()
  384. {
  385. global $context, $user_info, $scripturl, $smcFunc;
  386. // Got the info already?
  387. $cachekey = md5(serialize($user_info['mod_cache']['bq']));
  388. $context['reported_posts'] = array();
  389. if ($user_info['mod_cache']['bq'] == '0=1')
  390. return 'reported_posts_block';
  391. if (($reported_posts = cache_get_data('reported_posts_' . $cachekey, 90)) === null)
  392. {
  393. // By George, that means we in a position to get the reports, jolly good.
  394. $request = $smcFunc['db_query']('', '
  395. SELECT lr.id_report, lr.id_msg, lr.id_topic, lr.id_board, lr.id_member, lr.subject,
  396. lr.num_reports, IFNULL(mem.real_name, lr.membername) AS author_name,
  397. IFNULL(mem.id_member, 0) AS id_author
  398. FROM {db_prefix}log_reported AS lr
  399. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lr.id_member)
  400. 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']) . '
  401. AND lr.closed = {int:not_closed}
  402. AND lr.ignore_all = {int:not_ignored}
  403. ORDER BY lr.time_updated DESC
  404. LIMIT 10',
  405. array(
  406. 'not_closed' => 0,
  407. 'not_ignored' => 0,
  408. )
  409. );
  410. $reported_posts = array();
  411. while ($row = $smcFunc['db_fetch_assoc']($request))
  412. $reported_posts[] = $row;
  413. $smcFunc['db_free_result']($request);
  414. // Cache it.
  415. cache_put_data('reported_posts_' . $cachekey, $reported_posts, 90);
  416. }
  417. $context['reported_posts'] = array();
  418. foreach ($reported_posts as $i => $row)
  419. {
  420. $context['reported_posts'][] = array(
  421. 'id' => $row['id_report'],
  422. 'alternate' => $i % 2,
  423. 'topic_href' => $scripturl . '?topic=' . $row['id_topic'] . '.msg' . $row['id_msg'] . '#msg' . $row['id_msg'],
  424. 'report_href' => $scripturl . '?action=moderate;area=reports;report=' . $row['id_report'],
  425. 'author' => array(
  426. 'id' => $row['id_author'],
  427. 'name' => $row['author_name'],
  428. 'link' => $row['id_author'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_author'] . '">' . $row['author_name'] . '</a>' : $row['author_name'],
  429. 'href' => $scripturl . '?action=profile;u=' . $row['id_author'],
  430. ),
  431. 'comments' => array(),
  432. 'subject' => $row['subject'],
  433. 'num_reports' => $row['num_reports'],
  434. );
  435. }
  436. return 'reported_posts_block';
  437. }
  438. /**
  439. * Show a list of all the group requests they can see.
  440. */
  441. function ModBlockGroupRequests()
  442. {
  443. global $context, $user_info, $scripturl, $smcFunc;
  444. $context['group_requests'] = array();
  445. // Make sure they can even moderate someone!
  446. if ($user_info['mod_cache']['gq'] == '0=1')
  447. return 'group_requests_block';
  448. // What requests are outstanding?
  449. $request = $smcFunc['db_query']('', '
  450. SELECT lgr.id_request, lgr.id_member, lgr.id_group, lgr.time_applied, mem.member_name, mg.group_name, mem.real_name
  451. FROM {db_prefix}log_group_requests AS lgr
  452. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = lgr.id_member)
  453. INNER JOIN {db_prefix}membergroups AS mg ON (mg.id_group = lgr.id_group)
  454. 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']) . '
  455. AND lgr.status = {int:status_open}
  456. ORDER BY lgr.id_request DESC
  457. LIMIT 10',
  458. array(
  459. 'status_open' => 0,
  460. )
  461. );
  462. for ($i = 0; $row = $smcFunc['db_fetch_assoc']($request); $i ++)
  463. {
  464. $context['group_requests'][] = array(
  465. 'id' => $row['id_request'],
  466. 'alternate' => $i % 2,
  467. 'request_href' => $scripturl . '?action=groups;sa=requests;gid=' . $row['id_group'],
  468. 'member' => array(
  469. 'id' => $row['id_member'],
  470. 'name' => $row['real_name'],
  471. 'link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
  472. 'href' => $scripturl . '?action=profile;u=' . $row['id_member'],
  473. ),
  474. 'group' => array(
  475. 'id' => $row['id_group'],
  476. 'name' => $row['group_name'],
  477. ),
  478. 'time_submitted' => timeformat($row['time_applied']),
  479. );
  480. }
  481. $smcFunc['db_free_result']($request);
  482. return 'group_requests_block';
  483. }
  484. /**
  485. * Act as an entrace for all group related activity.
  486. * @todo As for most things in this file, this needs to be moved somewhere appropriate?
  487. */
  488. function ModerateGroups()
  489. {
  490. global $txt, $context, $scripturl, $user_info;
  491. // You need to be allowed to moderate groups...
  492. if ($user_info['mod_cache']['gq'] == '0=1')
  493. isAllowedTo('manage_membergroups');
  494. // Load the group templates.
  495. loadTemplate('ModerationCenter');
  496. // Setup the subactions...
  497. $subactions = array(
  498. 'requests' => 'GroupRequests',
  499. 'view' => 'ViewGroups',
  500. );
  501. if (!isset($_GET['sa']) || !isset($subactions[$_GET['sa']]))
  502. $_GET['sa'] = 'view';
  503. $context['sub_action'] = $_GET['sa'];
  504. // Call the relevant function.
  505. $subactions[$context['sub_action']]();
  506. }
  507. /**
  508. * Show a notice sent to a user.
  509. */
  510. function ShowNotice()
  511. {
  512. global $smcFunc, $txt, $context;
  513. $context['page_title'] = $txt['show_notice'];
  514. $context['sub_template'] = 'show_notice';
  515. $context['template_layers'] = array();
  516. loadTemplate('ModerationCenter');
  517. // @todo Assumes nothing needs permission more than accessing moderation center!
  518. $id_notice = (int) $_GET['nid'];
  519. $request = $smcFunc['db_query']('', '
  520. SELECT body, subject
  521. FROM {db_prefix}log_member_notices
  522. WHERE id_notice = {int:id_notice}',
  523. array(
  524. 'id_notice' => $id_notice,
  525. )
  526. );
  527. if ($smcFunc['db_num_rows']($request) == 0)
  528. fatal_lang_error('no_access', false);
  529. list ($context['notice_body'], $context['notice_subject']) = $smcFunc['db_fetch_row']($request);
  530. $smcFunc['db_free_result']($request);
  531. $context['notice_body'] = parse_bbc($context['notice_body'], false);
  532. }
  533. /**
  534. * View watched users.
  535. */
  536. function ViewWatchedUsers()
  537. {
  538. global $smcFunc, $modSettings, $context, $txt, $scripturl, $user_info, $sourcedir;
  539. // Some important context!
  540. $context['page_title'] = $txt['mc_watched_users_title'];
  541. $context['view_posts'] = isset($_GET['sa']) && $_GET['sa'] == 'post';
  542. $context['start'] = isset($_REQUEST['start']) ? (int) $_REQUEST['start'] : 0;
  543. loadTemplate('ModerationCenter');
  544. // Get some key settings!
  545. $modSettings['warning_watch'] = empty($modSettings['warning_watch']) ? 1 : $modSettings['warning_watch'];
  546. // Put some pretty tabs on cause we're gonna be doing hot stuff here...
  547. $context[$context['moderation_menu_name']]['tab_data'] = array(
  548. 'title' => $txt['mc_watched_users_title'],
  549. 'help' => '',
  550. 'description' => $txt['mc_watched_users_desc'],
  551. );
  552. // First off - are we deleting?
  553. if (!empty($_REQUEST['delete']))
  554. {
  555. checkSession(!is_array($_REQUEST['delete']) ? 'get' : 'post');
  556. $toDelete = array();
  557. if (!is_array($_REQUEST['delete']))
  558. $toDelete[] = (int) $_REQUEST['delete'];
  559. else
  560. foreach ($_REQUEST['delete'] as $did)
  561. $toDelete[] = (int) $did;
  562. if (!empty($toDelete))
  563. {
  564. require_once($sourcedir . '/RemoveTopic.php');
  565. // If they don't have permission we'll let it error - either way no chance of a security slip here!
  566. foreach ($toDelete as $did)
  567. removeMessage($did);
  568. }
  569. }
  570. // Start preparing the list by grabbing relevant permissions.
  571. if (!$context['view_posts'])
  572. {
  573. $approve_query = '';
  574. $delete_boards = array();
  575. }
  576. else
  577. {
  578. // Still obey permissions!
  579. $approve_boards = boardsAllowedTo('approve_posts');
  580. $delete_boards = boardsAllowedTo('delete_any');
  581. if ($approve_boards == array(0))
  582. $approve_query = '';
  583. elseif (!empty($approve_boards))
  584. $approve_query = ' AND m.id_board IN (' . implode(',', $approve_boards) . ')';
  585. // Nada, zip, etc...
  586. else
  587. $approve_query = ' AND 1=0';
  588. }
  589. require_once($sourcedir . '/Subs-List.php');
  590. // This is all the information required for a watched user listing.
  591. $listOptions = array(
  592. 'id' => 'watch_user_list',
  593. 'title' => $txt['mc_watched_users_title'] . ' - ' . ($context['view_posts'] ? $txt['mc_watched_users_post'] : $txt['mc_watched_users_member']),
  594. 'width' => '100%',
  595. 'items_per_page' => $modSettings['defaultMaxMessages'],
  596. 'no_items_label' => $context['view_posts'] ? $txt['mc_watched_users_no_posts'] : $txt['mc_watched_users_none'],
  597. 'base_href' => $scripturl . '?action=moderate;area=userwatch;sa=' . ($context['view_posts'] ? 'post' : 'member'),
  598. 'default_sort_col' => $context['view_posts'] ? '' : 'member',
  599. 'get_items' => array(
  600. 'function' => $context['view_posts'] ? 'list_getWatchedUserPosts' : 'list_getWatchedUsers',
  601. 'params' => array(
  602. $approve_query,
  603. $delete_boards,
  604. ),
  605. ),
  606. 'get_count' => array(
  607. 'function' => $context['view_posts'] ? 'list_getWatchedUserPostsCount' : 'list_getWatchedUserCount',
  608. 'params' => array(
  609. $approve_query,
  610. ),
  611. ),
  612. // This assumes we are viewing by user.
  613. 'columns' => array(
  614. 'member' => array(
  615. 'header' => array(
  616. 'value' => $txt['mc_watched_users_member'],
  617. ),
  618. 'data' => array(
  619. 'sprintf' => array(
  620. 'format' => '<a href="' . $scripturl . '?action=profile;u=%1$d">%2$s</a>',
  621. 'params' => array(
  622. 'id' => false,
  623. 'name' => false,
  624. ),
  625. ),
  626. ),
  627. 'sort' => array(
  628. 'default' => 'real_name',
  629. 'reverse' => 'real_name DESC',
  630. ),
  631. ),
  632. 'warning' => array(
  633. 'header' => array(
  634. 'value' => $txt['mc_watched_users_warning'],
  635. ),
  636. 'data' => array(
  637. 'function' => create_function('$member', '
  638. global $scripturl;
  639. return allowedTo(\'issue_warning\') ? \'<a href="\' . $scripturl . \'?action=profile;area=issuewarning;u=\' . $member[\'id\'] . \'">\' . $member[\'warning\'] . \'%</a>\' : $member[\'warning\'] . \'%\';
  640. '),
  641. ),
  642. 'sort' => array(
  643. 'default' => 'warning',
  644. 'reverse' => 'warning DESC',
  645. ),
  646. ),
  647. 'posts' => array(
  648. 'header' => array(
  649. 'value' => $txt['posts'],
  650. ),
  651. 'data' => array(
  652. 'sprintf' => array(
  653. 'format' => '<a href="' . $scripturl . '?action=profile;u=%1$d;area=showposts;sa=messages">%2$s</a>',
  654. 'params' => array(
  655. 'id' => false,
  656. 'posts' => false,
  657. ),
  658. ),
  659. ),
  660. 'sort' => array(
  661. 'default' => 'posts',
  662. 'reverse' => 'posts DESC',
  663. ),
  664. ),
  665. 'last_login' => array(
  666. 'header' => array(
  667. 'value' => $txt['mc_watched_users_last_login'],
  668. ),
  669. 'data' => array(
  670. 'db' => 'last_login',
  671. ),
  672. 'sort' => array(
  673. 'default' => 'last_login',
  674. 'reverse' => 'last_login DESC',
  675. ),
  676. ),
  677. 'last_post' => array(
  678. 'header' => array(
  679. 'value' => $txt['mc_watched_users_last_post'],
  680. ),
  681. 'data' => array(
  682. 'function' => create_function('$member', '
  683. global $scripturl;
  684. if ($member[\'last_post_id\'])
  685. return \'<a href="\' . $scripturl . \'?msg=\' . $member[\'last_post_id\'] . \'">\' . $member[\'last_post\'] . \'</a>\';
  686. else
  687. return $member[\'last_post\'];
  688. '),
  689. ),
  690. ),
  691. ),
  692. 'form' => array(
  693. 'href' => $scripturl . '?action=moderate;area=userwatch;sa=post',
  694. 'include_sort' => true,
  695. 'include_start' => true,
  696. 'hidden_fields' => array(
  697. $context['session_var'] => $context['session_id'],
  698. ),
  699. ),
  700. 'additional_rows' => array(
  701. $context['view_posts'] ?
  702. array(
  703. 'position' => 'bottom_of_list',
  704. 'value' => '
  705. <input type="submit" name="delete_selected" value="' . $txt['quickmod_delete_selected'] . '" class="button_submit">',
  706. 'align' => 'right',
  707. ) : array(),
  708. ),
  709. );
  710. // If this is being viewed by posts we actually change the columns to call a template each time.
  711. if ($context['view_posts'])
  712. {
  713. $listOptions['columns'] = array(
  714. 'posts' => array(
  715. 'data' => array(
  716. 'function' => create_function('$post', '
  717. return template_user_watch_post_callback($post);
  718. '),
  719. ),
  720. ),
  721. );
  722. }
  723. // Create the watched user list.
  724. createList($listOptions);
  725. $context['sub_template'] = 'show_list';
  726. $context['default_list'] = 'watch_user_list';
  727. }
  728. /**
  729. * Callback for createList().
  730. * @param $approve_query
  731. */
  732. function list_getWatchedUserCount($approve_query)
  733. {
  734. global $smcFunc, $modSettings;
  735. $request = $smcFunc['db_query']('', '
  736. SELECT COUNT(*)
  737. FROM {db_prefix}members
  738. WHERE warning >= {int:warning_watch}',
  739. array(
  740. 'warning_watch' => $modSettings['warning_watch'],
  741. )
  742. );
  743. list ($totalMembers) = $smcFunc['db_fetch_row']($request);
  744. $smcFunc['db_free_result']($request);
  745. return $totalMembers;
  746. }
  747. /**
  748. * Callback for createList().
  749. *
  750. * @param $start
  751. * @param $items_per_page
  752. * @param $sort
  753. * @param $approve_query
  754. * @param $dummy
  755. */
  756. function list_getWatchedUsers($start, $items_per_page, $sort, $approve_query, $dummy)
  757. {
  758. global $smcFunc, $txt, $scripturl, $modSettings, $user_info, $context;
  759. $request = $smcFunc['db_query']('', '
  760. SELECT id_member, real_name, last_login, posts, warning
  761. FROM {db_prefix}members
  762. WHERE warning >= {int:warning_watch}
  763. ORDER BY {raw:sort}
  764. LIMIT ' . $start . ', ' . $items_per_page,
  765. array(
  766. 'warning_watch' => $modSettings['warning_watch'],
  767. 'sort' => $sort,
  768. )
  769. );
  770. $watched_users = array();
  771. $members = array();
  772. while ($row = $smcFunc['db_fetch_assoc']($request))
  773. {
  774. $watched_users[$row['id_member']] = array(
  775. 'id' => $row['id_member'],
  776. 'name' => $row['real_name'],
  777. 'last_login' => $row['last_login'] ? timeformat($row['last_login']) : $txt['never'],
  778. 'last_post' => $txt['not_applicable'],
  779. 'last_post_id' => 0,
  780. 'warning' => $row['warning'],
  781. 'posts' => $row['posts'],
  782. );
  783. $members[] = $row['id_member'];
  784. }
  785. $smcFunc['db_free_result']($request);
  786. if (!empty($members))
  787. {
  788. // First get the latest messages from these users.
  789. $request = $smcFunc['db_query']('', '
  790. SELECT m.id_member, MAX(m.id_msg) AS last_post_id
  791. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  792. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  793. WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  794. AND m.approved = {int:is_approved}') . '
  795. GROUP BY m.id_member',
  796. array(
  797. 'member_list' => $members,
  798. 'is_approved' => 1,
  799. )
  800. );
  801. $latest_posts = array();
  802. while ($row = $smcFunc['db_fetch_assoc']($request))
  803. $latest_posts[$row['id_member']] = $row['last_post_id'];
  804. if (!empty($latest_posts))
  805. {
  806. // Now get the time those messages were posted.
  807. $request = $smcFunc['db_query']('', '
  808. SELECT id_member, poster_time
  809. FROM {db_prefix}messages
  810. WHERE id_msg IN ({array_int:message_list})',
  811. array(
  812. 'message_list' => $latest_posts,
  813. )
  814. );
  815. while ($row = $smcFunc['db_fetch_assoc']($request))
  816. {
  817. $watched_users[$row['id_member']]['last_post'] = timeformat($row['poster_time']);
  818. $watched_users[$row['id_member']]['last_post_id'] = $latest_posts[$row['id_member']];
  819. }
  820. $smcFunc['db_free_result']($request);
  821. }
  822. $request = $smcFunc['db_query']('', '
  823. SELECT MAX(m.poster_time) AS last_post, MAX(m.id_msg) AS last_post_id, m.id_member
  824. FROM {db_prefix}messages AS m' . ($user_info['query_see_board'] == '1=1' ? '' : '
  825. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board AND {query_see_board})') . '
  826. WHERE m.id_member IN ({array_int:member_list})' . (!$modSettings['postmod_active'] || allowedTo('approve_posts') ? '' : '
  827. AND m.approved = {int:is_approved}') . '
  828. GROUP BY m.id_member',
  829. array(
  830. 'member_list' => $members,
  831. 'is_approved' => 1,
  832. )
  833. );
  834. while ($row = $smcFunc['db_fetch_assoc']($request))
  835. {
  836. $watched_users[$row['id_member']]['last_post'] = timeformat($row['last_post']);
  837. $watched_users[$row['id_member']]['last_post_id'] = $row['last_post_id'];
  838. }
  839. $smcFunc['db_free_result']($request);
  840. }
  841. return $watched_users;
  842. }
  843. /**
  844. * Callback for createList().
  845. *
  846. * @param $approve_query
  847. */
  848. function list_getWatchedUserPostsCount($approve_query)
  849. {
  850. global $smcFunc, $modSettings, $user_info;
  851. $request = $smcFunc['db_query']('', '
  852. SELECT COUNT(*)
  853. FROM {db_prefix}messages AS m
  854. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  855. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  856. WHERE mem.warning >= {int:warning_watch}
  857. AND {query_see_board}
  858. ' . $approve_query,
  859. array(
  860. 'warning_watch' => $modSettings['warning_watch'],
  861. )
  862. );
  863. list ($totalMemberPosts) = $smcFunc['db_fetch_row']($request);
  864. $smcFunc['db_free_result']($request);
  865. return $totalMemberPosts;
  866. }
  867. /**
  868. * Callback for createList().
  869. *
  870. * @param $start
  871. * @param $items_per_page
  872. * @param $sort
  873. * @param $approve_query
  874. * @param $delete_boards
  875. */
  876. function list_getWatchedUserPosts($start, $items_per_page, $sort, $approve_query, $delete_boards)
  877. {
  878. global $smcFunc, $txt, $scripturl, $modSettings, $user_info;
  879. $request = $smcFunc['db_query']('', '
  880. SELECT m.id_msg, m.id_topic, m.id_board, m.id_member, m.subject, m.body, m.poster_time,
  881. m.approved, mem.real_name, m.smileys_enabled
  882. FROM {db_prefix}messages AS m
  883. INNER JOIN {db_prefix}members AS mem ON (mem.id_member = m.id_member)
  884. INNER JOIN {db_prefix}boards AS b ON (b.id_board = m.id_board)
  885. WHERE mem.warning >= {int:warning_watch}
  886. AND {query_see_board}
  887. ' . $approve_query . '
  888. ORDER BY m.id_msg DESC
  889. LIMIT ' . $start . ', ' . $items_per_page,
  890. array(
  891. 'warning_watch' => $modSettings['warning_watch'],
  892. )
  893. );
  894. $member_posts = array();
  895. while ($row = $smcFunc['db_fetch_assoc']($request))
  896. {
  897. $row['subject'] = censorText($row['subject']);
  898. $row['body'] = censorText($row['body']);
  899. $member_posts[$row['id_msg']] = array(
  900. 'id' => $row['id_msg'],
  901. 'id_topic' => $row['id_topic'],
  902. 'author_link' => '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>',
  903. 'subject' => $row['subject'],
  904. 'body' => parse_bbc($row['body'], $row['smileys_enabled'], $row['id_msg']),
  905. 'poster_time' => timeformat($row['poster_time']),
  906. 'approved' => $row['approved'],
  907. 'can_delete' => $delete_boards == array(0) || in_array($row['id_board'], $delete_boards),
  908. );
  909. }
  910. $smcFunc['db_free_result']($request);
  911. return $member_posts;
  912. }
  913. /**
  914. * Entry point for viewing warning related stuff.
  915. */
  916. function ViewWarnings()
  917. {
  918. global $context, $txt;
  919. $subActions = array(
  920. 'log' => array('ViewWarningLog'),
  921. 'templateedit' => array('ModifyWarningTemplate', 'issue_warning'),
  922. 'templates' => array('ViewWarningTemplates', 'issue_warning'),
  923. );
  924. $_REQUEST['sa'] = isset($_REQUEST['sa']) && isset($subActions[$_REQUEST['sa']]) && (empty($subActions[$_REQUEST['sa']][1]) || allowedTo($subActions[$_REQUEST['sa']]))? $_REQUEST['sa'] : 'log';
  925. // Some of this stuff is overseas, so to speak.
  926. loadTemplate('ModerationCenter');
  927. loadLanguage('Profile');
  928. // Setup the admin tabs.
  929. $context[$context['moderation_menu_name']]['tab_data'] = array(
  930. 'title' => $txt['mc_warnings'],
  931. 'description' => $txt['mc_warnings_description'],
  932. );
  933. // Call the right function.
  934. $subActions[$_REQUEST['sa']][0]();
  935. }
  936. /**
  937. * Simply put, look at the warning log!
  938. */
  939. function ViewWarningLog()
  940. {
  941. global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir;
  942. // Setup context as always.
  943. $context['page_title'] = $txt['mc_warning_log_title'];
  944. require_once($sourcedir . '/Subs-List.php');
  945. // This is all the information required for a watched user listing.
  946. $listOptions = array(
  947. 'id' => 'warning_list',
  948. 'title' => $txt['mc_warning_log_title'],
  949. 'items_per_page' => $modSettings['defaultMaxMessages'],
  950. 'no_items_label' => $txt['mc_warnings_none'],
  951. 'base_href' => $scripturl . '?action=moderate;area=warnings;sa=log;' . $context['session_var'] . '=' . $context['session_id'],
  952. 'default_sort_col' => 'time',
  953. 'get_items' => array(
  954. 'function' => 'list_getWarnings',
  955. ),
  956. 'get_count' => array(
  957. 'function' => 'list_getWarningCount',
  958. ),
  959. // This assumes we are viewing by user.
  960. 'columns' => array(
  961. 'issuer' => array(
  962. 'header' => array(
  963. 'value' => $txt['profile_warning_previous_issued'],
  964. ),
  965. 'data' => array(
  966. 'db' => 'issuer_link',
  967. ),
  968. 'sort' => array(
  969. 'default' => 'member_name_col',
  970. 'reverse' => 'member_name_col DESC',
  971. ),
  972. ),
  973. 'recipient' => array(
  974. 'header' => array(
  975. 'value' => $txt['mc_warnings_recipient'],
  976. ),
  977. 'data' => array(
  978. 'db' => 'recipient_link',
  979. ),
  980. 'sort' => array(
  981. 'default' => 'recipient_name',
  982. 'reverse' => 'recipient_name DESC',
  983. ),
  984. ),
  985. 'time' => array(
  986. 'header' => array(
  987. 'value' => $txt['profile_warning_previous_time'],
  988. ),
  989. 'data' => array(
  990. 'db' => 'time',
  991. ),
  992. 'sort' => array(
  993. 'default' => 'lc.log_time DESC',
  994. 'reverse' => 'lc.log_time',
  995. ),
  996. ),
  997. 'reason' => array(
  998. 'header' => array(
  999. 'value' => $txt['profile_warning_previous_reason'],
  1000. ),
  1001. 'data' => array(
  1002. 'function' => create_function('$warning', '
  1003. global $scripturl, $settings, $txt;
  1004. $output = \'
  1005. <div class="floatleft">
  1006. \' . $warning[\'reason\'] . \'
  1007. </div>\';
  1008. if (!empty($warning[\'id_notice\']))
  1009. $output .= \'
  1010. <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>\';
  1011. return $output;
  1012. '),
  1013. ),
  1014. ),
  1015. 'points' => array(
  1016. 'header' => array(
  1017. 'value' => $txt['profile_warning_previous_level'],
  1018. ),
  1019. 'data' => array(
  1020. 'db' => 'counter',
  1021. ),
  1022. ),
  1023. ),
  1024. );
  1025. // Create the watched user list.
  1026. createList($listOptions);
  1027. $context['sub_template'] = 'show_list';
  1028. $context['default_list'] = 'warning_list';
  1029. }
  1030. /**
  1031. * Callback for createList().
  1032. */
  1033. function list_getWarningCount()
  1034. {
  1035. global $smcFunc;
  1036. $request = $smcFunc['db_query']('', '
  1037. SELECT COUNT(*)
  1038. FROM {db_prefix}log_comments
  1039. WHERE comment_type = {string:warning}',
  1040. array(
  1041. 'warning' => 'warning',
  1042. )
  1043. );
  1044. list ($totalWarns) = $smcFunc['db_fetch_row']($request);
  1045. $smcFunc['db_free_result']($request);
  1046. return $totalWarns;
  1047. }
  1048. /**
  1049. * Callback for createList().
  1050. *
  1051. * @param $start
  1052. * @param $items_per_page
  1053. * @param $sort
  1054. */
  1055. function list_getWarnings($start, $items_per_page, $sort)
  1056. {
  1057. global $smcFunc, $txt, $scripturl, $user_info;
  1058. $request = $smcFunc['db_query']('', '
  1059. SELECT IFNULL(mem.id_member, 0) AS id_member, IFNULL(mem.real_name, lc.member_name) AS member_name_col,
  1060. IFNULL(mem2.id_member, 0) AS id_recipient, IFNULL(mem2.real_name, lc.recipient_name) AS recipient_name,
  1061. lc.log_time, lc.body, lc.id_notice, lc.counter
  1062. FROM {db_prefix}log_comments AS lc
  1063. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  1064. LEFT JOIN {db_prefix}members AS mem2 ON (mem2.id_member = lc.id_recipient)
  1065. WHERE lc.comment_type = {string:warning}
  1066. ORDER BY ' . $sort . '
  1067. LIMIT ' . $start . ', ' . $items_per_page,
  1068. array(
  1069. 'warning' => 'warning',
  1070. )
  1071. );
  1072. $warnings = array();
  1073. while ($row = $smcFunc['db_fetch_assoc']($request))
  1074. {
  1075. $warnings[] = array(
  1076. 'issuer_link' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['member_name_col'] . '</a>') : $row['member_name_col'],
  1077. 'recipient_link' => $row['id_recipient'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_recipient'] . '">' . $row['recipient_name'] . '</a>') : $row['recipient_name'],
  1078. 'time' => timeformat($row['log_time']),
  1079. 'reason' => $row['body'],
  1080. 'counter' => $row['counter'] > 0 ? '+' . $row['counter'] : $row['counter'],
  1081. 'id_notice' => $row['id_notice'],
  1082. );
  1083. }
  1084. $smcFunc['db_free_result']($request);
  1085. return $warnings;
  1086. }
  1087. /**
  1088. * Load all the warning templates.
  1089. */
  1090. function ViewWarningTemplates()
  1091. {
  1092. global $smcFunc, $modSettings, $context, $txt, $scripturl, $sourcedir, $user_info;
  1093. // Submitting a new one?
  1094. if (isset($_POST['add']))
  1095. return ModifyWarningTemplate();
  1096. elseif (isset($_POST['delete']) && !empty($_POST['deltpl']))
  1097. {
  1098. checkSession();
  1099. validateToken('mod-wt');
  1100. // Log the actions.
  1101. $request = $smcFunc['db_query']('', '
  1102. SELECT recipient_name
  1103. FROM {db_prefix}log_comments
  1104. WHERE id_comment IN ({array_int:delete_ids})
  1105. AND comment_type = {string:warntpl}
  1106. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  1107. array(
  1108. 'delete_ids' => $_POST['deltpl'],
  1109. 'warntpl' => 'warntpl',
  1110. 'generic' => 0,
  1111. 'current_member' => $user_info['id'],
  1112. )
  1113. );
  1114. while ($row = $smcFunc['db_fetch_assoc']($request))
  1115. logAction('delete_warn_template', array('template' => $row['recipient_name']));
  1116. $smcFunc['db_free_result']($request);
  1117. // Do the deletes.
  1118. $smcFunc['db_query']('', '
  1119. DELETE FROM {db_prefix}log_comments
  1120. WHERE id_comment IN ({array_int:delete_ids})
  1121. AND comment_type = {string:warntpl}
  1122. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  1123. array(
  1124. 'delete_ids' => $_POST['deltpl'],
  1125. 'warntpl' => 'warntpl',
  1126. 'generic' => 0,
  1127. 'current_member' => $user_info['id'],
  1128. )
  1129. );
  1130. }
  1131. // Setup context as always.
  1132. $context['page_title'] = $txt['mc_warning_templates_title'];
  1133. require_once($sourcedir . '/Subs-List.php');
  1134. // This is all the information required for a watched user listing.
  1135. $listOptions = array(
  1136. 'id' => 'warning_template_list',
  1137. 'title' => $txt['mc_warning_templates_title'],
  1138. 'items_per_page' => $modSettings['defaultMaxMessages'],
  1139. 'no_items_label' => $txt['mc_warning_templates_none'],
  1140. 'base_href' => $scripturl . '?action=moderate;area=warnings;sa=templates;' . $context['session_var'] . '=' . $context['session_id'],
  1141. 'default_sort_col' => 'title',
  1142. 'get_items' => array(
  1143. 'function' => 'list_getWarningTemplates',
  1144. ),
  1145. 'get_count' => array(
  1146. 'function' => 'list_getWarningTemplateCount',
  1147. ),
  1148. // This assumes we are viewing by user.
  1149. 'columns' => array(
  1150. 'title' => array(
  1151. 'header' => array(
  1152. 'value' => $txt['mc_warning_templates_name'],
  1153. ),
  1154. 'data' => array(
  1155. 'sprintf' => array(
  1156. 'format' => '<a href="' . $scripturl . '?action=moderate;area=warnings;sa=templateedit;tid=%1$d">%2$s</a>',
  1157. 'params' => array(
  1158. 'id_comment' => false,
  1159. 'title' => false,
  1160. 'body' => false,
  1161. ),
  1162. ),
  1163. ),
  1164. 'sort' => array(
  1165. 'default' => 'template_title',
  1166. 'reverse' => 'template_title DESC',
  1167. ),
  1168. ),
  1169. 'creator' => array(
  1170. 'header' => array(
  1171. 'value' => $txt['mc_warning_templates_creator'],
  1172. ),
  1173. 'data' => array(
  1174. 'db' => 'creator',
  1175. ),
  1176. 'sort' => array(
  1177. 'default' => 'creator_name',
  1178. 'reverse' => 'creator_name DESC',
  1179. ),
  1180. ),
  1181. 'time' => array(
  1182. 'header' => array(
  1183. 'value' => $txt['mc_warning_templates_time'],
  1184. ),
  1185. 'data' => array(
  1186. 'db' => 'time',
  1187. ),
  1188. 'sort' => array(
  1189. 'default' => 'lc.log_time DESC',
  1190. 'reverse' => 'lc.log_time',
  1191. ),
  1192. ),
  1193. 'delete' => array(
  1194. 'header' => array(
  1195. 'value' => '<input type="checkbox" class="input_check" onclick="invertAll(this, this.form);">',
  1196. 'style' => 'width: 4%;',
  1197. 'class' => 'centercol',
  1198. ),
  1199. 'data' => array(
  1200. 'function' => create_function('$rowData', '
  1201. global $context, $txt, $scripturl;
  1202. return \'<input type="checkbox" name="deltpl[]" value="\' . $rowData[\'id_comment\'] . \'" class="input_check">\';
  1203. '),
  1204. 'class' => 'centercol',
  1205. ),
  1206. ),
  1207. ),
  1208. 'form' => array(
  1209. 'href' => $scripturl . '?action=moderate;area=warnings;sa=templates',
  1210. 'token' => 'mod-wt',
  1211. ),
  1212. 'additional_rows' => array(
  1213. array(
  1214. 'position' => 'below_table_data',
  1215. '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">',
  1216. ),
  1217. array(
  1218. 'position' => 'bottom_of_list',
  1219. 'value' => '<input type="submit" name="add" value="' . $txt['mc_warning_template_add'] . '" class="button_submit">',
  1220. ),
  1221. ),
  1222. );
  1223. // Create the watched user list.
  1224. createToken('mod-wt');
  1225. createList($listOptions);
  1226. $context['sub_template'] = 'show_list';
  1227. $context['default_list'] = 'warning_template_list';
  1228. }
  1229. /**
  1230. * Callback for createList().
  1231. */
  1232. function list_getWarningTemplateCount()
  1233. {
  1234. global $smcFunc, $user_info;
  1235. $request = $smcFunc['db_query']('', '
  1236. SELECT COUNT(*)
  1237. FROM {db_prefix}log_comments
  1238. WHERE comment_type = {string:warntpl}
  1239. AND (id_recipient = {string:generic} OR id_recipient = {int:current_member})',
  1240. array(
  1241. 'warntpl' => 'warntpl',
  1242. 'generic' => 0,
  1243. 'current_member' => $user_info['id'],
  1244. )
  1245. );
  1246. list ($totalWarns) = $smcFunc['db_fetch_row']($request);
  1247. $smcFunc['db_free_result']($request);
  1248. return $totalWarns;
  1249. }
  1250. /**
  1251. * Callback for createList().
  1252. *
  1253. * @param $start
  1254. * @param $items_per_page
  1255. * @param $sort
  1256. */
  1257. function list_getWarningTemplates($start, $items_per_page, $sort)
  1258. {
  1259. global $smcFunc, $txt, $scripturl, $user_info;
  1260. $request = $smcFunc['db_query']('', '
  1261. SELECT lc.id_comment, IFNULL(mem.id_member, 0) AS id_member,
  1262. IFNULL(mem.real_name, lc.member_name) AS creator_name, recipient_name AS template_title,
  1263. lc.log_time, lc.body
  1264. FROM {db_prefix}log_comments AS lc
  1265. LEFT JOIN {db_prefix}members AS mem ON (mem.id_member = lc.id_member)
  1266. WHERE lc.comment_type = {string:warntpl}
  1267. AND (id_recipient = {string:generic} OR id_recipient = {int:current_member})
  1268. ORDER BY ' . $sort . '
  1269. LIMIT ' . $start . ', ' . $items_per_page,
  1270. array(
  1271. 'warntpl' => 'warntpl',
  1272. 'generic' => 0,
  1273. 'current_member' => $user_info['id'],
  1274. )
  1275. );
  1276. $templates = array();
  1277. while ($row = $smcFunc['db_fetch_assoc']($request))
  1278. {
  1279. $templates[] = array(
  1280. 'id_comment' => $row['id_comment'],
  1281. 'creator' => $row['id_member'] ? ('<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['creator_name'] . '</a>') : $row['creator_name'],
  1282. 'time' => timeformat($row['log_time']),
  1283. 'title' => $row['template_title'],
  1284. 'body' => $smcFunc['htmlspecialchars']($row['body']),
  1285. );
  1286. }
  1287. $smcFunc['db_free_result']($request);
  1288. return $templates;
  1289. }
  1290. /**
  1291. * Edit a warning template.
  1292. */
  1293. function ModifyWarningTemplate()
  1294. {
  1295. global $smcFunc, $context, $txt, $user_info, $sourcedir;
  1296. $context['id_template'] = isset($_REQUEST['tid']) ? (int) $_REQUEST['tid'] : 0;
  1297. $context['is_edit'] = $context['id_template'];
  1298. // Standard template things.
  1299. $context['page_title'] = $context['is_edit'] ? $txt['mc_warning_template_modify'] : $txt['mc_warning_template_add'];
  1300. $context['sub_template'] = 'warn_template';
  1301. $context[$context['moderation_menu_name']]['current_subsection'] = 'templates';
  1302. // Defaults.
  1303. $context['template_data'] = array(
  1304. 'title' => '',
  1305. 'body' => $txt['mc_warning_template_body_default'],
  1306. 'personal' => false,
  1307. 'can_edit_personal' => true,
  1308. );
  1309. // If it's an edit load it.
  1310. if ($context['is_edit'])
  1311. {
  1312. $request = $smcFunc['db_query']('', '
  1313. SELECT id_member, id_recipient, recipient_name AS template_title, body
  1314. FROM {db_prefix}log_comments
  1315. WHERE id_comment = {int:id}
  1316. AND comment_type = {string:warntpl}
  1317. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})',
  1318. array(
  1319. 'id' => $context['id_template'],
  1320. 'warntpl' => 'warntpl',
  1321. 'generic' => 0,
  1322. 'current_member' => $user_info['id'],
  1323. )
  1324. );
  1325. while ($row = $smcFunc['db_fetch_assoc']($request))
  1326. {
  1327. $context['template_data'] = array(
  1328. 'title' => $row['template_title'],
  1329. 'body' => $smcFunc['htmlspecialchars']($row['body']),
  1330. 'personal' => $row['id_recipient'],
  1331. 'can_edit_personal' => $row['id_member'] == $user_info['id'],
  1332. );
  1333. }
  1334. $smcFunc['db_free_result']($request);
  1335. }
  1336. // Wait, we are saving?
  1337. if (isset($_POST['save']))
  1338. {
  1339. checkSession();
  1340. validateToken('mod-wt');
  1341. // To check the BBC is pretty good...
  1342. require_once($sourcedir . '/Subs-Post.php');
  1343. // Bit of cleaning!
  1344. $_POST['template_body'] = trim($_POST['template_body']);
  1345. $_POST['template_title'] = trim($_POST['template_title']);
  1346. // Need something in both boxes.
  1347. if (!empty($_POST['template_body']) && !empty($_POST['template_title']))
  1348. {
  1349. // Safety first.
  1350. $_POST['template_title'] = $smcFunc['htmlspecialchars']($_POST['template_title']);
  1351. // Clean up BBC.
  1352. preparsecode($_POST['template_body']);
  1353. // But put line breaks back!
  1354. $_POST['template_body'] = strtr($_POST['template_body'], array('<br>' => "\n"));
  1355. // Is this personal?
  1356. $recipient_id = !empty($_POST['make_personal']) ? $user_info['id'] : 0;
  1357. // If we are this far it's save time.
  1358. if ($context['is_edit'])
  1359. {
  1360. // Simple update...
  1361. $smcFunc['db_query']('', '
  1362. UPDATE {db_prefix}log_comments
  1363. SET id_recipient = {int:personal}, recipient_name = {string:title}, body = {string:body}
  1364. WHERE id_comment = {int:id}
  1365. AND comment_type = {string:warntpl}
  1366. AND (id_recipient = {int:generic} OR id_recipient = {int:current_member})'.
  1367. ($recipient_id ? ' AND id_member = {int:current_member}' : ''),
  1368. array(
  1369. 'personal' => $recipient_id,
  1370. 'title' => $_POST['template_title'],
  1371. 'body' => $_POST['template_body'],
  1372. 'id' => $context['id_template'],
  1373. 'warntpl' => 'warntpl',
  1374. 'generic' => 0,
  1375. 'current_member' => $user_info['id'],
  1376. )
  1377. );
  1378. // If it wasn't visible and now is they've effectively added it.
  1379. if ($context['template_data']['personal'] && !$recipient_id)
  1380. logAction('add_warn_template', array('template' => $_POST['template_title']));
  1381. // Conversely if they made it personal it's a delete.
  1382. elseif (!$context['template_data']['personal'] && $recipient_id)
  1383. logAction('delete_warn_template', array('template' => $_POST['template_title']));
  1384. // Otherwise just an edit.
  1385. else
  1386. logAction('modify_warn_template', array('template' => $_POST['template_title']));
  1387. }
  1388. else
  1389. {
  1390. $smcFunc['db_insert']('',
  1391. '{db_prefix}log_comments',
  1392. array(
  1393. 'id_member' => 'int', 'member_name' => 'string', 'comment_type' => 'string', 'id_recipient' => 'int',
  1394. 'recipient_name' => 'string-255', 'body' => 'string-65535', 'log_time' => 'int',
  1395. ),
  1396. array(
  1397. $user_info['id'], $user_info['name'], 'warntpl', $recipient_id,
  1398. $_POST['template_title'], $_POST['template_body'], time(),
  1399. ),
  1400. array('id_comment')
  1401. );
  1402. logAction('add_warn_template', array('template' => $_POST['template_title']));
  1403. }
  1404. // Get out of town...
  1405. redirectexit('action=moderate;area=warnings;sa=templates');
  1406. }
  1407. else
  1408. {
  1409. $context['warning_errors'] = array();
  1410. $context['template_data']['title'] = !empty($_POST['template_title']) ? $_POST['template_title'] : '';
  1411. $context['template_data']['body'] = !empty($_POST['template_body']) ? $_POST['template_body'] : $txt['mc_warning_template_body_default'];
  1412. $context['template_data']['personal'] = !empty($_POST['make_personal']);
  1413. if (empty($_POST['template_title']))
  1414. $context['warning_errors'][] = $txt['mc_warning_template_error_no_title'];
  1415. if (empty($_POST['template_body']))
  1416. $context['warning_errors'][] = $txt['mc_warning_template_error_no_body'];
  1417. }
  1418. }
  1419. createToken('mod-wt');
  1420. }
  1421. /**
  1422. * Change moderation preferences.
  1423. */
  1424. function ModerationSettings()
  1425. {
  1426. global $context, $smcFunc, $txt, $sourcedir, $scripturl, $user_settings, $user_info;
  1427. // Some useful context stuff.
  1428. loadTemplate('ModerationCenter');
  1429. $context['page_title'] = $txt['mc_settings'];
  1430. $context['sub_template'] = 'moderation_settings';
  1431. $context[$context['moderation_menu_name']]['tab_data'] = array(
  1432. 'title' => $txt['mc_prefs_title'],
  1433. 'help' => '',
  1434. 'description' => $txt['mc_prefs_desc']
  1435. );
  1436. $mod_blocks = '';
  1437. $pref_binary = 5;
  1438. $show_reports = 0;
  1439. // Are we saving?
  1440. if (isset($_POST['save']))
  1441. {
  1442. checkSession();
  1443. validateToken('mod-set');
  1444. /* Current format of mod_prefs is:
  1445. x|ABCD|yyy
  1446. WHERE:
  1447. x = Show report count on forum header.
  1448. ABCD = Block indexes to show on moderation main page.
  1449. yyy = Integer with the following bit status:
  1450. - yyy & 4 = Notify about posts awaiting approval.
  1451. */
  1452. // Now check other options!
  1453. $pref_binary = 0;
  1454. if ($context['can_moderate_approvals'] && !empty($_POST['mod_notify_approval']))
  1455. $pref_binary |= 4;
  1456. // Put it all together.
  1457. $mod_prefs = '0||' . $pref_binary;
  1458. updateMemberData($user_info['id'], array('mod_prefs' => $mod_prefs));
  1459. }
  1460. // What blocks does the user currently have selected?
  1461. $context['mod_settings'] = array(
  1462. 'notify_approval' => $pref_binary & 4,
  1463. );
  1464. createToken('mod-set');
  1465. }
  1466. /**
  1467. * This ends a moderator session, requiring authentication to access the MCP again.
  1468. */
  1469. function ModEndSession()
  1470. {
  1471. // This is so easy!
  1472. unset($_SESSION['moderate_time']);
  1473. // Clean any moderator tokens as well.
  1474. foreach ($_SESSION['token'] as $key => $token)
  1475. if (strpos($key, '-mod') !== false)
  1476. unset($_SESSION['token'][$key]);
  1477. redirectexit();
  1478. }
  1479. ?>