mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Page/Notes
* also color code notes according to message severity
This commit is contained in:
@@ -136,7 +136,7 @@ set_error_handler(function($errNo, $errStr, $errFile, $errLine)
|
||||
|
||||
if (Cfg::get('DEBUG') >= $logLevel)
|
||||
{
|
||||
Util::addNote($uGroup, $errName.' - '.$errStr.' @ '.$errFile. ':'.$errLine);
|
||||
Util::addNote($errName.' - '.$errStr.' @ '.$errFile. ':'.$errLine, $uGroup, $logLevel);
|
||||
if (CLI)
|
||||
CLI::write($errName.' - '.$errStr.' @ '.$errFile. ':'.$errLine, $errNo & (E_WARNING | E_USER_WARNING | E_NOTICE | E_USER_NOTICE) ? CLI::LOG_WARN : CLI::LOG_ERROR);
|
||||
}
|
||||
@@ -147,7 +147,7 @@ set_error_handler(function($errNo, $errStr, $errFile, $errLine)
|
||||
// handle exceptions
|
||||
set_exception_handler(function ($e)
|
||||
{
|
||||
Util::addNote(U_GROUP_EMPLOYEE, 'Exception - '.$e->getMessage().' @ '.$e->getFile(). ':'.$e->getLine()."\n".$e->getTraceAsString());
|
||||
Util::addNote('Exception - '.$e->getMessage().' @ '.$e->getFile(). ':'.$e->getLine()."\n".$e->getTraceAsString());
|
||||
|
||||
if (DB::isConnected(DB_AOWOW))
|
||||
DB::Aowow()->query('INSERT INTO ?_errors (`date`, `version`, `phpError`, `file`, `line`, `query`, `userGroups`, `message`) VALUES (UNIX_TIMESTAMP(), ?d, ?d, ?, ?d, ?, ?d, ?) ON DUPLICATE KEY UPDATE `date` = UNIX_TIMESTAMP()',
|
||||
|
||||
@@ -544,20 +544,27 @@ abstract class Util
|
||||
public static $tcEncoding = '0zMcmVokRsaqbdrfwihuGINALpTjnyxtgevElBCDFHJKOPQSUWXYZ123456789';
|
||||
private static $notes = [];
|
||||
|
||||
public static function addNote(int $uGroupMask, string $str) : void
|
||||
public static function addNote(string $note, int $uGroupMask = U_GROUP_EMPLOYEE, int $level = CLI::LOG_ERROR) : void
|
||||
{
|
||||
self::$notes[] = [$uGroupMask, $str];
|
||||
self::$notes[] = [$note, $uGroupMask, $level];
|
||||
}
|
||||
|
||||
public static function getNotes() : array
|
||||
{
|
||||
$notes = [];
|
||||
$severity = CLI::LOG_INFO;
|
||||
foreach (self::$notes as [$note, $uGroup, $level])
|
||||
{
|
||||
if ($uGroup && !User::isInGroup($uGroup))
|
||||
continue;
|
||||
|
||||
foreach (self::$notes as $data)
|
||||
if (!$data[0] || User::isInGroup($data[0]))
|
||||
$notes[] = $data[1];
|
||||
if ($level < $severity)
|
||||
$severity = $level;
|
||||
|
||||
return $notes;
|
||||
$notes[] = $note;
|
||||
}
|
||||
|
||||
return [$notes, $severity];
|
||||
}
|
||||
|
||||
private static $execTime = 0.0;
|
||||
|
||||
@@ -343,7 +343,7 @@ class GenericPage
|
||||
if (Cfg::get('MAINTENANCE') && !User::isInGroup(U_GROUP_EMPLOYEE))
|
||||
$this->maintenance();
|
||||
else if (Cfg::get('MAINTENANCE') && User::isInGroup(U_GROUP_EMPLOYEE))
|
||||
Util::addNote(U_GROUP_EMPLOYEE, 'Maintenance mode enabled!');
|
||||
Util::addNote('Maintenance mode enabled!');
|
||||
|
||||
// get errors from previous page from session and apply to template
|
||||
if (method_exists($this, 'applyCCErrors'))
|
||||
@@ -602,9 +602,14 @@ class GenericPage
|
||||
$this->announcements = [];
|
||||
|
||||
// display occured notices
|
||||
if ($_ = Util::getNotes())
|
||||
if (([$notes, $level] = Util::getNotes()) && $notes)
|
||||
{
|
||||
array_unshift($_, 'One or more errors occured, while generating this page.');
|
||||
array_unshift($notes, 'One or more issues occured, while generating this page.');
|
||||
$colors = array( // [border, text]
|
||||
CLI::LOG_ERROR => ['C50F1F', 'E51223'],
|
||||
CLI::LOG_WARN => ['C19C00', 'E5B700'],
|
||||
CLI::LOG_INFO => ['3A96DD', '42ADFF']
|
||||
);
|
||||
|
||||
$this->announcements[0] = array(
|
||||
'parent' => 'announcement-0',
|
||||
@@ -612,8 +617,8 @@ class GenericPage
|
||||
'mode' => 1,
|
||||
'status' => 1,
|
||||
'name' => 'internal error',
|
||||
'style' => 'color: #ff3333; font-weight: bold; font-size: 14px; padding-left: 40px; background-image: url('.Cfg::get('STATIC_URL').'/images/announcements/warn-small.png); background-size: 15px 15px; background-position: 12px center; border: dashed 2px #C03030;',
|
||||
'text' => '[span]'.implode("[br]", $_).'[/span]'
|
||||
'style' => 'color: #'.($colors[$level][1] ?? 'fff').'; font-weight: bold; font-size: 14px; padding-left: 40px; background-image: url('.Cfg::get('STATIC_URL').'/images/announcements/warn-small.png); background-size: 15px 15px; background-position: 12px center; border: dashed 2px #'.($colors[$level][0] ?? 'fff').';',
|
||||
'text' => '[span]'.implode("[br]", $notes).'[/span]'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user