]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/CampaignLog/CampaignLog.php
Release 6.4.0beta3
[Github/sugarcrm.git] / modules / CampaignLog / CampaignLog.php
1 <?php
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.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 /*********************************************************************************
39
40  * Description:
41  ********************************************************************************/
42
43
44
45
46
47
48
49
50 class CampaignLog extends SugarBean {
51
52     var $table_name = 'campaign_log';
53     var $object_name = 'CampaignLog';
54     var $module_dir = 'CampaignLog';
55
56     var $new_schema = true;
57
58     var $campaign_id;
59     var $target_tracker_key;
60     var $target_id;
61     var $target_type;
62     var $activity_type;
63     var $activity_date;
64     var $related_id;
65     var $related_type;
66     var $deleted;
67     var $list_id;
68     var $hits;
69     var $more_information;
70     var $marketing_id;
71     function CampaignLog() {
72         global $sugar_config;
73         parent::SugarBean();
74
75     }
76
77     function get_list_view_data(){
78         global $locale;
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");
84             $emptyArr = array();
85             return $emptyArr;
86         }
87
88         $table = strtolower($temp_array['TARGET_TYPE']);
89
90         if ( ( $this->db->dbType == 'mysql' ) or ( $this->db->dbType == 'oci8' ) )
91         {
92             $query="select first_name, last_name, CONCAT(CONCAT(first_name, ' '), last_name) name from ".strtolower($temp_array['TARGET_TYPE']) .  " where id ='{$temp_array['TARGET_ID']}'";
93         }
94         if($this->db->dbType == 'mssql')
95         {
96             $query="select first_name, last_name, (first_name + ' ' + last_name) name from ".strtolower($temp_array['TARGET_TYPE']) .  " where id ='{$temp_array['TARGET_ID']}'";
97         }
98
99         if($temp_array['TARGET_TYPE']=='Accounts'){
100             $query = "select name from $table where id = ".$this->db->quoted($temp_array['TARGET_ID']);
101         }else{
102             $query = "select first_name, last_name, ".$this->db->concat($table, array('first_name', 'last_name'))." name from $table" .
103                 " where id = ".$this->db->quoted($temp_array['TARGET_ID']);
104         }
105         $result=$this->db->query($query);
106         $row=$this->db->fetchByAssoc($result);
107
108         if ($row) {
109             if($temp_array['TARGET_TYPE']=='Accounts'){
110                 $temp_array['RECIPIENT_NAME']=$row['name'];
111             }else{
112                 $full_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name'], '');
113                 $temp_array['RECIPIENT_NAME']=$full_name;
114             }
115         }
116         $temp_array['RECIPIENT_EMAIL']=$this->retrieve_email_address($temp_array['TARGET_ID']);
117
118         $query = 'select name from email_marketing where id = \'' . $temp_array['MARKETING_ID'] . '\'';
119         $result=$this->db->query($query);
120         $row=$this->db->fetchByAssoc($result);
121
122         if ($row)
123         {
124                 $temp_array['MARKETING_NAME'] = $row['name'];
125         }
126
127         return $temp_array;
128     }
129
130     function retrieve_email_address($trgt_id = ''){
131         $return_str = '';
132         if(!empty($trgt_id)){
133             $qry  = " select eabr.primary_address, ea.email_address";
134             $qry .= " from email_addresses ea ";
135             $qry .= " Left Join email_addr_bean_rel eabr on eabr.email_address_id = ea.id ";
136             $qry .= " where eabr.bean_id = '{$trgt_id}' ";
137             $qry .= " and ea.deleted = 0 ";
138             $qry .= " and eabr.deleted = 0" ;
139             $qry .= " order by primary_address desc ";
140
141             $result=$this->db->query($qry);
142             $row=$this->db->fetchByAssoc($result);
143
144             if (!empty($row['email_address'])){
145                 $return_str = $row['email_address'];
146             }
147         }
148         return $return_str;
149     }
150
151
152
153
154     //this function is called statically by the campaing_log subpanel.
155     function get_related_name($related_id, $related_type) {
156         global $locale;
157         $db= DBManagerFactory::getInstance();
158         if ($related_type == 'Emails') {
159             $query="SELECT name from emails where id='$related_id'";
160             $result=$db->query($query);
161             $row=$db->fetchByAssoc($result);
162             if ($row != null) {
163                 return $row['name'];
164             }
165         }
166         if ($related_type == 'Contacts') {
167             $query="SELECT first_name, last_name from contacts where id='$related_id'";
168             $result=$db->query($query);
169             $row=$db->fetchByAssoc($result);
170             if ($row != null) {
171                 return $full_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
172             }
173         }
174         if ($related_type == 'Leads') {
175             $query="SELECT first_name, last_name from leads where id='$related_id'";
176             $result=$db->query($query);
177             $row=$db->fetchByAssoc($result);
178             if ($row != null) {
179                 return $full_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
180             }
181         }
182         if ($related_type == 'Prospects') {
183             $query="SELECT first_name, last_name from prospects where id='$related_id'";
184             $result=$db->query($query);
185             $row=$db->fetchByAssoc($result);
186             if ($row != null) {
187                 return $full_name = $locale->getLocaleFormattedName($row['first_name'], $row['last_name']);
188             }
189         }
190         if ($related_type == 'CampaignTrackers') {
191             $query="SELECT tracker_url from campaign_trkrs where id='$related_id'";
192             $result=$db->query($query);
193             $row=$db->fetchByAssoc($result);
194             if ($row != null) {
195                 return $row['tracker_url'] ;
196             }
197         }
198         if ($related_type == 'Accounts') {
199             $query="SELECT name from accounts where id='$related_id'";
200             $result=$db->query($query);
201             $row=$db->fetchByAssoc($result);
202             if ($row != null) {
203                 return $row['name'];
204             }
205         }
206                 return $related_id.$related_type;
207         }
208 }
209
210 ?>