engelsystem/includes/sys_auth.php

44 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2011-06-02 00:48:29 +02:00
<?php
use Engelsystem\Database\Db;
2011-06-03 15:30:17 +02:00
2017-01-03 03:22:48 +01:00
/**
* @param int $user_id
* @return array
*/
2017-01-02 03:57:23 +01:00
function privileges_for_user($user_id)
{
$privileges = [];
2022-06-16 22:50:52 +02:00
$user_privileges = Db::select('
2017-01-02 15:43:36 +01:00
SELECT `Privileges`.`name`
FROM `users`
JOIN `UserGroups` ON (`users`.`id` = `UserGroups`.`uid`)
2017-01-02 15:43:36 +01:00
JOIN `GroupPrivileges` ON (`UserGroups`.`group_id` = `GroupPrivileges`.`group_id`)
JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`)
WHERE `users`.`id`=?
', [$user_id]);
foreach ($user_privileges as $user_privilege) {
$privileges[] = $user_privilege['name'];
2017-01-02 03:57:23 +01:00
}
return $privileges;
2011-06-03 15:30:17 +02:00
}
2017-01-03 03:22:48 +01:00
/**
* @param int $group_id
* @return array
*/
2017-01-02 03:57:23 +01:00
function privileges_for_group($group_id)
{
$privileges = [];
2022-06-16 22:50:52 +02:00
$groups_privileges = Db::select('
SELECT `name`
2017-01-02 15:43:36 +01:00
FROM `GroupPrivileges`
JOIN `Privileges` ON (`GroupPrivileges`.`privilege_id` = `Privileges`.`id`)
WHERE `group_id`=?
', [$group_id]);
foreach ($groups_privileges as $guest_privilege) {
$privileges[] = $guest_privilege['name'];
2017-01-02 03:57:23 +01:00
}
return $privileges;
2011-06-03 15:30:17 +02:00
}