]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/WizardMarketing.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Campaigns / WizardMarketing.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:  TODO: To be written.
41  * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42  * All Rights Reserved.
43  * Contributor(s): ______________________________________..
44  ********************************************************************************/
45
46 /**************************** general UI Stuff *******************/
47
48
49
50 require_once('modules/Campaigns/utils.php');
51
52
53 global $app_strings;
54 global $timedate;
55 global $app_list_strings;
56 global $mod_strings;
57 global $current_user;
58 global $sugar_version, $sugar_config;
59
60
61 /**************************** GENERAL SETUP WORK*******************/
62 $campaign_focus = new Campaign();
63 if (isset($_REQUEST['campaign_id']) && !empty($_REQUEST['campaign_id'])) {
64     $campaign_focus->retrieve($_REQUEST['campaign_id']);
65 }else{
66     sugar_die($app_strings['ERROR_NO_RECORD']);
67 }
68
69 global $theme;
70
71
72
73 $json = getJSONobj();
74
75 $GLOBALS['log']->info("Wizard Continue Create Wizard");
76  if($campaign_focus->campaign_type=='NewsLetter'){
77     echo getClassicModuleTitle($mod_strings['LBL_MODULE_NAME'], array($mod_strings['LBL_NEWSLETTER WIZARD_TITLE'].' '.$campaign_focus->name), true);
78  }else{
79     echo getClassicModuleTitle($mod_strings['LBL_MODULE_NAME'], array($mod_strings['LBL_CAMPAIGN'].' '.$campaign_focus->name), true);
80  }
81
82 $ss = new Sugar_Smarty();
83 $ss->assign("MOD", $mod_strings);
84 $ss->assign("APP", $app_strings);
85 if (isset($_REQUEST['return_module'])) $ss->assign("RETURN_MODULE", $_REQUEST['return_module']);
86 if (isset($_REQUEST['return_action'])) $ss->assign("RETURN_ACTION", $_REQUEST['return_action']);
87 if (isset($_REQUEST['return_id'])) $ss->assign("RETURN_ID", $_REQUEST['return_id']);
88 // handle Create $module then Cancel
89 $ss->assign('CAMPAIGN_ID', $campaign_focus->id);
90
91 $seps = get_number_seperators();
92 $ss->assign("NUM_GRP_SEP", $seps[0]);
93 $ss->assign("DEC_SEP", $seps[1]);
94
95
96 /**************************** MARKETING UI DIV Stuff *******************/
97 //$campaign_focus->load_relationship('emailmarketing');
98 //$mrkt_ids = $campaign_focus->emailmarketing->get();
99
100 $mrkt_focus = new EmailMarketing();
101
102 //if record param exists and it is not empty, then retrieve this bean
103 if(isset($_REQUEST['record']) and !empty($_REQUEST['record'])){
104     $mrkt_focus->retrieve($_REQUEST['record']);
105 }else{
106         //check to see if this campaign has an email marketing already attached, and if so, create duplicate
107         $campaign_focus->load_relationship('emailmarketing');
108         $mrkt_lists = $campaign_focus->emailmarketing->get();
109         if(!empty($mrkt_lists)){
110             //reverse array so we always use the most recent one:
111             $mrkt_lists = array_reverse($mrkt_lists);
112             $mrkt_focus->retrieve($mrkt_lists[0]);
113             $mrkt_focus->id = '';
114             $mrkt_focus->name = $mod_strings['LBL_COPY_OF'] . ' '. $mrkt_focus->name;
115         }
116
117 }
118
119
120 $ss->assign("CALENDAR_LANG", "en");
121 $ss->assign("USER_DATEFORMAT", '('. $timedate->get_user_date_format().')');
122 $ss->assign("CALENDAR_DATEFORMAT", $timedate->get_cal_date_format());
123 $ss->assign("TIME_MERIDIEM", $timedate->AMPMMenu('', $mrkt_focus->time_start));
124 $ss->assign("MRKT_ID", $mrkt_focus->id);
125 $ss->assign("MRKT_NAME", $mrkt_focus->name);
126 $ss->assign("MRKT_FROM_NAME", $mrkt_focus->from_name);
127 $ss->assign("MRKT_FROM_ADDR", $mrkt_focus->from_addr);
128 $def = $mrkt_focus->getFieldDefinition('from_name');
129 $ss->assign("MRKT_FROM_NAME_LEN", $def['len']);
130
131 //jc: bug 15498
132 // assigning the length of the reply name from the var defs to the template to be used
133 // as the max length for the input field
134 $def = $mrkt_focus->getFieldDefinition('reply_to_name');
135 $ss->assign("MRKT_REPLY_NAME_LEN", $def['len']);
136 $ss->assign("MRKT_REPLY_NAME", $mrkt_focus->reply_to_name);
137 $def = $mrkt_focus->getFieldDefinition('reply_to_addr');
138 $ss->assign("MRKT_REPLY_ADDR_LEN", $def['len']);
139 // end bug 15498
140 $ss->assign("MRKT_REPLY_ADDR", $mrkt_focus->reply_to_addr);
141 $ss->assign("MRKT_DATE_START", $mrkt_focus->date_start);
142 $ss->assign("MRKT_TIME_START", $mrkt_focus->time_start);
143 //$_REQUEST['mass'] = $mrkt_focus->id;
144 $ss->assign("MRKT_ID", $mrkt_focus->id);
145 $emails=array();
146 $mailboxes=get_campaign_mailboxes($emails);
147
148 /*
149  * get full array of stored options
150  */
151 $IEStoredOptions = get_campaign_mailboxes_with_stored_options();
152 $IEStoredOptionsJSON = (!empty($IEStoredOptions)) ? $json->encode($IEStoredOptions, false) : 'new Object()';
153 $ss->assign("IEStoredOptions", $IEStoredOptionsJSON);
154
155 //add empty options.
156 $emails['']='nobody@example.com';
157 $mailboxes['']='';
158
159 //inbound_email_id
160 $default_email_address='nobody@example.com';
161 $from_emails = '';
162 foreach ($mailboxes as $id=>$name) {
163     if (!empty($from_emails)) {
164         $from_emails.=',';
165     }
166     if ($id=='') {
167         $from_emails.="'EMPTY','$name','$emails[$id]'";
168     } else {
169         $from_emails.="'$id','$name','$emails[$id]'";
170     }
171 }
172 $ss->assign("FROM_EMAILS",$from_emails);
173 $ss->assign("DEFAULT_FROM_EMAIL",$default_email_address);
174 $ss->assign("STATUS_OPTIONS", get_select_options_with_id($app_list_strings['email_marketing_status_dom'],$mrkt_focus->status));
175 if (empty($mrkt_focus->inbound_email_id)) {
176     $ss->assign("MAILBOXES", get_select_options_with_id($mailboxes, ''));
177 } else {
178     $ss->assign("MAILBOXES", get_select_options_with_id($mailboxes, $mrkt_focus->inbound_email_id));
179 }
180
181 $ss->assign("TIME_MERIDIEM", $timedate->AMPMMenu('', $mrkt_focus->time_start));
182 $ss->assign("TIME_FORMAT", '('. $timedate->get_user_time_format().')');
183
184 $email_templates_arr = get_bean_select_array(true, 'EmailTemplate','name','','name');
185 if($mrkt_focus->template_id) {
186     $ss->assign("TEMPLATE_ID", $mrkt_focus->template_id);
187     $ss->assign("EMAIL_TEMPLATE_OPTIONS", get_select_options_with_id($email_templates_arr, $mrkt_focus->template_id));
188     $ss->assign("EDIT_TEMPLATE","visibility:inline");
189 }
190 else {
191     $ss->assign("EMAIL_TEMPLATE_OPTIONS", get_select_options_with_id($email_templates_arr, ""));
192     $ss->assign("EDIT_TEMPLATE","visibility:hidden");
193 }
194
195
196 $scope_options=get_message_scope_dom($campaign_focus->id,$campaign_focus->name,$mrkt_focus->db);
197 $prospectlists=array();
198 if (isset($mrkt_focus->all_prospect_lists) && $mrkt_focus->all_prospect_lists==1) {
199     $ss->assign("ALL_PROSPECT_LISTS_CHECKED","checked");
200     $ss->assign("MESSAGE_FOR_DISABLED","disabled");
201 }
202 else {
203     //get select prospect list.
204     if (!empty($mrkt_focus->id)) {
205         $mrkt_focus->load_relationship('prospectlists');
206         $prospectlists=$mrkt_focus->prospectlists->get();
207     };
208 }
209 if (empty($prospectlists)) $prospectlists=array();
210 if (empty($scope_options)) $scope_options=array();
211 $ss->assign("SCOPE_OPTIONS", get_select_options_with_id($scope_options, $prospectlists));
212 $ss->assign("SAVE_CONFIRM_MESSAGE", $mod_strings['LBL_CONFIRM_SEND_SAVE']);
213
214
215
216 $javascript = new javascript();
217 $javascript->setFormName('wizform');
218 $javascript->setSugarBean($mrkt_focus);
219 $javascript->addAllFields('');
220 echo $javascript->getScript();
221
222 /**************************** Final Step UI DIV *******************/
223
224     //Grab the prospect list of type default
225     $default_pl_focus = ' ';
226         $campaign_focus->load_relationship('prospectlists');
227         $prospectlists=$campaign_focus->prospectlists->get();
228
229     
230     $pl_count = 0;
231     $pl_lists = 0;
232     if(!empty($prospectlists)){
233         foreach ($prospectlists as $prospect_id){
234             $pl_focus = new ProspectList();
235             $pl_focus->retrieve($prospect_id);
236
237             if (($pl_focus->list_type == 'default') || ($pl_focus->list_type == 'seed')){
238                 $default_pl_focus= $pl_focus;
239                 // get count of all attached target types
240                 $pl_count = $default_pl_focus->get_entry_count();
241              }
242              $pl_lists = $pl_lists+1;
243         }
244
245
246     }
247     //if count is 0, then hide inputs and and print warning message
248     if ($pl_count==0){
249         if ($pl_lists==0){
250             //print no target list warning
251             $ss->assign("WARNING_MESSAGE", $mod_strings['LBL_NO_TARGETS_WARNING']);
252         }else{
253             //print no entries warning
254             if($campaign_focus->campaign_type='NewsLetter'){
255                 $ss->assign("WARNING_MESSAGE", $mod_strings['LBL_NO_SUBS_ENTRIES_WARNING']);
256             }else{
257                $ss->assign("WARNING_MESSAGE", $mod_strings['LBL_NO_TARGET_ENTRIES_WARNING']);
258             }
259         }
260         //disable the send email options
261         $ss->assign("PL_DISABLED",'disabled');
262
263     }else{
264         //show inputs and assign type to be radio
265     }
266
267
268
269 /**************************** WIZARD UI DIV Stuff *******************/
270
271 $camp_url = "index.php?action=WizardNewsletter&module=Campaigns&return_module=Campaigns&return_action=WizardHome";
272 $camp_url .= "&return_id=".$campaign_focus->id."&record=".$campaign_focus->id."&direct_step=";
273 $ss->assign("CAMP_WIZ_URL", $camp_url);
274     $summ_url = $mod_strings['LBL_NAVIGATION_MENU_SUMMARY'];
275     if(!empty($focus->id)){
276         $summ_url = "<a href='index.php?action=WizardHome&module=Campaigns";
277         $summ_url .= "&return_id=".$focus->id."&record=".$focus->id;
278         $summ_url .= "'> ". $mod_strings['LBL_NAVIGATION_MENU_SUMMARY']."</a>";
279     }
280 $summ_url = $mod_strings['LBL_NAVIGATION_MENU_SUMMARY'];
281 if(!empty($focus->id)){
282     $summ_url = "index.php?action=WizardHome&module=Campaigns&return_id=".$focus->id."&record=".$focus->id;
283 }
284 $ss->assign("SUMM_URL", $summ_url);
285
286 //  this is the wizard control script that resides in page
287  $divScript = <<<EOQ
288
289  <script type="text/javascript" language="javascript">
290     /*
291      * this is the custom validation script that will call the right validation for each div
292      */
293     function validate_wiz_form(step){
294         switch (step){
295             case 'step1':
296             return check_form('wizform');
297             break;
298             default://no additional validation needed
299         }
300         return true;
301
302     }
303
304     showfirst('marketing')
305 </script>
306 EOQ;
307
308 //$ss->assign("WIZ_JAVASCRIPT", print_wizard_jscript());
309 $ss->assign("DIV_JAVASCRIPT", $divScript);
310
311
312
313
314
315 /**************************** FINAL END OF PAGE UI Stuff *******************/
316
317       $ss->display('modules/Campaigns/WizardMarketing.html');
318 ?>