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

edit_collection_external_access()

Description

Update an existing external access share

"collection" - int collection ID
"upload" - bool Set to true if share is an upload link (no visibility of existing resources)

Parameters

ColumnTypeDefaultDescription
$key string External access key
$access int -1 Share access level
$expires string "" Share expiration date
$group int "" ID of usergroup that share will emulate permissions for
$sharepwd string "" Share password
$shareopts array array Array of additional share options

Return

boolean

Location

include/collections_functions.php lines 3813 to 3887

Definition

 
function edit_collection_external_access($key,$access=-1,$expires="",$group="",$sharepwd=""$shareopts=array())
    {
    global 
$usergroup$scramble_key$lang;
    
    if (
$key=="")
        {
        return 
false;
        }

    if (
        (!isset(
$shareopts['upload']) || !$shareopts['upload'] )
        && (
$group=="" || !checkperm("x"))
        ) {
            
// Default to sharing with the permission of the current usergroup if not specified OR no access to alternative group selection.
            
$group=$usergroup;
        }
    
// Ensure these are escaped as required here
    
$setvals = array(
        
"access"    => (int)$access,
        
"usergroup" => (int)$group,
        );
    if(isset(
$shareopts['upload']) && $shareopts['upload']){$setvals['upload'] = 1;}
    if(
$expires!=""
        {
        
$expires date_format(date_create($expires), 'Y-m-d') . ' 23:59:59';
        
$setvals["expires"] = $expires;
        }
    else
        {
        
$setvals["expires"] = null;
        }
    if(
$sharepwd != "(unchanged)")
        {
        
$setvals["password_hash"] = ($sharepwd == "") ? "" hash('sha256'$key $sharepwd $scramble_key);
        }
    
$setsql ""$params = [];
    foreach(
$setvals as $setkey => $setval)
        {
        
$setsql .= $setsql == "" "" ",";
        
$setsql .= $setkey "= ?";
        
$params array_merge($params, ['s'$setval]);
        }
    
$setsql .= ', date = now()';
    
$params array_merge($params, ['s'$key]);
    
$condition '';
    if(isset(
$shareopts['collection']))
        {
        
$condition ' AND collection = ?';
        
$params array_merge($params, ['i'$shareopts['collection']]);
        }

    
ps_query("UPDATE external_access_keys
                  SET " 
$setsql "
                WHERE access_key= ?" 
$condition
                
$params);
    
hook("edit_collection_external_access","",array($key,$access,$expires,$group,$sharepwd$shareopts));
    if(isset(
$shareopts['collection']))
        {
        
$lognotes = array("access_key" => $key);
        foreach(
$setvals as $column => $value)
            {
            if(
$column=="password_hash")
                {
                
$lognotes[] = trim($value) != "" "password=TRUE" "";
                }
            else
                {
                
$lognotes[] = $column "=" .  $value;
                }
            }
        
collection_log($shareopts['collection'],LOG_CODE_COLLECTION_EDIT_UPLOAD_SHARE,null,"(" implode(",",$lognotes) . ")");
        }    
       
    return 
true;
    }

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