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.
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 ********************************************************************************/
39 $GLOBALS['log']->info("Email edit view");
41 require_once('include/SugarTinyMCE.php');
48 global $app_list_strings;
51 global $sugar_version, $sugar_config;
54 ///////////////////////////////////////////////////////////////////////////////
55 //// PREPROCESS BEAN DATA FOR DISPLAY
57 $email_type = 'archived';
59 if(isset($_REQUEST['record'])) {
60 $focus->retrieve($_REQUEST['record']);
62 if(!empty($_REQUEST['type'])) {
63 $email_type = $_REQUEST['type'];
64 } elseif(!empty($focus->id)) {
65 $email_type = $focus->type;
68 $focus->type = $email_type;
70 //needed when creating a new email with default values passed in
71 if(isset($_REQUEST['contact_name']) && is_null($focus->contact_name)) {
72 $focus->contact_name = $_REQUEST['contact_name'];
75 if(!empty($_REQUEST['load_id']) && !empty($beanList[$_REQUEST['load_module']])) {
76 $class_name = $beanList[$_REQUEST['load_module']];
77 require_once($beanFiles[$class_name]);
78 $contact = new $class_name();
79 if($contact->retrieve($_REQUEST['load_id'])) {
80 $link_id = $class_name . '_id';
81 $focus->$link_id = $_REQUEST['load_id'];
82 $focus->contact_name = (isset($contact->full_name)) ? $contact->full_name : $contact->name;
83 $focus->to_addrs_names = $focus->contact_name;
84 $focus->to_addrs_ids = $_REQUEST['load_id'];
85 //Retrieve the email address.
86 //If Opportunity or Case then Oppurtinity/Case->Accounts->(email_addr_bean_rel->email_addresses)
87 //If Contacts, Leads etc.. then Contact->(email_addr_bean_rel->email_addresses)
88 $sugarEmailAddress = new SugarEmailAddress();
89 if($class_name == 'Opportunity' || $class_name == 'aCase'){
90 $account = new Account();
91 if($contact->account_id != null && $account->retrieve($contact->account_id)){
92 $sugarEmailAddress->handleLegacyRetrieve($account);
93 if(isset($account->email1)){
94 $focus->to_addrs_emails = $account->email1;
95 $focus->to_addrs = "$focus->contact_name <$account->email1>";
100 $sugarEmailAddress->handleLegacyRetrieve($contact);
101 if(isset($contact->email1)){
102 $focus->to_addrs_emails = $contact->email1;
103 $focus->to_addrs = "$focus->contact_name <$contact->email1>";
106 if(!empty($_REQUEST['parent_type']) && empty($app_list_strings['record_type_display'][$_REQUEST['parent_type']])){
107 if(!empty($app_list_strings['record_type_display'][$_REQUEST['load_module']])){
108 $_REQUEST['parent_type'] = $_REQUEST['load_module'];
109 $_REQUEST['parent_id'] = $focus->contact_id;
110 $_REQUEST['parent_name'] = $focus->to_addrs_names;
112 unset($_REQUEST['parent_type']);
113 unset($_REQUEST['parent_id']);
114 unset($_REQUEST['parent_name']);
119 if(isset($_REQUEST['contact_id']) && is_null($focus->contact_id)) {
120 $focus->contact_id = $_REQUEST['contact_id'];
122 if(isset($_REQUEST['parent_name'])) {
123 $focus->parent_name = $_REQUEST['parent_name'];
125 if(isset($_REQUEST['parent_id'])) {
126 $focus->parent_id = $_REQUEST['parent_id'];
128 if(isset($_REQUEST['parent_type'])) {
129 $focus->parent_type = $_REQUEST['parent_type'];
131 elseif(is_null($focus->parent_type)) {
132 $focus->parent_type = $app_list_strings['record_type_default_key'];
134 if(isset($_REQUEST['to_email_addrs'])) {
135 $focus->to_addrs = $_REQUEST['to_email_addrs'];
137 // needed when clicking through a Contacts detail view:
138 if(isset($_REQUEST['to_addrs_ids'])) {
139 $focus->to_addrs_ids = $_REQUEST['to_addrs_ids'];
141 if(isset($_REQUEST['to_addrs_emails'])) {
142 $focus->to_addrs_emails = $_REQUEST['to_addrs_emails'];
144 if(isset($_REQUEST['to_addrs_names'])) {
145 $focus->to_addrs_names = $_REQUEST['to_addrs_names'];
147 // user's email, go through 3 levels of precedence:
148 $from = $current_user->getEmailInfo();
149 //// END PREPROCESSING
150 ///////////////////////////////////////////////////////////////////////////////
153 ///////////////////////////////////////////////////////////////////////////////
154 //// XTEMPLATE ASSIGNMENT
155 if($email_type == 'archived') {
156 if(isset($focus->name)) $params_module_title=array($mod_strings['LBL_ARCHIVED_EMAILS_CREATE'], $focus->name);
157 else $params_module_title=array($mod_strings['LBL_ARCHIVED_EMAILS_CREATE']);
158 echo getClassicModuleTitle('Emails', $params_module_title, true);
159 $xtpl=new XTemplate('modules/Emails/EditViewArchive.html');
162 if(empty($_REQUEST['parent_module'])) {
163 $parent_module = "Emails";
165 $parent_module = $_REQUEST['parent_module'];
167 if(empty($_REQUEST['parent_id'])) {
170 $parent_id = $_REQUEST['parent_id'];
172 if(empty($_REQUEST['return_module'])) {
173 $return_module = "Emails";
175 $return_module = $_REQUEST['return_module'];
177 if(empty($_REQUEST['return_module'])) {
180 $return_id = $_REQUEST['return_module'];
182 $replyType = "reply";
183 if ($_REQUEST['type'] == 'forward') {
184 $replyType = 'forward';
186 header("Location: index.php?module=Emails&action=Compose&record=$focus->id&replyForward=true&reply=$replyType");
191 // CHECK USER'S EMAIL SETTINGS TO ENABLE/DISABLE 'SEND' BUTTON
192 if(!$focus->check_email_settings() &&($email_type == 'out' || $email_type == 'draft')) {
193 print "<font color='red'>".$mod_strings['WARNING_SETTINGS_NOT_CONF']." <a href='index.php?module=Users&action=EditView&record=".$current_user->id."&return_module=Emails&type=out&return_action=EditView'>".$mod_strings['LBL_EDIT_MY_SETTINGS']."</a></font>";
194 $xtpl->assign("DISABLE_SEND", 'DISABLED');
197 // CHECK THAT SERVER HAS A PLACE TO PUT UPLOADED TEMP FILES SO THAT ATTACHMENTS WILL WORK
199 $tmpUploadDir = ini_get('upload_tmp_dir');
200 if(!empty($tmpUploadDir)) {
201 if(!is_writable($tmpUploadDir)) {
202 echo "<font color='red'>{$mod_strings['WARNING_UPLOAD_DIR_NOT_WRITABLE']}</font>";
205 //echo "<font color='red'>{$mod_strings['WARNING_NO_UPLOAD_DIR']}</font>";
209 ///////////////////////////////////////////////////////////////////////////////
210 //// INBOUND EMAIL HANDLING
211 if(isset($_REQUEST['email_name'])) {
212 $name = str_replace('_',' ',$_REQUEST['email_name']);
214 if(isset($_REQUEST['inbound_email_id'])) {
215 $ieMail = new Email();
216 $ieMail->retrieve($_REQUEST['inbound_email_id']);
219 // cn: bug 9725: replies/forwards lose real content
220 $quotedHtml = $ieMail->quoteHtmlEmail($ieMail->description_html);
223 $desc = nl2br(trim($ieMail->description));
225 $exDesc = explode('<br />', $desc);
226 foreach($exDesc as $k => $line) {
227 $quoted .= '> '.trim($line)."\r";
230 // prefill empties with the other's contents
231 if(empty($quotedHtml) && !empty($quoted)) {
232 $quotedHtml = nl2br($quoted);
234 if(empty($quoted) && !empty($quotedHtml)) {
235 $quoted = strip_tags(br2nl($quotedHtml));
238 // forwards have special text
239 if($_REQUEST['type'] == 'forward') {
240 $header = $ieMail->getForwardHeader();
241 // subject is handled in Subject line handling below
243 // we have a reply in focus
244 $header = $ieMail->getReplyHeader();
247 $quoted = br2nl($header.$quoted);
248 $quotedHtml = $header.$quotedHtml;
251 // if not a forward: it's a reply
252 if($_REQUEST['type'] != 'forward') {
253 $ieMailName = 'RE: '.$ieMail->name;
255 $ieMailName = $ieMail->name;
258 $focus->id = null; // nulling this to prevent overwriting a replied email(we're basically doing a "Duplicate" function)
259 $focus->to_addrs = $ieMail->from_addr;
260 $focus->description = $quoted; // don't know what i was thinking: ''; // this will be filled on save/send
261 $focus->description_html = $quotedHtml; // cn: bug 7357 - htmlentities() breaks FCKEditor
262 $focus->parent_type = $ieMail->parent_type;
263 $focus->parent_id = $ieMail->parent_id;
264 $focus->parent_name = $ieMail->parent_name;
265 $focus->name = $ieMailName;
266 $xtpl->assign('INBOUND_EMAIL_ID',$_REQUEST['inbound_email_id']);
268 if(!empty($ieMail->status)) {
269 // "Read" flag for InboundEmail
270 if($ieMail->status == 'unread') {
271 // creating a new instance here to avoid data corruption below
273 $e->retrieve($ieMail->id);
276 $email_type = $e->status;
280 ///////////////////////////////////////////////////////////////////////////
281 //// PRIMARY PARENT LINKING
282 if(empty($focus->parent_type) && empty($focus->parent_id)) {
283 $focus->fillPrimaryParentFields();
285 //// END PRIMARY PARENT LINKING
286 ///////////////////////////////////////////////////////////////////////////
288 // setup for my/mailbox email switcher
289 $mbox = $ieMail->getMailboxDefaultEmail();
290 $user = $current_user->getPreferredEmail();
291 $useGroup = ' <input id="use_mbox" name="use_mbox" type="checkbox" CHECKED onClick="switchEmail()" >
292 <script type="text/javascript">
293 function switchEmail() {
294 var mboxName = "'.$mbox['name'].'";
295 var mboxAddr = "'.$mbox['email'].'";
296 var userName = "'.$user['name'].'";
297 var userAddr = "'.$user['email'].'";
299 if(document.getElementById("use_mbox").checked) {
300 document.getElementById("from_addr_field").value = mboxName + " <" + mboxAddr + ">";
301 document.getElementById("from_addr_name").value = mboxName;
302 document.getElementById("from_addr_email").value = mboxAddr;
304 document.getElementById("from_addr_field").value = userName + " <" + userAddr + ">";
305 document.getElementById("from_addr_name").value = userName;
306 document.getElementById("from_addr_email").value = userAddr;
312 $useGroup .= $mod_strings['LBL_USE_MAILBOX_INFO'];
314 $xtpl->assign('FROM_ADDR_GROUP', $useGroup);
316 //// END INBOUND EMAIL HANDLING
317 ///////////////////////////////////////////////////////////////////////////////
319 ///////////////////////////////////////////////////////////////////////////////
320 //// SUBJECT FIELD MANIPULATION
322 if(!empty($_REQUEST['parent_id']) && !empty($_REQUEST['parent_type'])) {
323 $focus->parent_id = $_REQUEST['parent_id'];
324 $focus->parent_type = $_REQUEST['parent_type'];
326 if(!empty($focus->parent_id) && !empty($focus->parent_type)) {
327 if($focus->parent_type == 'Cases') {
329 $myCase = new aCase();
330 $myCase->retrieve($focus->parent_id);
331 $myCaseMacro = $myCase->getEmailSubjectMacro();
332 if(isset($ieMail->name) && !empty($ieMail->name)) { // if replying directly to an InboundEmail
333 $oldEmailSubj = $ieMail->name;
334 } elseif(isset($_REQUEST['parent_name']) && !empty($_REQUEST['parent_name'])) {
335 $oldEmailSubj = $_REQUEST['parent_name'];
337 $oldEmailSubj = $focus->name; // replying to an email using old subject
340 if(!preg_match('/^re:/i', $oldEmailSubj)) {
341 $oldEmailSubj = 'RE: '.$oldEmailSubj;
343 $focus->name = $oldEmailSubj;
345 if(strpos($focus->name, str_replace('%1',$myCase->case_number,$myCaseMacro))) {
346 $name = $focus->name;
348 $name = $focus->name.' '.str_replace('%1',$myCase->case_number,$myCaseMacro);
351 $name = $focus->name;
354 if(empty($focus->name)) {
357 $name = $focus->name;
360 if($email_type == 'forward') {
361 $name = 'FW: '.$name;
363 //// END SUBJECT FIELD MANIPULATION
364 ///////////////////////////////////////////////////////////////////////////////
366 ///////////////////////////////////////////////////////////////////////////////
367 //// GENERAL TEMPLATE ASSIGNMENTS
368 $xtpl->assign('MOD', $mod_strings);
369 $xtpl->assign('APP', $app_strings);
370 $xtpl->assign('THEME', SugarThemeRegistry::current()->__toString());
371 if(!isset($focus->id)) $xtpl->assign('USER_ID', $current_user->id);
372 if(!isset($focus->id) && isset($_REQUEST['contact_id'])) $xtpl->assign('CONTACT_ID', $_REQUEST['contact_id']);
374 if(isset($_REQUEST['return_module']) && !empty($_REQUEST['return_module'])) {
375 $xtpl->assign('RETURN_MODULE', $_REQUEST['return_module']);
377 $xtpl->assign('RETURN_MODULE', 'Emails');
379 if(isset($_REQUEST['return_action']) && !empty($_REQUEST['return_action']) && ($_REQUEST['return_action'] != 'SubPanelViewer')) {
380 $xtpl->assign('RETURN_ACTION', $_REQUEST['return_action']);
382 $xtpl->assign('RETURN_ACTION', 'DetailView');
384 if(isset($_REQUEST['return_id']) && !empty($_REQUEST['return_id'])) {
385 $xtpl->assign('RETURN_ID', $_REQUEST['return_id']);
387 // handle Create $module then Cancel
388 if(empty($_REQUEST['return_id']) && !isset($_REQUEST['type'])) {
389 $xtpl->assign('RETURN_ACTION', 'index');
392 $xtpl->assign('PRINT_URL', 'index.php?'.$GLOBALS['request_string']);
395 ///////////////////////////////////////////////////////////////////////////////
396 //// QUICKSEARCH CODE
397 require_once('include/QuickSearchDefaults.php');
398 $qsd = QuickSearchDefaults::getQuickSearchDefaults();
399 $sqs_objects = array('EditView_parent_name' => $qsd->getQSParent(),
400 'EditView_assigned_user_name' => $qsd->getQSUser(),
404 $json = getJSONobj();
406 $sqs_objects_encoded = $json->encode($sqs_objects);
407 $quicksearch_js = <<<EOQ
408 <script type="text/javascript" language="javascript">sqs_objects = $sqs_objects_encoded; var dialog_loaded;
409 function parent_typechangeQS() {
410 var new_module = document.EditView.parent_type.value;
411 var sqsId = 'EditView_parent_name';
412 if(new_module == 'Contacts' || new_module == 'Leads' || typeof(disabledModules[new_module]) != 'undefined') {
413 sqs_objects[sqsId]['disable'] = true;
414 document.getElementById('parent_name').readOnly = true;
417 sqs_objects[sqsId]['disable'] = false;
418 document.getElementById('parent_name').readOnly = false;
421 sqs_objects[sqsId]['modules'] = new Array(new_module);
422 if (typeof(QSFieldsArray[sqsId]) != 'undefined')
424 QSFieldsArray[sqsId].sqs.modules = new Array(new_module);
428 parent_typechangeQS();
431 $xtpl->assign('JAVASCRIPT', get_set_focus_js().$quicksearch_js);
432 //// END QUICKSEARCH CODE
433 ///////////////////////////////////////////////////////////////////////////////
435 // cn: bug 14191 - duping archive emails overwrites the original
436 if(!isset($_REQUEST['isDuplicate']) || $_REQUEST['isDuplicate'] != 'true') {
437 $xtpl->assign('ID', $focus->id);
440 if(isset($_REQUEST['parent_type']) && !empty($_REQUEST['parent_type']) && isset($_REQUEST['parent_id']) && !empty($_REQUEST['parent_id'])) {
441 $xtpl->assign('OBJECT_ID', $_REQUEST['parent_id']);
442 $xtpl->assign('OBJECT_TYPE', $_REQUEST['parent_type']);
444 $xtpl->assign('FROM_ADDR', $focus->from_addr);
445 //// prevent TO: prefill when type is 'forward'
446 if($email_type != 'forward') {
447 $xtpl->assign('TO_ADDRS', $focus->to_addrs);
448 $xtpl->assign('TO_ADDRS_IDS', $focus->to_addrs_ids);
449 $xtpl->assign('TO_ADDRS_NAMES', $focus->to_addrs_names);
450 $xtpl->assign('TO_ADDRS_EMAILS', $focus->to_addrs_emails);
451 $xtpl->assign('CC_ADDRS', $focus->cc_addrs);
452 $xtpl->assign('CC_ADDRS_IDS', $focus->cc_addrs_ids);
453 $xtpl->assign('CC_ADDRS_NAMES', $focus->cc_addrs_names);
454 $xtpl->assign('CC_ADDRS_EMAILS', $focus->cc_addrs_emails);
455 $xtpl->assign('BCC_ADDRS', $focus->bcc_addrs);
456 $xtpl->assign('BCC_ADDRS_IDS', $focus->bcc_addrs_ids);
457 $xtpl->assign('BCC_ADDRS_NAMES', $focus->bcc_addrs_names);
458 $xtpl->assign('BCC_ADDRS_EMAILS', $focus->bcc_addrs_emails);
461 //$xtpl->assign('FROM_ADDR', $from['name'].' <'.$from['email'].'>');
462 $xtpl->assign('FROM_ADDR_NAME', $from['name']);
463 $xtpl->assign('FROM_ADDR_EMAIL', $from['email']);
465 $xtpl->assign('NAME', from_html($name));
466 //$xtpl->assign('DESCRIPTION_HTML', from_html($focus->description_html));
467 $xtpl->assign('DESCRIPTION', $focus->description);
468 $xtpl->assign('TYPE',$email_type);
470 // Unimplemented until jscalendar language files are fixed
471 // $xtpl->assign('CALENDAR_LANG',((empty($cal_codes[$current_language])) ? $cal_codes[$default_language] : $cal_codes[$current_language]));
472 $xtpl->assign('CALENDAR_LANG', 'en');
473 $xtpl->assign('CALENDAR_DATEFORMAT', $timedate->get_cal_date_format());
474 $xtpl->assign('DATE_START', $focus->date_start);
475 $xtpl->assign('TIME_FORMAT', '('. $timedate->get_user_time_format().')');
476 $xtpl->assign('TIME_START', substr($focus->time_start,0,5));
477 $xtpl->assign('TIME_MERIDIEM', $timedate->AMPMMenu('',$focus->time_start));
479 $parent_types = $app_list_strings['record_type_display'];
480 $disabled_parent_types = ACLController::disabledModuleList($parent_types,false, 'list');
482 foreach($disabled_parent_types as $disabled_parent_type){
483 if($disabled_parent_type != $focus->parent_type){
484 unset($parent_types[$disabled_parent_type]);
488 $xtpl->assign('TYPE_OPTIONS', get_select_options_with_id($parent_types, $focus->parent_type));
489 $xtpl->assign('USER_DATEFORMAT', '('. $timedate->get_user_date_format().')');
490 $xtpl->assign('PARENT_NAME', $focus->parent_name);
491 $xtpl->assign('PARENT_ID', $focus->parent_id);
492 if(empty($focus->parent_type)) {
493 $xtpl->assign('PARENT_RECORD_TYPE', '');
495 $xtpl->assign('PARENT_RECORD_TYPE', $focus->parent_type);
498 if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])){
500 if(!empty($_REQUEST['record'])){
501 $record = $_REQUEST['record'];
503 $xtpl->assign('ADMIN_EDIT',"<a href='index.php?action=index&module=DynamicLayout&from_action=".$_REQUEST['action'] ."&from_module=".$_REQUEST['module'] ."&record=".$record. "'>".SugarThemeRegistry::current()->getImage("EditLayout","border='0' align='bottom'",null,null,'.gif',$mod_strings['LBL_EDIT_LAYOUT'])."</a>");
506 //// END GENERAL TEMPLATE ASSIGNMENTS
507 ///////////////////////////////////////////////////////////////////////////////
510 ///////////////////////////////////////
512 /// SETUP PARENT POPUP
514 $popup_request_data = array(
515 'call_back_function' => 'set_return',
516 'form_name' => 'EditView',
517 'field_to_name_array' => array(
519 'name' => 'parent_name',
523 $encoded_popup_request_data = $json->encode($popup_request_data);
526 $popup_request_data = array(
527 'call_back_function' => 'set_return',
528 'form_name' => 'EditView',
529 'field_to_name_array' => array(
530 'id' => 'assigned_user_id',
531 'user_name' => 'assigned_user_name',
534 $xtpl->assign('encoded_users_popup_request_data', $json->encode($popup_request_data));
538 ///////////////////////////////////////
540 $change_parent_button = '<input type="button" name="button" tabindex="2" class="button" '
541 . 'title="' . $app_strings['LBL_SELECT_BUTTON_TITLE'] . '" '
542 . 'value="' . $app_strings['LBL_SELECT_BUTTON_LABEL'] . '" '
543 . "onclick='ValidateParentType();' />\n"
544 .'<script>function ValidateParentType() {
545 var parentTypeValue = document.getElementById("parent_type").value;
546 if (trim(parentTypeValue) == ""){
547 alert("' . $mod_strings['LBL_ERROR_SELECT_MODULE'] .'");
550 open_popup(document.EditView.parent_type.value,600,400,"&tree=ProductsProd",true,false,' .$encoded_popup_request_data.');
553 $xtpl->assign("CHANGE_PARENT_BUTTON", $change_parent_button);
556 if(!ACLController::checkAccess('Contacts', 'list', true)){
557 $button_attr = 'disabled="disabled"';
560 $change_to_addrs_button = '<input type="button" name="to_button" tabindex="3" class="button" '
561 . 'title="' . $app_strings['LBL_SELECT_BUTTON_TITLE'] . '" '
562 . 'value="' . $mod_strings['LBL_EMAIL_SELECTOR_SELECT'] . '" '
563 . "onclick='button_change_onclick(this);' $button_attr />\n";
564 $xtpl->assign("CHANGE_TO_ADDRS_BUTTON", $change_to_addrs_button);
566 $change_cc_addrs_button = '<input type="button" name="cc_button" tabindex="3" class="button" '
567 . 'title="' . $app_strings['LBL_SELECT_BUTTON_TITLE'] . '" '
568 . 'value="' . $mod_strings['LBL_EMAIL_SELECTOR_SELECT'] . '" '
569 . "onclick='button_change_onclick(this);' $button_attr />\n";
570 $xtpl->assign("CHANGE_CC_ADDRS_BUTTON", $change_cc_addrs_button);
572 $change_bcc_addrs_button = '<input type="button" name="bcc_button" tabindex="3" class="button" '
573 . 'title="' . $app_strings['LBL_SELECT_BUTTON_TITLE'] . '" '
574 . 'value="' . $mod_strings['LBL_EMAIL_SELECTOR_SELECT'] . '" '
575 . "onclick='button_change_onclick(this);' $button_attr />\n";
576 $xtpl->assign("CHANGE_BCC_ADDRS_BUTTON", $change_bcc_addrs_button);
579 ///////////////////////////////////////
581 global $current_user;
582 if(is_admin($current_user) && $_REQUEST['module'] != 'DynamicLayout' && !empty($_SESSION['editinplace'])) {
584 if(!empty($_REQUEST['record'])) {
585 $record = $_REQUEST['record'];
587 $xtpl->assign('ADMIN_EDIT',"<a href='index.php?action=index&module=DynamicLayout&from_action=".$_REQUEST['action'] ."&from_module=".$_REQUEST['module'] ."&record=".$record. "'>".SugarThemeRegistry::current()->getImage("EditLayout","border='0' align='bottom'",null,null,'.gif',$mod_strings['LBL_EDIT_LAYOUT'])."</a>");
590 if(empty($focus->assigned_user_id) && empty($focus->id))
591 $focus->assigned_user_id = $current_user->id;
592 if(empty($focus->assigned_name) && empty($focus->id))
593 $focus->assigned_user_name = $current_user->user_name;
594 $xtpl->assign('ASSIGNED_USER_OPTIONS', get_select_options_with_id(get_user_array(TRUE, 'Active', $focus->assigned_user_id), $focus->assigned_user_id));
595 $xtpl->assign('ASSIGNED_USER_NAME', $focus->assigned_user_name);
596 $xtpl->assign('ASSIGNED_USER_ID', $focus->assigned_user_id);
597 $xtpl->assign('DURATION_HOURS', $focus->duration_hours);
598 $xtpl->assign('TYPE_OPTIONS', get_select_options_with_id($parent_types, $focus->parent_type));
600 if(isset($focus->duration_minutes)) {
601 $xtpl->assign('DURATION_MINUTES_OPTIONS', get_select_options_with_id($focus->minutes_values,$focus->duration_minutes));
603 //// END USER ASSIGNMENT
604 ///////////////////////////////////////
609 require_once('modules/DynamicFields/templates/Files/EditView.php');
612 ///////////////////////////////////////
615 if(!empty($focus->id) || (!empty($_REQUEST['record']) && $_REQUEST['type'] == 'forward')) {
617 $attachments = "<input type='hidden' name='removeAttachment' id='removeAttachment' value=''>\n";
620 $focusId = empty($focus->id) ? $_REQUEST['record'] : $focus->id;
622 $where = "notes.parent_id='{$focusId}' AND notes.filename IS NOT NULL";
623 $notes_list = $note->get_full_list("", $where,true);
625 if(!isset($notes_list)) {
626 $notes_list = array();
628 for($i = 0;$i < count($notes_list);$i++) {
629 $the_note = $notes_list[$i];
630 if(empty($the_note->filename)) {
634 // cn: bug 8034 - attachments from forwards/replies lost when saving drafts
638 $ids .= $the_note->id;
641 <div id='noteDiv{$the_note->id}'>
642 " . SugarThemeRegistry::current()->getImage('delete_inline', "onclick='deletePriorAttachment(\"{$the_note->id}\");' value='{$the_note->id}'", null, null, ".gif", $mod_strings['LBL_DELETE_INLINE']) . " ";
643 $attachments .= "<a href=\"index.php?entryPoint=download&id=".$the_note->id."&type=Notes\">".$the_note->name."</a><div />";
644 //$attachments .= '<a href="'.UploadFile::get_url($the_note->filename,$the_note->id).'&entryPoint=download&type=Notes' . '" target="_blank">'. $the_note->filename .'</a></div>';
647 // cn: bug 8034 - attachments from forwards/replies lost when saving drafts
648 $attachments .= "<input type='hidden' name='prior_attachments' value='{$ids}'>";
650 // workaround $mod_strings being overriden by Note object instantiation above.
651 global $current_language, $mod_strings;
652 $mod_strings = return_module_language($current_language, 'Emails');
655 $attJs = '<script type="text/javascript">';
656 $attJs .= 'var lnk_remove = "'.$app_strings['LNK_REMOVE'].'";';
657 $attJs .= '</script>';
658 $xtpl->assign('ATTACHMENTS', $attachments);
659 $xtpl->assign('ATTACHMENTS_JAVASCRIPT', $attJs);
661 ///////////////////////////////////////
663 ///////////////////////////////////////////////////////////////////////////////
665 $popup_request_data = array(
666 'call_back_function' => 'document_set_return',
667 'form_name' => 'EditView',
668 'field_to_name_array' => array(
669 'id' => 'related_doc_id',
670 'document_name' => 'related_document_name',
673 $json = getJSONobj();
674 $xtpl->assign('encoded_document_popup_request_data', $json->encode($popup_request_data));
676 ///////////////////////////////////////////////////////////////////////////////
681 $xtpl->parse('main.open_source_1');
683 ///////////////////////////////////////////////////////////////////////////////
685 if(ACLController::checkAccess('EmailTemplates', 'list', true) && ACLController::checkAccess('EmailTemplates', 'view', true)) {
686 $et = new EmailTemplate();
687 $etResult = $focus->db->query($et->create_new_list_query('','',array(),array(),''));
688 $email_templates_arr[] = '';
689 while($etA = $focus->db->fetchByAssoc($etResult)) {
690 $email_templates_arr[$etA['id']] = $etA['name'];
693 $email_templates_arr = array('' => $app_strings['LBL_NONE']);
696 $xtpl->assign('EMAIL_TEMPLATE_OPTIONS', get_select_options_with_id($email_templates_arr, ''));
697 //// END EMAIL TEMPLATES
698 ///////////////////////////////////////////////////////////////////////////////
700 ///////////////////////////////////////
702 // cascade from User to Sys Default
703 $editor = $focus->getUserEditorPreference();
705 if($editor != 'plain') {
706 // this box is checked by Javascript on-load.
707 $xtpl->assign('EMAIL_EDITOR_OPTION', 'CHECKED');
709 $description_html = from_html($focus->description_html);
710 $description = $focus->description;
712 /////////////////////////////////////////////////
714 if($sig = $current_user->getDefaultSignature()) {
715 if(!$focus->hasSignatureInBody($sig) && $focus->type != 'draft') {
716 if($current_user->getPreference('signature_prepend')) {
717 $description_html = '<br />'.from_html($sig['signature_html']).'<br /><br />'.$description_html;
718 $description = "\n".$sig['signature']."\n\n".$description;
720 $description_html .= '<br /><br />'.from_html($sig['signature_html']);
721 $description = $description."\n\n".$sig['signature'];
725 $xtpl->assign('DESCRIPTION', $description);
727 /////////////////////////////////////////////////
728 $tiny = new SugarTinyMCE();
729 $ed = $tiny->getInstance("description_html");
730 $xtpl->assign("TINY", $ed);
731 $xtpl->assign("DESCRIPTION_HTML", $description_html);
733 $xtpl->parse('main.htmlarea');
735 ///////////////////////////////////////
737 ///////////////////////////////////////
738 //// SPECIAL INBOUND LANDING SCREEN ASSIGNS
739 if(!empty($_REQUEST['inbound_email_id'])) {
740 if(!empty($_REQUEST['start'])) {
741 $parts = $focus->getStartPage(base64_decode($_REQUEST['start']));
742 $xtpl->assign('RETURN_ACTION', $parts['action']);
743 $xtpl->assign('RETURN_MODULE', $parts['module']);
744 $xtpl->assign('GROUP', $parts['group']);
746 $xtpl->assign('ASSIGNED_USER_ID', $current_user->id);
747 $xtpl->assign('MYINBOX', 'this.form.type.value=\'inbound\';');
749 //// END SPECIAL INBOUND LANDING SCREEN ASSIGNS
750 ///////////////////////////////////////
752 echo '<script>var disabledModules='. $json->encode($disabled_parent_types) . ';</script>';
753 $jsVars = 'var lbl_send_anyways = "'.$mod_strings['LBL_SEND_ANYWAYS'].'";';
754 $xtpl->assign('JS_VARS', $jsVars);
755 $xtpl->parse("main");
757 echo '<script>checkParentType(document.EditView.parent_type.value, document.EditView.change_parent);</script>';
758 //// END XTEMPLATE ASSIGNMENT
759 ///////////////////////////////////////////////////////////////////////////////
762 $javascript = new javascript();
763 $javascript->setFormName('EditView');
764 $javascript->setSugarBean($focus);
765 $skip_fields = array();
766 if($email_type == 'out') {
767 $skip_fields['name'] = 1;
768 $skip_fields['date_start'] = 1;
770 $javascript->addAllFields('',$skip_fields);
771 $javascript->addToValidateBinaryDependency('parent_name', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $mod_strings['LBL_MEMBER_OF'], 'false', '', 'parent_id');
772 $javascript->addToValidateBinaryDependency('parent_type', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $mod_strings['LBL_MEMBER_OF'], 'false', '', 'parent_id');
773 $javascript->addToValidateBinaryDependency('user_name', 'alpha', $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ASSIGNED_TO'], 'false', '', 'assigned_user_id');
774 if($email_type == 'archived') {
775 $javascript->addFieldIsValidDate('date_start', 'date', $mod_strings['LBL_DATE'], $mod_strings['ERR_DATE_START'], true);
776 $javascript->addFieldIsValidTime('time_start', 'time', $mod_strings['LBL_TIME'], $mod_strings['ERR_TIME_SENT'], true);
778 echo $javascript->getScript();