public function filedepot::updatePerms in filedepot 6
Same name and namespace in other branches
- 7 filedepot.class.php \filedepot::updatePerms()
1 call to filedepot::updatePerms()
File
- ./
filedepot.class.php, line 324 - filedepot.class.php Main class for the Filedepot module
Class
- filedepot
- @file filedepot.class.php Main class for the Filedepot module
Code
public function updatePerms($id, $accessrights, $users = '', $groups = '', $roles = '') {
if ($users != '' and !is_array($users)) {
$users = array(
$users,
);
}
if (!empty($accessrights)) {
if (in_array('view', $accessrights)) {
$view = 1;
}
else {
$view = 0;
}
if (in_array('upload', $accessrights)) {
$upload = 1;
}
else {
$upload = 0;
}
if (in_array('approval', $accessrights)) {
$approval = 1;
}
else {
$approval = 0;
}
if (in_array('upload_dir', $accessrights)) {
$direct = 1;
}
else {
$direct = 0;
}
if (in_array('admin', $accessrights)) {
$admin = 1;
}
else {
$admin = 0;
}
if (in_array('upload_ver', $accessrights)) {
$versions = 1;
}
else {
$versions = 0;
}
if (!empty($users)) {
foreach ($users as $uid) {
$uid = intval($uid);
$query = db_query("SELECT accid FROM {filedepot_access} WHERE catid=%d AND permtype='user' AND permid=%d", $id, $uid);
if (db_result($query) === FALSE) {
$sql = "INSERT INTO {filedepot_access} " . "(catid,permid,permtype,view,upload,upload_direct,upload_ver,approval,admin) " . "VALUES (%d,%d,'user',%d,%d,%d,%d,%d,%d)";
db_query($sql, $id, $uid, $view, $upload, $direct, $versions, $approval, $admin);
}
else {
$sql = "UPDATE {filedepot_access} SET view=%d, upload=%d, " . "upload_direct=%d, upload_ver=%d, approval=%d, " . "admin=%d WHERE catid=%d AND permtype='user' AND permid=%d";
db_query($sql, $view, $upload, $direct, $versions, $approval, $admin, $id, $uid);
}
}
}
if (!empty($groups)) {
foreach ($groups as $gid) {
$gid = intval($gid);
$query = db_query("SELECT accid FROM {filedepot_access} WHERE catid=%d AND permtype='group' AND permid=%d", $id, $gid);
if (db_result($query) === FALSE) {
$sql = "INSERT INTO {filedepot_access} " . "(catid,permid,permtype,view,upload,upload_direct,upload_ver,approval,admin) " . "VALUES (%d,%d,'group',%d,%d,%d,%d,%d,%d)";
db_query($sql, $id, $gid, $view, $upload, $direct, $versions, $approval, $admin);
}
else {
$sql = "UPDATE {filedepot_access} SET view=%d, upload=%d, " . "upload_direct=%d, upload_ver=%d, approval=%d, " . "admin=%d WHERE catid=%d AND permtype='group' AND permid=%d";
db_query($sql, $view, $upload, $direct, $versions, $approval, $admin, $id, $gid);
}
}
}
if (!empty($roles)) {
foreach ($roles as $rid) {
$rid = intval($rid);
$query = db_query("SELECT accid FROM {filedepot_access} WHERE catid=%d AND permtype='role' AND permid=%d", $id, $rid);
if (db_result($query) === FALSE) {
$sql = "INSERT INTO {filedepot_access} " . "(catid,permid,permtype,view,upload,upload_direct,upload_ver,approval,admin) " . "VALUES (%d,%d,'role',%d,%d,%d,%d,%d,%d)";
db_query($sql, $id, $rid, $view, $upload, $direct, $versions, $approval, $admin);
}
else {
$sql = "UPDATE {filedepot_access} SET view=%d, upload=%d, " . "upload_direct=%d, upload_ver=%d, approval=%d, " . "admin=%d WHERE catid=%d AND permtype='role' AND permid=%d";
db_query($sql, $view, $upload, $direct, $versions, $approval, $admin, $id, $rid);
}
}
}
/* May need to review this - and clear only those users that have been updated later.
But determining the users in updated groups and sorting out duplicates from the individual user perms
and only updating them may take more processing then simply clearing all.
The users setting will be updated the next time they use the application - public/filedepot/library.php
Distributing the load to update the cached setting.
This cached setting will really only benefit when there are many thousand access records like portal23
*/
db_query("UPDATE {filedepot_usersettings} set allowable_view_folders = ''");
return TRUE;
}
else {
return FALSE;
}
}