Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

edit_filter_to_restype_permission()

Parameters

ColumnTypeDefaultDescription
$filtertext
$usergroup
$existingperms
$updatecurrent false

Location

include/migration_functions.php lines 613 to 668

Definition

 
function edit_filter_to_restype_permission($filtertext$usergroup$existingperms$updatecurrent false)
    {
    global 
$userpermissions;
    
$addpermissions = array();
    
// Replace any resource type edit filter sections with new XE/XE-?/XE? permissions
    
$filterrules explode(";"$filtertext);
    
$cleanedrules = array();
    foreach(
$filterrules as $filterrule)
        {
        
$filterparts explode("=",$filterrule);
        
$checkattr trim(strtolower($filterparts[0]));
        if(
substr($checkattr,0,13) == "resource_type")
            {
            
$filternot false;
            if(
substr($checkattr,-1) == "!")
                {
                
$filternot true;
                }
            else
                {
                
// Only allowing certain resource types. Add permission to block all resource types 
                // and then add a permission for each permitted type
                
$addpermissions[] = "XE";
                }
            
            
$checkrestypes explode("|",$filterparts[1]);
            foreach(
$checkrestypes as $checkrestype)
                {
                
// Add either XE-? or XE? permission, depending on whether group is only allowed to edit the specified types or everything except these types
                
$addpermissions[] = "XE" . ($filternot "" "-") . (int)trim($checkrestype);
                }
            }
        else
            {
            
$cleanedrules[] = trim($filterrule);
            }
        }

    
$currentgroup get_usergroup($usergroup);
    if(
in_array("permissions",$currentgroup["inherit"]))
        {
        
$existingperms explode(",",$currentgroup["permissions"]);
        }
    
$newperms array_diff($addpermissions,$existingperms);
    if(
count($newperms) > 0)
        {
        
ps_query("UPDATE usergroup SET permissions = CONCAT(permissions," ps_param_insert(count($newperms)) . ") WHERE ref = ?"array_merge(ps_param_fill(array_map(function($v) {return ',' $v;}, $newperms), "s"), array("i"$usergroup)));
        }
    if(
$updatecurrent)
        {
        
$userpermissions array_merge($userpermissions$newperms);
        }

    
// Reconstruct filter text without this to create new filter
    
return implode(";"$cleanedrules);
    }

This article was last updated 25th April 2024 18:35 Europe/London time based on the source file dated 15th April 2024 16:05 Europe/London time.