2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
41 ********************************************************************************/
50 class CampaignLog extends SugarBean {
52 var $table_name = 'campaign_log';
53 var $object_name = 'CampaignLog';
54 var $module_dir = 'CampaignLog';
56 var $new_schema = true;
59 var $target_tracker_key;
69 var $more_information;
71 function CampaignLog() {
77 function get_list_view_data(){
79 $temp_array = $this->get_list_view_array();
80 //make sure that both items in array are set to some value, else return null
81 if(!(isset($temp_array['TARGET_TYPE']) && $temp_array['TARGET_TYPE']!= '') || !(isset($temp_array['TARGET_ID']) && $temp_array['TARGET_ID']!= ''))
82 { //needed values to construct query are empty/null, so return null
83 $GLOBALS['log']->debug("CampaignLog.php:get_list_view_data duntion: temp_array['TARGET_TYPE'] and/or temp_array['TARGET_ID'] are empty, return null");
87 if ( ( $this->db->dbType == 'mysql' ) or ( $this->db->dbType == 'oci8' ) )
89 $query="select first_name, last_name, CONCAT(CONCAT(first_name, ' '), last_name) name, date_modified from ".strtolower($temp_array['TARGET_TYPE']) . " where id ='{$temp_array['TARGET_ID']}'";
91 if($this->db->dbType == 'mssql')
93 $query="select first_name, last_name, (first_name + ' ' + last_name) name, date_modified from ".strtolower($temp_array['TARGET_TYPE']) . " where id ='{$temp_array['TARGET_ID']}'";
95 if($temp_array['TARGET_TYPE']=='Accounts'){
96 $query="select name from ".strtolower($temp_array['TARGET_TYPE']) . " where id ='{$temp_array['TARGET_ID']}'";
99 $result=$this->db->query($query);
100 $row=$this->db->fetchByAssoc($result);
103 if($temp_array['TARGET_TYPE']=='Accounts'){
104 $temp_array['RECIPIENT_NAME']=$row['name'];
106 $full_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name'], '');
107 $temp_array['RECIPIENT_NAME']=$full_name;
108 $temp_array['ACTIVITY_DATE'] = $row['date_modified'];
111 $temp_array['RECIPIENT_EMAIL']=$this->retrieve_email_address($temp_array['TARGET_ID']);
113 $query = 'select name from email_marketing where id = \'' . $temp_array['MARKETING_ID'] . '\'';
114 $result=$this->db->query($query);
115 $row=$this->db->fetchByAssoc($result);
119 $temp_array['MARKETING_NAME'] = $row['name'];
125 function retrieve_email_address($trgt_id = ''){
127 if(!empty($trgt_id)){
128 $qry = " select eabr.primary_address, ea.email_address";
129 $qry .= " from email_addresses ea ";
130 $qry .= " Left Join email_addr_bean_rel eabr on eabr.email_address_id = ea.id ";
131 $qry .= " where eabr.bean_id = '{$trgt_id}' ";
132 $qry .= " and ea.deleted = 0 ";
133 $qry .= " and eabr.deleted = 0" ;
134 $qry .= " order by primary_address desc ";
136 $result=$this->db->query($qry);
137 $row=$this->db->fetchByAssoc($result);
139 if (!empty($row['email_address'])){
140 $return_str = $row['email_address'];
149 //this function is called statically by the campaing_log subpanel.
150 function get_related_name($related_id, $related_type) {
152 $db= DBManagerFactory::getInstance();
153 if ($related_type == 'Emails') {
154 $query="SELECT name from emails where id='$related_id'";
155 $result=$db->query($query);
156 $row=$db->fetchByAssoc($result);
161 if ($related_type == 'Contacts') {
162 $query="SELECT first_name, last_name from contacts where id='$related_id'";
163 $result=$db->query($query);
164 $row=$db->fetchByAssoc($result);
166 return $full_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
169 if ($related_type == 'Leads') {
170 $query="SELECT first_name, last_name from leads where id='$related_id'";
171 $result=$db->query($query);
172 $row=$db->fetchByAssoc($result);
174 return $full_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
177 if ($related_type == 'Prospects') {
178 $query="SELECT first_name, last_name from prospects where id='$related_id'";
179 $result=$db->query($query);
180 $row=$db->fetchByAssoc($result);
182 return $full_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
185 if ($related_type == 'CampaignTrackers') {
186 $query="SELECT tracker_url from campaign_trkrs where id='$related_id'";
187 $result=$db->query($query);
188 $row=$db->fetchByAssoc($result);
190 return $row['tracker_url'] ;
193 if ($related_type == 'Accounts') {
194 $query="SELECT name from accounts where id='$related_id'";
195 $result=$db->query($query);
196 $row=$db->fetchByAssoc($result);
201 return $related_id.$related_type;