2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
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.
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
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
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.
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.
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 ********************************************************************************/
38 /*********************************************************************************
40 * Description: TODO: To be written.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
46 /**************************** general UI Stuff *******************/
50 require_once('modules/Campaigns/utils.php');
55 global $app_list_strings;
58 global $sugar_version, $sugar_config;
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']);
66 sugar_die($app_strings['ERROR_NO_RECORD']);
75 $GLOBALS['log']->info("Wizard Continue Create Wizard");
76 if($campaign_focus->campaign_type=='NewsLetter'){
77 echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_NEWSLETTER WIZARD_TITLE'].' '.$campaign_focus->name, true);
79 echo get_module_title($mod_strings['LBL_MODULE_NAME'], $mod_strings['LBL_CAMPAIGN'].' '.$campaign_focus->name, true);
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);
91 $seps = get_number_seperators();
92 $ss->assign("NUM_GRP_SEP", $seps[0]);
93 $ss->assign("DEC_SEP", $seps[1]);
96 /**************************** MARKETING UI DIV Stuff *******************/
97 //$campaign_focus->load_relationship('emailmarketing');
98 //$mrkt_ids = $campaign_focus->emailmarketing->get();
100 $mrkt_focus = new EmailMarketing();
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']);
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;
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']);
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']);
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);
146 $mailboxes=get_campaign_mailboxes($emails);
149 * get full array of stored options
151 $IEStoredOptions = get_campaign_mailboxes_with_stored_options();
152 $IEStoredOptionsJSON = (!empty($IEStoredOptions)) ? $json->encode($IEStoredOptions, false) : 'new Object()';
153 $ss->assign("IEStoredOptions", $IEStoredOptionsJSON);
156 $emails['']='nobody@example.com';
160 $default_email_address='nobody@example.com';
162 foreach ($mailboxes as $id=>$name) {
163 if (!empty($from_emails)) {
167 $from_emails.="'EMPTY','$name','$emails[$id]'";
169 $from_emails.="'$id','$name','$emails[$id]'";
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, ''));
178 $ss->assign("MAILBOXES", get_select_options_with_id($mailboxes, $mrkt_focus->inbound_email_id));
181 $ss->assign("TIME_MERIDIEM", $timedate->AMPMMenu('', $mrkt_focus->time_start));
182 $ss->assign("TIME_FORMAT", '('. $timedate->get_user_time_format().')');
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");
191 $ss->assign("EMAIL_TEMPLATE_OPTIONS", get_select_options_with_id($email_templates_arr, ""));
192 $ss->assign("EDIT_TEMPLATE","visibility:hidden");
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");
203 //get select prospect list.
204 if (!empty($mrkt_focus->id)) {
205 $mrkt_focus->load_relationship('prospectlists');
206 $prospectlists=$mrkt_focus->prospectlists->get();
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']);
216 $javascript = new javascript();
217 $javascript->setFormName('wizform');
218 $javascript->setSugarBean($mrkt_focus);
219 $javascript->addAllFields('');
220 echo $javascript->getScript();
222 /**************************** Final Step UI DIV *******************/
224 //Grab the prospect list of type default
225 $default_pl_focus = ' ';
226 $campaign_focus->load_relationship('prospectlists');
227 $prospectlists=$campaign_focus->prospectlists->get();
232 if(!empty($prospectlists)){
233 foreach ($prospectlists as $prospect_id){
234 $pl_focus = new ProspectList();
235 $pl_focus->retrieve($prospect_id);
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();
242 $pl_lists = $pl_lists+1;
247 //if count is 0, then hide inputs and and print warning message
250 //print no target list warning
251 $ss->assign("WARNING_MESSAGE", $mod_strings['LBL_NO_TARGETS_WARNING']);
253 //print no entries warning
254 if($campaign_focus->campaign_type='NewsLetter'){
255 $ss->assign("WARNING_MESSAGE", $mod_strings['LBL_NO_SUBS_ENTRIES_WARNING']);
257 $ss->assign("WARNING_MESSAGE", $mod_strings['LBL_NO_TARGET_ENTRIES_WARNING']);
260 //disable the send email options
261 $ss->assign("PL_DISABLED",'disabled');
264 //show inputs and assign type to be radio
269 /**************************** WIZARD UI DIV Stuff *******************/
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>";
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;
284 $ss->assign("SUMM_URL", $summ_url);
286 // this is the wizard control script that resides in page
289 <script type="text/javascript" language="javascript">
291 * this is the custom validation script that will call the right validation for each div
293 function validate_wiz_form(step){
296 return check_form('wizform');
298 default://no additional validation needed
304 showfirst('marketing')
308 //$ss->assign("WIZ_JAVASCRIPT", print_wizard_jscript());
309 $ss->assign("DIV_JAVASCRIPT", $divScript);
315 /**************************** FINAL END OF PAGE UI Stuff *******************/
317 $ss->display('modules/Campaigns/WizardMarketing.html');