Collections functions
General functions
Render functions
Theme permission functions
Resource functions

create_resource()

Parameters

ColumnTypeDefaultDescription
$resource_type
$archive 999
$user -1

Location

include/resource_functions.php lines 498 to 555

Definition

 
function create_resource($resource_type,$archive=999,$user=-1)
    {
    
# 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);
    if(
upload_share_active())
        {
        
resource_log($insertLOG_CODE_EXTERNAL_UPLOAD0,'','',$k ' ('  get_ip() . ')');
        }

    return 
$insert;
    }

This article was last updated 2nd October 2022 17:05 Europe/London time based on the source file dated 30th September 2022 14:20 Europe/London time.