PageRenderTime 68ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 1ms

/sources/controllers/ModerationCenter.controller.php

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