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

resource_log()

Description

Log resource activity

Parameters

ColumnTypeDefaultDescription
$resource int - resource ref -- resource_log.resource
$type string - log code defined in include/definitions.php -- resource_log.type
$field int - resource type field -- resource_log.resource_type_field
$notes string "" - text notes -- resource_log.notes
$fromvalue string "" - original value -- resource_log.previous_value
$tovalue string "" - new value
$usage int -1 -- resource_log.usageoption
$purchase_size string "" -- resource_log.purchase_size
$purchase_price float 0.00 -- resource_log.purchase_price

Return

int (or false)

Location

include/resource_functions.php lines 3440 to 3561

Definition

 
function resource_log($resource$type$field$notes=""$fromvalue=""$tovalue=""$usage=-1$purchase_size=""$purchase_price=0.00)
    {
    global 
$userref,$k,$lang,$resource_log_previous_ref$internal_share_access;

    
// Param type checks
    
$param_str = array($type,$notes,$fromvalue,$tovalue,$purchase_size);
    
$param_num = array($resource,$usage,$purchase_price);
 
    foreach(
$param_str as $par)
        {
        if (!
is_string($par))
            {
            return 
false;
            } 
        }
 
    foreach(
$param_num as $par)
        {
        if (!
is_numeric($par))
            {
            return 
false;
            } 
        }

    
// check that $usage is valid value for int type db field
    // https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
    
$options_db_int = [ 'options' => [ 'min_range' => -2147483648,   'max_range' => 2147483647] ];
    if (!
filter_var($usageFILTER_VALIDATE_INT$options_db_int) && $usage != 0)
        {
        return 
false;
        }
 
    
// check that purchase_price is valid for decimal 10,2 field
    
$options_db_purchase_price = [ 'options' => [  'regexp' => "/^[0-9]{0,10}\.?[0-9]{0,2}$/"   ]  ];
    if (
filter_var($purchase_priceFILTER_VALIDATE_REGEXP$options_db_purchase_price) == "")
        {
        return 
false;
        } 
        
    
// check that purchase_size is valid for varchar(10) field
    
$options_db_purchase_size = [ 'options' => [ 'regexp' => "/^[\w\W]{0,10}$/"]  ];
    if (
$purchase_size != "" && filter_var($purchase_sizeFILTER_VALIDATE_REGEXP$options_db_purchase_size) == "" )
        {
        return 
false;
        } 
            
    
// If it is worthy of logging, update the modified date in the resource table
    
update_timestamp($resource);
    
    if((
$resource === RESOURCE_LOG_APPEND_PREVIOUS && !isset($resource_log_previous_ref)) || ($resource !== RESOURCE_LOG_APPEND_PREVIOUS && $resource 0))
        {
        return 
false;
        }

    if (
$fromvalue===$tovalue)
        {
        
$diff="";
        }
    else
        {
        switch (
$type)
            {
            case 
LOG_CODE_STATUS_CHANGED:
                
$diff $lang["status" $fromvalue] . " -> " $lang["status" $tovalue];
                break;

            case 
LOG_CODE_ACCESS_CHANGED:
                
$diff $lang["access" $fromvalue] . " -> " $lang["access" $tovalue];
                break;

            
// do not do a diff, just dump out whole new value (this is so we can cleanly append transform output)
            
case LOG_CODE_TRANSFORMED:
                
$diff $tovalue;
                break;

            case 
LOG_CODE_NODE_REVERT:
                
$diff $tovalue;
                break;

            case 
LOG_CODE_CREATED:
                
$diff $tovalue;
                break;

            default:                
                
$diff log_diff($fromvalue$tovalue);
            }
        }

    
// Avoid out of memory errors such as when working with large PDF files
    
if(mb_strlen($diff) > 10000)
        {
        
$diff mb_strcut($diff010000);
        }

    
$modifiedlogtype=hook("modifylogtype","",array($type));
    if (
$modifiedlogtype)
        {
        
$type $modifiedlogtype;
        }
    
    
$modifiedlognotes=hook("modifylognotes","",array($notes,$type,$resource));
    if(
$modifiedlognotes)
        {
        
$notes $modifiedlognotes;
        }

    if (
$resource === RESOURCE_LOG_APPEND_PREVIOUS)
        {
        
sql_query("UPDATE `resource_log` SET `diff`=left(concat(`diff`,'\n','" escape_check($diff) . "'),60000) WHERE `ref`=" $resource_log_previous_ref);
        return 
$resource_log_previous_ref;
        }
    else
        {
        
sql_query("INSERT INTO `resource_log` (`date`, `user`, `resource`, `type`, `resource_type_field`, `notes`, `diff`, `usageoption`, `purchase_size`, " .
            
"`purchase_price`, `access_key`, `previous_value`) VALUES (now()," .
            ((
$userref != "") ? "'" escape_check($userref) . "'" "null") . ",'" escape_check($resource) . "','" escape_check($type) . "'," . (($field=="" || !is_numeric($field)) ? "null" "'" escape_check($field) . "'") . ",'" escape_check($notes) . "','" .
            
escape_check($diff) . "','" escape_check($usage) . "','" escape_check($purchase_size) . "','" escape_check($purchase_price) . "'," . ((isset($k) && !$internal_share_access) ? "'{$k}'" "null") . ",'" escape_check($fromvalue) . "')");
        
$log_ref sql_insert_id();
        
$resource_log_previous_ref $log_ref;
        return 
$log_ref;
        }
    }

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