ModerationCenter.php 68 KB

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