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

put_resource_data()

Description

Updates $resource with the name/value pairs in $data - this relates to the resource table column, not metadata.

Parameters

ColumnTypeDefaultDescription
$resource int ID of resource
$data array Array of data to be applied to resource

Return

boolean

Location

include/resource_functions.php lines 441 to 464

Definition

 
function put_resource_data($resource,$data)
    {   
    global 
$edit_contributed_by;

    
// Check access
    
if (!get_edit_access($resource)) {return false;}
    
    
// Define safe columns
    
$safe_columns=array("resource_type","creation_date","rating","user_rating","archive","access","mapzoom","modified","geo_lat","geo_long");

    
// Permit the created by column to be changed also
    
if (checkperm("v") && $edit_contributed_by) {$safe_columns[]="created_by";}
    
    
$sql="";
    foreach (
$data as $column=>$value)
        {
        if (!
in_array($column,$safe_columns)) {return false;} // Attempted to update a column outside of the expected set
        
if ($sql!="") {$sql.=",";}
        
$sql.=$column "='" escape_check($value) . "'";
        }
    if (
$sql=="") {return false;} // Nothing to do.
    
sql_query("update resource set $sql where ref='" escape_check($resource) . "'");
    return 
true;
    }

This article was last updated 3rd December 2020 13:35 Europe/London time based on the source file dated 30th November 2020 11:55 Europe/London time.