Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

resource_log()

Parameters

ColumnTypeDefaultDescription
$resource
$type
$field
$notes ""
$fromvalue ""
$tovalue ""
$usage -1
$purchase_size ""
$purchase_price 0

Location

include/resource_functions.php lines 3147 to 3226

Definition

 
function resource_log($resource$type$field$notes=""$fromvalue=""$tovalue=""$usage=-1$purchase_size=""$purchase_price=0)
    {
    global 
$userref,$k,$lang,$resource_log_previous_ref$internal_share_access;
    
    
// 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=="") ? "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 13th July 2020 16:35 Europe/London time based on the source file dated 13th July 2020 14:40 Europe/London time.