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

send_research_request()

Description

Sends a research request by inserting it into the requests table and notifying the relevant users.

This function takes an array of custom fields related to the research request,
processes the input data, and sends an email notification to the designated research admins.
It gathers resource types, deadlines, contact information, and custom fields, and stores them
in the database. It also constructs and sends a notification message with the request details.

@throws Exception If there is an error during JSON encoding of custom fields.

Parameters

ColumnTypeDefaultDescription
$rr_cfields array An array of custom fields associated with the research request.

Return

void This function does not return any value but performs database operations and sends notifications.

Location

include/research_functions.php lines 17 to 99

Definition

 
function send_research_request(array $rr_cfields)
    {
    
# Insert a search request into the requests table.
    
global $baseurl,$username,$userfullname,$useremail$userref;

    
# 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"];
            }
        }
    
$as_user=getval("as_user",$userref,true); # If userref submitted, use that, else use this user
    
$rr_name=getval("name","");
    
$rr_description=getval("description","");
    
$parameters=array("i",$as_user"s",$rr_name"s",$rr_description);

    
$rr_deadline getval("deadline","");
    if(
$rr_deadline=="")
        {
        
$rr_deadline=null;
        }
    
$rr_contact mb_strcut(getval("contact",""),0,100);
    
$rr_email mb_strcut(getval("email",""),0,200);
    
$rr_finaluse getval("finaluse","");
    
$parameters=array_merge($parameters,array("s",$rr_deadline"s",$rr_contact"s",$rr_email"s",$rr_finaluse));

    
# $rt
    
$rr_noresources getval("noresources","");
    if(
$rr_noresources=="")
        {
        
$rr_noresources=null;
        }
    
$rr_shape mb_strcut(getval("shape",""),0,50);

    
$parameters=array_merge($parameters,array("s",$rt"i",$rr_noresources"s",$rr_shape));

    
/**
    * @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 == "" "" $rr_cfields_json);
    
$parameters=array_merge($parameters,array("s",$rr_cfields_json_sql));

    
ps_query("insert into research_request(created,user,name,description,deadline,contact,email,finaluse,resource_types,noresources,shape, custom_fields_json)
                values (now(), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
$parameters);

    
# Send request 
    
$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']=getval("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'];

    
$research_notify_users=get_notification_users("RESEARCH_ADMIN");
    
$userconfirmmessage = new ResourceSpaceUserNotification();
    
$userconfirmmessage->set_subject("lang_newresearchrequestwaiting");
    
$userconfirmmessage->set_text("'$username' ($userfullname - $useremail) ");
    
$userconfirmmessage->append_text("lang_haspostedresearchrequest");
    
$userconfirmmessage->append_text(".\n\n");  
    
$userconfirmmessage->user_preference "user_pref_resource_access_notifications";
    
$userconfirmmessage->template "emailnewresearchrequestwaiting";
    
$userconfirmmessage->templatevars $templatevars;
    
$userconfirmmessage->url $templatevars["teamresearchurl"];

    
// Hook needs to update the ResourceSpaceUserNotification object
    
hook("modifyresearchrequestemail""", array($userconfirmmessage));
    
send_user_notification($research_notify_users,$userconfirmmessage);
    }

This article was last updated 4th December 2024 09:05 Europe/London time based on the source file dated 8th November 2024 12:05 Europe/London time.