]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/Schedule.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Campaigns / Schedule.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-2012 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  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45  
46
47
48
49
50
51
52     $test=false;
53 //account for case when called from marketing wizard
54 if(isset($_REQUEST['return_action']) && $_REQUEST['return_action'] == 'WizardMarketing'){
55     $_POST['return_module'] = $_REQUEST['return_module'];
56     $_POST['return_action'] = 'TrackDetailView';
57     $_POST['record'] = $_REQUEST['record'];    
58 }
59
60
61 if (isset($_REQUEST['mode']) && $_REQUEST['mode'] == 'test') {
62     $test=true;
63     $_POST['mode'] = 'test';
64 }
65
66
67 global $app_strings;
68 global $app_list_strings;
69 global $current_language;
70 global $current_user;
71 global $urlPrefix;
72 global $currentModule;
73
74 $current_module_strings = return_module_language($current_language, 'EmailMarketing');
75 if ($test)  {
76         echo getClassicModuleTitle('Campaigns', array($current_module_strings['LBL_MODULE_SEND_TEST']), false);
77 } else {
78         echo getClassicModuleTitle('Campaigns', array($current_module_strings['LBL_MODULE_SEND_EMAILS']), false);
79 }
80
81 $campaign_id = isset($_REQUEST['record']) ? $_REQUEST['record'] : false;
82
83 if (!empty($campaign_id)) {
84         $campaign = new Campaign();
85         $campaign->retrieve($campaign_id);
86 }
87
88 if ($campaign_id && isset($campaign) && $campaign->status == 'Inactive') {
89         $ss = new Sugar_Smarty();
90         $ss->assign('campaignName', $campaign->name);
91         $ss->display('modules/Campaigns/tpls/campaign-inactive.tpl');
92 } else {
93         $focus = new EmailMarketing();
94         if($campaign_id)
95         {
96                 $where_clauses = Array();
97
98                 if(!empty($campaign_id)) array_push($where_clauses, "campaign_id = '".$GLOBALS['db']->quote($campaign_id)."'");
99
100                 $where = "";
101                 foreach($where_clauses as $clause)
102                 {
103                         if($where != "")
104                         $where .= " and ";
105                         $where .= $clause;
106                 }
107
108                 $GLOBALS['log']->info("Here is the where clause for the list view: $where");
109         }
110
111         $ListView = new ListView();
112         $ListView->initNewXTemplate('modules/Campaigns/Schedule.html',$current_module_strings);
113
114         if ($test)  {
115                 $ListView->xTemplateAssign("SCHEDULE_MESSAGE_HEADER",$current_module_strings['LBL_SCHEDULE_MESSAGE_TEST']);
116         } else {
117                 $ListView->xTemplateAssign("SCHEDULE_MESSAGE_HEADER",$current_module_strings['LBL_SCHEDULE_MESSAGE_EMAILS']);
118         }
119
120         //force multi-select popup
121         $ListView->process_for_popups=true;
122         $ListView->multi_select_popup=true;
123         //end
124         $ListView->mergeduplicates = false;
125         $ListView->show_export_button = false;
126         $ListView->show_select_menu = false;
127         $ListView->show_delete_button = false;
128         $ListView->setDisplayHeaderAndFooter(false);
129         $ListView->xTemplateAssign("RETURN_MODULE",$_POST['return_module']);
130         $ListView->xTemplateAssign("RETURN_ACTION",$_POST['return_action']);
131         $ListView->xTemplateAssign("RETURN_ID",$_POST['record']);
132         $ListView->setHeaderTitle($current_module_strings['LBL_LIST_FORM_TITLE']);
133         $ListView->setQuery($where, "", "name", "EMAILMARKETING");
134
135         if ($test) {
136                         $ListView->xTemplateAssign("MODE",$_POST['mode']);
137                         //finds all marketing messages that have an association with prospect list of the test.
138                         //this query can be siplified using sub-selects.
139                         $query="select distinct email_marketing.id email_marketing_id from email_marketing ";
140                         $query.=" inner join email_marketing_prospect_lists empl on empl.email_marketing_id = email_marketing.id ";
141                         $query.=" inner join prospect_lists on prospect_lists.id = empl.prospect_list_id ";
142                         $query.=" inner join prospect_list_campaigns plc on plc.prospect_list_id = empl.prospect_list_id ";
143                         $query.=" where empl.deleted=0  ";
144                         $query.=" and prospect_lists.deleted=0 ";
145                         $query.=" and prospect_lists.list_type='test' ";
146                         $query.=" and plc.deleted=0 ";
147                         $query.=" and plc.campaign_id='$campaign_id'";
148                         $query.=" and email_marketing.campaign_id='$campaign_id'";
149                         $query.=" and email_marketing.deleted=0 ";
150                         $query.=" and email_marketing.all_prospect_lists=0 ";
151
152                         $seed=array();
153
154                         $result=$focus->db->query($query);
155                         while(($row=$focus->db->fetchByAssoc($result)) != null) {
156
157                                 $bean = new EmailMarketing();
158                                 $bean->retrieve($row['email_marketing_id']);
159                                 $bean->mode='test';     
160                                 $seed[]=$bean;
161                         }
162                         $query=" select email_marketing.id email_marketing_id from email_marketing ";
163                         $query.=" WHERE email_marketing.campaign_id='$campaign_id'";
164                         $query.=" and email_marketing.deleted=0 ";
165                         $query.=" and email_marketing.all_prospect_lists=1 ";
166
167                         $result=$focus->db->query($query);
168                         while(($row=$focus->db->fetchByAssoc($result)) != null) {
169
170                                 $bean = new EmailMarketing();
171                                 $bean->retrieve($row['email_marketing_id']);
172                                 $bean->mode='test';     
173                                 $seed[]=$bean;
174                         }
175
176                         $ListView->processListView($seed, "main", "EMAILMARKETING");
177         } else {
178                 $ListView->processListView($focus, "main", "EMAILMARKETING");
179         }
180 }
181 ?>