Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

create_resource_type_field()

Description

Create a new resource type field with the specified name of the required type

Parameters

ColumnTypeDefaultDescription
$name string - name of new field
$restype integer 0 - resource type - resource type that field applies to (0 = global)
$type integer FIELD_TYPE_TEXT_BOX_SINGLE_LINE - field type - refer to include/definitions.php
$shortname string "" - shortname of new field
$index boolean false - should new field be indexed?

Return

boolean|integer - ref of new field, false if unsuccessful

Location

include/resource_functions.php lines 8205 to 8240

Definition

 
function create_resource_type_field($name$restype 0$type FIELD_TYPE_TEXT_BOX_SINGLE_LINE$shortname ""$index=false)
    {
    if((
trim($name)=="") || !is_numeric($type) || !is_numeric($restype))
        {
        return 
false;
        }

    if(
trim($shortname) == "")
        {
        
$shortname mb_substr(mb_strtolower(str_replace("_","",safe_file_name($name))),0,20);
        }

    
$duplicate = (boolean) sql_value(sprintf(
        
"SELECT count(ref) AS `value` FROM resource_type_field WHERE `name` = '%s'",
        
escape_check($shortname)), 0"schema");

    
sql_query(sprintf("INSERT INTO resource_type_field (title, resource_type, type, `name`, keywords_index) VALUES ('%s', '%s', '%s', '%s', %s)",
        
escape_check($name),
        
escape_check($restype),
        
escape_check($type),
        
escape_check($shortname),
        (
$index "1" "0")
    ));
    
$new sql_insert_id();

    if(
$duplicate)
        {
        
sql_query(sprintf("UPDATE resource_type_field SET `name` = '%s' WHERE ref = '%s'"escape_check($shortname $new), $new));
        }

    
log_activity(nullLOG_CODE_CREATED$name'resource_type_field''title'$newnull'');

    
clear_query_cache("schema");

    return 
$new;
    }

This article was last updated 25th November 2020 05:05 Europe/London time based on the source file dated 13th November 2020 16:50 Europe/London time.