Completed
Push — master ( b35b0f...acc097 )
by Greg
05:21
created

admin/debug-log/index.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * /admin/debug-log/index.php
4
 *
5
 * This file is part of DomainMOD, an open source domain and internet asset manager.
6
 * Copyright (c) 2010-2017 Greg Chetcuti <[email protected]>
7
 *
8
 * Project: http://domainmod.org   Author: http://chetcuti.com
9
 *
10
 * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
11
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
15
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see
18
 * http://www.gnu.org/licenses/.
19
 *
20
 */
21
?>
22
<?php
23
require_once('../../_includes/start-session.inc.php');
24
require_once('../../_includes/init.inc.php');
25
26
require_once(DIR_ROOT . '/classes/Autoloader.php');
27
spl_autoload_register('DomainMOD\Autoloader::classAutoloader');
28
29
$system = new DomainMOD\System();
30
$log = new DomainMOD\Log('admin.debuglog');
31
32
$layout = new DomainMOD\Layout();
33
$time = new DomainMOD\Time();
34
35
require_once(DIR_INC . '/head.inc.php');
36
require_once(DIR_INC . '/config.inc.php');
37
require_once(DIR_INC . '/software.inc.php');
38
require_once(DIR_INC . '/debug.inc.php');
39
require_once(DIR_INC . '/settings/admin-debug-log-main.inc.php');
40
require_once(DIR_INC . '/database.inc.php');
41
42
$system->authCheck();
43
$system->checkAdminUser($_SESSION['s_is_admin']);
44
45
$export_data = $_GET['export_data'];
46
47
$tmpq = $system->db()->query("
48
    SELECT id, user_id, area, `level`, message, extra, url, insert_time
49
    FROM log
50
    ORDER BY insert_time DESC, id DESC");
51
52
if ($export_data == '1') {
53
54
    $export = new DomainMOD\Export();
55
    $export_file = $export->openFile('debug_log', strtotime($time->stamp()));
56
57
    $row_contents = array($page_title);
58
    $export->writeRow($export_file, $row_contents);
59
60
    $export->writeBlankRow($export_file);
61
62
    $row_contents = array(
63
        'ID',
64
        'User ID',
65
        'Area',
66
        'Level',
67
        'Message',
68
        'Extra',
69
        'URL',
70
        'Inserted'
71
    );
72
    $export->writeRow($export_file, $row_contents);
73
74
    $result = $tmpq->fetchAll();
75
76
    if (!$result) {
1 ignored issue
show
Bug Best Practice introduced by
The expression $result of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
77
78
        $log_message = 'Unable to retrieve debugging data';
79
        $log->error($log_message);
80
81
    } else {
82
83
        foreach ($result as $row) {
84
85
            $row_contents = array(
86
                $row->id,
87
                $row->user_id,
88
                $row->area,
89
                $row->level,
90
                $row->message,
91
                $row->extra,
92
                $row->url,
93
                $row->insert_time
94
            );
95
            $export->writeRow($export_file, $row_contents);
96
97
        }
98
99
    }
100
101
    $export->closeFile($export_file);
102
103
}
104
?>
105
<?php require_once(DIR_INC . '/doctype.inc.php'); ?>
106
<html>
107
<head>
108
    <title><?php echo $system->pageTitle($page_title); ?></title>
109
    <?php require_once(DIR_INC . '/layout/head-tags.inc.php'); ?>
110
</head>
111
<body class="hold-transition skin-red sidebar-mini">
112
<?php
113
require_once(DIR_INC . '/layout/header.inc.php');
114
115
$result = $tmpq->fetchAll();
116
117
if (!$result) {
1 ignored issue
show
Bug Best Practice introduced by
The expression $result of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
118
119
    echo "The Debug Log is empty";
120
121
    if (DEBUG_MODE != '1') { ?>
122
123
        <BR><BR>Debugging can be enabled in <a href="<?php echo WEB_ROOT; ?>/admin/settings/">Settings</a>.<?php
124
125
    }
126
127
} else { ?>
128
129
    <a href="../maintenance/clear-log.php"><?php echo $layout->showButton('button', 'Clear Debug Log'); ?></a>
130
    <a href="index.php?export_data=1"><?php echo $layout->showButton('button', 'Export'); ?></a><BR><BR>
131
132
    <table id="<?php echo $slug; ?>" class="<?php echo $datatable_class; ?>">
133
        <thead>
134
        <tr>
135
            <th width="20px"></th>
136
            <th class="all">ID</th>
137
            <th class="none">User ID</th>
138
            <th class="all">Area</th>
139
            <th class="all">Level</th>
140
            <th class="all">Message</th>
141
            <th>Extra</th>
142
            <th class="none">URL</th>
143
            <th>Insert Time</th>
144
        </tr>
145
        </thead>
146
        <tbody><?php
147
148
        foreach ($result as $row) { ?>
149
150
            <tr>
151
            <td></td>
152
            <td>
153
                <?php echo $row->id; ?>
154
            </td>
155
            <td>
156
                <?php echo $row->user_id; ?>
157
            </td>
158
            <td>
159
                <?php echo $row->area; ?>
160
            </td>
161
            <td>
162
                <?php echo $row->level; ?>
163
            </td>
164
            <td>
165
                <?php echo $row->message; ?>
166
            </td>
167
            <td>
168
                <?php echo $row->extra; ?>
169
            </td>
170
            <td>
171
                <?php echo $row->url; ?>
172
            </td>
173
            <td>
174
                <?php echo $time->toUserTimezone($row->insert_time); ?>
175
            </td>
176
            </tr><?php
177
178
        } ?>
179
180
        </tbody>
181
    </table><?php
182
183
} ?>
184
<BR>
185
<?php require_once(DIR_INC . '/layout/footer.inc.php'); ?>
186
</body>
187
</html>
188