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

save_research_request()

Parameters

ColumnTypeDefaultDescription
$ref

Location

include/research_functions.php lines 126 to 209

Definition

 
function save_research_request($ref)
    {
    
# Save
    
global $baseurl,$email_from,$applicationname,$lang;
    
    
$parameters=array("i",$ref);

    if (
getval("delete","")!="")
        {
        
# Delete this request.
        
ps_query("delete from research_request where ref=? limit 1"$parameters);
        return 
true;
        }

    
# Check the status, if changed e-mail the originator
    
$currentrequest=ps_query("select status, assigned_to, collection from research_request where ref=?"$parameters);

    
$oldstatus=(count($currentrequest)>0)?$currentrequest[0]["status"]:0;
    
$newstatus=getval("status",0);
    
$collection=(count($currentrequest)>0)?$currentrequest[0]["collection"]:0;
    
$oldassigned_to=(count($currentrequest)>0)?$currentrequest[0]["assigned_to"]:0;
    
$assigned_to=getval("assigned_to",0);
    
    
$templatevars['url']=$baseurl "/?c=" $collection;
    
$templatevars['teamresearchurl']=$baseurl."/pages/team/team_research_edit.php?ref=" $ref
    
    if (
$oldstatus!=$newstatus)
        {
        
$requesting_user=ps_query("SELECT u.email, u.ref FROM user u,research_request r WHERE u.ref=r.user AND r.ref = ?"$parameters);
        
$requesting_user $requesting_user[0];
        if (
$newstatus==1
            {
            
$assignedmessage = new ResourceSpaceUserNotification();
            
$assignedmessage->set_subject("lang_researchrequestassigned");
            
$assignedmessage->set_text("lang_researchrequestassignedmessage");
            
$assignedmessage->template "emailresearchrequestassigned";
            
$assignedmessage->templatevars $templatevars;
            
$assignedmessage->url $templatevars["teamresearchurl"];
            
send_user_notification([$requesting_user['ref']],$assignedmessage);
            
# Log this
            
daily_stat("Assigned research request",0);
            }
        if (
$newstatus==2)
            {
            
$completemessage = new ResourceSpaceUserNotification();
            
$completemessage->set_subject("lang_researchrequestcomplete");
            
$completemessage->set_text("lang_researchrequestcompletemessage");
            
$completemessage->append_text("\n\n");
            
$completemessage->append_text("lang_clicklinkviewcollection");
            
$completemessage->template "emailresearchrequestcomplete";
            
$completemessage->templatevars $templatevars;
            
$completemessage->url $templatevars["teamresearchurl"];
            
send_user_notification([$requesting_user['ref']],$completemessage);
            
            
# Log this          
            
daily_stat("Processed research request",0);
            }
        }

    if (
$oldassigned_to!=$assigned_to)
        {        
        
$assignedmessage = new ResourceSpaceUserNotification();
        
$assignedmessage->set_subject("lang_researchrequestassigned");
        
$assignedmessage->set_text("lang_researchrequestassignedmessage");
        
$assignedmessage->template "emailresearchrequestassigned";
        
$assignedmessage->templatevars $templatevars;
        
$assignedmessage->url $templatevars["teamresearchurl"];
        
send_user_notification([$assigned_to],$assignedmessage);
        }

    
$parameters=array("i",$newstatus"i",$assigned_to"i",$ref);
    
ps_query("UPDATE research_request SET status = ?, assigned_to = ? WHERE ref= ?"$parameters);

    
# Copy existing collection
    
$rr_copyexisting=getval("copyexisting","");
    
$rr_copyexistingref=getval("copyexistingref","");
    if (
$rr_copyexisting !="" && is_numeric($collection))
        {
        
$parameters=array("i",$collection"i",$rr_copyexistingref"i",$collection);
        
ps_query("INSERT INTO collection_resource(collection,resource) 
                    SELECT ?, resource FROM collection_resource 
                    WHERE collection = ? AND resource NOT IN (SELECT resource FROM collection_resource WHERE collection = ?)"
$parameters);
        }
    }

This article was last updated 17th September 2024 08:35 Europe/London time based on the source file dated 16th May 2024 18:10 Europe/London time.