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.
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 ****************/
52 global $mod_strings,$app_list_strings,$app_strings,$current_user;
55 if (!is_admin($current_user)&& !is_admin_for_module($GLOBALS['current_user'],'Campaigns')) sugar_die("Unauthorized access to administration.");
58 $params[] = "<a href='index.php?module=Campaigns&action=index'>{$mod_strings['LBL_MODULE_NAME']}</a>";
59 $params[] = $mod_strings['LBL_EMAIL_SETUP_WIZARD_TITLE'];
61 echo getClassicModuleTitle('Campaigns', $params, true);
64 global $theme, $currentModule, $sugar_config;
70 //get administration bean for email setup
71 $focus = new Administration();
72 $focus->retrieveSettings(); //retrieve all admin settings.
73 $GLOBALS['log']->info("Mass Emailer(EmailMan) ConfigureSettings view");
75 $ss = new Sugar_Smarty();
76 $ss->assign("MOD", $mod_strings);
77 $ss->assign("APP", $app_strings);
78 if (isset($_REQUEST['return_module'])) $ss->assign("RETURN_MODULE", $_REQUEST['return_module']);
79 if (isset($_REQUEST['return_action'])) $ss->assign("RETURN_ACTION", $_REQUEST['return_action']);
80 if (isset($_REQUEST['return_id'])) $ss->assign("RETURN_ID", $_REQUEST['return_id']);
84 /******** Email Setup UI DIV Stuff **********/
85 //get Settings if they exist
86 $ss->assign("notify_fromaddress", $focus->settings['notify_fromaddress']);
87 $ss->assign("notify_send_from_assigning_user", ($focus->settings['notify_send_from_assigning_user']) ? "checked='checked'" : "");
88 $ss->assign("notify_on", ($focus->settings['notify_on']) ? "checked='checked'" : "");
89 $ss->assign("notify_fromname", $focus->settings['notify_fromname']);
90 $ss->assign("mail_smtpserver", $focus->settings['mail_smtpserver']);
91 $ss->assign("mail_smtpport", $focus->settings['mail_smtpport']);
92 $ss->assign("mail_sendtype_options", get_select_options_with_id($app_list_strings['notifymail_sendtype'], $focus->settings['mail_sendtype']));
93 $ss->assign("mail_smtpuser", $focus->settings['mail_smtpuser']);
94 $ss->assign("mail_smtppass", $focus->settings['mail_smtppass']);
95 $ss->assign("mail_smtpauth_req", ($focus->settings['mail_smtpauth_req']) ? "checked='checked'" : "");
97 $protocol = filterInboundEmailPopSelection($app_list_strings['dom_email_server_type']);
98 $ss->assign('PROTOCOL', get_select_options_with_id($protocol, ''));
99 if (isset($focus->settings['massemailer_campaign_emails_per_run']) && !empty($focus->settings['massemailer_campaign_emails_per_run'])) {
100 $ss->assign("EMAILS_PER_RUN", $focus->settings['massemailer_campaign_emails_per_run']);
102 $ss->assign("EMAILS_PER_RUN", 500);
105 if (!isset($focus->settings['massemailer_tracking_entities_location_type']) or empty($focus->settings['massemailer_tracking_entities_location_type']) or $focus->settings['massemailer_tracking_entities_location_type']=='1') {
106 $ss->assign("DEFAULT_CHECKED", "checked");
107 $ss->assign("TRACKING_ENTRIES_LOCATION_STATE", "disabled");
108 $ss->assign("TRACKING_ENTRIES_LOCATION",$mod_strings['TRACKING_ENTRIES_LOCATION_DEFAULT_VALUE']);
110 $ss->assign("USERDEFINED_CHECKED", "checked");
111 $ss->assign("TRACKING_ENTRIES_LOCATION",$focus->settings["massemailer_tracking_entities_location"]);
114 $ss->assign("SITEURL",$sugar_config['site_url']);
116 // Change the default campaign to not store a copy of each message.
117 if (!empty($focus->settings['massemailer_email_copy']) and $focus->settings['massemailer_email_copy']=='1') {
118 $ss->assign("YES_CHECKED", "checked='checked'");
120 $ss->assign("NO_CHECKED", "checked='checked'");
123 $ss->assign("MAIL_SSL_OPTIONS", get_select_options_with_id($app_list_strings['email_settings_for_ssl'], $focus->settings['mail_smtpssl']));
126 /*********** New Mail Box UI DIV Stuff ****************/
127 $mbox_qry = "select * from inbound_email where deleted ='0' and mailbox_type = 'bounce'";
128 $mbox_res = $focus->db->query($mbox_qry);
129 while ($mbox_row = $focus->db->fetchByAssoc($mbox_res)){$mbox[] = $mbox_row;}
133 $mboxTable = "<table class='list view' width='100%' border='0' cellspacing='1' cellpadding='1'>";
134 if(isset($mbox) && count($mbox)>0){
135 $mboxTable .= "<tr><td colspan='5'><b>" .count($mbox) ." ". $mod_strings['LBL_MAILBOX_CHECK_WIZ_GOOD']." </b>.</td></tr>";
136 $mboxTable .= "<tr class='listViewHRS1'><td width='20%'><b>".$mod_strings['LBL_MAILBOX_NAME']."</b></td>"
137 . " <td width='20%'><b>".$mod_strings['LBL_LOGIN']."</b></td>"
138 . " <td width='20%'><b>".$mod_strings['LBL_MAILBOX']."</b></td>"
139 . " <td width='20%'><b>".$mod_strings['LBL_SERVER_URL']."</b></td>"
140 . " <td width='20%'><b>".$mod_strings['LBL_LIST_STATUS']."</b></td></tr>";
142 foreach($mbox as $details){
144 if( $colorclass == "class='evenListRowS1'"){
145 $colorclass= "class='oddListRowS1'";
147 $colorclass= "class='evenListRowS1'";
150 $mboxTable .= "<tr $colorclass>";
151 $mboxTable .= "<td>".$details['name']."</td>";
152 $mboxTable .= "<td>".$details['email_user']."</td>";
153 $mboxTable .= "<td>".$details['mailbox']."</td>";
154 $mboxTable .= "<td>".$details['server_url']."</td>";
155 $mboxTable .= "<td>".$details['status']."</td></tr>";
160 $need_mbox = 'checked';
161 $mboxTable .= "<tr><td colspan='5'><b>".$mod_strings['LBL_MAILBOX_CHECK_WIZ_BAD']." </b>.</td></tr>";
163 $mboxTable .= "</table>";
164 $ss->assign("MAILBOXES_DETECTED_MESSAGE", $mboxTable);
165 $ss->assign("MBOX_NEEDED", $need_mbox);
166 $ss->assign('ROLLOVER', $email->rolloverStyle);
167 if(!function_exists('imap_open')) {
168 $ss->assign('IE_DISABLED', 'DISABLED');
170 /**************************** SUMMARY UI DIV Stuff *******************/
172 /**************************** WIZARD UI DIV Stuff *******************/
174 // this is the wizard control script that resides in page
176 <script type="text/javascript" language="javascript">
178 //this function toggles visibility of fields based on selected options
179 function notify_setrequired() {
180 f = document.getElementById("wizform");
181 document.getElementById("smtp_settings").style.display = (f.mail_sendtype.value == "SMTP") ? "inline" : "none";
182 document.getElementById("smtp_settings").style.visibility = (f.mail_sendtype.value == "SMTP") ? "visible" : "hidden";
183 document.getElementById("smtp_auth").style.display = (document.getElementById('mail_smtpauth_req').checked) ? "inline" : "none";
184 document.getElementById("smtp_auth").style.visibility = (document.getElementById('mail_smtpauth_req').checked) ? "visible" : "hidden";
185 document.getElementById("new_mbox").style.display = (document.getElementById('create_mbox').checked) ? "inline" : "none";
186 document.getElementById("new_mbox").style.visibility = (document.getElementById('create_mbox').checked) ? "visible" : "hidden";
187 document.getElementById("wiz_new_mbox").value = (document.getElementById('create_mbox').checked) ? "1" : "0";
191 //this function will copy as much information as possible from the first step in wizard
192 //onto the the second step in wizard
193 function copy_down() {
194 document.getElementById("name").value = document.getElementById("notify_fromname").value;
195 document.getElementById("email_user").value = document.getElementById("notify_fromaddress").value;
196 document.getElementById("from_addr").value = document.getElementById("notify_fromaddress").value;
197 if(document.getElementById("mail_sendtype").value=='SMTP'){
198 document.getElementById("protocol").value = "SMTP";
199 document.getElementById("server_url").value = document.getElementById("mail_smtpserver").value;
200 if(document.getElementById('mail_smtpauth_req').checked){
201 document.getElementById("email_user").value = document.getElementById("mail_smtpuser").value;
202 document.getElementById("email_password").value = document.getElementById("mail_smtppass").value;
209 //this calls the validation functions for each step that needs validation
210 function validate_wiz_form(step){
213 if(!validate_step1()){return false;}
217 if(!validate_step2()){return false;}
219 default://no additional validation needed
225 //this function will add validation to step1
226 function validate_step1(){
227 requiredTxt = SUGAR.language.get('app_strings', 'ERR_MISSING_REQUIRED_FIELDS');
229 var fields = new Array();
231 //create list of fields that need validation, based on selected options
232 fields[0] = 'notify_fromname';
233 fields[1] = 'notify_fromaddress';
234 fields[2] = 'massemailer_campaign_emails_per_run';
235 fields[3] = 'massemailer_tracking_entities_location';
236 if(document.getElementById("mail_sendtype").value=='SMTP'){
237 fields[4] = 'mail_smtpserver';
238 fields[5] = 'mail_smtpport';
239 if(document.getElementById('mail_smtpauth_req').checked){
240 fields[6] = 'mail_smtpuser';
241 fields[7] = 'mail_smtppass';
245 var field_value = '';
246 //iterate through required fields and set empty string values (' '') to null, this will cause failure later on
247 for (i=0; i < fields.length; i++){
248 elem = document.getElementById(fields[i]);
249 field_value = trim(elem.value);
250 if(field_value.length<1){
254 //add to generic validation and call function to calidate
255 if(validate['wizform']!='undefined'){delete validate['wizform']};
256 addToValidate('wizform', 'notify_fromaddress', 'email', true, document.getElementById('notify_fromaddress').title);
257 addToValidate('wizform', 'notify_fromname', 'alphanumeric', true, document.getElementById('notify_fromname').title);
258 addToValidate('wizform', 'massemailer_campaign_emails_per_run', 'int', true, document.getElementById('massemailer_campaign_emails_per_run').title);
259 addToValidate('wizform', 'massemailer_tracking_entities_location', 'alphanumeric', true, document.getElementById('massemailer_tracking_entities_location').title);
260 if(document.getElementById("mail_sendtype").value=='SMTP'){
261 addToValidate('wizform', 'mail_smtpserver', 'alphanumeric', true, document.getElementById('mail_smtpserver').title);
262 addToValidate('wizform', 'mail_smtpport', 'int', true, document.getElementById('mail_smtpport').title);
263 if(document.getElementById('mail_smtpauth_req').checked){
264 addToValidate('wizform', 'mail_smtpuser', 'alphanumeric', true, document.getElementById('mail_smtpuser').title);
265 addToValidate('wizform', 'mail_smtppass', 'alphanumeric', true, document.getElementById('mail_smtppass').title);
270 return check_form('wizform');
275 function validate_step2(){
276 requiredTxt = SUGAR.language.get('app_strings', 'ERR_MISSING_REQUIRED_FIELDS');
277 //validate only if the create mailbox form input has been selected
278 if(document.getElementById("wiz_new_mbox").value == "0"){
279 //this form is not checked, do not validate
283 var wiz_message = document.getElementById('wiz_message');
285 //create list of fields that need validation, based on selected options
286 var fields = new Array();
288 fields[1] = 'server_url';
289 fields[2] = 'email_user';
290 fields[3] = 'protocol';
291 fields[4] = 'email_password';
292 fields[5] = 'mailbox';
295 //iterate through required fields and set empty string values (' '') to null, this will cause failure later on
296 var field_value = '';
297 for (i=0; i < fields.length; i++){
298 field_value = trim(document.getElementById(fields[i]).value);
299 if(field_value.length<1){
300 add_error_style('wizform', fields[i], requiredTxt +' ' +document.getElementById(fields[i]).title );
305 //add to generic validation and call function to calidate
306 if(validate['wizform']!='undefined'){delete validate['wizform']};
307 addToValidate('wizform', 'name', 'alphanumeric', true, document.getElementById('name').title);
308 addToValidate('wizform', 'server_url', 'alphanumeric', true, document.getElementById('server_url').title);
309 addToValidate('wizform', 'email_user', 'alphanumeric', true, document.getElementById('email_user').title);
310 addToValidate('wizform', 'email_password', 'alphanumeric', true, document.getElementById('email_password').title);
311 addToValidate('wizform', 'mailbox', 'alphanumeric', true, document.getElementById('mailbox').title);
312 addToValidate('wizform', 'protocol', 'alphanumeric', true, document.getElementById('protocol').title);
313 addToValidate('wizform', 'port', 'int', true, document.getElementById('port').title);
318 return check_form('wizform');
324 * The generic create summary will not work for this wizard, as we have a step that only gets
325 * displayed if a check box is marked, and we also have certain inputs we do not want displayed(ie. password)
326 * so this function will override the genereic version
328 function create_summary(){
329 var current_step = document.getElementById('wiz_current_step');
330 var currentValue = parseInt(current_step.value);
333 // alert(test.title);alert(test.name);alert(test.id);
334 var fields = new Array();
335 //create the list of fields to create summary table
336 fields[0] = 'notify_fromname';
337 fields[1] = 'notify_fromaddress';
338 fields[2] = 'massemailer_campaign_emails_per_run';
339 fields[3] = 'massemailer_tracking_entities_location';
341 if(document.getElementById("mail_sendtype").value=='SMTP'){
342 fields[4] = 'mail_smtpserver';
343 fields[5] = 'mail_smtpport';
344 if(document.getElementById('mail_smtpauth_req').checked){
345 fields[6] = 'mail_smtpuser';
347 fields[7] = 'mail_smtpssl';
350 if(document.getElementById("wiz_new_mbox").value != "0"){
352 fields[9] = 'server_url';
353 fields[10] = 'email_user';
354 fields[11] = 'from_addr';
355 fields[12] = 'protocol';
356 fields[13] = 'mailbox';
361 //iterate through list and create table
362 var summhtml = "<table class='detail view' width='100%' border='0' cellspacing='1' cellpadding='1'>";
363 var colorclass = 'tabDetailViewDF2';
365 for (var i=0; i<fields.length; i++)
366 {elem = document.getElementById(fields[i]);
368 if(elem.type.indexOf('select') >= 0 ){
369 var selInd = elem.selectedIndex;
370 if(selInd<0){selInd =0;}
371 summhtml = summhtml+ "<tr class='"+colorclass+"' ><td scope='row' width='15%'><b>" +elem.title+ "</b></td><td class='tabDetailViewDF' width='30%'>" + YAHOO.lang.escapeHTML(elem.options[selInd].text)+ " </td></tr>";
372 }else if(elem.type == 'checked'){
373 summhtml = summhtml+ "<tr class='"+colorclass+"' ><td scope='row' width='15%'><b>" +elem.title+ "</b></td><td class='tabDetailViewDF' width='30%'>" + YAHOO.lang.escapeHTML(elem.value) + " </td></tr>";
374 }else if(elem.type == 'checkbox'){
376 summhtml = summhtml+ "<tr class='"+colorclass+"' ><td scope='row' width='15%'><b>" +elem.title+ "</b></td><td class='tabDetailViewDF' width='30%'><input type='checkbox' class='checkbox' disabled checked> </td></tr>";
378 summhtml = summhtml+ "<tr class='"+colorclass+"' ><td scope='row' width='15%'><b>" +elem.title+ "</b></td><td class='tabDetailViewDF' width='30%'><input type='checkbox' class='checkbox' disabled > </td></tr>";
381 summhtml = summhtml+ "<tr class='"+colorclass+"' ><td scope='row' width='15%'><b>" +elem.title+ "</b></td><td class='tabDetailViewDF' width='30%'>" + YAHOO.lang.escapeHTML(elem.value) + " </td></tr>";
384 if( colorclass== 'tabDetailViewDL2'){
385 colorclass= 'tabDetailViewDF2';
387 colorclass= 'tabDetailViewDL2'
391 summhtml = summhtml+ "</table>";
392 temp_elem = document.getElementById('wiz_summ');
393 temp_elem.innerHTML = summhtml;
398 notify_setrequired();
406 if(isset($_REQUEST['error'])){
407 //if there is an error flagged, then we are coming here after a save where there was an error detected
408 //on an inbound email save. Display error to user so they are aware.
409 $errorString = "<div class='error'>".$mod_strings['ERR_NO_OPTS_SAVED']." <a href='index.php?module=InboundEmail&action=index'>".$mod_strings['ERR_REVIEW_EMAIL_SETTINGS']."</a></div>";
410 $ss->assign('ERROR', $errorString);
411 //navigate to inbound email page by default
412 $divScript .=" <script>navigate('next');</script>";
415 $ss->assign("DIV_JAVASCRIPT", $divScript);
418 /**************************** FINAL END OF PAGE UI Stuff *******************/
420 //$ss->assign("JAVASCRIPT", get_validate_record_js());
422 $ss->display('modules/Campaigns/WizardEmailSetup.html');