From 84555afae3b424b986180de2cf7c50340fda2b9d Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Fri, 31 May 2024 18:24:29 +0200 Subject: [PATCH] Page/Notes * also color code notes according to message severity --- includes/kernel.php | 4 ++-- includes/utilities.php | 19 +++++++++++++------ pages/genericPage.class.php | 15 ++++++++++----- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/includes/kernel.php b/includes/kernel.php index c4a18365..f0089481 100644 --- a/includes/kernel.php +++ b/includes/kernel.php @@ -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()', diff --git a/includes/utilities.php b/includes/utilities.php index c855ed91..f09ad705 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -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; diff --git a/pages/genericPage.class.php b/pages/genericPage.class.php index 62222d70..faf465e9 100644 --- a/pages/genericPage.class.php +++ b/pages/genericPage.class.php @@ -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]' ); }