Collections functions
General functions
Node functions
Render functions
Theme permission functions
User 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 542 to 601

Definition

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

    
$alltypes=get_resource_types("",false,false,false);
    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() !== false)
        {
        
# Terms needed to be accepted to complete upload
        
$notes = ($terms_upload "Terms accepted" "");
        
resource_log($insertLOG_CODE_EXTERNAL_UPLOAD0,$notes,'',$k ' ('  get_ip() . ')');
        }

    return 
$insert;
    }

This article was last updated 19th March 2024 11:35 Europe/London time based on the source file dated 11th March 2024 14:25 Europe/London time.