ModerationCenter.php 66 KB

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