]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/Campaigns/WizardEmailSetup.php
Release 6.5.0
[Github/sugarcrm.git] / modules / Campaigns / WizardEmailSetup.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
51
52 global $mod_strings,$app_list_strings,$app_strings,$current_user;
53
54
55 if (!is_admin($current_user)&& !is_admin_for_module($GLOBALS['current_user'],'Campaigns')) sugar_die("Unauthorized access to administration.");
56
57 $params = array();
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'];
60
61 echo getClassicModuleTitle('Campaigns', $params, true);
62
63
64 global $theme, $currentModule, $sugar_config;
65
66
67
68
69
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");
74 $email = new Email();
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']);
81
82
83
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'" : "");
96
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']);
101 } else  {
102     $ss->assign("EMAILS_PER_RUN", 500);
103 }
104
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']);
109 } else  {
110     $ss->assign("USERDEFINED_CHECKED", "checked");
111     $ss->assign("TRACKING_ENTRIES_LOCATION",$focus->settings["massemailer_tracking_entities_location"]);
112 }
113
114 $ss->assign("SITEURL",$sugar_config['site_url']);
115
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'");
119 } else  {
120     $ss->assign("NO_CHECKED", "checked='checked'");
121 }
122
123 $ss->assign("MAIL_SSL_OPTIONS", get_select_options_with_id($app_list_strings['email_settings_for_ssl'], $focus->settings['mail_smtpssl']));
124
125
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;}
130 $mbox_msg = ' ';
131 $need_mbox = '';  
132
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>";
141     $colorclass=' ';
142     foreach($mbox as $details){
143                 
144      if( $colorclass == "class='evenListRowS1'"){
145             $colorclass= "class='oddListRowS1'";
146         }else{ 
147             $colorclass= "class='evenListRowS1'";
148         }           
149         
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>";
156     }
157
158
159 }else{
160 $need_mbox = 'checked';
161 $mboxTable .= "<tr><td colspan='5'><b>".$mod_strings['LBL_MAILBOX_CHECK_WIZ_BAD']." </b>.</td></tr>";
162 }        
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');   
169 }
170 /**************************** SUMMARY UI DIV Stuff *******************/
171
172 /**************************** WIZARD UI DIV Stuff *******************/
173   
174 //  this is the wizard control script that resides in page    
175  $divScript = <<<EOQ
176  <script type="text/javascript" language="javascript">  
177
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";
188         return true;
189     }
190     
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;
203             }
204         
205         }
206         return true;
207     }
208
209     //this calls the validation functions for each step that needs validation 
210     function validate_wiz_form(step){
211         switch (step){
212             case 'step1':
213             if(!validate_step1()){return false;}
214               copy_down();
215             break;
216             case 'step2':
217            if(!validate_step2()){return false;} 
218             break;                  
219             default://no additional validation needed      
220         }
221         return true;
222     
223     }
224     
225     //this function will add validation to step1
226     function validate_step1(){
227         requiredTxt = SUGAR.language.get('app_strings', 'ERR_MISSING_REQUIRED_FIELDS');
228         var haserrors = 0;
229         var fields = new Array();
230
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';
242                 }
243         }
244         
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){
251                 elem.value = '';
252             }
253         }
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);
266                 }
267         }
268     
269       
270         return check_form('wizform');    
271     }    
272     
273     
274     
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
280          return true;   
281         }
282         var haserrors = 0;
283         var wiz_message = document.getElementById('wiz_message');
284
285         //create list of fields that need validation, based on selected options        
286         var fields = new Array();
287         fields[0] = 'name';
288         fields[1] = 'server_url';
289         fields[2] = 'email_user';
290         fields[3] = 'protocol';
291         fields[4] = 'email_password';
292         fields[5] = 'mailbox';
293         fields[6] = 'port';
294     
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 );
301                 haserrors = 1;
302             }
303         }
304
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);        
314
315         if(haserrors == 1){
316             return false;
317         }
318         return check_form('wizform');
319
320
321     }    
322
323     /*
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 
327      */
328     function create_summary(){
329         var current_step = document.getElementById('wiz_current_step');
330         var currentValue = parseInt(current_step.value);
331         var temp_elem = '';
332
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';
340         
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';
346                  }
347               fields[7] = 'mail_smtpssl';
348           }
349         
350           if(document.getElementById("wiz_new_mbox").value != "0"){
351                 fields[8] = 'name';
352                 fields[9] = 'server_url';
353                 fields[10] = 'email_user';
354                 fields[11] = 'from_addr';
355                 fields[12] = 'protocol';
356                 fields[13] = 'mailbox';
357                 fields[14] = 'port';
358                 fields[15] = 'ssl';
359           }
360     
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';
364         var elem ='';
365         for (var i=0; i<fields.length; i++)
366           {elem = document.getElementById(fields[i]);
367             if(elem!=null){
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)+ "&nbsp;</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) + "&nbsp;</td></tr>";
374                 }else if(elem.type == 'checkbox'){
375                     if(elem.checked){
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>&nbsp;</td></tr>";
377                     }else{
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 >&nbsp;</td></tr>";
379                     }
380                 }else{
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) + "&nbsp;</td></tr>";
382                 }
383             }
384             if( colorclass== 'tabDetailViewDL2'){
385                 colorclass= 'tabDetailViewDF2';
386             }else{ 
387                 colorclass= 'tabDetailViewDL2'
388             }            
389           }
390
391         summhtml = summhtml+ "</table>";
392         temp_elem = document.getElementById('wiz_summ');
393         temp_elem.innerHTML = summhtml;
394         
395     }
396
397     showfirst('email');
398     notify_setrequired();
399     
400     
401     
402     
403 </script>
404 EOQ;
405
406 $ss->assign("DIV_JAVASCRIPT", $divScript);
407
408
409 /**************************** FINAL END OF PAGE UI Stuff *******************/
410
411 //$ss->assign("JAVASCRIPT", get_validate_record_js());
412
413 $ss->display('modules/Campaigns/WizardEmailSetup.html');
414
415 ?>