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-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 ****************/
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);
65 global $currentModule;
71 //get administration bean for email setup
72 $focus = new Administration();
73 $focus->retrieveSettings(); //retrieve all admin settings.
74 $GLOBALS['log']->info("Mass Emailer(EmailMan) ConfigureSettings view");
76 $ss = new Sugar_Smarty();
77 $ss->assign("MOD", $mod_strings);
78 $ss->assign("APP", $app_strings);
79 if (isset($_REQUEST['return_module'])) $ss->assign("RETURN_MODULE", $_REQUEST['return_module']);
80 if (isset($_REQUEST['return_action'])) $ss->assign("RETURN_ACTION", $_REQUEST['return_action']);
81 if (isset($_REQUEST['return_id'])) $ss->assign("RETURN_ID", $_REQUEST['return_id']);
85 /******** Email Setup UI DIV Stuff **********/
86 //get Settings if they exist
87 $ss->assign("notify_fromaddress", $focus->settings['notify_fromaddress']);
88 $ss->assign("notify_send_from_assigning_user", ($focus->settings['notify_send_from_assigning_user']) ? "checked='checked'" : "");
89 $ss->assign("notify_on", ($focus->settings['notify_on']) ? "checked='checked'" : "");
90 $ss->assign("notify_fromname", $focus->settings['notify_fromname']);
91 $ss->assign("mail_smtpserver", $focus->settings['mail_smtpserver']);
92 $ss->assign("mail_smtpport", $focus->settings['mail_smtpport']);
93 $ss->assign("mail_sendtype_options", get_select_options_with_id($app_list_strings['notifymail_sendtype'], $focus->settings['mail_sendtype']));
94 $ss->assign("mail_smtpuser", $focus->settings['mail_smtpuser']);
95 $ss->assign("mail_smtppass", $focus->settings['mail_smtppass']);
96 $ss->assign("mail_smtpauth_req", ($focus->settings['mail_smtpauth_req']) ? "checked='checked'" : "");
98 $protocol = filterInboundEmailPopSelection($app_list_strings['dom_email_server_type']);
99 $ss->assign('PROTOCOL', get_select_options_with_id($protocol, ''));
100 if (isset($focus->settings['massemailer_campaign_emails_per_run']) && !empty($focus->settings['massemailer_campaign_emails_per_run'])) {
101 $ss->assign("EMAILS_PER_RUN", $focus->settings['massemailer_campaign_emails_per_run']);
103 $ss->assign("EMAILS_PER_RUN", 500);
106 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') {
107 $ss->assign("DEFAULT_CHECKED", "checked");
108 $ss->assign("TRACKING_ENTRIES_LOCATION_STATE", "disabled");
109 $ss->assign("TRACKING_ENTRIES_LOCATION",$mod_strings['TRACKING_ENTRIES_LOCATION_DEFAULT_VALUE']);
111 $ss->assign("USERDEFINED_CHECKED", "checked");
112 $ss->assign("TRACKING_ENTRIES_LOCATION",$focus->settings["massemailer_tracking_entities_location"]);
114 // Change the default campaign to not store a copy of each message.
115 if (!empty($focus->settings['massemailer_email_copy']) and $focus->settings['massemailer_email_copy']=='1') {
116 $ss->assign("YES_CHECKED", "checked='checked'");
118 $ss->assign("NO_CHECKED", "checked='checked'");
121 $ss->assign("MAIL_SSL_OPTIONS", get_select_options_with_id($app_list_strings['email_settings_for_ssl'], $focus->settings['mail_smtpssl']));
124 /*********** New Mail Box UI DIV Stuff ****************/
125 $mbox_qry = "select * from inbound_email where deleted ='0' and mailbox_type = 'bounce'";
126 $mbox_res = $focus->db->query($mbox_qry);
127 while ($mbox_row = $focus->db->fetchByAssoc($mbox_res)){$mbox[] = $mbox_row;}
131 $mboxTable = "<table class='list view' width='100%' border='0' cellspacing='1' cellpadding='1'>";
132 if(isset($mbox) && count($mbox)>0){
133 $mboxTable .= "<tr><td colspan='5'><b>" .count($mbox) ." ". $mod_strings['LBL_MAILBOX_CHECK_WIZ_GOOD']." </b>.</td></tr>";
134 $mboxTable .= "<tr class='listViewHRS1'><td width='20%'><b>".$mod_strings['LBL_MAILBOX_NAME']."</b></td>"
135 . " <td width='20%'><b>".$mod_strings['LBL_LOGIN']."</b></td>"
136 . " <td width='20%'><b>".$mod_strings['LBL_MAILBOX']."</b></td>"
137 . " <td width='20%'><b>".$mod_strings['LBL_SERVER_URL']."</b></td>"
138 . " <td width='20%'><b>".$mod_strings['LBL_LIST_STATUS']."</b></td></tr>";
140 foreach($mbox as $details){
142 if( $colorclass == "class='evenListRowS1'"){
143 $colorclass= "class='oddListRowS1'";
145 $colorclass= "class='evenListRowS1'";
148 $mboxTable .= "<tr $colorclass>";
149 $mboxTable .= "<td>".$details['name']."</td>";
150 $mboxTable .= "<td>".$details['email_user']."</td>";
151 $mboxTable .= "<td>".$details['mailbox']."</td>";
152 $mboxTable .= "<td>".$details['server_url']."</td>";
153 $mboxTable .= "<td>".$details['status']."</td></tr>";
158 $need_mbox = 'checked';
159 $mboxTable .= "<tr><td colspan='5'><b>".$mod_strings['LBL_MAILBOX_CHECK_WIZ_BAD']." </b>.</td></tr>";
161 $mboxTable .= "</table>";
162 $ss->assign("MAILBOXES_DETECTED_MESSAGE", $mboxTable);
163 $ss->assign("MBOX_NEEDED", $need_mbox);
164 $ss->assign('ROLLOVER', $email->rolloverStyle);
165 if(!function_exists('imap_open')) {
166 $ss->assign('IE_DISABLED', 'DISABLED');
168 /**************************** SUMMARY UI DIV Stuff *******************/
170 /**************************** WIZARD UI DIV Stuff *******************/
172 // this is the wizard control script that resides in page
174 <script type="text/javascript" language="javascript">
176 //this function toggles visibility of fields based on selected options
177 function notify_setrequired() {
178 f = document.getElementById("wizform");
179 document.getElementById("smtp_settings").style.display = (f.mail_sendtype.value == "SMTP") ? "inline" : "none";
180 document.getElementById("smtp_settings").style.visibility = (f.mail_sendtype.value == "SMTP") ? "visible" : "hidden";
181 document.getElementById("smtp_auth").style.display = (document.getElementById('mail_smtpauth_req').checked) ? "inline" : "none";
182 document.getElementById("smtp_auth").style.visibility = (document.getElementById('mail_smtpauth_req').checked) ? "visible" : "hidden";
183 document.getElementById("new_mbox").style.display = (document.getElementById('create_mbox').checked) ? "inline" : "none";
184 document.getElementById("new_mbox").style.visibility = (document.getElementById('create_mbox').checked) ? "visible" : "hidden";
185 document.getElementById("wiz_new_mbox").value = (document.getElementById('create_mbox').checked) ? "1" : "0";
189 //this function will copy as much information as possible from the first step in wizard
190 //onto the the second step in wizard
191 function copy_down() {
192 document.getElementById("name").value = document.getElementById("notify_fromname").value;
193 document.getElementById("email_user").value = document.getElementById("notify_fromaddress").value;
194 document.getElementById("from_addr").value = document.getElementById("notify_fromaddress").value;
195 if(document.getElementById("mail_sendtype").value=='SMTP'){
196 document.getElementById("protocol").value = "SMTP";
197 document.getElementById("server_url").value = document.getElementById("mail_smtpserver").value;
198 if(document.getElementById('mail_smtpauth_req').checked){
199 document.getElementById("email_user").value = document.getElementById("mail_smtpuser").value;
200 document.getElementById("email_password").value = document.getElementById("mail_smtppass").value;
207 //this calls the validation functions for each step that needs validation
208 function validate_wiz_form(step){
211 if(!validate_step1()){return false;}
215 if(!validate_step2()){return false;}
217 default://no additional validation needed
223 //this function will add validation to step1
224 function validate_step1(){
225 requiredTxt = SUGAR.language.get('app_strings', 'ERR_MISSING_REQUIRED_FIELDS');
227 var fields = new Array();
229 //create list of fields that need validation, based on selected options
230 fields[0] = 'notify_fromname';
231 fields[1] = 'notify_fromaddress';
232 fields[2] = 'massemailer_campaign_emails_per_run';
233 fields[3] = 'massemailer_tracking_entities_location';
234 if(document.getElementById("mail_sendtype").value=='SMTP'){
235 fields[4] = 'mail_smtpserver';
236 fields[5] = 'mail_smtpport';
237 if(document.getElementById('mail_smtpauth_req').checked){
238 fields[6] = 'mail_smtpuser';
239 fields[7] = 'mail_smtppass';
243 var field_value = '';
244 //iterate through required fields and set empty string values (' '') to null, this will cause failure later on
245 for (i=0; i < fields.length; i++){
246 elem = document.getElementById(fields[i]);
247 field_value = trim(elem.value);
248 if(field_value.length<1){
252 //add to generic validation and call function to calidate
253 if(validate['wizform']!='undefined'){delete validate['wizform']};
254 addToValidate('wizform', 'notify_fromaddress', 'email', true, document.getElementById('notify_fromaddress').title);
255 addToValidate('wizform', 'notify_fromname', 'alphanumeric', true, document.getElementById('notify_fromname').title);
256 addToValidate('wizform', 'massemailer_campaign_emails_per_run', 'int', true, document.getElementById('massemailer_campaign_emails_per_run').title);
257 addToValidate('wizform', 'massemailer_tracking_entities_location', 'alphanumeric', true, document.getElementById('massemailer_tracking_entities_location').title);
258 if(document.getElementById("mail_sendtype").value=='SMTP'){
259 addToValidate('wizform', 'mail_smtpserver', 'alphanumeric', true, document.getElementById('mail_smtpserver').title);
260 addToValidate('wizform', 'mail_smtpport', 'int', true, document.getElementById('mail_smtpport').title);
261 if(document.getElementById('mail_smtpauth_req').checked){
262 addToValidate('wizform', 'mail_smtpuser', 'alphanumeric', true, document.getElementById('mail_smtpuser').title);
263 addToValidate('wizform', 'mail_smtppass', 'alphanumeric', true, document.getElementById('mail_smtppass').title);
268 return check_form('wizform');
273 function validate_step2(){
274 requiredTxt = SUGAR.language.get('app_strings', 'ERR_MISSING_REQUIRED_FIELDS');
275 //validate only if the create mailbox form input has been selected
276 if(document.getElementById("wiz_new_mbox").value == "0"){
277 //this form is not checked, do not validate
281 var wiz_message = document.getElementById('wiz_message');
283 //create list of fields that need validation, based on selected options
284 var fields = new Array();
286 fields[1] = 'server_url';
287 fields[2] = 'email_user';
288 fields[3] = 'protocol';
289 fields[4] = 'email_password';
290 fields[5] = 'mailbox';
293 //iterate through required fields and set empty string values (' '') to null, this will cause failure later on
294 var field_value = '';
295 for (i=0; i < fields.length; i++){
296 field_value = trim(document.getElementById(fields[i]).value);
297 if(field_value.length<1){
298 add_error_style('wizform', fields[i], requiredTxt +' ' +document.getElementById(fields[i]).title );
303 //add to generic validation and call function to calidate
304 if(validate['wizform']!='undefined'){delete validate['wizform']};
305 addToValidate('wizform', 'name', 'alphanumeric', true, document.getElementById('name').title);
306 addToValidate('wizform', 'server_url', 'alphanumeric', true, document.getElementById('server_url').title);
307 addToValidate('wizform', 'email_user', 'alphanumeric', true, document.getElementById('email_user').title);
308 addToValidate('wizform', 'email_password', 'alphanumeric', true, document.getElementById('email_password').title);
309 addToValidate('wizform', 'mailbox', 'alphanumeric', true, document.getElementById('mailbox').title);
310 addToValidate('wizform', 'protocol', 'alphanumeric', true, document.getElementById('protocol').title);
311 addToValidate('wizform', 'port', 'int', true, document.getElementById('port').title);
316 return check_form('wizform');
322 * The generic create summary will not work for this wizard, as we have a step that only gets
323 * displayed if a check box is marked, and we also have certain inputs we do not want displayed(ie. password)
324 * so this function will override the genereic version
326 function create_summary(){
327 var current_step = document.getElementById('wiz_current_step');
328 var currentValue = parseInt(current_step.value);
331 // alert(test.title);alert(test.name);alert(test.id);
332 var fields = new Array();
333 //create the list of fields to create summary table
334 fields[0] = 'notify_fromname';
335 fields[1] = 'notify_fromaddress';
336 fields[2] = 'massemailer_campaign_emails_per_run';
337 fields[3] = 'massemailer_tracking_entities_location';
339 if(document.getElementById("mail_sendtype").value=='SMTP'){
340 fields[4] = 'mail_smtpserver';
341 fields[5] = 'mail_smtpport';
342 if(document.getElementById('mail_smtpauth_req').checked){
343 fields[6] = 'mail_smtpuser';
345 fields[7] = 'mail_smtpssl';
348 if(document.getElementById("wiz_new_mbox").value != "0"){
350 fields[9] = 'server_url';
351 fields[10] = 'email_user';
352 fields[11] = 'from_addr';
353 fields[12] = 'protocol';
354 fields[13] = 'mailbox';
359 //iterate through list and create table
360 var summhtml = "<table class='detail view' width='100%' border='0' cellspacing='1' cellpadding='1'>";
361 var colorclass = 'tabDetailViewDF2';
363 for (var i=0; i<fields.length; i++)
364 {elem = document.getElementById(fields[i]);
366 if(elem.type.indexOf('select') >= 0 ){
367 var selInd = elem.selectedIndex;
368 if(selInd<0){selInd =0;}
369 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>";
370 }else if(elem.type == 'checked'){
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.value) + " </td></tr>";
372 }else if(elem.type == 'checkbox'){
374 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>";
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 > </td></tr>";
379 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>";
382 if( colorclass== 'tabDetailViewDL2'){
383 colorclass= 'tabDetailViewDF2';
385 colorclass= 'tabDetailViewDL2'
389 summhtml = summhtml+ "</table>";
390 temp_elem = document.getElementById('wiz_summ');
391 temp_elem.innerHTML = summhtml;
396 notify_setrequired();
404 $ss->assign("DIV_JAVASCRIPT", $divScript);
407 /**************************** FINAL END OF PAGE UI Stuff *******************/
409 //$ss->assign("JAVASCRIPT", get_validate_record_js());
411 $ss->display('modules/Campaigns/WizardEmailSetup.html');