ModerationCenter.php 68 KB

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