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

Return

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

Location

include/resource_functions.php lines 600 to 659

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 9th November 2024 16:35 Europe/London time based on the source file dated 7th November 2024 17:40 Europe/London time.