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