diff --git a/database/2019_02_22_084055_super_user_flag.php b/database/2019_02_22_084055_super_user_flag.php new file mode 100644 index 00000000..5e75a988 --- /dev/null +++ b/database/2019_02_22_084055_super_user_flag.php @@ -0,0 +1,20 @@ +exec(" + ALTER TABLE `msz_users` + ADD COLUMN `user_super` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0' AFTER `last_ip`; + "); +} + +function migrate_down(PDO $conn): void +{ + $conn->exec(" + ALTER TABLE `msz_users` + DROP COLUMN `user_super`; + "); +} diff --git a/public/manage/users.php b/public/manage/users.php index 38cff514..25721a44 100644 --- a/public/manage/users.php +++ b/public/manage/users.php @@ -1,7 +1,8 @@ execute() ? $getAddress->fetchColumn() : ''; } +function user_check_super(int $userId): bool +{ + static $superUsers = []; + + if (!isset($superUsers[$userId])) { + $checkSuperUser = db_prepare(" + SELECT `user_super` + FROM `msz_users` + WHERE `user_id` = :user_id + "); + $checkSuperUser->bindValue('user_id', $userId); + $superUsers[$userId] = (bool)($checkSuperUser->execute() ? $checkSuperUser->fetchColumn() : false); + } + + return $superUsers[$userId]; +} + function user_check_authority(int $userId, int $subjectId, bool $canManageSelf = true): bool { if ($canManageSelf && $userId === $subjectId) {