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()

Parameters

ColumnTypeDefaultDescription
$resource
$resourcename
$fromusername
$userlist
$message
$access -1
$expires ""
$sharepwd ""
$useremail ""
$from_name ""
$cc ""
$list_recipients false
$open_internal_access false
$useraccess 2
$group ""

Location

include/resource_functions.php lines 3052 to 3193

Definition

 
function email_resource($resource,$resourcename,$fromusername,$userlist,$message,$access=-1,$expires="",$sharepwd "",$useremail="",$from_name="",$cc="",$list_recipients=false$open_internal_access=false$useraccess=2,$group="")
    {
    
# Attempt to resolve all users in the string $userlist to user references.

    
global $baseurl,$email_from,$applicationname,$lang,$userref,$usergroup;

    if (
$useremail==""){$useremail=$email_from;}
    if (
$group=="") {$group=$usergroup;}

    
# remove any line breaks that may have been entered
    
$userlist=str_replace("\\r\\n",",",$userlist);

    if (
trim($userlist)=="") {return $lang["mustspecifyoneusername"];}
    
$userlist=resolve_userlist_groups($userlist);
    if(
strpos($userlist,$lang["groupsmart"] . ": ")!==false)
        {
        
$userlist_with_groups=$userlist;
        
$groups_users=resolve_userlist_groups_smart($userlist,true);
        if(
$groups_users!='')
            {
            if(
$userlist!="")
                {
                
$userlist=remove_groups_smart_from_userlist($userlist);
                if(
$userlist!="")
                    {
                    
$userlist.=",";
                    }
                }
            
$userlist.=$groups_users;
            }
        }

    
$ulist=trim_array(explode(",",$userlist));
    
$ulist=array_filter($ulist);
    
$ulist=array_values($ulist);

    
$ulist=trim_array(explode(",",$userlist));
    
$ulist=array_filter($ulist);
    
$ulist=array_values($ulist);

    
$emails=array();
    
$key_required=array();

    
$emails_keys resolve_user_emails($ulist);

    if(
=== count($emails_keys))
        {
        return 
$lang['email_error_user_list_not_valid'];
        }

    
$unames       $emails_keys['unames'];
    
$emails       $emails_keys['emails'];
    
$key_required $emails_keys['key_required'];

    
# Send an e-mail to each resolved user / e-mail address
    
$subject="$applicationname$resourcename";
    if (
$fromusername==""){$fromusername=$applicationname;} // fromusername is used for describing the sender's name inside the email
    
if ($from_name==""){$from_name=$applicationname;} // from_name is for the email headers, and needs to match the email address (app name or user name)

    
$message=str_replace(array("\\n","\\r","\\"),array("\n","\r",""),$message);

    
$resolve_open_access=false;

    for (
$n=0;$n<count($emails);$n++)
        {
        
$key="";
        
# Do we need to add an external access key for this user (e-mail specified rather than username)?
        
if ($key_required[$n])
            {
            
$k=generate_resource_access_key($resource,$userref,$access,$expires,$emails[$n],$group$sharepwd);
            
$key="&k="$k;
            }
        elseif (
$useraccess==&& $open_internal_access && !$resolve_open_access)
            {
debug("smart_groups: going to resolve open access");
            
# get this all done at once
            
resolve_open_access((isset($userlist_with_groups)?$userlist_with_groups:$userlist),$resource,$expires);
            
$resolve_open_access=true;
            }

        
# make vars available to template
        
global $watermark;
        
$templatevars['thumbnail']=get_resource_path($resource,true,"thm",false,"jpg",-1,1,($watermark)?(($access==1)?true:false):false);
        if (!
file_exists($templatevars['thumbnail'])){
            
$resourcedata=get_resource_data($resource);
            
$templatevars['thumbnail']="../gfx/no_preview/default.png";
        }
        
$templatevars['url']=$baseurl "/?r=" $resource $key;
        
$templatevars['fromusername']=$fromusername;
        
$templatevars['message']=$message;
        
$templatevars['resourcename']=$resourcename;
        
$templatevars['from_name']=$from_name;
        if(isset(
$k))
            {
            if(
$expires=="")
                {
                
$templatevars['expires_date']=$lang["email_link_expires_never"];
                
$templatevars['expires_days']=$lang["email_link_expires_never"];
                }
            else
                {
                
$day_count=round((strtotime($expires)-strtotime('now'))/(60*60*24));
                
$templatevars['expires_date']=$lang['email_link_expires_date'].nicedate($expires);
                
$templatevars['expires_days']=$lang['email_link_expires_days'].$day_count;
                if(
$day_count>1)
                    {
                    
$templatevars['expires_days'].=" ".$lang['expire_days'].".";
                    }
                else
                    {
                    
$templatevars['expires_days'].=" ".$lang['expire_day'].".";
                    }
                }
            }
        else
            {
            
# Set empty expiration templatevars
            
$templatevars['expires_date']='';
            
$templatevars['expires_days']='';
            }

        
# Build message and send.
        
if (count($emails) > && $list_recipients===true)
            {
            
$body $lang["list-recipients"] ."\n"implode("\n",$emails) ."\n\n";
            
$templatevars['list-recipients']=$lang["list-recipients"] ."\n"implode("\n",$emails) ."\n\n";
            }
        else
            {
            
$body "";
            }

        
$body.=$templatevars['fromusername']." "$lang["hasemailedyouaresource"]."\n\n" $templatevars['message']."\n\n" $lang["clicktoviewresource"] . "\n\n" $templatevars['url'];
        
$send_result=send_mail($emails[$n],$subject,$body,$fromusername,$useremail,"emailresource",$templatevars,$from_name,$cc);
        if (
$send_result!==true) {return $send_result;}

        
# log this
        
resource_log($resource,LOG_CODE_EMAILED,"",$unames[$n]);
        }
    
hook("additional_email_resource","",array($resource,$resourcename,$fromusername,$userlist,$message,$access,$expires,$useremail,$from_name,$cc,$templatevars));
    
# Return an empty string (all OK).
    
return "";
    }

This article was last updated 17th November 2024 15:05 Europe/London time based on the source file dated 15th November 2024 18:30 Europe/London time.