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

email_resource_request()

Description

E-mails a basic resource request for a single resource (posted) to the team (not a managed request)

Parameters

ColumnTypeDefaultDescription
$ref mixed The resource ID
$details mixed The request details provided by the user

Return

void|false|string

Location

include/request_functions.php lines 881 to 1073

Definition

 
function email_resource_request($ref,$details)
    {
    global 
$applicationname,$email_from,$baseurl,$email_notify,$username,$useremail,$userref,$lang,$watermark,$filename_field,$view_title_field,$access,$resource_type_request_emails,$resource_request_reason_required$user_dl_limit$user_dl_days$k$user_is_anon,$resource_type_request_emails_and_email_notify,$admin_resource_access_notifications;

    
$message = new ResourceSpaceUserNotification;
    
$detailstext = new ResourceSpaceUserNotification;
    
$detailstext->set_text($details);

    if(
intval($user_dl_limit) > 0)
        {
        
$download_limit_check get_user_downloads($userref,$user_dl_days);
        if(
$download_limit_check >= $user_dl_limit)
            {
            
$detailstext->prepend_text("<br />");
            
$detailstext->prepend_text("lang_download_limit_request_text",["[downloaded]","[limit]"],[$download_limit_check,$user_dl_limit]);
            }
        }

    
$resourcedata=get_resource_data($ref);
    
$templatevars['thumbnail']=get_resource_path($ref,true,"thm",false,"jpg",-1,1,($watermark)?(($access==1)?true:false):false);
    if (!
file_exists($templatevars['thumbnail']))
        {
        
$templatevars['thumbnail']="../gfx/no_preview/default.png";
        }

    if (isset(
$filename_field))
        {
        
$templatevars["filename"]=$lang["fieldtitle-original_filename"] . ": " get_data_by_field($ref,$filename_field);
        }
    if (isset(
$resourcedata["field" $view_title_field]))
        {
        
$templatevars["title"]=$resourcedata["field" $view_title_field];
        }
    
$templatevars['username']=$username " (" $useremail ")";
    
$templatevars['formfullname']=getval("fullname","");
    
$templatevars['formemail']=getval("email","");
    
$templatevars['formtelephone']=getval("contact","");
    
$templatevars['url']=$baseurl."/?r=".$ref;
    
$templatevars["requesturl"]=$templatevars['url'];
        
    
// for anon user access use form vars
    
if ($k!="" || $user_is_anon)
        {
        
$templatevars["fullname"] = getval("fullname","");
        
$useremail getval("email","");
        }
    else 
        {
        
$userdata=get_user($userref);
        
$templatevars["fullname"]= isset($userdata["fullname"]) ? $userdata["fullname"] : ""
        }

    
$htmlbreak="<br /><br />";

    
$list="";
    
reset ($_POST);
    foreach (
$_POST as $key=>$value)
        {
        if (
strpos($key,"_label")!==false)
            {
            
# Add custom field  
            
$data="";
            
$data=$_POST[str_replace("_label","",$key)];
            
$list.=$htmlbreak$value ": " $data."\n";
            }
        }
    
$list.=$htmlbreak;
    
$templatevars['list']=$list;
    
$templatevars['details']= stripslashes($detailstext->get_text());
    
$adddetails="";
    if (
$templatevars['details']!="")
        {
        
$adddetails=$lang["requestreason"] . ": " newlines($templatevars['details'])."<br />";
        }
    elseif (
$resource_request_reason_required)
        {
        return 
false;
        }

    
# Add custom fields
    
$c="";
    global 
$custom_request_fields,$custom_request_required;
    if (isset(
$custom_request_fields))
        {
        
$custom=explode(",",$custom_request_fields);
        
# Required fields?
        
if (isset($custom_request_required)) {$required=explode(",",$custom_request_required);}
        for (
$n=0;$n<count($custom);$n++)
            {
            if (isset(
$required) && in_array($custom[$n],$required) && getval("custom" $n,"")=="")
                {
                
# Required field was not set.
                
return false;
                }
            
$c.=i18n_get_translated($custom[$n]) . ": " getval("custom" $n,"") . "<br />";
            }
        }
    
$templatevars["requestreason"]=$lang["requestreason"] . ": " $templatevars['details']. $c ."";
    if(isset(
$username))
        {
        
$message->append_text("lang_username");
        
$message->append_text(": " $username " (" $useremail ")<br />");
        }
    if(!empty(
$templatevars["formfullname"]))
        {
        
$message->append_text("lang_fullname");
        
$message->append_text(": " $templatevars["formfullname"] . "<br />");
        }
    if(!empty(
$templatevars["formemail"]))
        {
        
$message->append_text("lang_email");
        
$message->append_text(": " $templatevars["formemail"] ."<br />");
        }
    if(!empty(
$templatevars["formtelephone"]))
        {
        
$message->append_text("lang_contacttelephone");
        
$message->append_text(": " $templatevars["formtelephone"] . "<br />");
        }

    
$notification_message = clone $message;
    
$notification_message->set_subject($applicationname ": ");
    
$notification_message->append_subject("lang_requestresource");
    
$notification_message->append_subject(" - "  $ref);
    
$notification_message->prepend_text($htmlbreak);
    
$notification_message->prepend_text("lang_user_made_request");
    
$notification_message->append_text($adddetails $c); 
    
$notification_message->append_text("<br />");
    
$notification_message->append_text("lang_clicktoviewresource");
    
$notification_message->user_preference = ["user_pref_resource_access_notifications"=>["requiredvalue"=>true,"default"=>$admin_resource_access_notifications]];
    
$notification_message->url $templatevars['url'];

    
$notify_users = [];
    
$notify_emails = [];
    
# Legacy: Check if alternative request email notification address is set
    
if(isset($resource_type_request_emails) && !can_use_owner_field())
        {
        if(isset(
$resource_type_request_emails[$resourcedata["resource_type"]]))
            {
            
$restype_email=$resource_type_request_emails[$resourcedata["resource_type"]];
            }
        
$emailusers get_user_by_email($restype_email);
        if(
is_array($emailusers) && count($emailusers) > 0)
            {
            
$notify_users array_merge($notify_users,$emailusers);
            }
        else
            {
            
$notify_emails[]=$restype_email;
            }
        }
   
    if((
count($notify_users)==&& count($notify_emails)==0) || $resource_type_request_emails_and_email_notify)
        {
        
// Add the default notifications
        
$admin_notify_users=get_notification_users("RESOURCE_ACCESS");
        
$notify_users array_merge($notify_users,$admin_notify_users);
        }
    
$notify_users array_keys(get_notification_users_by_owner_field($notify_users, [$ref]));

    
send_user_notification($notify_users,$notification_message);
    foreach(
$notify_emails as $notify_email)
        {
        
$send_result=send_mail($notify_email,$applicationname ": " $lang["requestresource"] . " - $ref",$message->get_text(),$email_from,$email_from,"emailresourcerequest",$templatevars);
        if (
$send_result!==true) {return $send_result;}
        }

    
$userconfirmmessage = clone $message;
    
$userconfirmmessage->set_subject($applicationname ": ");
    
$userconfirmmessage->append_subject(" - "  $ref);
    
$userconfirmmessage->prepend_text("<br /><br />");
    
$userconfirmmessage->prepend_text("lang_requestsenttext");
    
$userconfirmmessage->append_text($adddetails $c); 
    
$key_str=($k!="") ? "&k=" $k "";

    if (isset(
$userref))
        {
        
$userconfirmmessage->url $baseurl "/?r=" $ref $key_str;
        
send_user_notification([$userref],$userconfirmmessage);
        }
    else
        {
        
$sender =  (!empty($useremail)) ? $useremail : ((!empty($templatevars["formemail"]))? $templatevars["formemail"] : "");
        if(
$sender!="" && filter_var($senderFILTER_VALIDATE_EMAIL))
            {
            
$userconfirmmessage->append_text("<br /><a href='" $baseurl "/?r=" $ref $key_str "'>" $baseurl "/?r=" $ref $key_str "</a>");
            
send_mail($sender,$applicationname ": " $lang["requestsent"] . " - $ref",$userconfirmmessage->get_text(),$email_from,$email_notify);
            }  
        }
        

    
# Increment the request counter
    
ps_query("UPDATE resource SET request_count=request_count+1 WHERE ref = ?", array("i",$ref));
    }

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 27th September 2024 12:30 Europe/London time.