ModerationCenter.php 66 KB

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