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

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 7122 to 7174

Definition

 
function copy_locked_data($resource$locked_fields$lastedited$save=false)
    {
    
debug_function_call(__FUNCTION__, [$resource['ref'], $locked_fields$lastedited$save]);
    global 
$custom_access;

    
// Get details of the last resource edited and use these for this resource if field is 'locked'
    
$lastresource get_resource_data($lastedited,false);

    if(
in_array("resource_type",$locked_fields) && $resource["resource_type"] != $lastresource["resource_type"])
        {
        if (!
checkperm("XU" $lastresource["resource_type"]))
            {
            
update_resource_type($resource["ref"],$lastresource["resource_type"]);
            
apply_resource_default((int) $resource["resource_type"], (int) $lastresource["resource_type"], (int) $resource["ref"]);
            }
        
$resource["resource_type"] = $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])
                {
                
ps_query("update resource set access=? where ref=?",array("i",$newaccess,"i",$resource["ref"]));

                if (
$newaccess==3)
                        {
                        
# Copy custom access
                        
ps_query("insert into resource_custom_access (resource,usergroup,user,access) select ?, usergroup,user,access from resource_custom_access where resource = ?",array("i",$resource["ref"],"i",$lastresource["ref"]));
                        }
                
resource_log($resource["ref"],LOG_CODE_ACCESS_CHANGED,0,"",$resource["access"],$newaccess);
                }
            }
        
$resource["access"] = $newaccess;
        }

    return 
$resource;
    }

This article was last updated 13th December 2024 11:35 Europe/London time based on the source file dated 13th December 2024 09:45 Europe/London time.