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

save_resource_type()

Description

Save updated resource_type data

Parameters

ColumnTypeDefaultDescription
$ref int Ref of resource type
$savedata array Array of column values

Return

bool *

Location

include/config_functions.php lines 1595 to 1683

Definition

 
function save_resource_type(int $ref, array $savedata)
    {
    global 
$execution_lockout;
    
$restypes get_resource_types("",true,false,true);
    
$restype_refs array_column($restypes,"ref");
    if(!
checkperm('a') || !in_array($ref,$restype_refs))
        {
        return 
false;
        }

    
$setcolumns = [];
    
$setparams = [];
    
$restypes array_combine($restype_refs,$restypes);
    foreach(
$savedata as $savecol=>$saveval)
        {
        
debug("checking for column " $savecol " in " json_encode(($restype_refs),true));
        if(
$saveval === $restypes[$ref][$savecol])
            {
            
// Unchanged value, skip
            
continue;
            }
        switch(
$savecol)
            {
            case 
"name":
                
$setcolumns[] = "name";
                
$setparams[] = "s";
                
$setparams[] = mb_strcut($saveval0100);
                break;

            case 
"order_by":
            case 
"push_metadata":
            case 
"tab":
            case 
"colour":
            case 
"pull_images":
                
$setcolumns[] = $savecol;
                
$setparams[] = "i";
                
$setparams[] = $saveval;
                break;

            case 
"config_options":
                if (!
$execution_lockout)
                    {
                    
// Not allowed to save PHP if execution_lockout set.
                    
$setcolumns[] = $savecol;
                    
$setparams[] = "s";
                    
$setparams[] = $saveval;
                    }
                break;

            case 
"allowed_extensions":
                
$setcolumns[] = $savecol;
                
$setparams[] = "s";
                
$setparams[] = $saveval;
                break;

            case 
"icon":
                
$setcolumns[] = $savecol;
                
$setparams[] = "s";
                
$setparams[] = mb_strcut($saveval0120);
                break;

            default:
                
// Invalid option, ignore
                
break;
            }
        }
    if(
count($setcolumns) === 0)
        {
        return 
false;
        }

    
$setparams[] = "i";
    
$setparams[] = $ref;

    
ps_query(
        
"UPDATE resource_type
            SET " 
implode("=?,",$setcolumns) . "=?
            WHERE ref = ?"
$setparams
        
);

    for(
$n=0;$n<count($setcolumns);$n++)
        {
        
log_activity(null,LOG_CODE_EDITED,$setparams[(2*$n)+1],'resource_type',$setcolumns[$n],$ref,null,$restypes[$ref][$setcolumns[$n]]);
        }

    
clear_query_cache("schema");
    
clear_restype_cache();
    return 
true;
    }

This article was last updated 17th November 2024 15:05 Europe/London time based on the source file dated 13th November 2024 15:50 Europe/London time.