2017-05-19 00:45:14 +02:00
|
|
|
<?php defined('BLUDIT') or die('Bludit CMS.');
|
|
|
|
|
2018-08-03 18:59:23 +02:00
|
|
|
class Syslog extends dbJSON {
|
|
|
|
|
2019-01-26 12:50:48 +01:00
|
|
|
protected $dbFields = array(
|
2017-05-19 00:45:14 +02:00
|
|
|
'date'=> array('inFile'=>false, 'value'=>''),
|
|
|
|
'dictionaryKey'=> array('inFile'=>false, 'value'=>''),
|
|
|
|
'notes'=> array('inFile'=>false, 'value'=>''),
|
|
|
|
'username'=> array('inFile'=>false, 'value'=>''),
|
|
|
|
'idExecution'=> array('inFile'=>false, 'value'=>''),
|
|
|
|
'method'=> array('inFile'=>false, 'value'=>'')
|
|
|
|
);
|
|
|
|
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct(DB_SYSLOG);
|
|
|
|
}
|
|
|
|
|
2017-06-01 00:22:20 +02:00
|
|
|
// Returns TRUE if the ID of execution exists, FALSE otherwise
|
|
|
|
public function exists($idExecution)
|
|
|
|
{
|
2018-02-26 00:18:21 +01:00
|
|
|
foreach ($this->db as $field) {
|
|
|
|
if ($field['idExecution']==$idExecution) {
|
2017-06-01 00:22:20 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get($idExecution)
|
|
|
|
{
|
2018-02-26 00:18:21 +01:00
|
|
|
foreach ($this->db as $field) {
|
|
|
|
if ($field['idExecution']==$idExecution) {
|
2017-06-01 00:22:20 +02:00
|
|
|
return $field;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-19 00:45:14 +02:00
|
|
|
public function add($args)
|
|
|
|
{
|
2018-08-05 17:54:20 +02:00
|
|
|
global $L;
|
2017-05-19 00:45:14 +02:00
|
|
|
|
|
|
|
$data = array();
|
|
|
|
$data['date'] = Date::current(DB_DATE_FORMAT);
|
|
|
|
$data['dictionaryKey'] = $args['dictionaryKey'];
|
|
|
|
$data['notes'] = Sanitize::html($args['notes']);
|
2018-02-26 00:18:21 +01:00
|
|
|
// Unique ID for each execution, defined in boot/init.php
|
2017-05-19 00:45:14 +02:00
|
|
|
$data['idExecution'] = $GLOBALS['ID_EXECUTION'];
|
|
|
|
$data['method'] = $_SERVER['REQUEST_METHOD'];
|
|
|
|
|
|
|
|
// Username
|
|
|
|
$data['username'] = Session::get('username');
|
2018-02-26 00:18:21 +01:00
|
|
|
if (Text::isEmpty($data['username'])) {
|
2017-05-19 00:45:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert at beggining of the database
|
|
|
|
array_unshift($this->db, $data);
|
|
|
|
|
2017-06-28 00:31:40 +02:00
|
|
|
// Keep just NOTIFICATIONS_AMOUNT notifications
|
|
|
|
$this->db = array_slice($this->db, 0, NOTIFICATIONS_AMOUNT);
|
|
|
|
|
2017-05-19 00:45:14 +02:00
|
|
|
// Save
|
|
|
|
return $this->save();
|
|
|
|
}
|
|
|
|
}
|