Collections functions
General functions
Render functions
Theme permission 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 3680 to 3763

Definition

 
function edit_collection_external_access($key,$access=-1,$expires="",$group="",$sharepwd=""$shareopts=array())
    {
    global 
$usergroup$scramble_key$lang;
    
    
$extraopts = array("collection""upload");
    foreach(
$extraopts as $extraopt)
        {
        if(isset(
$shareopts[$extraopt]))
            {
            $
$extraopt $shareopts[$extraopt];
            }
        }
    if (
$key=="")
        {
        return 
false;
        }

    if(!isset(
$upload) || !$upload)
        {
        
// Only relevant for non-upload shares
        
if ($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(
$upload) && $upload){$setvals['upload'] = 1;}
    if(
$expires!=""
        {
        
$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(
$collection))
        {
        
$condition ' AND collection = ?';
        
$params array_merge($params, ['i'$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(
$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($collection,LOG_CODE_COLLECTION_EDIT_UPLOAD_SHARE,NULL,"(" implode(",",$lognotes) . ")");
        }    
       
    return 
true;
    }

This article was last updated 4th October 2022 10:05 Europe/London time based on the source file dated 4th October 2022 09:50 Europe/London time.