Collections functions
General functions
Render functions
Theme permission functions
Resource functions

create_resource()

Description

create_resource

Parameters

ColumnTypeDefaultDescription
$resource_type integer ID of target resource type
$archive integer 999 ID of target archive state, 999 if archived
$user integer -1 User ID, -1 for current user
$origin string '' Source of resource, should not be blank

Return

mixed false if invalid inputs given, integer of resource reference if resource is created

Location

include/resource_functions.php lines 502 to 559

Definition

 
function create_resource($resource_type,$archive=999,$user=-1,$origin='')
    {
    
# Create a new resource.
    
global $k;
    
    if(!
is_numeric($archive))
        {
        return 
false;
        }

    
$alltypes=get_resource_types();
    if(!
in_array($resource_type,array_column($alltypes,"ref")))
        {
        return 
false;
        }

    if (
$archive==999)
        {
        
# Work out an appropriate default state
        
for ($n=-2;$n<3;$n++)
            {
            if (
checkperm("e" $n))
                {
                
$archive $n;
                break;
                }
            }
        }

    if(
$user == -1)
        {
        global 
$userref;
        
$user $userref;
        }

    
ps_query("INSERT INTO resource(resource_type,creation_date,archive,created_by) VALUES (?,NOW(),?,?)",["i",$resource_type,"i",$archive,"i",$user]);

    
$insert=sql_insert_id();

    
# set defaults for resource here (in case there are edit filters that depend on them)
    
set_resource_defaults($insert);

    
hook('resourcecreate''', array($insert$resource_type));

    
# Autocomplete any blank fields.
    
autocomplete_blank_fields($inserttrue);

    
# Log this
    
daily_stat("Create resource",$insert);

    
resource_log($insertLOG_CODE_CREATED0,$origin);
    if(
upload_share_active())
        {
        
resource_log($insertLOG_CODE_EXTERNAL_UPLOAD0,'','',$k ' ('  get_ip() . ')');
        }

    return 
$insert;
    }

This article was last updated 7th February 2023 04:35 Europe/London time based on the source file dated 3rd February 2023 13:55 Europe/London time.