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 $_REQUEST['edit']='true';
40 require_once('include/SugarFolders/SugarFolders.php');
41 require_once('include/templates/TemplateGroupChooser.php');
46 global $app_list_strings;
49 $focus = new InboundEmail();
51 $javascript = new Javascript();
53 /* Start standard EditView setup logic */
55 $domMailBoxType = $app_list_strings['dom_mailbox_type'];
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']);
62 sugar_die($app_strings['ERROR_NO_RECORD']);
67 if(!empty($_REQUEST['mailbox_type']))
68 $focus->mailbox_type = $_REQUEST['mailbox_type'];
70 //Default to imap protocol for new accounts.
71 $focus->protocol = 'imap';
74 if($focus->mailbox_type == 'bounce')
76 unset($domMailBoxType['pick']);
77 unset($domMailBoxType['createcase']);
80 unset($domMailBoxType['bounce']);
82 if(isset($_REQUEST['isDuplicate']) && $_REQUEST['isDuplicate'] == 'true') {
83 $GLOBALS['log']->debug("isDuplicate found - duplicating record of id: ".$focus->id);
84 $origin_id = $focus->id;
88 $GLOBALS['log']->info("InboundEmail Edit View");
89 /* End standard EditView setup logic */
91 /* Start custom setup logic */
93 $status = get_select_options_with_id_separate_key($app_list_strings['user_status_dom'],$app_list_strings['user_status_dom'], $focus->status);
94 // default MAILBOX value
95 if(empty($focus->mailbox)) {
98 $mailbox = $focus->mailbox;
101 // service options breakdown
105 $novalidate_cert = '';
107 if(!empty($focus->service)) {
108 // will always have 2 values: /tls || /notls and /validate-cert || /novalidate-cert
109 $exServ = explode('::', $focus->service);
110 if($exServ[0] == 'tls') {
112 } elseif($exServ[5] == 'notls') {
115 if($exServ[1] == 'validate-cert') {
117 } elseif($exServ[4] == 'novalidate-cert') {
118 $novalidate_cert = 'CHECKED';
120 if(isset($exServ[2]) && !empty($exServ[2]) && $exServ[2] == 'ssl') {
125 if($focus->delete_seen == 0 || empty($focus->delete_seen)) {
126 $mark_read = 'CHECKED';
131 if ($focus->is_personal) {
132 array_splice($domMailBoxType, 1, 1);
134 $mailbox_type = get_select_options_with_id($domMailBoxType, $focus->mailbox_type);
136 // auto-reply email template
137 $email_templates_arr = get_bean_select_array(true, 'EmailTemplate','name', '','name',true);
139 if(!empty($focus->stored_options)) {
140 $storedOptions = unserialize(base64_decode($focus->stored_options));
141 $from_name = $storedOptions['from_name'];
142 $from_addr = $storedOptions['from_addr'];
144 $reply_to_name = (isset($storedOptions['reply_to_name'])) ? $storedOptions['reply_to_name'] : "";
145 $reply_to_addr = (isset($storedOptions['reply_to_addr'])) ? $storedOptions['reply_to_addr'] : "";
147 $trashFolder = (isset($storedOptions['trashFolder'])) ? $storedOptions['trashFolder'] : "";
148 $sentFolder = (isset($storedOptions['sentFolder'])) ? $storedOptions['sentFolder'] : "";
149 $distrib_method = (isset($storedOptions['distrib_method'])) ? $storedOptions['distrib_method'] : "";
150 $create_case_email_template = (isset($storedOptions['create_case_email_template'])) ? $storedOptions['create_case_email_template'] : "";
151 $email_num_autoreplies_24_hours = (isset($storedOptions['email_num_autoreplies_24_hours'])) ? $storedOptions['email_num_autoreplies_24_hours'] : $focus->defaultEmailNumAutoreplies24Hours;
153 if($storedOptions['only_since']) {
154 $only_since = 'CHECKED';
158 if(isset($storedOptions['filter_domain']) && !empty($storedOptions['filter_domain'])) {
159 $filterDomain = $storedOptions['filter_domain'];
163 if(!isset($storedOptions['leaveMessagesOnMailServer']) || $storedOptions['leaveMessagesOnMailServer'] == 1) {
164 $leaveMessagesOnMailServer = 1;
166 $leaveMessagesOnMailServer = 0;
168 } else { // initialize empty vars for template
169 $from_name = $current_user->name;
170 $from_addr = $current_user->email1;
178 $create_case_email_template='';
179 $leaveMessagesOnMailServer = 1;
180 $email_num_autoreplies_24_hours = $focus->defaultEmailNumAutoreplies24Hours;
184 if(isset($focus->id)) {
185 $return_action = 'DetailView';
186 $validatePass = FALSE;
188 $return_action = 'ListView';
189 $validatePass = TRUE;
193 $javascript->setSugarBean($focus);
194 $javascript->setFormName('EditView');
195 $javascript->addRequiredFields();
196 $javascript->addFieldGeneric('email_user', 'alpha', $mod_strings['LBL_LOGIN'], true);
197 $javascript->addFieldGeneric('email_password', 'alpha', $mod_strings['LBL_PASSWORD'], $validatePass);
198 $javascript->addFieldRange('email_num_autoreplies_24_hours', 'int', $mod_strings['LBL_MAX_AUTO_REPLIES'], true, "", 1, $focus->maxEmailNumAutoreplies24Hours);
200 $r = $focus->db->query('SELECT value FROM config WHERE name = \'fromname\'');
201 $a = $focus->db->fetchByAssoc($r);
202 $default_from_name = $a['value'];
203 $r = $focus->db->query('SELECT value FROM config WHERE name = \'fromaddress\'');
204 $a = $focus->db->fetchByAssoc($r);
205 $default_from_addr = $a['value'];
207 /* End custom setup logic */
210 // TEMPLATE ASSIGNMENTS
211 if ($focus->mailbox_type == 'template') {
212 $xtpl = new XTemplate('modules/InboundEmail/EmailAccountTemplateEditView.html');
214 $xtpl = new XTemplate('modules/InboundEmail/EditView.html');
216 // if no IMAP libraries available, disable Save/Test Settings
217 if(!function_exists('imap_open')) {
218 $xtpl->assign('IE_DISABLED', 'DISABLED');
221 $xtpl->assign('MOD', $mod_strings);
222 $xtpl->assign('APP', $app_strings);
223 $xtpl->assign('THEME', SugarThemeRegistry::current()->__toString());
224 $xtpl->assign('GRIDLINE', $gridline);
225 $xtpl->assign('MODULE', 'InboundEmail');
226 $xtpl->assign('RETURN_MODULE', 'InboundEmail');
227 $xtpl->assign('RETURN_ID', $focus->id);
228 $xtpl->assign('RETURN_ACTION', $return_action);
230 //$xtpl->assign('ROLLOVER', $email->rolloverStyle);
231 $xtpl->assign("EMAIL_OPTIONS", $mod_strings['LBL_EMAIL_OPTIONS']);
232 $xtpl->assign('MODULE_TITLE', getClassicModuleTitle($mod_strings['LBL_MODULE_TITLE'], array($mod_strings['LBL_MODULE_NAME'],$focus->name), true));
233 $xtpl->assign('ID', $focus->id);
234 $xtpl->assign('NAME', $focus->name);
235 $xtpl->assign('STATUS', $status);
236 $xtpl->assign('SERVER_URL', $focus->server_url);
237 $xtpl->assign('USER', $focus->email_user);
238 $xtpl->assign('ORIGIN_ID', isset($origin_id)?$origin_id:'');
239 // Don't send password back
240 $xtpl->assign('HAS_PASSWORD', empty($focus->email_password)?0:1);
241 $xtpl->assign('TRASHFOLDER', $trashFolder);
242 $xtpl->assign('SENTFOLDER', $sentFolder);
243 $xtpl->assign('MAILBOX', $mailbox);
244 $xtpl->assign('TLS', $tls);
245 $xtpl->assign('NOTLS', $notls);
246 $xtpl->assign('CERT', $cert);
247 $xtpl->assign('NOVALIDATE_CERT', $novalidate_cert);
248 $xtpl->assign('SSL', $ssl);
250 $protocol = filterInboundEmailPopSelection($app_list_strings['dom_email_server_type']);
251 $xtpl->assign('PROTOCOL', get_select_options_with_id($protocol, $focus->protocol));
252 $xtpl->assign('MARK_READ', $mark_read);
253 $xtpl->assign('MAILBOX_TYPE', $focus->mailbox_type);
254 $xtpl->assign('TEMPLATE_ID', $focus->template_id);
255 $xtpl->assign('EMAIL_TEMPLATE_OPTIONS', get_select_options_with_id($email_templates_arr, $focus->template_id));
256 $xtpl->assign('ONLY_SINCE', $only_since);
257 $xtpl->assign('FILTER_DOMAIN', $filterDomain);
258 $xtpl->assign('EMAIL_NUM_AUTOREPLIES_24_HOURS', $email_num_autoreplies_24_hours);
259 if(!empty($focus->port)) {
260 $xtpl->assign('PORT', $focus->port);
264 $is_auto_import = "";
265 $allow_outbound = '';
266 if(isset($focus->id))
267 $groupId = $focus->group_id;
270 $groupId = create_guid();
271 $is_auto_import = 'checked';
272 $xtpl->assign('EMAIL_PASS_REQ_SYMB', $app_strings['LBL_REQUIRED_SYMBOL']);
275 $xtpl->assign('GROUP_ID', $groupId);
277 $xtpl->assign('FROM_NAME', $from_name);
278 $xtpl->assign('FROM_ADDR', $from_addr);
279 $xtpl->assign('DEFAULT_FROM_NAME', $default_from_name);
280 $xtpl->assign('DEFAULT_FROM_ADDR', $default_from_addr);
281 $xtpl->assign('REPLY_TO_NAME', $reply_to_name);
282 $xtpl->assign('REPLY_TO_ADDR', $reply_to_addr);
283 $createCaseRowStyle = "display:none";
284 if($focus->template_id) {
285 $xtpl->assign("EDIT_TEMPLATE","visibility:inline");
287 $xtpl->assign("EDIT_TEMPLATE","visibility:hidden");
289 if($focus->port == 110 || $focus->port == 995) {
290 $xtpl->assign('DISPLAY', "display:''");
292 $xtpl->assign('DISPLAY', "display:none");
294 $leaveMessagesOnMailServerStyle = "display:none";
295 if($focus->is_personal) {
296 $xtpl->assign('DISABLE_GROUP', 'DISABLED');
297 $xtpl->assign('EDIT_GROUP_FOLDER_STYLE', "display:none");
298 $xtpl->assign('CREATE_GROUP_FOLDER_STYLE', "display:none");
299 $xtpl->assign('MAILBOX_TYPE_STYLE', "display:none");
300 $xtpl->assign('AUTO_IMPORT_STYLE', "display:none");
302 $folder = new SugarFolder();
303 $xtpl->assign('CREATE_GROUP_FOLDER_STYLE', "display:''");
304 $xtpl->assign('MAILBOX_TYPE_STYLE', "display:''");
305 $xtpl->assign('AUTO_IMPORT_STYLE', "display:''");
306 $ret = $folder->getFoldersForSettings($current_user);
308 //For existing records, do not allow
309 $is_auto_import_disabled = "";
310 if (!empty($focus->groupfolder_id))
312 $is_auto_import = "checked";
313 $xtpl->assign('EDIT_GROUP_FOLDER_STYLE', "visibility:inline");
314 $leaveMessagesOnMailServerStyle = "display:''";
315 $allow_outbound = (isset($storedOptions['allow_outbound_group_usage']) && $storedOptions['allow_outbound_group_usage'] == 1) ? 'CHECKED' : '';
319 $xtpl->assign('EDIT_GROUP_FOLDER_STYLE', "visibility:hidden");
322 $xtpl->assign('ALLOW_OUTBOUND_USAGE', $allow_outbound);
323 $xtpl->assign('IS_AUTO_IMPORT', $is_auto_import);
325 if ($focus->isMailBoxTypeCreateCase())
326 $createCaseRowStyle = "display:''";
330 $xtpl->assign('hasGrpFld',$focus->groupfolder_id == null ? '' : 'checked="1"');
331 $xtpl->assign('LEAVEMESSAGESONMAILSERVER_STYLE', $leaveMessagesOnMailServerStyle);
332 $xtpl->assign('LEAVEMESSAGESONMAILSERVER', get_select_options_with_id($app_list_strings['dom_int_bool'], $leaveMessagesOnMailServer));
333 $distributionMethod = get_select_options_with_id($app_list_strings['dom_email_distribution_for_auto_create'], $distrib_method);
334 $xtpl->assign('DISTRIBUTION_METHOD', $distributionMethod);
335 $xtpl->assign('CREATE_CASE_ROW_STYLE', $createCaseRowStyle);
336 $xtpl->assign('CREATE_CASE_EMAIL_TEMPLATE_OPTIONS', get_select_options_with_id($email_templates_arr, $create_case_email_template));
337 if(!empty($create_case_email_template)) {
338 $xtpl->assign("CREATE_CASE_EDIT_TEMPLATE","visibility:inline");
340 $xtpl->assign("CREATE_CASE_EDIT_TEMPLATE","visibility:hidden");
343 $quicksearch_js = "";
345 //$javascript = get_set_focus_js(). $javascript->getScript() . $quicksearch_js;
346 $xtpl->assign('JAVASCRIPT', get_set_focus_js(). $javascript->getScript() . $quicksearch_js);
348 // WINDOWS work arounds
350 // $xtpl->assign('MAYBE', '<style> div.maybe { display:none; }</style>');
353 //Overrides for bounce mailbox accounts
354 if ($focus->mailbox_type == 'bounce')
356 $xtpl->assign('MODULE_TITLE', getClassicModuleTitle($mod_strings['LBL_MODULE_TITLE'], array($mod_strings['LBL_BOUNCE_MODULE_NAME'],$focus->name), true));
357 $xtpl->assign("EMAIL_OPTIONS", $mod_strings['LBL_EMAIL_BOUNCE_OPTIONS']);
358 $xtpl->assign('MAILBOX_TYPE_STYLE', "display:none");
359 $xtpl->assign('AUTO_IMPORT_STYLE', "display:none");
361 elseif ($focus->mailbox_type == 'createcase')
362 $xtpl->assign("IS_CREATE_CASE", 'checked');
364 else if( $focus->is_personal == '1')
365 $xtpl->assign('MODULE_TITLE', getClassicModuleTitle($mod_strings['LBL_MODULE_TITLE'], array($mod_strings['LBL_PERSONAL_MODULE_NAME'],$focus->name), true));
370 $xtpl->parse("main");