Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

copy_locked_data()

Description

Update resource data for 'locked' fields from last edited resource. Used for upload_then_edit

Parameters

ColumnTypeDefaultDescription
$resource array - existing resource data
$locked_fields array - array of locked data columns (may also include field ids which are handled by copy_locked_fields)
$lastedited integer - last edited resource to copy data from
$save boolean false - if true, save data to database (as opposed to just updating the $resource array e.g. for edit page)

Return

array $resource - modified resource data array

Location

include/resource_functions.php lines 6006 to 6059

Definition

 
function copy_locked_data($resource$locked_fields$lastedited$save=false)
    {
    global 
$custom_access;
    
    
debug("copy_locked_data resource " $resource["ref"] . " lastedited: " $lastedited);
    
    
// Get details of the last resource edited and use these for this resource if field is 'locked'
    
$lastresource get_resource_data($lastedited,false);
    
$lockable_columns = array("resource_type","archive","access");
    
    if(
in_array("resource_type",$locked_fields) && $resource["resource_type"] != $lastresource["resource_type"])
        {
        
$resource["resource_type"] = $lastresource["resource_type"];
        if (
$save && !checkperm("XU" $lastresource["resource_type"]))
            {
            
update_resource_type($resource["ref"],$lastresource["resource_type"]);   
            }
        }
    
    if(
in_array("archive",$locked_fields) && $resource["archive"] != $lastresource["archive"])
        {
        
$resource["archive"] = $lastresource["archive"];
        if (
$save && checkperm("e" $lastresource["archive"]))
            {
            
update_archive_status($resource["ref"],$lastresource["archive"],$resource["archive"]);
            }
        }
        
    if(
in_array("access",$locked_fields) && $resource["access"] != $lastresource["access"])
        {
        
$newaccess $lastresource["access"];
        if (
$save)
            {
            
$ea[0]=!checkperm('ea0');
            
$ea[1]=!checkperm('ea1');
            
$ea[2]=checkperm("v")?(!checkperm('ea2')?true:false):false;
            
$ea[3]=$custom_access?!checkperm('ea3'):false;
            if(
$ea[$newaccess])
                {
                
sql_query("update resource set access='" $newaccess "' where ref=' " $resource["ref"] . "'");
                
                if (
$newaccess==3)
                        {
                        
# Copy custom access
                        
sql_query("insert into resource_custom_access (resource,usergroup,user,access) select '" $resource["ref"] . "', usergroup,user,access from resource_custom_access where resource = '" $lastresource["ref"] . "'");
                        }
                
resource_log($resource["ref"],LOG_CODE_ACCESS_CHANGED,0,"",$resource["access"],$newaccess);
                }
            }
        
$resource["access"] = $newaccess;
        }
        
    return 
$resource;
    }

This article was last updated 14th July 2020 01:35 Europe/London time based on the source file dated 13th July 2020 14:40 Europe/London time.