Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video 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 2987 to 3062

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,
        
"date"      => "now()",
        
"usergroup" => (int)$group,
        
"upload"    => isset($upload) && $upload "1" "upload",
        );
    if(
$expires!=""
        {
        
$setvals["expires"] = "'" escape_check($expires) . "'";
        }
    else
        {
        
$setvals["expires"] = "NULL";
        }
    if(
$sharepwd != "(unchanged)")
        {
        
$setvals["password_hash"] = ($sharepwd == "") ? "''" "'" hash('sha256'$key $sharepwd $scramble_key) . "'";
        }
    
$setsql "";
    foreach(
$setvals as $setkey => $setval)
        {
        
$setsql .= $setsql == "" "" ",";
        
$setsql .= $setkey "=" $setval ;
        }
    
sql_query("UPDATE external_access_keys
                  SET " 
$setsql "
                WHERE access_key='
$key'" 
                      (isset(
$collection) ? " AND collection='" . (int)$collection "'""")
                );
    
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 25th February 2021 21:05 Europe/London time based on the source file dated 24th February 2021 09:50 Europe/London time.