Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

send_research_request()

Parameters

ColumnTypeDefaultDescription
$rr_cfields array

Location

include/research_functions.php lines 5 to 79

Definition

 
function send_research_request(array $rr_cfields)
    {
    
# Insert a search request into the requests table.
    
    # Resolve resource types
    
$rt="";
    
$types=get_resource_types();for ($n=0;$n<count($types);$n++) {if (getval("resource" $types[$n]["ref"],"")!="") {if ($rt!="") {$rt.=", ";} $rt.=$types[$n]["ref"];}}
    
    global 
$userref$custom_researchrequest_fields;
    
$as_user=getvalescaped("as_user",$userref,true); # If userref submitted, use that, else use this user

    /**
    * @var string JSON representation of custom research request fields after removing the generated HTML properties we 
    *             needed during form processing
    * @see gen_custom_fields_html_props()
    */
    
$rr_cfields_json json_encode(array_map(function($v) { unset($v["html_properties"]); return $v; }, $rr_cfields), JSON_UNESCAPED_UNICODE);
    if(
json_last_error() !== JSON_ERROR_NONE)
        {
        
trigger_error(json_last_error_msg());
        }
    
$rr_cfields_json_sql = ($rr_cfields_json == "" "NULL" "'" escape_check($rr_cfields_json) . "'");

    
sql_query("insert into research_request(created,user,name,description,deadline,contact,email,finaluse,resource_types,noresources,shape, custom_fields_json)
    values (now(),'
$as_user','" getvalescaped("name","") . "','" getvalescaped("description","") . "'," .
    ((
getvalescaped("deadline","")=="")?"null":"'" getvalescaped("deadline","") . "'") . 
    
",'" getvalescaped("contact","") . "','" getvalescaped("email","") . "','" getvalescaped("finaluse","") . "','" $rt "'," .
    ((
getvalescaped("noresources","")=="")?"null":"'" getvalescaped("noresources","") . "'") . 
    
",'" getvalescaped("shape","") . "', {$rr_cfields_json_sql})");
    
    
# E-mails a resource request (posted) to the team
    
global $applicationname,$email_from,$baseurl,$email_notify,$username,$userfullname,$useremail,$lang$admin_resource_access_notifications;
    
    
$templatevars['ref']=sql_insert_id();
    
$templatevars['teamresearchurl']=$baseurl."/pages/team/team_research_edit.php?ref=" $templatevars['ref'];
    
$templatevars['username']=$username;
    
$templatevars['userfullname']=$userfullname;
    
$templatevars['useremail']=getvalescaped("email",$useremail); # Use provided e-mail (for anonymous access) or drop back to user email.
    
$templatevars['url']=$baseurl."/pages/team/team_research_edit.php?ref=".$templatevars['ref'];
    
    
$message="'$username' ($userfullname - $useremail) " $lang["haspostedresearchrequest"] . ".\n\n";
    
$notification_message $message;
    
$message.=$templatevars['teamresearchurl'];
    
hook("modifyresearchrequestemail");
    
    
$research_notify_emails=array();
    
$research_notify_users = array();
    
$notify_users=get_notification_users("RESEARCH_ADMIN");
    foreach(
$notify_users as $notify_user)
        {
        
get_config_option($notify_user['ref'],'user_pref_resource_access_notifications'$send_message$admin_resource_access_notifications);          
        if(
$send_message==false){continue;}        
        
        
get_config_option($notify_user['ref'],'email_user_notifications'$send_email);    
        if(
$send_email && $notify_user["email"]!="")
            {
            
$research_notify_emails[] = $notify_user['email'];                
            }        
        else
            {
            
$research_notify_users[]=$notify_user["ref"];
            }
        }
    
    foreach(
$research_notify_emails as $research_notify_email)
        {
        
send_mail($research_notify_email,$applicationname ": " $lang["newresearchrequestwaiting"],$message,$useremail,"","emailnewresearchrequestwaiting",$templatevars);
        }
    
    if (
count($research_notify_users)>0)
        {
        global 
$userref;
        
message_add($research_notify_users,$notification_message,$templatevars["teamresearchurl"]);
        }
    }

This article was last updated 3rd December 2020 14:05 Europe/London time based on the source file dated 14th September 2020 11:40 Europe/London time.