Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

get_external_shares()

Description

Get details of external shares

"share_group" - (int) Usergroup ref 'shared as'
"share_user" - (int) user ID of share creator
"share_order_by" - (string) order by column
"share_sort" - (string) sortorder (ASC or DESC)
"share_type" - (int) 0=view, 1=upload
"share_collection" - (int) Collection ID
"share_resource" - (int) Resource ID
"access_key" - (string) Access key

Parameters

ColumnTypeDefaultDescription
$filteropts array Array of options to filter shares returned

Return

array

Location

include/resource_functions.php lines 8679 to 8788

Definition

 
function get_external_shares(array $filteropts)
    {
    global 
$userref;

    
$validfilterops = array(
        
"share_group",
        
"share_user",
        
"share_order_by",
        
"share_sort",
        
"share_type",
        
"share_collection",
        
"share_resource",
        
"access_key",
    );
    foreach(
$validfilterops as $validfilterop)
        {
        if(isset(
$filteropts[$validfilterop]))
            {
            $
$validfilterop $filteropts[$validfilterop];
            }
        else
            {
            $
$validfilterop NULL;
            }
        }

    
$valid_orderby = array("collection","user""sharedas""expires""date""email""lastused""access_key""upload");
    if(!
in_array($share_order_by$valid_orderby))
        {
        
$share_order_by "expires";
        }
    
$share_sort strtoupper($share_sort) == "ASC" "ASC" "DESC";

    
$conditions = array();
    if((int)
$share_user && ($share_user == $userref || checkperm_user_edit($share_user))
        )
        {
        
$conditions[] = "eak.user ='" . (int)$share_user "'";
        }
    elseif(!
checkperm('a'))
        {
        
$usercondition "eak.user ='" . (int)$userref "'";
        if(
checkperm("ex"))
            {
            
// Can also see shares that never expire
            
$usercondition " (expires IS NULL OR " $usercondition ")";
            }
        
$conditions[] =$usercondition;
        }

    if(!
is_null($share_group) && (int)$share_group 0  && checkperm('a'))
        {
        
$conditions[] = "eak.usergroup ='" . (int)$share_group "'";
        }
    
    if(!
is_null($access_key))
        {
        
$conditions[] = "eak.access_key ='" escape_check($access_key) . "'";
        }

    if((int)
$share_type === 0)
        {
        
$conditions[] = "(eak.upload=0 OR eak.upload IS NULL)";
        }
    elseif((int)
$share_type === 1)
        {
        
$conditions[] = "eak.upload=1";
        }
    if((int)
$share_collection 0)
        {
        
$conditions[] = "eak.collection ='" . (int)$share_collection "'";
        }
    if((int)
$share_resource 0)
        {
        
$conditions[] = "eak.resource ='" . (int)$share_resource "'";
        }

    
$conditional_sql="";
    if (
count($conditions)>0){$conditional_sql=" WHERE " implode(" AND ",$conditions);}

    
$external_access_keys_query 
        
"SELECT access_key,
                ifnull(collection,'-') collection,
                CASE 
                    WHEN collection IS NULL THEN resource
                    ELSE '-'
                END AS 'resource',
                user,
                eak.email,
                min(date) date,
                MAX(date) maxdate,
                max(lastused) lastused,
                eak.access,
                eak.expires,
                eak.usergroup,
                eak.password_hash,
                eak.upload,
                ug.name sharedas,
                u.fullname,
                u.username
           FROM external_access_keys eak
      LEFT JOIN user u ON u.ref=eak.user 
      LEFT JOIN usergroup ug ON ug.ref=eak.usergroup " 
.
                
$conditional_sql .
     
" GROUP BY access_key, collection
       ORDER BY eak." 
escape_check($share_order_by) . " " $share_sort;

    
$external_shares sql_query($external_access_keys_query);
    return 
$external_shares;
    }

This article was last updated 28th February 2021 16:05 Europe/London time based on the source file dated 26th February 2021 17:25 Europe/London time.