Collections functions
Encryption functions
General functions
Theme permission functions
Resource 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

Location

include/request_functions.php lines 904 to 1055

Definition

 
function email_resource_request($ref,$details)
    {
    global 
$applicationname,$email_from,$baseurl,$email_notify,$username,$useremail,$userref,$lang,$request_senduserupdates,$watermark,$filename_field,$view_title_field,$access,$resource_type_request_emails,$resource_request_reason_required$admin_resource_access_notifications$user_dl_limit$user_dl_days;
    
    if(
intval($user_dl_limit) > 0)
        {
        
$download_limit_check get_user_downloads($userref,$user_dl_days);
        if(
$download_limit_check >= $user_dl_limit)
            {
            
$details str_replace(array("%%DOWNLOADED%%","%%LIMIT%%"),array($download_limit_check,$user_dl_limit),$lang['download_limit_request_text']) . "\n" $details;
            }
        }

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

    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['formemail']=getval("email","");
    
$templatevars['url']=$baseurl."/?r=".$ref;
    
$templatevars["requesturl"]=$templatevars['url'];
    
    
$userdata=get_user($userref);
    
$templatevars["fullname"]=$userdata["fullname"];
    
    
$htmlbreak="";
    global 
$use_phpmailer;
    if (
$use_phpmailer){$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($details);
    
$adddetails="";
    if (
$templatevars['details']!=""){$adddetails=$lang["requestreason"] . ": " newlines($templatevars['details'])."\n\n";} 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,"")=="")
                {
                return 
false# Required field was not set.
                
}
            
            
$c.=i18n_get_translated($custom[$n]) . ": " getval("custom" $n,"") . "\n\n";
            }
        }
    
$templatevars["requestreason"]=$lang["requestreason"] . ": " $templatevars['details']. $c ."";
    
    
$message=$lang["user_made_request"] . "<br /><br />";
    
$message.= isset($username)? $lang["username"] . ": " $username " (" $useremail ")<br />":"";
    
$message.= (!empty($templatevars["formemail"]))? $lang["email"].":".$templatevars["formemail"]."<br />":"";
    
$notification_message $message $adddetails $c 
    
$message.= $adddetails$c "<br /><br />" $lang["clicktoviewresource"] . "<br />"$templatevars['url'];
    

    
$admin_notify_emails=array();    
    
$admin_notify_users=array();
    
# Check if alternative request email notification address is set
    
if(isset($resource_type_request_emails))
        {
        if(isset(
$resource_type_request_emails[$resourcedata["resource_type"]]))
            {
            
$admin_notify_emails[]=$resource_type_request_emails[$resourcedata["resource_type"]];
            }
        } 
    else
        {
        
$admin_notify_emails[]=$email_notify;
        
$notify_users=get_notification_users("RESOURCE_ACCESS");
        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 && filter_var($notify_user["email"], FILTER_VALIDATE_EMAIL))
                {
                
$admin_notify_emails[] = $notify_user['email'];             
                }        
            else
                {
                
$admin_notify_users[]=$notify_user["ref"];
                }
            }
        }
        
    foreach(
$admin_notify_emails as $admin_notify_email)
        {
        
send_mail($admin_notify_email,$applicationname ": " $lang["requestresource"] . " - $ref",$message,$useremail,$useremail,"emailresourcerequest",$templatevars);
        }
    
    if (
count($admin_notify_users)>0)
        {
        global 
$userref;
        
message_add($admin_notify_users,$notification_message,$templatevars["requesturl"]);
        }
              
    if (
$request_senduserupdates)
        { 
        
$k=(getval("k","")!="")? "&k=".getval("k",""):"";
        
$userconfirmmessage $lang["requestsenttext"] . "<br /><br />" $lang["requestreason"] . ": " $templatevars['details'] . $c "<br /><br />" $lang["clicktoviewresource"] . "\n$baseurl/?r=$ref".$k;
        if(isset(
$userref))
            {
            
get_config_option($userref,'email_user_notifications'$send_email);    
            if(
$send_email && filter_var($useremailFILTER_VALIDATE_EMAIL))
                {
                
send_mail($useremail,$applicationname ": " $lang["requestsent"] . " - $ref",$userconfirmmessage,$email_from,$email_notify,"emailusercollectionrequest",$templatevars);
                }        
            else
                {               
                
message_add($userref,$userconfirmmessage$templatevars['url']);
                }
            }
        else
            {
            
$sender =  (!empty($useremail)) ? $useremail : ((!empty($templatevars["formemail"]))? $templatevars["formemail"] : "");
            
            if(
$sender!="" && filter_var($senderFILTER_VALIDATE_EMAIL)){send_mail($sender,$applicationname ": " $lang["requestsent"] . " - $ref",$userconfirmmessage,$email_from,$email_notify,"emailuserresourcerequest",$templatevars);}  
            }
        }
    
    
# Increment the request counter
    
sql_query("update resource set request_count=request_count+1 where ref='$ref'");
    }

This article was last updated 10th July 2020 22:05 Europe/London time based on the source file dated 26th June 2020 11:03 Europe/London time.