Collections functions
General functions
Render 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 1939 to 2219

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,$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));
    
// Take out the FC category from the list as this is more of a dummy record rather than a collection we'll be giving
    // access to users. See generate_collection_access_key() when collection is a featured collection category.
    
$fc_category_ref = ($themeshare array_shift($reflist) : null);

    
$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'];
    
$internal_user_ids $emails_keys['refs'];

    
# Add the collection(s) to the user's My Collections page
    
$urefs=ps_array("SELECT ref value FROM user WHERE username IN ("  ps_param_insert(count($ulist)) . ")",ps_param_fill($ulist,"i"));
    if (
count($urefs)>0)
        {
        
# Delete any existing collection entries
        
ps_query("DELETE FROM user_collection WHERE collection IN (" ps_param_insert(count($reflist)) . ") AND user IN (" ps_param_insert(count($urefs)) . ")",array_merge(ps_param_fill($reflist,"i"),ps_param_fill($urefs,"i")));
        
        
# 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++)
                {
                
ps_query("INSERT INTO user_collection(collection,user,request_feedback) VALUES (?,?,?)",["i",$reflist[$nx1],"i",$urefs[$nx2],"i",$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],LOG_CODE_COLLECTION_SHARED_COLLECTION,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'];
        
$message "lang_nomessage";
        } 

    
$templatevars['fromusername']=$fromusername;
    
$templatevars['from_name']=$from_name;

    
// Create notification message
    
$notifymessage     = new ResourceSpaceUserNotification();
    if(
count($reflist)>1)
        {
        
$notifymessage->set_subject($applicationname ": ");
        
$notifymessage->append_subject("lang_mycollections");
        }
    else
        {
        
$notifymessage->set_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
    
$themeurl "";
    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
            
{
            
$notifymessage->set_subject($applicationname.": " $themename);
            
$url $baseurl "/pages/collections_featured.php" $themeurlsuffix;
            
$viewlinktext="lang_clicklinkviewthemes";
            
$notifymessage->url $url;
            
$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],LOG_CODE_COLLECTION_EMAILED_COLLECTION,0$emails[$nx1]);
                }
            }
        else
            {
            
// E-mail external share, generate the access key based on the FC category. Each sub-collection will have the same key.
            
if($key_required[$nx1] && $themeshare && !is_null($fc_category_ref))
                {
                
$k generate_collection_access_key($fc_category_ref$feedback$emails[$nx1], $access$expires$group$sharepwd$reflist);
                
$fc_key "&k={$k}";
                }

            for (
$nx2=0;$nx2<count($reflist);$nx2++)
                {
                
$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] && !$themeshare)
                    {
                    
$k=generate_collection_access_key($reflist[$nx2],$feedback,$emails[$nx1],$access,$expires,$group,$sharepwd);
                    
$key="&k="$k;
                    
$emailcollectionmessageexternal=true;
                    }
                
// If FC category, the key is valid across all sub-featured collections. See generate_collection_access_key()
                
else if($key_required[$nx1] && $themeshare && !is_null($fc_category_ref))
                    {
                    
$key $fc_key;
                    
$emailcollectionmessageexternal true;
                    }
                
$url $baseurl .     "/?c=" $reflist[$nx2] . $key;
                
$collection = array();
                
$collection ps_query("SELECT name,savedsearch FROM collection WHERE ref = ?", ["i",$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],LOG_CODE_COLLECTION_EMAILED_COLLECTION,0$emails[$nx1]);
                }
            }    
        
$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"];
                }
         &n