Results 1 to 2 of 2

Thread: Non email campaign - Mark as Sent

  1. #1
    JWG
    JWG is offline Sugar Community Member
    Join Date
    Sep 2006
    Posts
    48

    Default Non email campaign - Mark as Sent

    If we create a non-email based Campaign for existing Contacts (rather than Targets) we are unable to automatically log the Campaign activity in the Campaign Log for each Contact that is on the Target List.

    I tried using the “Mark As Sent” button shown on the Campaign / Detail page to update the Campaign Log for Contacts included on the associated Target List. It works fine for Targets but does not update the relevant Contacts.

    Any help greatly appreciated.

  2. #2
    JWG
    JWG is offline Sugar Community Member
    Join Date
    Sep 2006
    Posts
    48

    Default Re: Non email campaign - Mark as Sent

    I have found the relevent code in /modules/Campaigns/utils.php and it looks as if it should be updating the Contacts, but not sure why it isn't.


    PHP Code:

    /**
     * Function creates a campaign_log entry for campaigns processesed using the mail-merge feature. If any entry
     * exist the hit counter is updated. target_tracker_key is used to locate duplicate entries.
     * @param string campaign_id Primary key of the campaign
     * @param array $pl_row A row of data from prospect_lists_prospects table.
     */
    function write_mail_merge_log_entry($campaign_id,$pl_row) {
        
        
    //Update the log entry if it exists.
        
    $update="update campaign_log set hits=hits+1 where campaign_id='$campaign_id' and target_tracker_key='" $pl_row['id'] . "'";
        
    $result=$GLOBALS['db']->query($update);
        
        
    //get affected row count...
        
    if ($GLOBALS['db']->dbType=='oci8')
            
    $count=$GLOBALS['db']->getRowCount($result);
        else {
            
    $count=$GLOBALS['db']->getAffectedRowCount($result);
        }
        if (
    $count==0) {
            
    $data=array();
            
            
    $data['id']="'" create_guid() . "'";
            
    $data['campaign_id']="'" $campaign_id "'";
            
    $data['target_tracker_key']="'" $pl_row['id'] . "'";
            
    $data['target_id']="'" .  $pl_row['related_id'] . "'";
            
    $data['target_type']="'" .  $pl_row['related_type'] . "'";
            
    $data['activity_type']="'targeted'";
            
    $data['activity_date']="'" gmdate("Y-m-d H:i:s") . "'";
            
    $data['list_id']="'" .  $pl_row['prospect_list_id'] . "'";
            
    $data['hits']=1;
            
            
    $insert_query="INSERT into campaign_log (" implode(",",array_keys($data)) . ")"
            
    $insert_query.=" VALUES  (" implode(",",array_values($data)) . ")"
            
    $GLOBALS['db']->query($insert_query);       
        }
    }     

        function 
    track_campaign_prospects($focus){
            global 
    $mod_strings;
            
             
    //load target list relationships
            
    $focus->load_relationship('prospectlists');
            
    $target_lists $focus->prospectlists->get();
            
    $prospect_lists = array();
            require_once(
    'modules/ProspectLists/ProspectList.php');       

            
    //retrieve the default target list if it exists
            
    foreach($target_lists as $list){
                 
    //create subscription list     
                 
    $p_list = new ProspectList();
                 
    $p_list->retrieve($list);
                 if(
    $p_list->list_type == 'default'){
                    
    $prospect_lists[] = $p_list;
                 }
            }
            
    //list does not exist, send back error message
            
    if(count($prospect_lists) == 0){
                return 
    $mod_strings['LBL_DEFAULT_LIST_NOT_FOUND'];
            }
            
            
    //iterate through each Prospect list and make sure entries exist.
            
    $entry_count =0;
            foreach(
    $prospect_lists as $default_target_list){
                
    $entry_count $entry_count $default_target_list->get_entry_count();
            }
            
    //if no entries exist, then return error message.
            
    if($entry_count == 0){
                return 
    $mod_strings['LBL_DEFAULT_LIST_ENTRIES_NOT_FOUND'];
            }
            

            
    //iterate through each member of list and enter campaign log
            
    foreach($prospect_lists as $default_target_list){
                
    //process targets/prospects          
                
    require_once('modules/Prospects/Prospect.php');
                
    $rel_bean = new Prospect();
                
    create_campaign_log_entry($focus->id$default_target_list'prospects'$rel_bean);
        
                
    //process users          
                
    require_once('modules/Users/User.php');
                
    $rel_bean = new User();
                
    create_campaign_log_entry($focus->id$default_target_list'users'$rel_bean);
        
                
    //process contacts          
                
    require_once('modules/Contacts/Contact.php');
                
    $rel_bean = new Contact();
                
    create_campaign_log_entry($focus->id$default_target_list'contacts'$rel_bean);
        
                
    //process leads          
                
    require_once('modules/Leads/Lead.php');
                
    $rel_bean = new Lead();
                
    create_campaign_log_entry($focus->id$default_target_list'leads'$rel_bean);
                
            }
            
            
            
            
            
    //return success message   
            
    return $mod_strings['LBL_DEFAULT_LIST_ENTRIES_WERE_PROCESSED'];
            
        }
        
        function 
    create_campaign_log_entry($campaign_id$focus$rel_name$rel_bean$target_id ''){
            global 
    $timedate;
            
    $target_ids = array();

            
    //check if this is specified for one target/contact/prospect/lead (from contact/lead detail subpanel)
            
    if(!empty($target_id)){
                
    $target_ids[] = $target_id;
            }else{
                
    //this is specified for all, so load target/prospect relationships (mark as sent button)
                
    $focus->load_relationship($rel_name);
                
    $target_ids $focus->$rel_name->get();
            
            }
            if(
    count($target_ids)>0){
                require_once(
    'modules/CampaignLog/CampaignLog.php');
              
                
    //retrieve the target beans and create campaign log entry
                
    foreach($target_ids as $id){
                     
    //perform duplicate check
                     
    $dup_query "select id from campaign_log where campaign_id = '$campaign_id' and target_id = '$id'";
                     
    $dup_result $focus->db->query($dup_query);
                     
    $row $focus->db->fetchByAssoc($dup_result);

                    
    //process if this is not a duplicate campaign log entry
                    
    if(empty($row)){
                        
    //create campaign tracker id and retrieve related bio bean                 
                         
    $tracker_id create_guid();     
                         
    $rel_bean->retrieve($id);
        
                        
    //create new campaign log record.
                        
    $campaign_log = new CampaignLog();
                        
    $campaign_log->campaign_id $campaign_id;
                        
    $campaign_log->target_tracker_key $tracker_id;
                        
    $campaign_log->target_id $rel_bean->id;
                        
    $campaign_log->target_type $rel_bean->module_dir;
                        
    $campaign_log->activity_type 'targeted';
                        
    $campaign_log->activity_date=$timedate->to_display_date_time(gmdate("Y-m-d H:i:s"));                    
                        
    //save the campaign log entry
                        
    $campaign_log->save();
                    }
                }    
            }
        
        } 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. HOW-TO guide for Email Campaigns.
    By agupta in forum Marketing/Campaign Management
    Replies: 146
    Last Post: 2012-01-31, 03:08 PM
  2. Email Template for Campaign
    By khinester in forum Marketing/Campaign Management
    Replies: 6
    Last Post: 2008-01-14, 04:39 PM
  3. SugarSuite 4.0 - New Campaign management
    By manoj in forum Feature Requests
    Replies: 2
    Last Post: 2007-11-23, 10:13 PM
  4. Non-email campaign management
    By tomv in forum Feature Requests
    Replies: 0
    Last Post: 2006-06-05, 06:13 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •