]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/EmailMarketing/EmailMarketing.php
Release 6.2.0
[Github/sugarcrm.git] / modules / EmailMarketing / EmailMarketing.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 EmailMarketing extends SugarBean {
51
52         var $field_name_map;
53         
54         var $id;
55         var $deleted;
56         var $date_entered;
57         var $date_modified;
58         var $modified_user_id;
59         var $created_by;
60         var $name;
61         var $from_addr;
62         var $from_name;
63         var $reply_to_name;
64         var $reply_to_addr;
65         var $date_start;
66         var $time_start;
67         var $template_id;
68         var $campaign_id;
69         var $all_prospect_lists;
70         var $status;
71         var $inbound_email_id;
72         
73         var $table_name = 'email_marketing';
74         var $object_name = 'EmailMarketing';
75         var $module_dir = 'EmailMarketing';
76         
77         var $new_schema = true;
78
79         function EmailMarketing()
80         {
81                 parent::SugarBean();
82
83
84
85         }
86         
87         function retrieve($id) {
88             parent::retrieve($id);      
89         
90         global $timedate;
91         $date_start_array=explode(" ",trim($this->date_start));
92         if (count($date_start_array)==2) {
93                         $this->time_start = $date_start_array[1];
94                 $this->date_start = $date_start_array[0];
95         }
96         return $this;
97         }
98         
99         function get_summary_text()
100         {
101                 return $this->name;
102         }
103         
104         function create_export_query($order_by, $where)
105         {
106                 return $this->create_new_list_query($order_by, $where);
107         }       
108         
109         function get_list_view_data(){
110
111                 $temp_array = $this->get_list_view_array();
112                 
113                 $id = $temp_array['ID'];
114                 $template_id = $temp_array['TEMPLATE_ID'];
115                 
116                 //mode is set by schedule.php from campaigns module.
117                 if (!isset($this->mode) or empty($this->mode) or $this->mode!='test') {
118                         $this->mode='rest';
119                 }
120                 
121                 if ($temp_array['ALL_PROSPECT_LISTS']==1) {
122                         $query="SELECT name from prospect_lists ";
123                         $query.=" INNER JOIN prospect_list_campaigns plc ON plc.prospect_list_id = prospect_lists.id";
124                         $query.=" WHERE plc.campaign_id='{$temp_array['CAMPAIGN_ID']}'"; 
125                         $query.=" AND prospect_lists.deleted=0";
126                         $query.=" AND plc.deleted=0";
127                         if ($this->mode=='test') {
128                                 $query.=" AND prospect_lists.list_type='test'";                 
129                         } else {
130                                 $query.=" AND prospect_lists.list_type!='test'";                        
131                         }
132                 } else {
133                         $query="SELECT name from prospect_lists ";
134                         $query.=" INNER JOIN email_marketing_prospect_lists empl ON empl.prospect_list_id = prospect_lists.id";
135                         $query.=" WHERE empl.email_marketing_id='{$id}'"; 
136                         $query.=" AND prospect_lists.deleted=0";
137                         $query.=" AND empl.deleted=0";
138                         if ($this->mode=='test') {
139                                 $query.=" AND prospect_lists.list_type='test'";                 
140                         } else {
141                                 $query.=" AND prospect_lists.list_type!='test'";                        
142                         }
143                 }
144                 $res = $this->db->query($query);
145                 while (($row = $this->db->fetchByAssoc($res)) != null) {
146                         if (!empty($temp_array['PROSPECT_LIST_NAME'])) {
147                                 $temp_array['PROSPECT_LIST_NAME'].="<BR>";
148                         }
149                         $temp_array['PROSPECT_LIST_NAME'].=$row['name'];
150                 }
151                 return $temp_array;
152         }       
153
154         function bean_implements($interface){
155                 switch($interface){
156                         case 'ACL':return true;
157                 }
158                 return false;
159         }
160
161         function get_all_prospect_lists() {
162                 
163                 $query="select prospect_lists.* from prospect_lists ";
164                 $query.=" left join prospect_list_campaigns on prospect_list_campaigns.prospect_list_id=prospect_lists.id";
165                 $query.=" where prospect_list_campaigns.deleted=0";
166                 $query.=" and prospect_list_campaigns.campaign_id='$this->campaign_id'";
167                 $query.=" and prospect_lists.deleted=0";
168                 $query.=" and prospect_lists.list_type not like 'exempt%'";
169                 
170                 return $query;
171         }
172 }
173 ?>