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

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
$file_extension string '' If specified

Return

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

Location

include/resource_functions.php lines 601 to 660

Definition

 
function create_resource($resource_type,$archive=999,$user=-1,$origin='',$file_extension='')
    {
    
# 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,file_extension) VALUES (?,NOW(),?,?,?)",["i",$resource_type,"i",$archive,"i",$user,"s",$file_extension]);

    
$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 17th November 2024 15:05 Europe/London time based on the source file dated 15th November 2024 18:30 Europe/London time.