ModerationCenter.php 65 KB

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