Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 120
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
mcp_logs
0.00% covered (danger)
0.00%
0 / 118
0.00% covered (danger)
0.00%
0 / 2
812
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 main
0.00% covered (danger)
0.00%
0 / 117
0.00% covered (danger)
0.00%
0 / 1
756
1<?php
2/**
3*
4* This file is part of the phpBB Forum Software package.
5*
6* @copyright (c) phpBB Limited <https://www.phpbb.com>
7* @license GNU General Public License, version 2 (GPL-2.0)
8*
9* For full copyright and license information, please see
10* the docs/CREDITS.txt file.
11*
12*/
13
14/**
15* @ignore
16*/
17if (!defined('IN_PHPBB'))
18{
19    exit;
20}
21
22/**
23* mcp_logs
24* Handling warning the users
25*/
26class mcp_logs
27{
28    var $u_action;
29    var $p_master;
30
31    function __construct($p_master)
32    {
33        $this->p_master = $p_master;
34    }
35
36    function main($id, $mode)
37    {
38        global $auth, $db, $user, $template, $request;
39        global $config, $phpbb_container, $phpbb_log;
40
41        $user->add_lang('acp/common');
42        $this->p_master->add_mod_info('acp');
43
44        $action = $request->variable('action', array('' => ''));
45
46        if (is_array($action))
47        {
48            $action = key($action);
49        }
50        else
51        {
52            $action = $request->variable('action', '');
53        }
54
55        // Set up general vars
56        $start        = $request->variable('start', 0);
57        $deletemark = ($action == 'del_marked') ? true : false;
58        $deleteall    = ($action == 'del_all') ? true : false;
59        $marked        = $request->variable('mark', array(0));
60
61        // Sort keys
62        $sort_days    = $request->variable('st', 0);
63        $sort_key    = $request->variable('sk', 't');
64        $sort_dir    = $request->variable('sd', 'd');
65
66        $this->tpl_name = 'mcp_logs';
67        $this->page_title = 'MCP_LOGS';
68
69        /* @var $pagination \phpbb\pagination */
70        $pagination = $phpbb_container->get('pagination');
71
72        $forum_list = array_values(array_intersect(get_forum_list('f_read'), get_forum_list('m_')));
73        $forum_list[] = 0;
74
75        $forum_id = $topic_id = 0;
76
77        switch ($mode)
78        {
79            case 'front':
80            break;
81
82            case 'forum_logs':
83                $forum_id = $request->variable('f', 0);
84
85                if (!in_array($forum_id, $forum_list))
86                {
87                    send_status_line(403, 'Forbidden');
88                    trigger_error('NOT_AUTHORISED');
89                }
90
91                $forum_list = array($forum_id);
92            break;
93
94            case 'topic_logs':
95                $topic_id = $request->variable('t', 0);
96
97                $sql = 'SELECT forum_id
98                    FROM ' . TOPICS_TABLE . '
99                    WHERE topic_id = ' . $topic_id;
100                $result = $db->sql_query($sql);
101                $forum_id = (int) $db->sql_fetchfield('forum_id');
102                $db->sql_freeresult($result);
103
104                if (!in_array($forum_id, $forum_list))
105                {
106                    send_status_line(403, 'Forbidden');
107                    trigger_error('NOT_AUTHORISED');
108                }
109
110                $forum_list = array($forum_id);
111            break;
112        }
113
114        // Delete entries if requested and able
115        if (($deletemark || $deleteall) && $auth->acl_get('a_clearlogs'))
116        {
117            if (confirm_box(true))
118            {
119                if ($deletemark && count($marked))
120                {
121                    $conditions = array(
122                        'forum_id'    => array('IN' => $forum_list),
123                        'log_id'    => array('IN' => $marked),
124                    );
125
126                    $phpbb_log->delete('mod', $conditions);
127                }
128                else if ($deleteall)
129                {
130                    $keywords = $request->variable('keywords', '', true);
131
132                    $conditions = array(
133                        'forum_id'    => array('IN' => $forum_list),
134                        'keywords'    => $keywords,
135                    );
136
137                    if ($sort_days)
138                    {
139                        $conditions['log_time'] = array('>=', time() - ($sort_days * 86400));
140                    }
141
142                    if ($mode == 'topic_logs')
143                    {
144                        $conditions['topic_id'] = $topic_id;
145                    }
146
147                    $phpbb_log->delete('mod', $conditions);
148                }
149            }
150            else
151            {
152                confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array(
153                    'f'            => $forum_id,
154                    't'            => $topic_id,
155                    'start'        => $start,
156                    'delmarked'    => $deletemark,
157                    'delall'    => $deleteall,
158                    'mark'        => $marked,
159                    'st'        => $sort_days,
160                    'sk'        => $sort_key,
161                    'sd'        => $sort_dir,
162                    'i'            => $id,
163                    'mode'        => $mode,
164                    'action'    => $request->variable('action', array('' => ''))))
165                );
166            }
167        }
168
169        // Sorting
170        $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']);
171        $sort_by_text = array('u' => $user->lang['SORT_USERNAME'], 't' => $user->lang['SORT_DATE'], 'i' => $user->lang['SORT_IP'], 'o' => $user->lang['SORT_ACTION']);
172        $sort_by_sql = array('u' => 'u.username_clean', 't' => 'l.log_time', 'i' => 'l.log_ip', 'o' => 'l.log_operation');
173
174        $s_limit_days = $s_sort_key = $s_sort_dir = $u_sort_param = '';
175        gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param);
176
177        // Define where and sort sql for use in displaying logs
178        $sql_where = ($sort_days) ? (time() - ($sort_days * 86400)) : 0;
179        $sql_sort = $sort_by_sql[$sort_key] . ' ' . (($sort_dir == 'd') ? 'DESC' : 'ASC');
180
181        $keywords = $request->variable('keywords', '', true);
182        $keywords_param = !empty($keywords) ? '&amp;keywords=' . urlencode(html_entity_decode($keywords, ENT_COMPAT)) : '';
183
184        // Grab log data
185        $log_data = array();
186        $log_count = 0;
187        $start = view_log('mod', $log_data, $log_count, $config['topics_per_page'], $start, $forum_list, $topic_id, 0, $sql_where, $sql_sort, $keywords);
188
189        $base_url = $this->u_action . "&amp;$u_sort_param$keywords_param";
190        $pagination->generate_template_pagination($base_url, 'pagination', 'start', $log_count, $config['topics_per_page'], $start);
191
192        $template->assign_vars(array(
193            'TOTAL'                => $user->lang('TOTAL_LOGS', (int) $log_count),
194
195            'L_TITLE'            => $user->lang['MCP_LOGS'],
196
197            'U_POST_ACTION'            => $this->u_action . "&amp;$u_sort_param$keywords_param&amp;start=$start",
198            'S_CLEAR_ALLOWED'        => ($auth->acl_get('a_clearlogs')) ? true : false,
199            'S_SELECT_SORT_DIR'        => $s_sort_dir,
200            'S_SELECT_SORT_KEY'        => $s_sort_key,
201            'S_SELECT_SORT_DAYS'    => $s_limit_days,
202            'S_LOGS'                => ($log_count > 0),
203            'S_KEYWORDS'            => $keywords,
204            )
205        );
206
207        foreach ($log_data as $row)
208        {
209            $data = array();
210
211            $checks = array('viewpost', 'viewtopic', 'viewforum');
212            foreach ($checks as $check)
213            {
214                if (isset($row[$check]) && $row[$check])
215                {
216                    $data[] = '<a href="' . $row[$check] . '">' . $user->lang['LOGVIEW_' . strtoupper($check)] . '</a>';
217                }
218            }
219
220            $template->assign_block_vars('log', array(
221                'USERNAME'        => $row['username_full'],
222                'IP'            => $row['ip'],
223                'DATE'            => $user->format_date($row['time']),
224                'ACTION'        => $row['action'],
225                'DATA'            => (count($data)) ? implode(' | ', $data) : '',
226                'ID'            => $row['id'],
227                )
228            );
229        }
230    }
231}