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