Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 3857 to 3931

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 4th December 2024 08:35 Europe/London time based on the source file dated 27th November 2024 15:30 Europe/London time.