diff options
author | Udo Walter | 2017-04-07 15:49:54 +0200 |
---|---|---|
committer | Udo Walter | 2017-04-07 15:49:54 +0200 |
commit | d033483d3ed9e05f1109a3713ec6a3df883a1dae (patch) | |
tree | 13df2276d6c137901d87ea5daf23464e5c7bb869 /modules-available/permissionmanager/inc/permissiondbupdate.inc.php | |
parent | [permission-manager] added possibility to select all permissions (diff) | |
download | slx-admin-d033483d3ed9e05f1109a3713ec6a3df883a1dae.tar.gz slx-admin-d033483d3ed9e05f1109a3713ec6a3df883a1dae.tar.xz slx-admin-d033483d3ed9e05f1109a3713ec6a3df883a1dae.zip |
[permission-manager] renamed some files, moved html generation to templates,
using bind variables in mysql code, changed order of modules in role editor
Diffstat (limited to 'modules-available/permissionmanager/inc/permissiondbupdate.inc.php')
-rw-r--r-- | modules-available/permissionmanager/inc/permissiondbupdate.inc.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/modules-available/permissionmanager/inc/permissiondbupdate.inc.php b/modules-available/permissionmanager/inc/permissiondbupdate.inc.php new file mode 100644 index 00000000..87c989fa --- /dev/null +++ b/modules-available/permissionmanager/inc/permissiondbupdate.inc.php @@ -0,0 +1,57 @@ +<?php + +class PermissionDbUpdate { + + // insert new user_x_role to database. "ignore" to ignore duplicate entry try + public static function addRoleToUser($users, $roles) { + foreach($users AS $user) { + foreach ($roles AS $role) { + $query = "INSERT IGNORE INTO user_x_role (userid, roleid) VALUES (:user, :role)"; + Database::exec($query, array("user" => $user, "role" => $role)); + } + } + } + + // remove user_x_role entry from database + public static function removeRoleFromUser($users, $roles) { + foreach($users AS $user) { + foreach ($roles AS $role) { + $query = "DELETE FROM user_x_role WHERE userid = :user AND roleid = :role"; + Database::exec($query, array("user" => $user, "role" => $role)); + } + } + } + + // delete role, delete user_x_role relationships, delete role_x_location relationships, delete role_x_permission relationships + public static function deleteRole($id) { + $query = "DELETE FROM role WHERE id = :id"; + Database::exec($query, array("id" => $id)); + $query = "DELETE FROM user_x_role WHERE roleid = :id"; + Database::exec($query, array("id" => $id)); + $query = "DELETE FROM role_x_location WHERE roleid = :id"; + Database::exec($query, array("id" => $id)); + $query = "DELETE FROM role_x_permission WHERE roleid = :id"; + Database::exec($query, array("id" => $id)); + } + + public static function saveRole($roleName, $locations, $permissions, $role = NULL) { + if ($role) { + Database::exec("UPDATE role SET name = :roleName WHERE id = :role", + array("roleName" => $roleName, "role" => $role)); + Database::exec("DELETE FROM role_x_location WHERE roleid = :role", array("role" => $role)); + Database::exec("DELETE FROM role_x_permission WHERE roleid = :role", array("role" => $role)); + } else { + Database::exec("INSERT INTO role (name) VALUES (:roleName)", array("roleName" => $roleName)); + $role = Database::lastInsertId(); + } + foreach ($locations as $locID) { + Database::exec("INSERT INTO role_x_location (roleid, locid) VALUES (:role, :locid)", + array("role" => $role, "locid" => $locID)); + } + foreach ($permissions as $permission) { + Database::exec("INSERT INTO role_x_permission (roleid, permissionid) VALUES (:role, :permission)", + array("role" => $role, "permission" => $permission)); + } + } + +} |