Collections functions
General functions
Render functions
Theme permission functions
Resource functions

save_research_request()

Parameters

ColumnTypeDefaultDescription
$ref

Location

include/research_functions.php lines 129 to 213

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];
        
$message="";
        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 2nd October 2022 16:05 Europe/London time based on the source file dated 1st July 2022 09:30 Europe/London time.