pics/controllers/ManageErrors.php

133 lines
3.6 KiB
PHP
Raw Permalink Normal View History

<?php
/*****************************************************************************
* ManageErrors.php
* Contains the controller for managing errors.
*
* Kabuki CMS (C) 2013-2015, Aaron van Geffen
*****************************************************************************/
class ManageErrors extends HTMLController
{
public function __construct()
{
// Ensure it's just admins at this point.
if (!Registry::get('user')->isAdmin())
throw new NotAllowedException();
// Flushing, are we?
if (isset($_POST['flush']) && Session::validateSession('get'))
{
ErrorLog::flush();
header('Location: ' . BASEURL . '/manageerrors/');
2017-11-05 16:27:12 +01:00
exit;
}
Session::resetSessionToken();
$options = [
'title' => 'Error log',
'form' => [
'action' => BASEURL . '/manageerrors/?' . Session::getSessionTokenKey() . '=' . Session::getSessionToken(),
'method' => 'post',
'class' => 'floatright',
'buttons' => [
'flush' => [
'type' => 'submit',
'caption' => 'Delete all',
],
],
],
'columns' => [
'id' => [
'value' => 'id_entry',
'header' => '#',
'is_sortable' => true,
],
'message' => [
'parse' => [
'type' => 'function',
'data' => function($row) {
2021-03-10 17:09:01 +01:00
return $row['message'] . '<br>' .
'<div><a onclick="this.parentNode.childNodes[1].style.display=\'block\';this.style.display=\'none\';">Show debug info</a>' .
'<pre style="display: none">' . htmlspecialchars($row['debug_info']) .
'</pre></div>' .
'<small><a href="' . BASEURL .
htmlspecialchars($row['request_uri']) . '">' .
htmlspecialchars($row['request_uri']) . '</a></small>';
}
],
'header' => 'Message / URL',
'is_sortable' => false,
],
'file' => [
'value' => 'file',
'header' => 'File',
'is_sortable' => true,
],
'line' => [
'value' => 'line',
'header' => 'Line',
'is_sortable' => true,
],
'time' => [
'parse' => [
'type' => 'timestamp',
'data' => [
'timestamp' => 'time',
'pattern' => 'long',
],
],
'header' => 'Time',
'is_sortable' => true,
],
'ip' => [
'value' => 'ip_address',
'header' => 'IP',
'is_sortable' => true,
],
'uid' => [
'header' => 'UID',
'is_sortable' => true,
'parse' => [
2022-05-07 13:25:19 +02:00
'link' => BASEURL . '/edituser/?id={ID_USER}',
'data' => 'id_user',
],
],
],
'start' => !empty($_GET['start']) ? (int) $_GET['start'] : 0,
'sort_order' => !empty($_GET['order']) ? $_GET['order'] : '',
'sort_direction' => !empty($_GET['dir']) ? $_GET['dir'] : '',
'no_items_label' => "No errors to display -- we're all good!",
'items_per_page' => 20,
'index_class' => 'floatleft',
'base_url' => BASEURL . '/manageerrors/',
'get_count' => 'ErrorLog::getCount',
'get_data' => function($offset = 0, $limit = 20, $order = '', $direction = 'down') {
if (!in_array($order, ['id_entry', 'file', 'line', 'time', 'ipaddress', 'id_user']))
$order = 'id_entry';
$data = Registry::get('db')->queryAssocs('
SELECT *
FROM log_errors
ORDER BY {raw:order}
LIMIT {int:offset}, {int:limit}',
[
'order' => $order . ($direction === 'up' ? ' ASC' : ' DESC'),
'offset' => $offset,
'limit' => $limit,
]);
return [
'rows' => $data,
'order' => $order,
'direction' => $direction,
];
},
];
$error_log = new GenericTable($options);
parent::__construct('Error log - Page ' . $error_log->getCurrentPage() .' - ' . SITE_TITLE);
$this->page->adopt(new TabularData($error_log));
}
}