]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/Schedule.php
Release 6.5.16
[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-2013 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
91     $data = array($campaign->name);
92     $ss->assign('campaignInactive', string_format(translate('LBL_CAMPAIGN_INACTIVE_SCHEDULE', 'Campaigns'), $data));
93
94         $ss->display('modules/Campaigns/tpls/campaign-inactive.tpl');
95 } else {
96         $focus = new EmailMarketing();
97         if($campaign_id)
98         {
99                 $where_clauses = Array();
100
101                 if(!empty($campaign_id)) array_push($where_clauses, "campaign_id = '".$GLOBALS['db']->quote($campaign_id)."'");
102
103                 $where = "";
104                 foreach($where_clauses as $clause)
105                 {
106                         if($where != "")
107                         $where .= " and ";
108                         $where .= $clause;
109                 }
110
111                 $GLOBALS['log']->info("Here is the where clause for the list view: $where");
112         }
113
114         $ListView = new ListView();
115         $ListView->initNewXTemplate('modules/Campaigns/Schedule.html',$current_module_strings);
116
117         if ($test)  {
118                 $ListView->xTemplateAssign("SCHEDULE_MESSAGE_HEADER",$current_module_strings['LBL_SCHEDULE_MESSAGE_TEST']);
119         } else {
120                 $ListView->xTemplateAssign("SCHEDULE_MESSAGE_HEADER",$current_module_strings['LBL_SCHEDULE_MESSAGE_EMAILS']);
121         }
122
123         //force multi-select popup
124         $ListView->process_for_popups=true;
125         $ListView->multi_select_popup=true;
126         //end
127         $ListView->mergeduplicates = false;
128         $ListView->show_export_button = false;
129         $ListView->show_select_menu = false;
130         $ListView->show_delete_button = false;
131         $ListView->setDisplayHeaderAndFooter(false);
132         $ListView->xTemplateAssign("RETURN_MODULE",$_POST['return_module']);
133         $ListView->xTemplateAssign("RETURN_ACTION",$_POST['return_action']);
134         $ListView->xTemplateAssign("RETURN_ID",$_POST['record']);
135         $ListView->setHeaderTitle($current_module_strings['LBL_LIST_FORM_TITLE']);
136         $ListView->setQuery($where, "", "date_modified desc", "EMAILMARKETING", false);
137
138         if ($test) {
139                         $ListView->xTemplateAssign("MODE",$_POST['mode']);
140                         //finds all marketing messages that have an association with prospect list of the test.
141                         //this query can be siplified using sub-selects.
142                         $query="select distinct email_marketing.id email_marketing_id from email_marketing ";
143                         $query.=" inner join email_marketing_prospect_lists empl on empl.email_marketing_id = email_marketing.id ";
144                         $query.=" inner join prospect_lists on prospect_lists.id = empl.prospect_list_id ";
145                         $query.=" inner join prospect_list_campaigns plc on plc.prospect_list_id = empl.prospect_list_id ";
146                         $query.=" where empl.deleted=0  ";
147                         $query.=" and prospect_lists.deleted=0 ";
148                         $query.=" and prospect_lists.list_type='test' ";
149                         $query.=" and plc.deleted=0 ";
150                         $query.=" and plc.campaign_id='$campaign_id'";
151                         $query.=" and email_marketing.campaign_id='$campaign_id'";
152                         $query.=" and email_marketing.deleted=0 ";
153                         $query.=" and email_marketing.all_prospect_lists=0 ";
154
155                         $seed=array();
156
157                         $result=$focus->db->query($query);
158                         while(($row=$focus->db->fetchByAssoc($result)) != null) {
159
160                                 $bean = new EmailMarketing();
161                                 $bean->retrieve($row['email_marketing_id']);
162                                 $bean->mode='test';     
163                                 $seed[]=$bean;
164                         }
165                         $query=" select email_marketing.id email_marketing_id from email_marketing ";
166                         $query.=" WHERE email_marketing.campaign_id='$campaign_id'";
167                         $query.=" and email_marketing.deleted=0 ";
168                         $query.=" and email_marketing.all_prospect_lists=1 ";
169
170                         $result=$focus->db->query($query);
171                         while(($row=$focus->db->fetchByAssoc($result)) != null) {
172
173                                 $bean = new EmailMarketing();
174                                 $bean->retrieve($row['email_marketing_id']);
175                                 $bean->mode='test';     
176                                 $seed[]=$bean;
177                         }
178
179                         $ListView->processListView($seed, "main", "EMAILMARKETING");
180         } else {
181                 $ListView->processListView($focus, "main", "EMAILMARKETING");
182         }
183 }
184 ?>