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