ModerationCenter.php 67 KB

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