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