ModerationCenter.php 64 KB

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