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: Base form for contact
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
46 require_once('include/SugarObjects/forms/PersonFormBase.php');
48 class ContactFormBase extends PersonFormBase {
50 var $moduleName = 'Contacts';
51 var $objectName = 'Contact';
56 * This function returns the SQL String used for initial duplicate Contacts check
58 * @see checkForDuplicates (method), ContactFormBase.php, LeadFormBase.php, ProspectFormBase.php
59 * @param $prefix String value of prefix that may be present in $_POST variables
60 * @return SQL String of the query that should be used for the initial duplicate lookup check
62 public function getDuplicateQuery($prefix='')
64 $query = 'SELECT id, first_name, last_name, title FROM contacts where deleted = 0 AND ';
65 if(isset($_POST[$prefix.'first_name']) && strlen($_POST[$prefix.'first_name']) != 0 && isset($_POST[$prefix.'last_name']) && strlen($_POST[$prefix.'last_name']) != 0){
66 $query .= " first_name LIKE '". $_POST[$prefix.'first_name'] . "%' AND last_name = '". $_POST[$prefix.'last_name'] ."'";
68 $query .= " last_name = '". $_POST[$prefix.'last_name'] ."'";
71 if(!empty($_POST[$prefix.'record'])) {
72 $query .= " AND id != '". $_POST[$prefix.'record'] ."'";
78 function getWideFormBody($prefix, $mod='',$formname='', $contact = '', $portal = true){
80 if(!ACLController::checkAccess('Contacts', 'edit', true)){
85 $contact = new Contact();
89 $temp_strings = $mod_strings;
91 global $current_language;
92 $mod_strings = return_module_language($current_language, $mod);
96 global $app_list_strings;
97 $primary_address_country_options = get_select_options_with_id($app_list_strings['countries_dom'], $contact->primary_address_country);
98 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
99 $lbl_first_name = $mod_strings['LBL_FIRST_NAME'];
100 $lbl_last_name = $mod_strings['LBL_LAST_NAME'];
101 $lbl_phone = $mod_strings['LBL_OFFICE_PHONE'];
102 $lbl_address = $mod_strings['LBL_PRIMARY_ADDRESS'];
104 if (isset($contact->assigned_user_id)) {
105 $user_id=$contact->assigned_user_id;
107 $user_id = $current_user->id;
110 //Retrieve Email address and set email1, email2
111 $sugarEmailAddress = new SugarEmailAddress();
112 $sugarEmailAddress->handleLegacyRetrieve($contact);
113 if(!isset($contact->email1)){
114 $contact->email1 = '';
116 if(!isset($contact->email2)){
117 $contact->email2 = '';
119 if(!isset($contact->email_opt_out)){
120 $contact->email_opt_out = '';
122 $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS'];
123 $salutation_options=get_select_options_with_id($app_list_strings['salutation_dom'], $contact->salutation);
125 if (isset($contact->lead_source)) {
126 $lead_source_options=get_select_options_with_id($app_list_strings['lead_source_dom'], $contact->lead_source);
128 $lead_source_options=get_select_options_with_id($app_list_strings['lead_source_dom'], '');
134 if ($formname == 'ConvertProspect') {
135 $lead_source_label = "<td scope='row'> </td>";
136 $lead_source_field = "<td > </td>";
138 $lead_source_label = "<td scope='row' nowrap>${mod_strings['LBL_LEAD_SOURCE']}</td>";
139 $lead_source_field = "<td ><select name='${prefix}lead_source'>$lead_source_options</select></td>";
145 if(!empty($_REQUEST['birthdate'])){
146 $birthdate=$_REQUEST['birthdate'];
150 $jsCalendarImage = SugarThemeRegistry::current()->getImageURL('jscalendar.gif');
151 $ntc_date_format = $timedate->get_user_date_format();
152 $cal_dateformat = $timedate->get_cal_date_format();
153 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
156 <input type="hidden" name="${prefix}record" value="">
157 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
158 <table border='0' celpadding="0" cellspacing="0" width='100%'>
160 <td nowrap scope='row'>$lbl_first_name</td>
161 <td scope='row'>$lbl_last_name <span class="required">$lbl_required_symbol</span></td>
162 <td scope='row' nowrap>${mod_strings['LBL_TITLE']}</td>
163 <td scope='row' nowrap>${mod_strings['LBL_DEPARTMENT']}</td>
166 <td ><select name='${prefix}salutation'>$salutation_options</select> <input name="${prefix}first_name" type="text" value="{$contact->first_name}"></td>
167 <td ><input name='${prefix}last_name' type="text" value="{$contact->last_name}"></td>
168 <td nowrap><input name='${prefix}title' type="text" value="{$contact->title}"></td>
169 <td nowrap><input name='${prefix}department' type="text" value="{$contact->department}"></td>
172 <td nowrap colspan='4' scope='row'>$lbl_address</td>
176 <td nowrap colspan='4' ><textarea cols='80' rows='2' name='${prefix}primary_address_street'>{$contact->primary_address_street}</textarea></td>
180 <td scope='row'>${mod_strings['LBL_CITY']}</td>
181 <td scope='row'>${mod_strings['LBL_STATE']}</td>
182 <td scope='row'>${mod_strings['LBL_POSTAL_CODE']}</td>
183 <td scope='row'>${mod_strings['LBL_COUNTRY']}</td>
187 <td ><input name='${prefix}primary_address_city' maxlength='100' value='{$contact->primary_address_city}'></td>
188 <td ><input name='${prefix}primary_address_state' maxlength='100' value='{$contact->primary_address_state}'></td>
189 <td ><input name='${prefix}primary_address_postalcode' maxlength='100' value='{$contact->primary_address_postalcode}'></td>
190 <td ><input name='${prefix}primary_address_country' maxlength='100' value='{$contact->primary_address_country}'></td>
195 <td nowrap scope='row'>$lbl_phone</td>
196 <td nowrap scope='row'>${mod_strings['LBL_MOBILE_PHONE']}</td>
197 <td nowrap scope='row'>${mod_strings['LBL_FAX_PHONE']}</td>
198 <td nowrap scope='row'>${mod_strings['LBL_HOME_PHONE']}</td>
202 <td nowrap ><input name='${prefix}phone_work' type="text" value="{$contact->phone_work}"></td>
203 <td nowrap ><input name='${prefix}phone_mobile' type="text" value="{$contact->phone_mobile}"></td>
204 <td nowrap ><input name='${prefix}phone_fax' type="text" value="{$contact->phone_fax}"></td>
205 <td nowrap ><input name='${prefix}phone_home' type="text" value="{$contact->phone_home}"></td>
209 <td scope='row' nowrap>${mod_strings['LBL_OTHER_PHONE']}</td>
212 <td scope="row">${mod_strings['LBL_BIRTHDATE']} </td>
217 <td nowrap><input name='${prefix}phone_other' type="text" value="{$contact->phone_other}"></td>
221 <input name='{$prefix}birthdate' onblur="parseDate(this, '$cal_dateformat');" size='12' maxlength='10' id='${prefix}jscal_field' type="text" value="{$birthdate}">
222 <!--not_in_theme!--><img src="{$jsCalendarImage}" alt="{$app_strings['LBL_ENTER_DATE']}" id="${prefix}jscal_trigger" align="absmiddle">
228 $form .= $sugarEmailAddress->getEmailAddressWidgetEditView($contact->id, $_REQUEST['action']=='ConvertLead'?'Leads':'Contacts', false, 'include/SugarEmailAddress/templates/forWideFormBodyView.tpl');
230 require_once('include/SugarFields/Fields/Text/SugarFieldText.php');
231 $sugarfield = new SugarFieldText('Text');
232 $description_text = $sugarfield->getClassicEditView('description', $contact->description, $prefix, true);
236 <td nowrap colspan='4' scope='row'>${mod_strings['LBL_DESCRIPTION']}</td>
239 <td nowrap colspan='4' >{$description_text}</td>
245 //carry forward custom lead fields common to contacts during Lead Conversion
246 $tempContact = new Contact();
248 if (method_exists($contact, 'convertCustomFieldsForm')) $contact->convertCustomFieldsForm($form, $tempContact, $prefix);
254 <input type='hidden' name='${prefix}alt_address_street' value='{$contact->alt_address_street}'>
255 <input type='hidden' name='${prefix}alt_address_city' value='{$contact->alt_address_city}'><input type='hidden' name='${prefix}alt_address_state' value='{$contact->alt_address_state}'><input type='hidden' name='${prefix}alt_address_postalcode' value='{$contact->alt_address_postalcode}'><input type='hidden' name='${prefix}alt_address_country' value='{$contact->alt_address_country}'>
256 <input type='hidden' name='${prefix}do_not_call' value='{$contact->do_not_call}'>
257 <input type='hidden' name='${prefix}email_opt_out' value='{$contact->email_opt_out}'>
260 if ($portal == true){
261 if (isset($contact->portal_name)) {
262 $form.="<input type='hidden' name='${prefix}portal_name' value='{$contact->portal_name}'>";
264 $form.="<input type='hidden' name='${prefix}portal_name' value=''>";
266 if (isset($contact->portal_app)) {
267 $form.="<input type='hidden' name='${prefix}portal_app' value='{$contact->portal_app}'>";
269 $form.="<input type='hidden' name='${prefix}portal_app' value=''>";
273 if(!empty($contact->portal_name) && !empty($contact->portal_app)){
274 $form .= "<input name='${prefix}portal_active' type='hidden' size='25' value='1' >";
277 if(isset($contact->portal_password)){
278 $form.="<input type='password' name='${prefix}portal_password1' value='{$contact->portal_password}'>";
279 $form.="<input type='password' name='${prefix}portal_password' value='{$contact->portal_password}'>";
280 $form .= "<input name='${prefix}old_portal_password' type='hidden' size='25' value='{$contact->portal_password}' >";
282 $form.="<input type='password' name='${prefix}portal_password1' value=''>";
283 $form.="<input type='password' name='${prefix}portal_password' value=''>";
284 $form .= "<input name='${prefix}old_portal_password' type='hidden' size='25' value='' >";
289 <script type="text/javascript">
291 inputField : "{$prefix}jscal_field", daFormat : "$cal_dateformat", ifFormat : "$cal_dateformat", showsTime : false, button : "{$prefix}jscal_trigger", singleClick : true, step : 1, weekNumbers:false
298 $javascript = new javascript();
299 $javascript->setFormName($formname);
300 $javascript->setSugarBean(new Contact());
301 $javascript->addField('email1','false',$prefix);
302 $javascript->addField('email2','false',$prefix);
303 $javascript->addRequiredFields($prefix);
305 $form .=$javascript->getScript();
306 $mod_strings = $temp_strings;
312 function getFormBody($prefix, $mod='', $formname=''){
313 if(!ACLController::checkAccess('Contacts', 'edit', true)){
317 $temp_strings = $mod_strings;
319 global $current_language;
320 $mod_strings = return_module_language($current_language, $mod);
323 global $current_user;
324 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
325 $lbl_first_name = $mod_strings['LBL_FIRST_NAME'];
326 $lbl_last_name = $mod_strings['LBL_LAST_NAME'];
327 $lbl_phone = $mod_strings['LBL_PHONE'];
328 $user_id = $current_user->id;
329 $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS'];
330 if ($formname == 'EmailEditView')
333 <input type="hidden" name="${prefix}record" value="">
334 <input type="hidden" name="${prefix}email2" value="">
335 <input type="hidden" name="${prefix}phone_work" value="">
336 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
338 <input name="${prefix}first_name" type="text" value="" size=10><br>
339 $lbl_last_name <span class="required">$lbl_required_symbol</span><br>
340 <input name='${prefix}last_name' type="text" value="" size=10><br>
341 $lbl_email_address <span class="required">$lbl_required_symbol</span><br>
342 <input name='${prefix}email1' type="text" value=""><br><br>
349 <input type="hidden" name="${prefix}record" value="">
350 <input type="hidden" name="${prefix}email2" value="">
351 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
353 <input name="${prefix}first_name" type="text" value=""><br>
354 $lbl_last_name <span class="required">$lbl_required_symbol</span><br>
355 <input name='${prefix}last_name' type="text" value=""><br>
357 <input name='${prefix}phone_work' type="text" value=""><br>
358 $lbl_email_address<br>
359 <input name='${prefix}email1' type="text" value=""><br><br>
365 $javascript = new javascript();
366 $javascript->setFormName($formname);
367 $javascript->setSugarBean(new Contact());
368 $javascript->addField('email1','false',$prefix);
369 $javascript->addRequiredFields($prefix);
371 $form .=$javascript->getScript();
372 $mod_strings = $temp_strings;
376 function getForm($prefix, $mod=''){
377 if(!ACLController::checkAccess('Contacts', 'edit', true)){
381 global $current_language;
382 $mod_strings = return_module_language($current_language, $mod);
383 }else global $mod_strings;
386 $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE'];
387 $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY'];
388 $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL'];
391 $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']);
394 <form name="${prefix}ContactSave" onSubmit="return check_form('${prefix}ContactSave')" method="POST" action="index.php">
395 <input type="hidden" name="${prefix}module" value="Contacts">
396 <input type="hidden" name="${prefix}action" value="Save">
398 $the_form .= $this->getFormBody($prefix,'Contacts', "${prefix}ContactSave");
400 <input title="$lbl_save_button_title" accessKey="$lbl_save_button_key" class="button" type="submit" name="${prefix}button" value=" $lbl_save_button_label " >
404 $the_form .= get_left_form_footer();
405 $the_form .= get_validate_record_js();
413 function handleSave($prefix, $redirect=true, $useRequired=false){
414 global $theme, $current_user;
419 require_once('include/formbase.php');
423 $focus = new Contact();
425 if($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))){
429 if (!empty($_POST[$prefix.'new_reports_to_id'])) {
430 $focus->retrieve($_POST[$prefix.'new_reports_to_id']);
431 $focus->reports_to_id = $_POST[$prefix.'record'];
434 $focus = populateFromPost($prefix, $focus);
435 if( isset($_POST[$prefix.'old_portal_password']) && !empty($focus->portal_password) && $focus->portal_password != $_POST[$prefix.'old_portal_password']){
436 $focus->portal_password = md5($focus->portal_password);
438 if (!isset($_POST[$prefix.'email_opt_out'])) $focus->email_opt_out = 0;
439 if (!isset($_POST[$prefix.'do_not_call'])) $focus->do_not_call = 0;
442 if(!$focus->ACLAccess('Save')){
443 ACLController::displayNoAccess(true);
446 if($_REQUEST['action'] != 'BusinessCard' && $_REQUEST['action'] != 'ConvertLead' && $_REQUEST['action'] != 'ConvertProspect')
449 if (!empty($_POST[$prefix.'sync_contact']) || !empty($focus->sync_contact)){
450 $focus->contacts_users_id = $current_user->id;
453 if (!isset($focus->users))
455 $focus->load_relationship('user_sync');
457 $focus->contacts_users_id = null;
458 $focus->user_sync->delete($focus->id, $current_user->id);
462 if (isset($GLOBALS['check_notify'])) {
463 $check_notify = $GLOBALS['check_notify'];
466 $check_notify = FALSE;
470 if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
472 $duplicateContacts = $this->checkForDuplicates($prefix);
473 if(isset($duplicateContacts)){
474 $location='module=Contacts&action=ShowDuplicates';
476 if(isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
477 $get .= '&inbound_email_id='.$_POST['inbound_email_id'];
480 // Bug 25311 - Add special handling for when the form specifies many-to-many relationships
481 if(isset($_POST['relate_to']) && !empty($_POST['relate_to'])) {
482 $get .= '&Contactsrelate_to='.$_POST['relate_to'];
484 if(isset($_POST['relate_id']) && !empty($_POST['relate_id'])) {
485 $get .= '&Contactsrelate_id='.$_POST['relate_id'];
488 //add all of the post fields to redirect get string
489 foreach ($focus->column_fields as $field)
491 if (!empty($focus->$field) && !is_object($focus->$field))
493 $get .= "&Contacts$field=".urlencode($focus->$field);
497 foreach ($focus->additional_column_fields as $field)
499 if (!empty($focus->$field))
501 $get .= "&Contacts$field=".urlencode($focus->$field);
505 if($focus->hasCustomFields()) {
506 foreach($focus->field_defs as $name=>$field) {
507 if (!empty($field['source']) && $field['source'] == 'custom_fields')
509 $get .= "&Contacts$name=".urlencode($focus->$name);
515 $emailAddress = new SugarEmailAddress();
516 $get .= $emailAddress->getFormBaseURL($focus);
519 //create list of suspected duplicate contact id's in redirect get string
521 foreach ($duplicateContacts as $contact)
523 $get .= "&duplicate[$i]=".$contact['id'];
527 //add return_module, return_action, and return_id to redirect get string
528 $get .= "&return_module=";
529 if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
530 else $get .= "Contacts";
531 $get .= "&return_action=";
532 if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
533 //else $get .= "DetailView";
534 if(!empty($_POST['return_id'])) $get .= "&return_id=".$_POST['return_id'];
535 if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
536 if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
538 // for InboundEmail flow
539 if(!empty($_POST['start'])) $get .= '&start='.$_POST['start'];
542 $_SESSION['SHOW_DUPLICATES'] = $get;
543 //now redirect the post to modules/Contacts/ShowDuplicates.php
544 if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1')
547 $json = getJSONobj();
548 echo $json->encode(array('status' => 'dupe', 'get' => $location));
550 else if(!empty($_REQUEST['ajax_load']))
552 echo "<script>SUGAR.ajaxUI.loadContent('index.php?$location');</script>";
555 if(!empty($_POST['to_pdf'])) $location .= '&to_pdf='.$_POST['to_pdf'];
556 header("Location: index.php?$location");
562 global $current_user;
563 if(is_admin($current_user)){
564 if (!isset($_POST[$prefix.'portal_active'])) $focus->portal_active = '0';
565 //if no password is set set account to inactive for portal
566 if(empty($_POST[$prefix.'portal_name']))$focus->portal_active = '0';
570 ///////////////////////////////////////////////////////////////////////////////
571 //// INBOUND EMAIL HANDLING
572 ///////////////////////////////////////////////////////////////////////////////
573 if(isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
574 // fake this case like it's already saved.
575 $focus->save($check_notify);
577 $email = new Email();
578 $email->retrieve($_REQUEST['inbound_email_id']);
579 $email->parent_type = 'Contacts';
580 $email->parent_id = $focus->id;
581 $email->assigned_user_id = $current_user->id;
582 $email->status = 'read';
584 $email->load_relationship('contacts');
585 $email->contacts->add($focus->id);
587 header("Location: index.php?&module=Emails&action=EditView&type=out&inbound_email_id=".$_REQUEST['inbound_email_id']."&parent_id=".$email->parent_id."&parent_type=".$email->parent_type.'&start='.$_REQUEST['start'].'&assigned_user_id='.$current_user->id);
590 //// END INBOUND EMAIL HANDLING
591 ///////////////////////////////////////////////////////////////////////////////
593 $focus->save($check_notify);
594 $return_id = $focus->id;
596 $GLOBALS['log']->debug("Saved record with id of ".$return_id);
598 if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
599 $json = getJSONobj();
600 echo $json->encode(array('status' => 'success',
602 $trackerManager = TrackerManager::getInstance();
603 $timeStamp = TimeDate::getInstance()->nowDb();
604 if($monitor = $trackerManager->getMonitor('tracker')){
605 $monitor->setValue('action', 'detailview');
606 $monitor->setValue('user_id', $GLOBALS['current_user']->id);
607 $monitor->setValue('module_name', 'Contacts');
608 $monitor->setValue('date_modified', $timeStamp);
609 $monitor->setValue('visible', 1);
611 if (!empty($this->bean->id)) {
612 $monitor->setValue('item_id', $return_id);
613 $monitor->setValue('item_summary', $focus->get_summary_text());
615 $trackerManager->saveMonitor($monitor, true, true);
620 if(isset($_POST['popup']) && $_POST['popup'] == 'true') {
622 if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
623 else $get .= 'Contacts';
625 if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
626 else $get .= 'Popup';
627 if(!empty($_POST['return_id'])) $get .= '&return_id='.$_POST['return_id'];
628 if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
629 if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
630 if(!empty($_POST['to_pdf'])) $get .= '&to_pdf='.$_POST['to_pdf'];
631 $get .= '&first_name=' . urlencode($focus->first_name);
632 $get .= '&last_name=' . urlencode($focus->last_name);
633 $get .= '&query=true';
634 header("Location: index.php?$get");
639 $this->handleRedirect($return_id);
645 function handleRedirect($return_id){
646 if(isset($_POST['return_module']) && $_POST['return_module'] != "") {
647 $return_module = $_POST['return_module'];
650 $return_module = "Contacts";
653 if(isset($_POST['return_action']) && $_POST['return_action'] != "") {
654 if($_REQUEST['return_module'] == 'Emails') {
655 $return_action = $_REQUEST['return_action'];
657 // if we create a new record "Save", we want to redirect to the DetailView
658 elseif($_REQUEST['action'] == "Save" && $_REQUEST['return_module'] != "Home") {
659 $return_action = 'DetailView';
661 // if we "Cancel", we go back to the list view.
662 $return_action = $_REQUEST['return_action'];
666 $return_action = "DetailView";
669 if(isset($_POST['return_id']) && $_POST['return_id'] != "") {
670 $return_id = $_POST['return_id'];
673 //eggsurplus Bug 23816: maintain VCR after an edit/save. If it is a duplicate then don't worry about it. The offset is now worthless.
674 $redirect_url = "index.php?action=$return_action&module=$return_module&record=$return_id";
675 if(isset($_REQUEST['offset']) && empty($_REQUEST['duplicateSave'])) {
676 $redirect_url .= "&offset=".$_REQUEST['offset'];
679 if(!empty($_REQUEST['ajax_load'])){
680 echo "<script>SUGAR.ajaxUI.loadContent('$redirect_url');</script>\n";
683 header("Location: ". $redirect_url);