diff --git a/admin/inc/header.php b/admin/inc/header.php index dcbbded..acf5a10 100644 --- a/admin/inc/header.php +++ b/admin/inc/header.php @@ -24,10 +24,12 @@ require_once __DIR__ . '/bootstrap.php'; global $USER, $arUser; - if (!User::isAuthorized() && $_SERVER['REQUEST_URI'] !== '/login.php') { + if (User::isAuthorized() === false && $_SERVER['REQUEST_URI'] !== '/login.php') { header('Location: login.php'); die(); - } elseif (!$USER->isAdmin()) { + } + + if ($USER->isAdmin() === false && $USER->haveAccessToAdminPanel() === false) { header('Location: ../'); die(); } diff --git a/core/lib/Core/ExternalServices/TelegramSender.class.php b/core/lib/Core/ExternalServices/TelegramSender.class.php index 8cdf982..42fe656 100644 --- a/core/lib/Core/ExternalServices/TelegramSender.class.php +++ b/core/lib/Core/ExternalServices/TelegramSender.class.php @@ -105,7 +105,7 @@ * * @return $this */ - public function setChat(int $chatId): self + public function setChat(string $chatId): self { $this->chatId = $chatId; return $this; diff --git a/core/lib/Core/Models/Roles.class.php b/core/lib/Core/Models/Roles.class.php index 498ccaf..94bfc20 100644 --- a/core/lib/Core/Models/Roles.class.php +++ b/core/lib/Core/Models/Roles.class.php @@ -42,10 +42,20 @@ */ const ADMIN_ROLE_ID = 1; + /** + * Роль "система" + */ + const SYSTEM_ROLE_ID = 2; + + /** + * Роль "доступ в панель администратора" + */ + const ADMIN_PANEL_ROLE_ID = 3; + /** * Роль "пользователь" */ - const USER_ROLE_ID = 2; + const USER_ROLE_ID = 5; /** * @var User $user diff --git a/core/lib/Core/Models/User.class.php b/core/lib/Core/Models/User.class.php index 6288749..0909884 100644 --- a/core/lib/Core/Models/User.class.php +++ b/core/lib/Core/Models/User.class.php @@ -641,6 +641,17 @@ return in_array(Roles::ADMIN_ROLE_ID, $this->getRolesObject()->getRoles(), true); } + /** + * Проверка на админа + * + * @return bool + * @throws CoreException + */ + public function haveAccessToAdminPanel(): bool + { + return in_array(Roles::ADMIN_PANEL_ROLE_ID, $this->getRolesObject()->getRoles(), true); + } + /** * Метод выхода из системы */ diff --git a/test2.php b/test2.php index 30a1342..bd28904 100644 --- a/test2.php +++ b/test2.php @@ -1,124 +1,34 @@ query('SELECT * FROM podslyshano WHERE note <> "" ORDER BY RAND() LIMIT 10'); - //$res = $DB->query('SELECT * FROM podslyshano ORDER BY ID DESC LIMIT 1')[0]; + $deviceId = $_REQUEST['MachineName'] . '_' . $_REQUEST['UserName']; - //echo '
' . print_r($res, true). ''; - - - - function num_word($value, $words, $show = true) - { - $num = $value % 100; - if ($num > 19) { - $num = $num % 10; - } - - $out = ($show) ? $value . ' ' : ''; - switch ($num) { - case 1: $out .= $words[0]; break; - case 2: - case 3: - case 4: $out .= $words[1]; break; - default: $out .= $words[2]; break; - } - - return $out; + $uploadPath = './uploads/screenshots/' . $deviceId; + if (!file_exists($uploadPath)) { + mkdir($uploadPath, 0777, true); } - function secToStr($secs) - { - $days = floor($secs / 86400); - $secs %= 86400; - if ($days > 0) { - return num_word($days, ['день', 'дня', 'дней']); - } + $uploadfile = $uploadPath . '/' . date("YmdHis") . '_' . basename($_FILES['screenshot']['name']); + move_uploaded_file($_FILES['screenshot']['tmp_name'], $uploadfile); - $hours = floor($secs / 3600); - $secs %= 3600; - if ($hours > 0) { - return num_word($hours, ['час', 'часа', 'часов']); - } - - $minutes = floor($secs / 60); - $secs %= 60; - if ($minutes > 0) { - return num_word($minutes, ['минута', 'минуты', 'минут']); - } - return num_word($secs, ['секунда', 'секунды', 'секунд']); - } -?> - -
= $item['text'] ?>
+ рейтинг: = $item['rating'] ?> +