Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

email_collection()

Description

E-mail a collection to users

- Attempt to resolve all users in the string $userlist to user references.
- Add $collection to these user's 'My Collections' page
- Send them an e-mail linking to this collection
- Handle multiple collections (comma seperated list)

Parameters

ColumnTypeDefaultDescription
$colrefs mixed
$collectionname string
$fromusername string
$userlist string
$message string
$feedback string
$access integer -1
$expires string ""
$useremail string ""
$from_name string ""
$cc string ""
$themeshare boolean false
$themename string ""
$themeurlsuffix string ""
$list_recipients boolean false
$add_internal_access boolean false
$group string ""
$sharepwd string ""

Return

void

Location

include/collections_functions.php lines 1375 to 1590

Definition

 
function email_collection($colrefs,$collectionname,$fromusername,$userlist,$message,$feedback,$access=-1,$expires="",$useremail="",$from_name="",$cc="",$themeshare=false,$themename="",$themeurlsuffix="",$list_recipients=false$add_internal_access=false,$group="",$sharepwd="")
    {
    global 
$baseurl,$email_from,$applicationname,$lang,$userref$email_multi_collections,$usergroup,$attach_user_smart_groups;
    if (
$useremail==""){$useremail=$email_from;}
    if (
$group==""){$group=$usergroup;}
    
    if (
trim($userlist)=="") {return ($lang["mustspecifyoneusername"]);}
    
$userlist=resolve_userlist_groups($userlist);
    
    if(
$attach_user_smart_groups && strpos($userlist,$lang["groupsmart"] . ": ")!==false){
        
$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));
    
$emails=array();
    
$key_required=array();
    if (
$feedback) {$feedback=1;} else {$feedback=0;}
    
$reflist=trim_array(explode(",",$colrefs));
    
$emails_keys=resolve_user_emails($ulist);

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

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

    
# Add the collection(s) to the user's My Collections page
    
$urefs=sql_array("select ref value from user where username in ('" join("','",$ulist) . "')");
    if (
count($urefs)>0)
        {
        
# Delete any existing collection entries
        
sql_query("delete from user_collection where collection in ('" .join("','"$reflist) . "') and user in ('" join("','",$urefs) . "')");
        
        
# Insert new user_collection row(s)
        #loop through the collections
        
for ($nx1=0;$nx1<count($reflist);$nx1++)
            {
            
#loop through the users
            
for ($nx2=0;$nx2<count($urefs);$nx2++)
                {
                
sql_query("insert into user_collection(collection,user,request_feedback) values ($reflist[$nx1]$urefs[$nx2]$feedback )");
                if (
$add_internal_access)
                    {        
                    foreach (
get_collection_resources($reflist[$nx1]) as $resource)
                        {
                        if (
get_edit_access($resource))
                            {
                            
open_access_to_user($urefs[$nx2],$resource,$expires);
                            }
                        }
                    }
                
                
#log this
                
collection_log($reflist[$nx1],"S",0sql_value ("select username as value from user where ref = $urefs[$nx2]",""));

                }
            }
        }
    
    
# Send an e-mail to each resolved user
    
    # htmlbreak is for composing list
    
$htmlbreak="\r\n";
    global 
$use_phpmailer;
    if (
$use_phpmailer){$htmlbreak="<br /><br />";$htmlbreaksingle="<br />";} 
    
    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)
    
    
$templatevars['message']=str_replace(array("\\n","\\r","\\"),array("\n","\r",""),$message);    
    if (
trim($templatevars['message'])==""){$templatevars['message']=$lang['nomessage'];} 
    
    
$templatevars['fromusername']=$fromusername;
    
$templatevars['from_name']=$from_name;
    
    if(
count($reflist)>1){$subject=$applicationname.": ".$lang['mycollections'];}
    else { 
$subject=$applicationname.": ".$collectionname;}
    
    if (
$fromusername==""){$fromusername=$applicationname;}
    
    
$externalmessage=$lang["emailcollectionmessageexternal"];
    
$internalmessage=$lang["emailcollectionmessage"];
    
$viewlinktext=$lang["clicklinkviewcollection"];
    if (
$themeshare// Change the text if sharing a theme category
        
{
        
$externalmessage=$lang["emailthemecollectionmessageexternal"];
        
$internalmessage=$lang["emailthememessage"];
        
$viewlinktext=$lang["clicklinkviewcollections"];
        }
        
    
##  loop through recipients
    
for ($nx1=0;$nx1<count($emails);$nx1++)
        {
        
## loop through collections
        
$list="";
        
$list2="";
        
$origviewlinktext=$viewlinktext// Save this text as we may change it for internal theme shares for this user
        
if ($themeshare && !$key_required[$nx1]) # don't send a whole list of collections if internal, just send the theme category URL
            
{
            
$url="";
            
$subject=$applicationname.": " $themename;
            
$url=$baseurl "/pages/themes.php" $themeurlsuffix;            
            
$viewlinktext=$lang["clicklinkviewthemes"];
            
$emailcollectionmessageexternal=false;
            if (
$use_phpmailer){
                    
$link="<a href=\"$url\">" $themename "</a>";    
                    
                    
$list.= $htmlbreak.$link;    
                    
// alternate list style                
                    
$list2.=$htmlbreak.$themename.' -'.$htmlbreaksingle.$url;
                    
$templatevars['list2']=$list2;                    
                    }
                else
                    {
                    
$list.= $htmlbreak.$url;
                    }
            for (
$nx2=0;$nx2<count($reflist);$nx2++)
                {                
                
#log this
                
collection_log($reflist[$nx2],"E",0$emails[$nx1]);
                }
            
            }
        else
            {
            for (
$nx2=0;$nx2<count($reflist);$nx2++)
                {
                
$url="";
                
$key="";
                
$emailcollectionmessageexternal=false;
                
# Do we need to add an external access key for this user (e-mail specified rather than username)?
                
if ($key_required[$nx1])
                    {
                    
$k=generate_collection_access_key($reflist[$nx2],$feedback,$emails[$nx1],$access,$expires,$group,$sharepwd);
                    
$key="&k="$k;
                    
$emailcollectionmessageexternal=true;
                    }
                
$url=$baseurl .     "/?c=" $reflist[$nx2] . $key;        
                
$collection = array();
                
$collection sql_query("select name,savedsearch from collection where ref='$reflist[$nx2]'");
                if (
$collection[0]["name"]!="") {$collection_name i18n_get_collection_name($collection[0]);}
                else {
$collection_name $reflist[$nx2];}
                if (
$use_phpmailer){
                    
$link="<a href=\"$url\">$collection_name</a>";    
                    
$list.= $htmlbreak.$link;    
                    
// alternate list style                
                    
$list2.=$htmlbreak.$collection_name.' -'.$htmlbreaksingle.$url;
                    
$templatevars['list2']=$list2;                    
                    }
                else
                    {
                    
$list.= $htmlbreak $collection_name $htmlbreak $url $htmlbreak;
                    }
                
#log this
                
collection_log($reflist[$nx2],"E",0$emails[$nx1]);
                }
            }
        
//$list.=$htmlbreak;    
        
$templatevars['list']=$list;
        
$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 tempaltevars
            
$templatevars['expires_date']='';
            
$templatevars['expires_days']='';
        }
        if (
$emailcollectionmessageexternal ){
            
$template=($themeshare)?"emailthemeexternal":"emailcollectionexternal";
        }
        else {
            
$template=($themeshare)?"emailtheme":"emailcollection";
        }

        if (
is_array($emails) && (count($emails) > 1) && $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 {
         &