source: trunk/forum/mcp.php @ 865

Revision 865, 21.4 KB checked in by Minchi.Yang, 3 years ago (diff)

Merge Code from branch phpbb_305 to trunk

Line 
1<?php
2/**
3*
4* @package mcp
5* @version $Id: mcp.php 9414 2009-03-30 11:09:51Z acydburn $
6* @copyright (c) 2005 phpBB Group
7* @license http://opensource.org/licenses/gpl-license.php GNU Public License
8*
9*/
10
11/**
12* @ignore
13*/
14define('IN_PHPBB', true);
15$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
16$phpEx = substr(strrchr(__FILE__, '.'), 1);
17include($phpbb_root_path . 'common.' . $phpEx);
18include($phpbb_root_path . 'includes/functions_admin.' . $phpEx);
19require($phpbb_root_path . 'includes/functions_module.' . $phpEx);
20
21// Start session management
22$user->session_begin();
23$auth->acl($user->data);
24$user->setup('mcp');
25
26$module = new p_master();
27
28// Setting a variable to let the style designer know where he is...
29$template->assign_var('S_IN_MCP', true);
30
31// Basic parameter data
32$id = request_var('i', '');
33
34if (isset($_REQUEST['mode']) && is_array($_REQUEST['mode']))
35{
36        $mode = request_var('mode', array(''));
37        list($mode, ) = each($mode);
38}
39else
40{
41        $mode = request_var('mode', '');
42}
43
44// Only Moderators can go beyond this point
45if (!$user->data['is_registered'])
46{
47        if ($user->data['is_bot'])
48        {
49                redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
50        }
51
52        login_box('', $user->lang['LOGIN_EXPLAIN_MCP']);
53}
54
55$quickmod = (isset($_REQUEST['quickmod'])) ? true : false;
56$action = request_var('action', '');
57$action_ary = request_var('action', array('' => 0));
58
59$forum_action = request_var('forum_action', '');
60if ($forum_action !== '' && !empty($_POST['sort']))
61{
62        $action = $forum_action;
63}
64
65if (sizeof($action_ary))
66{
67        list($action, ) = each($action_ary);
68}
69unset($action_ary);
70
71if ($mode == 'topic_logs')
72{
73        $id = 'logs';
74        $quickmod = false;
75}
76
77$post_id = request_var('p', 0);
78$topic_id = request_var('t', 0);
79$forum_id = request_var('f', 0);
80$user_id = request_var('u', 0);
81$username = utf8_normalize_nfc(request_var('username', '', true));
82
83if ($post_id)
84{
85        // We determine the topic and forum id here, to make sure the moderator really has moderative rights on this post
86        $sql = 'SELECT topic_id, forum_id
87                FROM ' . POSTS_TABLE . "
88                WHERE post_id = $post_id";
89        $result = $db->sql_query($sql);
90        $row = $db->sql_fetchrow($result);
91        $db->sql_freeresult($result);
92
93        $topic_id = (int) $row['topic_id'];
94        $forum_id = (int) ($row['forum_id']) ? $row['forum_id'] : $forum_id;
95}
96else if ($topic_id)
97{
98        $sql = 'SELECT forum_id
99                FROM ' . TOPICS_TABLE . "
100                WHERE topic_id = $topic_id";
101        $result = $db->sql_query($sql);
102        $row = $db->sql_fetchrow($result);
103        $db->sql_freeresult($result);
104
105        $forum_id = (int) $row['forum_id'];
106}
107
108// If the user doesn't have any moderator powers (globally or locally) he can't access the mcp
109if (!$auth->acl_getf_global('m_'))
110{
111        // Except he is using one of the quickmod tools for users
112        $user_quickmod_actions = array(
113                'lock'                  => 'f_user_lock',
114                'make_sticky'   => 'f_sticky',
115                'make_announce' => 'f_announce',
116                'make_global'   => 'f_announce',
117                'make_normal'   => array('f_announce', 'f_sticky')
118        );
119
120        $allow_user = false;
121        if ($quickmod && isset($user_quickmod_actions[$action]) && $user->data['is_registered'] && $auth->acl_gets($user_quickmod_actions[$action], $forum_id))
122        {
123                $topic_info = get_topic_data(array($topic_id));
124                if ($topic_info[$topic_id]['topic_poster'] == $user->data['user_id'])
125                {
126                        $allow_user = true;
127                }
128        }
129
130        if (!$allow_user)
131        {
132                trigger_error('NOT_AUTHORISED');
133        }
134}
135
136// if the user cannot read the forum he tries to access then we won't allow mcp access either
137if ($forum_id && !$auth->acl_get('f_read', $forum_id))
138{
139        trigger_error('NOT_AUTHORISED');
140}
141
142if ($forum_id)
143{
144        $module->acl_forum_id = $forum_id;
145}
146
147// Instantiate module system and generate list of available modules
148$module->list_modules('mcp');
149
150if ($quickmod)
151{
152        $mode = 'quickmod';
153
154        switch ($action)
155        {
156                case 'lock':
157                case 'unlock':
158                case 'lock_post':
159                case 'unlock_post':
160                case 'make_sticky':
161                case 'make_announce':
162                case 'make_global':
163                case 'make_normal':
164                case 'fork':
165                case 'move':
166                case 'delete_post':
167                case 'delete_topic':
168                        $module->load('mcp', 'main', 'quickmod');
169                        return;
170                break;
171
172                case 'topic_logs':
173                        // Reset start parameter if we jumped from the quickmod dropdown
174                        if (request_var('start', 0))
175                        {
176                                $_REQUEST['start'] = 0;
177                        }
178
179                        $module->set_active('logs', 'topic_logs');
180                break;
181
182                case 'merge_topic':
183                        $module->set_active('main', 'forum_view');
184                break;
185
186                case 'split':
187                case 'merge':
188                        $module->set_active('main', 'topic_view');
189                break;
190
191                default:
192                        trigger_error("$action not allowed as quickmod", E_USER_ERROR);
193                break;
194        }
195}
196else
197{
198        // Select the active module
199        $module->set_active($id, $mode);
200}
201
202// Hide some of the options if we don't have the relevant information to use them
203if (!$post_id)
204{
205        $module->set_display('main', 'post_details', false);
206        $module->set_display('warn', 'warn_post', false);
207}
208
209if ($mode == '' || $mode == 'unapproved_topics' || $mode == 'unapproved_posts')
210{
211        $module->set_display('queue', 'approve_details', false);
212}
213
214if ($mode == '' || $mode == 'reports' || $mode == 'reports_closed')
215{
216        $module->set_display('reports', 'report_details', false);
217}
218
219if (!$topic_id)
220{
221        $module->set_display('main', 'topic_view', false);
222        $module->set_display('logs', 'topic_logs', false);
223}
224
225if (!$forum_id)
226{
227        $module->set_display('main', 'forum_view', false);
228        $module->set_display('logs', 'forum_logs', false);
229}
230
231if (!$user_id && $username == '')
232{
233        $module->set_display('notes', 'user_notes', false);
234        $module->set_display('warn', 'warn_user', false);
235}
236
237// Load and execute the relevant module
238$module->load_active();
239
240// Assign data to the template engine for the list of modules
241$module->assign_tpl_vars(append_sid("{$phpbb_root_path}mcp.$phpEx"));
242
243// Generate urls for letting the moderation control panel being accessed in different modes
244$template->assign_vars(array(
245        'U_MCP'                 => append_sid("{$phpbb_root_path}mcp.$phpEx", 'i=main'),
246        'U_MCP_FORUM'   => ($forum_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=forum_view&amp;f=$forum_id") : '',
247        'U_MCP_TOPIC'   => ($forum_id && $topic_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=topic_view&amp;t=$topic_id") : '',
248        'U_MCP_POST'    => ($forum_id && $topic_id && $post_id) ? append_sid("{$phpbb_root_path}mcp.$phpEx", "i=main&amp;mode=post_details&amp;t=$topic_id&amp;p=$post_id") : '',
249));
250
251// Generate the page, do not display/query online list
252$module->display($module->get_page_title(), false);
253
254/**
255* Functions used to generate additional URL paramters
256*/
257function _module__url($mode, &$module_row)
258{
259        return extra_url();
260}
261
262function _module_notes_url($mode, &$module_row)
263{
264        if ($mode == 'front')
265        {
266                return '';
267        }
268
269        global $user_id;
270        return ($user_id) ? "&amp;u=$user_id" : '';
271}
272
273function _module_warn_url($mode, &$module_row)
274{
275        if ($mode == 'front' || $mode == 'list')
276        {
277                global $forum_id;
278
279                return ($forum_id) ? "&amp;f=$forum_id" : '';
280        }
281
282        if ($mode == 'warn_post')
283        {
284                global $forum_id, $post_id;
285
286                $url_extra = ($forum_id) ? "&amp;f=$forum_id" : '';
287                $url_extra .= ($post_id) ? "&amp;p=$post_id" : '';
288
289                return $url_extra;
290        }
291        else
292        {
293                global $user_id;
294
295                return ($user_id) ? "&amp;u=$user_id" : '';
296        }
297}
298
299function _module_main_url($mode, &$module_row)
300{
301        return extra_url();
302}
303
304function _module_logs_url($mode, &$module_row)
305{
306        return extra_url();
307}
308
309function _module_ban_url($mode, &$module_row)
310{
311        return extra_url();
312}
313
314function _module_queue_url($mode, &$module_row)
315{
316        return extra_url();
317}
318
319function _module_reports_url($mode, &$module_row)
320{
321        return extra_url();
322}
323
324function extra_url()
325{
326        global $forum_id, $topic_id, $post_id, $user_id;
327
328        $url_extra = '';
329        $url_extra .= ($forum_id) ? "&amp;f=$forum_id" : '';
330        $url_extra .= ($topic_id) ? "&amp;t=$topic_id" : '';
331        $url_extra .= ($post_id) ? "&amp;p=$post_id" : '';
332        $url_extra .= ($user_id) ? "&amp;u=$user_id" : '';
333
334        return $url_extra;
335}
336
337/**
338* Get simple topic data
339*/
340function get_topic_data($topic_ids, $acl_list = false, $read_tracking = false)
341{
342        global $auth, $db, $config, $user;
343        static $rowset = array();
344
345        $topics = array();
346
347        if (!sizeof($topic_ids))
348        {
349                return array();
350        }
351
352        // cache might not contain read tracking info, so we can't use it if read
353        // tracking information is requested
354        if (!$read_tracking)
355        {
356                $cache_topic_ids = array_intersect($topic_ids, array_keys($rowset));
357                $topic_ids = array_diff($topic_ids, array_keys($rowset));
358        }
359        else
360        {
361                $cache_topic_ids = array();
362        }
363
364        if (sizeof($topic_ids))
365        {
366                $sql_array = array(
367                        'SELECT'        => 't.*, f.*',
368
369                        'FROM'          => array(
370                                TOPICS_TABLE    => 't',
371                        ),
372
373                        'LEFT_JOIN'     => array(
374                                array(
375                                        'FROM'  => array(FORUMS_TABLE => 'f'),
376                                        'ON'    => 'f.forum_id = t.forum_id'
377                                )
378                        ),
379
380                        'WHERE'         => $db->sql_in_set('t.topic_id', $topic_ids)
381                );
382
383                if ($read_tracking && $config['load_db_lastread'])
384                {
385                        $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
386
387                        $sql_array['LEFT_JOIN'][] = array(
388                                'FROM'  => array(TOPICS_TRACK_TABLE => 'tt'),
389                                'ON'    => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
390                        );
391
392                        $sql_array['LEFT_JOIN'][] = array(
393                                'FROM'  => array(FORUMS_TRACK_TABLE => 'ft'),
394                                'ON'    => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
395                        );
396                }
397
398                $sql = $db->sql_build_query('SELECT', $sql_array);
399                $result = $db->sql_query($sql);
400
401                while ($row = $db->sql_fetchrow($result))
402                {
403                        if (!$row['forum_id'])
404                        {
405                                // Global Announcement?
406                                $row['forum_id'] = request_var('f', 0);
407                        }
408
409                        $rowset[$row['topic_id']] = $row;
410
411                        if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id']))
412                        {
413                                continue;
414                        }
415
416                        $topics[$row['topic_id']] = $row;
417                }
418                $db->sql_freeresult($result);
419        }
420
421        foreach ($cache_topic_ids as $id)
422        {
423                if (!$acl_list || $auth->acl_gets($acl_list, $rowset[$id]['forum_id']))
424                {
425                        $topics[$id] = $rowset[$id];
426                }
427        }
428
429        return $topics;
430}
431
432/**
433* Get simple post data
434*/
435function get_post_data($post_ids, $acl_list = false, $read_tracking = false)
436{
437        global $db, $auth, $config, $user;
438
439        $rowset = array();
440
441        if (!sizeof($post_ids))
442        {
443                return array();
444        }
445
446        $sql_array = array(
447                'SELECT'        => 'p.*, u.*, t.*, f.*',
448
449                'FROM'          => array(
450                        USERS_TABLE             => 'u',
451                        POSTS_TABLE             => 'p',
452                        TOPICS_TABLE    => 't',
453                ),
454
455                'LEFT_JOIN'     => array(
456                        array(
457                                'FROM'  => array(FORUMS_TABLE => 'f'),
458                                'ON'    => 'f.forum_id = t.forum_id'
459                        )
460                ),
461
462                'WHERE'         => $db->sql_in_set('p.post_id', $post_ids) . '
463                        AND u.user_id = p.poster_id
464                        AND t.topic_id = p.topic_id',
465        );
466
467        if ($read_tracking && $config['load_db_lastread'])
468        {
469                $sql_array['SELECT'] .= ', tt.mark_time, ft.mark_time as forum_mark_time';
470
471                $sql_array['LEFT_JOIN'][] = array(
472                        'FROM'  => array(TOPICS_TRACK_TABLE => 'tt'),
473                        'ON'    => 'tt.user_id = ' . $user->data['user_id'] . ' AND t.topic_id = tt.topic_id'
474                );
475
476                $sql_array['LEFT_JOIN'][] = array(
477                        'FROM'  => array(FORUMS_TRACK_TABLE => 'ft'),
478                        'ON'    => 'ft.user_id = ' . $user->data['user_id'] . ' AND t.forum_id = ft.forum_id'
479                );
480        }
481
482        $sql = $db->sql_build_query('SELECT', $sql_array);
483        $result = $db->sql_query($sql);
484        unset($sql_array);
485
486        while ($row = $db->sql_fetchrow($result))
487        {
488                if (!$row['forum_id'])
489                {
490                        // Global Announcement?
491                        $row['forum_id'] = request_var('f', 0);
492                }
493
494                if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id']))
495                {
496                        continue;
497                }
498
499                if (!$row['post_approved'] && !$auth->acl_get('m_approve', $row['forum_id']))
500                {
501                        // Moderators without the permission to approve post should at least not see them. ;)
502                        continue;
503                }
504
505                $rowset[$row['post_id']] = $row;
506        }
507        $db->sql_freeresult($result);
508
509        return $rowset;
510}
511
512/**
513* Get simple forum data
514*/
515function get_forum_data($forum_id, $acl_list = 'f_list', $read_tracking = false)
516{
517        global $auth, $db, $user, $config;
518
519        $rowset = array();
520
521        if (!is_array($forum_id))
522        {
523                $forum_id = array($forum_id);
524        }
525
526        if (!sizeof($forum_id))
527        {
528                return array();
529        }
530
531        if ($read_tracking && $config['load_db_lastread'])
532        {
533                $read_tracking_join = ' LEFT JOIN ' . FORUMS_TRACK_TABLE . ' ft ON (ft.user_id = ' . $user->data['user_id'] . '
534                        AND ft.forum_id = f.forum_id)';
535                $read_tracking_select = ', ft.mark_time';
536        }
537        else
538        {
539                $read_tracking_join = $read_tracking_select = '';
540        }
541
542        $sql = "SELECT f.* $read_tracking_select
543                FROM " . FORUMS_TABLE . " f$read_tracking_join
544                WHERE " . $db->sql_in_set('f.forum_id', $forum_id);
545        $result = $db->sql_query($sql);
546
547        while ($row = $db->sql_fetchrow($result))
548        {
549                if ($acl_list && !$auth->acl_gets($acl_list, $row['forum_id']))
550                {
551                        continue;
552                }
553
554                if ($auth->acl_get('m_approve', $row['forum_id']))
555                {
556                        $row['forum_topics'] = $row['forum_topics_real'];
557                }
558
559                $rowset[$row['forum_id']] = $row;
560        }
561        $db->sql_freeresult($result);
562
563        return $rowset;
564}
565
566/**
567* sorting in mcp
568*
569* @param string $where_sql should either be WHERE (default if ommited) or end with AND or OR
570*/
571function mcp_sorting($mode, &$sort_days, &$sort_key, &$sort_dir, &$sort_by_sql, &$sort_order_sql, &$total, $forum_id = 0, $topic_id = 0, $where_sql = 'WHERE')
572{
573        global $db, $user, $auth, $template;
574
575        $sort_days = request_var('st', 0);
576        $min_time = ($sort_days) ? time() - ($sort_days * 86400) : 0;
577
578        switch ($mode)
579        {
580                case 'viewforum':
581                        $type = 'topics';
582                        $default_key = 't';
583                        $default_dir = 'd';
584
585                        $sql = 'SELECT COUNT(topic_id) AS total
586                                FROM ' . TOPICS_TABLE . "
587                                $where_sql forum_id = $forum_id
588                                        AND topic_type NOT IN (" . POST_ANNOUNCE . ', ' . POST_GLOBAL . ")
589                                        AND topic_last_post_time >= $min_time";
590
591                        if (!$auth->acl_get('m_approve', $forum_id))
592                        {
593                                $sql .= 'AND topic_approved = 1';
594                        }
595                break;
596
597                case 'viewtopic':
598                        $type = 'posts';
599                        $default_key = 't';
600                        $default_dir = 'a';
601
602                        $sql = 'SELECT COUNT(post_id) AS total
603                                FROM ' . POSTS_TABLE . "
604                                $where_sql topic_id = $topic_id
605                                        AND post_time >= $min_time";
606
607                        if (!$auth->acl_get('m_approve', $forum_id))
608                        {
609                                $sql .= 'AND post_approved = 1';
610                        }
611                break;
612
613                case 'unapproved_posts':
614                        $type = 'posts';
615                        $default_key = 't';
616                        $default_dir = 'd';
617                        $where_sql .= ($topic_id) ? ' topic_id = ' . $topic_id . ' AND' : '';
618
619                        $sql = 'SELECT COUNT(post_id) AS total
620                                FROM ' . POSTS_TABLE . "
621                                $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . '
622                                        AND post_approved = 0';
623
624                        if ($min_time)
625                        {
626                                $sql .= ' AND post_time >= ' . $min_time;
627                        }
628                break;
629
630                case 'unapproved_topics':
631                        $type = 'topics';
632                        $default_key = 't';
633                        $default_dir = 'd';
634
635                        $sql = 'SELECT COUNT(topic_id) AS total
636                                FROM ' . TOPICS_TABLE . "
637                                $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_approve'))) . '
638                                        AND topic_approved = 0';
639
640                        if ($min_time)
641                        {
642                                $sql .= ' AND topic_time >= ' . $min_time;
643                        }
644                break;
645
646                case 'reports':
647                case 'reports_closed':
648                        $type = 'reports';
649                        $default_key = 't';
650                        $default_dir = 'd';
651                        $limit_time_sql = ($min_time) ? "AND r.report_time >= $min_time" : '';
652
653                        if ($topic_id)
654                        {
655                                $where_sql .= ' p.topic_id = ' . $topic_id;
656                        }
657                        else if ($forum_id)
658                        {
659                                $where_sql .= ' p.forum_id = ' . $forum_id;
660                        }
661                        else
662                        {
663                                $where_sql .= ' ' . $db->sql_in_set('p.forum_id', get_forum_list(array('!f_read', '!m_report')), true, true);
664                        }
665
666                        if ($mode == 'reports')
667                        {
668                                $where_sql .= ' AND r.report_closed = 0';
669                        }
670                        else
671                        {
672                                $where_sql .= ' AND r.report_closed = 1';
673                        }
674
675                        $sql = 'SELECT COUNT(r.report_id) AS total
676                                FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . " p
677                                $where_sql
678                                        AND p.post_id = r.post_id
679                                        $limit_time_sql";
680                break;
681
682                case 'viewlogs':
683                        $type = 'logs';
684                        $default_key = 't';
685                        $default_dir = 'd';
686
687                        $sql = 'SELECT COUNT(log_id) AS total
688                                FROM ' . LOG_TABLE . "
689                                $where_sql " . $db->sql_in_set('forum_id', ($forum_id) ? array($forum_id) : array_intersect(get_forum_list('f_read'), get_forum_list('m_'))) . '
690                                        AND log_time >= ' . $min_time . '
691                                        AND log_type = ' . LOG_MOD;
692                break;
693        }
694
695        $sort_key = request_var('sk', $default_key);
696        $sort_dir = request_var('sd', $default_dir);
697        $sort_dir_text = array('a' => $user->lang['ASCENDING'], 'd' => $user->lang['DESCENDING']);
698
699        switch ($type)
700        {
701                case 'topics':
702                        $limit_days = array(0 => $user->lang['ALL_TOPICS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
703                        $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 'tt' => $user->lang['TOPIC_TIME'], 'r' => $user->lang['REPLIES'], 's' => $user->lang['SUBJECT'], 'v' => $user->lang['VIEWS']);
704
705                        $sort_by_sql = array('a' => 't.topic_first_poster_name', 't' => 't.topic_last_post_time', 'tt' => 't.topic_time', 'r' => (($auth->acl_get('m_approve', $forum_id)) ? 't.topic_replies_real' : 't.topic_replies'), 's' => 't.topic_title', 'v' => 't.topic_views');
706                        $limit_time_sql = ($min_time) ? "AND t.topic_last_post_time >= $min_time" : '';
707                break;
708
709                case 'posts':
710                        $limit_days = array(0 => $user->lang['ALL_POSTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
711                        $sort_by_text = array('a' => $user->lang['AUTHOR'], 't' => $user->lang['POST_TIME'], 's' => $user->lang['SUBJECT']);
712                        $sort_by_sql = array('a' => 'u.username_clean', 't' => 'p.post_time', 's' => 'p.post_subject');
713                        $limit_time_sql = ($min_time) ? "AND p.post_time >= $min_time" : '';
714                break;
715
716                case 'reports':
717                        $limit_days = array(0 => $user->lang['ALL_REPORTS'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
718                        $sort_by_text = array('a' => $user->lang['AUTHOR'], 'r' => $user->lang['REPORTER'], 'p' => $user->lang['POST_TIME'], 't' => $user->lang['REPORT_TIME'], 's' => $user->lang['SUBJECT']);
719                        $sort_by_sql = array('a' => 'u.username_clean', 'r' => 'ru.username', 'p' => 'p.post_time', 't' => 'r.report_time', 's' => 'p.post_subject');
720                break;
721
722                case 'logs':
723                        $limit_days = array(0 => $user->lang['ALL_ENTRIES'], 1 => $user->lang['1_DAY'], 7 => $user->lang['7_DAYS'], 14 => $user->lang['2_WEEKS'], 30 => $user->lang['1_MONTH'], 90 => $user->lang['3_MONTHS'], 180 => $user->lang['6_MONTHS'], 365 => $user->lang['1_YEAR']);
724                        $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
725
726                        $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
727                        $limit_time_sql = ($min_time) ? "AND l.log_time >= $min_time" : '';
728                break;
729        }
730
731        if (!isset($sort_by_sql[$sort_key]))
732        {
733                $sort_key = $default_key;
734        }
735
736        $sort_order_sql = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
737
738        $s_limit_days = $s_sort_key = $s_sort_dir = $sort_url = '';
739        gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $sort_url);
740
741        $template->assign_vars(array(
742                'S_SELECT_SORT_DIR'             => $s_sort_dir,
743                'S_SELECT_SORT_KEY'             => $s_sort_key,
744                'S_SELECT_SORT_DAYS'    => $s_limit_days)
745        );
746
747        if (($sort_days && $mode != 'viewlogs') || in_array($mode, array('reports', 'unapproved_topics', 'unapproved_posts')) || $where_sql != 'WHERE')
748        {
749                $result = $db->sql_query($sql);
750                $total = (int) $db->sql_fetchfield('total');
751                $db->sql_freeresult($result);
752        }
753        else
754        {
755                $total = -1;
756        }
757}
758
759/**
760* Validate ids
761*
762* @param        array   &$ids                   The relevant ids to check
763* @param        string  $table                  The table to find the ids in
764* @param        string  $sql_id                 The ids relevant column name
765* @param        array   $acl_list               A list of permissions the user need to have
766* @param        mixed   $singe_forum    Limit to one forum id (int) or the first forum found (true)
767*
768* @return       mixed   False if no ids were able to be retrieved, true if at least one id left.
769*                                       Additionally, this value can be the forum_id assigned if $single_forum was set.
770*                                       Therefore checking the result for with !== false is the best method.
771*/
772function check_ids(&$ids, $table, $sql_id, $acl_list = false, $single_forum = false)
773{
774        global $db, $auth;
775
776        if (!is_array($ids) || empty($ids))
777        {
778                return false;
779        }
780
781        $sql = "SELECT $sql_id, forum_id FROM $table
782                WHERE " . $db->sql_in_set($sql_id, $ids);
783        $result = $db->sql_query($sql);
784
785        $ids = array();
786        $forum_id = false;
787
788        while ($row = $db->sql_fetchrow($result))
789        {
790                if ($acl_list && $row['forum_id'] && !$auth->acl_gets($acl_list, $row['forum_id']))
791                {
792                        continue;
793                }
794
795                if ($acl_list && !$row['forum_id'] && !$auth->acl_getf_global($acl_list))
796                {
797                        continue;
798                }
799
800                // Limit forum? If not, just assign the id.
801                if ($single_forum === false)
802                {
803                        $ids[] = $row[$sql_id];
804                        continue;
805                }
806
807                // Limit forum to a specific forum id?
808                // This can get really tricky, because we do not want to create a failure on global topics. :)
809                if ($row['forum_id'])
810                {
811                        if ($single_forum !== true && $row['forum_id'] == (int) $single_forum)
812                        {
813                                $forum_id = (int) $single_forum;
814                        }
815                        else if ($forum_id === false)
816                        {
817                                $forum_id = $row['forum_id'];
818                        }
819
820                        if ($row['forum_id'] == $forum_id)
821                        {
822                                $ids[] = $row[$sql_id];
823                        }
824                }
825                else
826                {
827                        // Always add a global topic
828                        $ids[] = $row[$sql_id];
829                }
830        }
831        $db->sql_freeresult($result);
832
833        if (!sizeof($ids))
834        {
835                return false;
836        }
837
838        // If forum id is false and ids populated we may have only global announcements selected (returning 0 because of (int) $forum_id)
839
840        return ($single_forum === false) ? true : (int) $forum_id;
841}
842
843?>
Note: See TracBrowser for help on using the repository browser.