ModerationCenter.php 66 KB

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