]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/InboundEmail/EditView.php
Release 6.5.0
[Github/sugarcrm.git] / modules / InboundEmail / EditView.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 $_REQUEST['edit']='true';
39
40 require_once('include/SugarFolders/SugarFolders.php');
41 require_once('include/templates/TemplateGroupChooser.php');
42
43 // GLOBALS
44 global $mod_strings;
45 global $app_strings;
46 global $app_list_strings;
47 global $current_user;
48
49 $focus = new InboundEmail();
50 $focus->checkImap();
51 $javascript = new Javascript();
52 $email = new Email();
53 /* Start standard EditView setup logic */
54
55 $domMailBoxType = $app_list_strings['dom_mailbox_type'];
56
57 if(isset($_REQUEST['record'])) {
58         $GLOBALS['log']->debug("In InboundEmail edit view, about to retrieve record: ".$_REQUEST['record']);
59         $result = $focus->retrieve($_REQUEST['record']);
60     if($result == null)
61     {
62         sugar_die($app_strings['ERROR_NO_RECORD']);
63     }
64 }
65 else
66 {
67     if(!empty($_REQUEST['mailbox_type']))
68         $focus->mailbox_type = $_REQUEST['mailbox_type'];
69
70     //Default to imap protocol for new accounts.
71     $focus->protocol = 'imap';
72 }
73
74 if($focus->mailbox_type == 'bounce')
75 {
76     unset($domMailBoxType['pick']);
77     unset($domMailBoxType['createcase']);
78 }
79 else
80     unset($domMailBoxType['bounce']);
81
82 $isDuplicate = isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true';
83 if($isDuplicate) {
84         $GLOBALS['log']->debug("isDuplicate found - duplicating record of id: ".$focus->id);
85         $origin_id = $focus->id;
86         $focus->id = "";
87 }
88
89 $GLOBALS['log']->info("InboundEmail Edit View");
90 /* End standard EditView setup logic */
91
92 /* Start custom setup logic */
93 // status drop down
94 $status = get_select_options_with_id_separate_key($app_list_strings['user_status_dom'],$app_list_strings['user_status_dom'], $focus->status);
95 // default MAILBOX value
96 if(empty($focus->mailbox)) {
97         $mailbox = 'INBOX';
98 } else {
99         $mailbox = $focus->mailbox;
100 }
101
102 // service options breakdown
103 $tls = '';
104 $notls = '';
105 $cert = '';
106 $novalidate_cert = '';
107 $ssl = '';
108 if(!empty($focus->service)) {
109         // will always have 2 values: /tls || /notls and /validate-cert || /novalidate-cert
110         $exServ = explode('::', $focus->service);
111         if($exServ[0] == 'tls') {
112                 $tls = "CHECKED";
113         } elseif($exServ[5] == 'notls') {
114                 $notls = "CHECKED";
115         }
116         if($exServ[1] == 'validate-cert') {
117                 $cert = "CHECKED";
118         } elseif($exServ[4] == 'novalidate-cert') {
119                 $novalidate_cert = 'CHECKED';
120         }
121         if(isset($exServ[2]) && !empty($exServ[2]) && $exServ[2] == 'ssl') {
122                 $ssl = "CHECKED";
123         }
124 }
125 $mark_read = '';
126 if($focus->delete_seen == 0 || empty($focus->delete_seen)) {
127         $mark_read = 'CHECKED';
128 }
129
130 // mailbox type
131
132 if ($focus->is_personal) {
133         array_splice($domMailBoxType, 1, 1);
134 } // if
135 $mailbox_type = get_select_options_with_id($domMailBoxType, $focus->mailbox_type);
136
137 // auto-reply email template
138 $email_templates_arr = get_bean_select_array(true, 'EmailTemplate','name', '','name',true);
139
140 if(!empty($focus->stored_options)) {
141         $storedOptions = unserialize(base64_decode($focus->stored_options));
142         $from_name = $storedOptions['from_name'];
143         $from_addr = $storedOptions['from_addr'];
144
145         $reply_to_name = (isset($storedOptions['reply_to_name'])) ? $storedOptions['reply_to_name'] : "";
146         $reply_to_addr = (isset($storedOptions['reply_to_addr'])) ? $storedOptions['reply_to_addr'] : "";
147
148         $trashFolder = (isset($storedOptions['trashFolder'])) ? $storedOptions['trashFolder'] : "";
149         $sentFolder = (isset($storedOptions['sentFolder'])) ? $storedOptions['sentFolder'] : "";
150         $distrib_method = (isset($storedOptions['distrib_method'])) ? $storedOptions['distrib_method'] : "";
151         $create_case_email_template = (isset($storedOptions['create_case_email_template'])) ? $storedOptions['create_case_email_template'] : "";
152         $email_num_autoreplies_24_hours = (isset($storedOptions['email_num_autoreplies_24_hours'])) ? $storedOptions['email_num_autoreplies_24_hours'] : $focus->defaultEmailNumAutoreplies24Hours;
153
154         if($storedOptions['only_since']) {
155                 $only_since = 'CHECKED';
156         } else {
157                 $only_since = '';
158         }
159         if(isset($storedOptions['filter_domain']) && !empty($storedOptions['filter_domain'])) {
160                 $filterDomain = $storedOptions['filter_domain'];
161         } else {
162                 $filterDomain = '';
163         }
164         if(!isset($storedOptions['leaveMessagesOnMailServer']) || $storedOptions['leaveMessagesOnMailServer'] == 1) {
165                 $leaveMessagesOnMailServer = 1;
166         } else {
167                 $leaveMessagesOnMailServer = 0;
168         } // else
169 } else { // initialize empty vars for template
170         $from_name = $current_user->name;
171         $from_addr = $current_user->email1;
172         $reply_to_name = '';
173         $reply_to_addr = '';
174         $only_since = '';
175         $filterDomain = '';
176         $trashFolder = '';
177         $sentFolder = '';
178         $distrib_method ='';
179         $create_case_email_template='';
180         $leaveMessagesOnMailServer = 1;
181         $email_num_autoreplies_24_hours = $focus->defaultEmailNumAutoreplies24Hours;
182 } // else
183
184 // return action
185 if(isset($focus->id)) {
186         $return_action = 'DetailView';
187     $validatePass = FALSE;
188 } else {
189         $return_action = 'ListView';
190     $validatePass = TRUE;
191 }
192
193 // javascript
194 $javascript->setSugarBean($focus);
195 $javascript->setFormName('EditView');
196
197 //If we are creating a duplicate, remove the email_password from being required since this
198 //can be derived from the InboundEmail we are duplicating from
199 if($isDuplicate && isset($focus->required_fields['email_password']))
200 {
201    unset($focus->required_fields['email_password']);
202 }
203
204 $javascript->addRequiredFields();
205 $javascript->addFieldGeneric('email_user', 'alpha', $mod_strings['LBL_LOGIN'], true);
206 $javascript->addFieldGeneric('email_password', 'alpha', $mod_strings['LBL_PASSWORD'], $validatePass);
207 $javascript->addFieldRange('email_num_autoreplies_24_hours', 'int', $mod_strings['LBL_MAX_AUTO_REPLIES'], true, "", 1, $focus->maxEmailNumAutoreplies24Hours);
208
209 $r = $focus->db->query('SELECT value FROM config WHERE name = \'fromname\'');
210 $a = $focus->db->fetchByAssoc($r);
211 $default_from_name = $a['value'];
212 $r = $focus->db->query('SELECT value FROM config WHERE name = \'fromaddress\'');
213 $a = $focus->db->fetchByAssoc($r);
214 $default_from_addr = $a['value'];
215
216 /* End custom setup logic */
217
218
219 // TEMPLATE ASSIGNMENTS
220 if ($focus->mailbox_type == 'template') {
221         $xtpl = new XTemplate('modules/InboundEmail/EmailAccountTemplateEditView.html');
222 } else {
223         $xtpl = new XTemplate('modules/InboundEmail/EditView.html');
224 }
225 // if no IMAP libraries available, disable Save/Test Settings
226 if(!function_exists('imap_open')) {
227         $xtpl->assign('IE_DISABLED', 'DISABLED');
228 }
229 // standard assigns
230 $xtpl->assign('MOD', $mod_strings);
231 $xtpl->assign('APP', $app_strings);
232 $xtpl->assign('THEME', SugarThemeRegistry::current()->__toString());
233 $xtpl->assign('GRIDLINE', $gridline);
234 $xtpl->assign('MODULE', 'InboundEmail');
235 $xtpl->assign('RETURN_MODULE', 'InboundEmail');
236 $xtpl->assign('RETURN_ID', $focus->id);
237 $xtpl->assign('RETURN_ACTION', $return_action);
238 // module specific
239 //$xtpl->assign('ROLLOVER', $email->rolloverStyle);
240 $xtpl->assign("EMAIL_OPTIONS", $mod_strings['LBL_EMAIL_OPTIONS']);
241 $xtpl->assign('MODULE_TITLE', getClassicModuleTitle('InboundEmail', array($mod_strings['LBL_MODULE_NAME'],$focus->name), true));
242 $xtpl->assign('ID', $focus->id);
243 $xtpl->assign('NAME', $focus->name);
244 $xtpl->assign('STATUS', $status);
245 $xtpl->assign('SERVER_URL', $focus->server_url);
246 $xtpl->assign('USER', $focus->email_user);
247 $xtpl->assign('ORIGIN_ID', isset($origin_id)?$origin_id:'');
248 // Don't send password back
249 $xtpl->assign('HAS_PASSWORD', empty($focus->email_password)?0:1);
250 $xtpl->assign('TRASHFOLDER', $trashFolder);
251 $xtpl->assign('SENTFOLDER', $sentFolder);
252 $xtpl->assign('MAILBOX', $mailbox);
253 $xtpl->assign('TLS', $tls);
254 $xtpl->assign('NOTLS', $notls);
255 $xtpl->assign('CERT', $cert);
256 $xtpl->assign('NOVALIDATE_CERT', $novalidate_cert);
257 $xtpl->assign('SSL', $ssl);
258
259 $protocol = filterInboundEmailPopSelection($app_list_strings['dom_email_server_type']);
260 $xtpl->assign('PROTOCOL', get_select_options_with_id($protocol, $focus->protocol));
261 $xtpl->assign('MARK_READ', $mark_read);
262 $xtpl->assign('MAILBOX_TYPE', $focus->mailbox_type);
263 $xtpl->assign('TEMPLATE_ID', $focus->template_id);
264 $xtpl->assign('EMAIL_TEMPLATE_OPTIONS', get_select_options_with_id($email_templates_arr, $focus->template_id));
265 $xtpl->assign('ONLY_SINCE', $only_since);
266 $xtpl->assign('FILTER_DOMAIN', $filterDomain);
267 $xtpl->assign('EMAIL_NUM_AUTOREPLIES_24_HOURS', $email_num_autoreplies_24_hours);
268 if(!empty($focus->port)) {
269         $xtpl->assign('PORT', $focus->port);
270 }
271 // groups
272 $groupId = "";
273 $is_auto_import = "";
274 $allow_outbound = '';
275 if(isset($focus->id))
276         $groupId = $focus->group_id;
277 else
278 {
279         $groupId = create_guid();
280         $is_auto_import = 'checked';
281     $xtpl->assign('EMAIL_PASS_REQ_SYMB', $app_strings['LBL_REQUIRED_SYMBOL']);
282 }
283
284 $xtpl->assign('GROUP_ID', $groupId);
285 // auto-reply stuff
286 $xtpl->assign('FROM_NAME', $from_name);
287 $xtpl->assign('FROM_ADDR', $from_addr);
288 $xtpl->assign('DEFAULT_FROM_NAME', $default_from_name);
289 $xtpl->assign('DEFAULT_FROM_ADDR', $default_from_addr);
290 $xtpl->assign('REPLY_TO_NAME', $reply_to_name);
291 $xtpl->assign('REPLY_TO_ADDR', $reply_to_addr);
292 $createCaseRowStyle = "display:none";
293 if($focus->template_id) {
294         $xtpl->assign("EDIT_TEMPLATE","visibility:inline");
295 } else {
296         $xtpl->assign("EDIT_TEMPLATE","visibility:hidden");
297 }
298 if($focus->port == 110 || $focus->port == 995) {
299         $xtpl->assign('DISPLAY', "display:''");
300 } else {
301         $xtpl->assign('DISPLAY', "display:none");
302 }
303 $leaveMessagesOnMailServerStyle = "display:none";
304 if($focus->is_personal) {
305         $xtpl->assign('DISABLE_GROUP', 'DISABLED');
306         $xtpl->assign('EDIT_GROUP_FOLDER_STYLE', "display:none");
307         $xtpl->assign('CREATE_GROUP_FOLDER_STYLE', "display:none");
308         $xtpl->assign('MAILBOX_TYPE_STYLE', "display:none");
309         $xtpl->assign('AUTO_IMPORT_STYLE', "display:none");
310 } else {
311         $folder = new SugarFolder();
312         $xtpl->assign('CREATE_GROUP_FOLDER_STYLE', "display:''");
313         $xtpl->assign('MAILBOX_TYPE_STYLE', "display:''");
314         $xtpl->assign('AUTO_IMPORT_STYLE', "display:''");
315         $ret = $folder->getFoldersForSettings($current_user);
316
317         //For existing records, do not allow
318         $is_auto_import_disabled = "";
319         if (!empty($focus->groupfolder_id))
320         {
321                 $is_auto_import = "checked";
322             $xtpl->assign('EDIT_GROUP_FOLDER_STYLE', "visibility:inline");
323                 $leaveMessagesOnMailServerStyle = "display:''";
324                 $allow_outbound = (isset($storedOptions['allow_outbound_group_usage']) && $storedOptions['allow_outbound_group_usage'] == 1) ? 'CHECKED'  : '';
325         }
326         else
327         {
328                 $xtpl->assign('EDIT_GROUP_FOLDER_STYLE', "visibility:hidden");
329         }
330
331         $xtpl->assign('ALLOW_OUTBOUND_USAGE', $allow_outbound);
332         $xtpl->assign('IS_AUTO_IMPORT', $is_auto_import);
333
334         if ($focus->isMailBoxTypeCreateCase())
335                 $createCaseRowStyle = "display:''";
336
337 }
338
339 $xtpl->assign('hasGrpFld',$focus->groupfolder_id == null ? '' : 'checked="1"');
340 $xtpl->assign('LEAVEMESSAGESONMAILSERVER_STYLE', $leaveMessagesOnMailServerStyle);
341 $xtpl->assign('LEAVEMESSAGESONMAILSERVER', get_select_options_with_id($app_list_strings['dom_int_bool'], $leaveMessagesOnMailServer));
342 $distributionMethod = get_select_options_with_id($app_list_strings['dom_email_distribution_for_auto_create'], $distrib_method);
343 $xtpl->assign('DISTRIBUTION_METHOD', $distributionMethod);
344 $xtpl->assign('CREATE_CASE_ROW_STYLE', $createCaseRowStyle);
345 $xtpl->assign('CREATE_CASE_EMAIL_TEMPLATE_OPTIONS', get_select_options_with_id($email_templates_arr, $create_case_email_template));
346 if(!empty($create_case_email_template)) {
347         $xtpl->assign("CREATE_CASE_EDIT_TEMPLATE","visibility:inline");
348 } else {
349         $xtpl->assign("CREATE_CASE_EDIT_TEMPLATE","visibility:hidden");
350 }
351
352 $quicksearch_js = "";
353
354 //$javascript = get_set_focus_js(). $javascript->getScript() . $quicksearch_js;
355 $xtpl->assign('JAVASCRIPT', get_set_focus_js(). $javascript->getScript() . $quicksearch_js);
356
357 // WINDOWS work arounds
358 //if(is_windows()) {
359 //      $xtpl->assign('MAYBE', '<style> div.maybe { display:none; }</style>');
360 //}
361 // PARSE AND PRINT
362 //Overrides for bounce mailbox accounts
363 if ($focus->mailbox_type == 'bounce')
364 {
365     $xtpl->assign('MODULE_TITLE', getClassicModuleTitle('InboundEmail', array($mod_strings['LBL_BOUNCE_MODULE_NAME'],$focus->name), true));
366     $xtpl->assign("EMAIL_OPTIONS", $mod_strings['LBL_EMAIL_BOUNCE_OPTIONS']);
367     $xtpl->assign('MAILBOX_TYPE_STYLE', "display:none");
368     $xtpl->assign('AUTO_IMPORT_STYLE', "display:none");
369 }
370 elseif ($focus->mailbox_type == 'createcase')
371     $xtpl->assign("IS_CREATE_CASE", 'checked');
372
373 else if( $focus->is_personal == '1')
374      $xtpl->assign('MODULE_TITLE', getClassicModuleTitle('InboundEmail', array($mod_strings['LBL_PERSONAL_MODULE_NAME'],$focus->name), true));
375
376 //else
377
378
379 $xtpl->parse("main");
380 $xtpl->out("main");
381 ?>