Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

save_research_request()

Parameters

ColumnTypeDefaultDescription
$ref

Location

include/research_functions.php lines 94 to 185

Definition

 
function save_research_request($ref)
    {
    
# Save
    
global $baseurl,$email_from,$applicationname,$lang;
    
    if (
getval("delete","")!="")
        {
        
# Delete this request.
        
sql_query("delete from research_request where ref='$ref' limit 1");
        return 
true;
        }
    
# Check the status, if changed e-mail the originator
    
$currentrequest=sql_query("select status, assigned_to, collection from research_request where ref='$ref'");
    
$oldstatus=(count($currentrequest)>0)?$currentrequest[0]["status"]:0;
    
$newstatus=getvalescaped("status",0);
    
$collection=(count($currentrequest)>0)?$currentrequest[0]["collection"]:0;
    
$oldassigned_to=(count($currentrequest)>0)?$currentrequest[0]["assigned_to"]:0;
    
$assigned_to=getvalescaped("assigned_to",0);
    
    
$templatevars['url']=$baseurl "/?c=" $collection;
    
$templatevars['teamresearchurl']=$baseurl."/pages/team/team_research_edit.php?ref=" $ref;    
    
    if (
$oldstatus!=$newstatus)
        {
        
$requesting_user=sql_query("select u.email, u.ref from user u,research_request r where u.ref=r.user and r.ref='$ref'");
        
$requesting_user $requesting_user[0];
        
//$email=sql_value("select u.email value from user u,research_request r where u.ref=r.user and r.ref='$ref'","");
        
$message="";
        if (
$newstatus==1
            {
            
$message=$lang["researchrequestassignedmessage"];$subject=$lang["researchrequestassigned"];
            
//$message="'$username' ($userfullname - $useremail) " . $lang["haspostedresearchrequest"] . ".\n\n";
            
$notification_message $message;
            
$message.=$templatevars['url'];
            
get_config_option($requesting_user['ref'],'email_user_notifications'$send_email);    
            if(
$send_email && $requesting_user["email"]!="")
                {
                
send_mail ($requesting_user['email'],$applicationname ": " $subject,$message,"","","emailresearchrequestassigned",$templatevars);
                }        
            else
                {
                
message_add($requesting_user["ref"],$notification_message,(($collection!=0)?$templatevars["url"]:"#"));
                }
                
            
# Log this
            
daily_stat("Assigned research request",0);
            }
        if (
$newstatus==2)
            {
            
$message=$lang["researchrequestcompletemessage"] . "\n\n" $lang["clicklinkviewcollection"] . "\n\n" $templatevars['url'];$subject=$lang["researchrequestcomplete"];
            
$notification_message $message;
            
get_config_option($requesting_user['ref'],'email_user_notifications'$send_email);    
            if(
$send_email && $requesting_user["email"]!="")
                {
                
send_mail ($requesting_user['email'],$applicationname ": " $subject,$message,"","","emailresearchrequestcomplete",$templatevars);
                }        
            else
                {
                
message_add($requesting_user["ref"],$notification_message,(($collection!=0)?$templatevars["url"]:"#"));
                }
            
            
# Log this            
            
daily_stat("Processed research request",0);
            }
        }
        
    if (
$oldassigned_to!=$assigned_to)
            {
            
$message $lang["researchrequestassigned"];
            
$subject $lang["researchrequestassigned"];
            
$assigned_message $message;
            
$message .= $templatevars['teamresearchurl'];
            
$assigned_to_user=get_user($assigned_to);
            
get_config_option($assigned_to,'email_user_notifications'$send_email);    
            if(
$send_email && $assigned_to_user["email"]!="")
                {
                
send_mail ($assigned_to_user['email'],$applicationname ": " $subject,$assigned_message,"","","emailresearchrequestassigned",$templatevars);
                }        
            else
                {
                
message_add($assigned_to,$assigned_message,$templatevars['teamresearchurl']);
                }
            }
            
    
sql_query("update research_request set status='" $newstatus "',assigned_to='" $assigned_to "' where ref='$ref'");
    
    
# Copy existing collection
    
if (getvalescaped("copyexisting","")!="" && is_numeric($collection))
        {
        
sql_query("insert into collection_resource(collection,resource) select '$collection',resource from collection_resource where collection='" getvalescaped("copyexistingref","") . "' and resource not in (select resource from collection_resource where collection='$collection');");
        }
    }

This article was last updated 11th July 2020 23:35 Europe/London time based on the source file dated 7th July 2020 14:31 Europe/London time.