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-2013 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 $focus sugarbean
60 * @param $prefix String value of prefix that may be present in $_POST variables
61 * @return SQL String of the query that should be used for the initial duplicate lookup check
63 public function getDuplicateQuery($focus, $prefix='')
65 $query = 'SELECT contacts.id, contacts.first_name, contacts.last_name, contacts.title FROM contacts ';
67 // Bug #46427 : Records from other Teams shown on Potential Duplicate Contacts screen during Lead Conversion
70 $query .= ' where contacts.deleted = 0 AND ';
71 if(isset($_POST[$prefix.'first_name']) && strlen($_POST[$prefix.'first_name']) != 0 && isset($_POST[$prefix.'last_name']) && strlen($_POST[$prefix.'last_name']) != 0){
72 $query .= " contacts.first_name LIKE '". $_POST[$prefix.'first_name'] . "%' AND contacts.last_name = '". $_POST[$prefix.'last_name'] ."'";
74 $query .= " contacts.last_name = '". $_POST[$prefix.'last_name'] ."'";
77 if(!empty($_POST[$prefix.'record'])) {
78 $query .= " AND contacts.id != '". $_POST[$prefix.'record'] ."'";
84 function getWideFormBody($prefix, $mod='',$formname='', $contact = '', $portal = true){
86 if(!ACLController::checkAccess('Contacts', 'edit', true)){
91 $contact = $this->getContact();
95 $temp_strings = $mod_strings;
97 global $current_language;
98 $mod_strings = return_module_language($current_language, $mod);
101 global $current_user;
102 global $app_list_strings;
103 $primary_address_country_options = get_select_options_with_id($app_list_strings['countries_dom'], $contact->primary_address_country);
104 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
105 $lbl_first_name = $mod_strings['LBL_FIRST_NAME'];
106 $lbl_last_name = $mod_strings['LBL_LAST_NAME'];
107 $lbl_phone = $mod_strings['LBL_OFFICE_PHONE'];
108 $lbl_address = $mod_strings['LBL_PRIMARY_ADDRESS'];
110 if (isset($contact->assigned_user_id)) {
111 $user_id=$contact->assigned_user_id;
113 $user_id = $current_user->id;
116 //Retrieve Email address and set email1, email2
117 $sugarEmailAddress = new SugarEmailAddress();
118 $sugarEmailAddress->handleLegacyRetrieve($contact);
119 if(!isset($contact->email1)){
120 $contact->email1 = '';
122 if(!isset($contact->email2)){
123 $contact->email2 = '';
125 if(!isset($contact->email_opt_out)){
126 $contact->email_opt_out = '';
128 $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS'];
129 $salutation_options=get_select_options_with_id($app_list_strings['salutation_dom'], $contact->salutation);
131 if (isset($contact->lead_source)) {
132 $lead_source_options=get_select_options_with_id($app_list_strings['lead_source_dom'], $contact->lead_source);
134 $lead_source_options=get_select_options_with_id($app_list_strings['lead_source_dom'], '');
140 if ($formname == 'ConvertProspect') {
141 $lead_source_label = "<td scope='row'> </td>";
142 $lead_source_field = "<td > </td>";
144 $lead_source_label = "<td scope='row' nowrap>${mod_strings['LBL_LEAD_SOURCE']}</td>";
145 $lead_source_field = "<td ><select name='${prefix}lead_source'>$lead_source_options</select></td>";
151 if(!empty($_REQUEST['birthdate'])){
152 $birthdate=$_REQUEST['birthdate'];
156 $jsCalendarImage = SugarThemeRegistry::current()->getImageURL('jscalendar.gif');
157 $ntc_date_format = $timedate->get_user_date_format();
158 $cal_dateformat = $timedate->get_cal_date_format();
159 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
162 <input type="hidden" name="${prefix}record" value="">
163 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
164 <table border='0' celpadding="0" cellspacing="0" width='100%'>
166 <td nowrap scope='row'>$lbl_first_name</td>
167 <td scope='row'>$lbl_last_name <span class="required">$lbl_required_symbol</span></td>
168 <td scope='row' nowrap>${mod_strings['LBL_TITLE']}</td>
169 <td scope='row' nowrap>${mod_strings['LBL_DEPARTMENT']}</td>
172 <td ><select name='${prefix}salutation'>$salutation_options</select> <input name="${prefix}first_name" type="text" value="{$contact->first_name}"></td>
173 <td ><input name='${prefix}last_name' type="text" value="{$contact->last_name}"></td>
174 <td nowrap><input name='${prefix}title' type="text" value="{$contact->title}"></td>
175 <td nowrap><input name='${prefix}department' type="text" value="{$contact->department}"></td>
178 <td nowrap colspan='4' scope='row'>$lbl_address</td>
182 <td nowrap colspan='4' ><textarea cols='80' rows='2' name='${prefix}primary_address_street'>{$contact->primary_address_street}</textarea></td>
186 <td scope='row'>${mod_strings['LBL_CITY']}</td>
187 <td scope='row'>${mod_strings['LBL_STATE']}</td>
188 <td scope='row'>${mod_strings['LBL_POSTAL_CODE']}</td>
189 <td scope='row'>${mod_strings['LBL_COUNTRY']}</td>
193 <td ><input name='${prefix}primary_address_city' maxlength='100' value='{$contact->primary_address_city}'></td>
194 <td ><input name='${prefix}primary_address_state' maxlength='100' value='{$contact->primary_address_state}'></td>
195 <td ><input name='${prefix}primary_address_postalcode' maxlength='100' value='{$contact->primary_address_postalcode}'></td>
196 <td ><input name='${prefix}primary_address_country' maxlength='100' value='{$contact->primary_address_country}'></td>
201 <td nowrap scope='row'>$lbl_phone</td>
202 <td nowrap scope='row'>${mod_strings['LBL_MOBILE_PHONE']}</td>
203 <td nowrap scope='row'>${mod_strings['LBL_FAX_PHONE']}</td>
204 <td nowrap scope='row'>${mod_strings['LBL_HOME_PHONE']}</td>
208 <td nowrap ><input name='${prefix}phone_work' type="text" value="{$contact->phone_work}"></td>
209 <td nowrap ><input name='${prefix}phone_mobile' type="text" value="{$contact->phone_mobile}"></td>
210 <td nowrap ><input name='${prefix}phone_fax' type="text" value="{$contact->phone_fax}"></td>
211 <td nowrap ><input name='${prefix}phone_home' type="text" value="{$contact->phone_home}"></td>
215 <td scope='row' nowrap>${mod_strings['LBL_OTHER_PHONE']}</td>
218 <td scope="row">${mod_strings['LBL_BIRTHDATE']} </td>
223 <td nowrap><input name='${prefix}phone_other' type="text" value="{$contact->phone_other}"></td>
227 <input name='{$prefix}birthdate' onblur="parseDate(this, '$cal_dateformat');" size='12' maxlength='10' id='${prefix}jscal_field' type="text" value="{$birthdate}">
228 <!--not_in_theme!--><img src="{$jsCalendarImage}" alt="{$app_strings['LBL_ENTER_DATE']}" id="${prefix}jscal_trigger" align="absmiddle">
234 $form .= $sugarEmailAddress->getEmailAddressWidgetEditView($contact->id, $_REQUEST['action']=='ConvertLead'?'Leads':'Contacts', false, 'include/SugarEmailAddress/templates/forWideFormBodyView.tpl');
236 require_once('include/SugarFields/Fields/Text/SugarFieldText.php');
237 $sugarfield = new SugarFieldText('Text');
238 $description_text = $sugarfield->getClassicEditView('description', $contact->description, $prefix, true);
242 <td nowrap colspan='4' scope='row'>${mod_strings['LBL_DESCRIPTION']}</td>
245 <td nowrap colspan='4' >{$description_text}</td>
251 //carry forward custom lead fields common to contacts during Lead Conversion
252 $tempContact = $this->getContact();
254 if (method_exists($contact, 'convertCustomFieldsForm')) $contact->convertCustomFieldsForm($form, $tempContact, $prefix);
260 <input type='hidden' name='${prefix}alt_address_street' value='{$contact->alt_address_street}'>
261 <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}'>
262 <input type='hidden' name='${prefix}do_not_call' value='{$contact->do_not_call}'>
263 <input type='hidden' name='${prefix}email_opt_out' value='{$contact->email_opt_out}'>
266 if ($portal == true){
267 if (isset($contact->portal_name)) {
268 $form.="<input type='hidden' name='${prefix}portal_name' value='{$contact->portal_name}'>";
270 $form.="<input type='hidden' name='${prefix}portal_name' value=''>";
272 if (isset($contact->portal_app)) {
273 $form.="<input type='hidden' name='${prefix}portal_app' value='{$contact->portal_app}'>";
275 $form.="<input type='hidden' name='${prefix}portal_app' value=''>";
279 if(!empty($contact->portal_name) && !empty($contact->portal_app)){
280 $form .= "<input name='${prefix}portal_active' type='hidden' size='25' value='1' >";
283 if(isset($contact->portal_password)){
284 $form.="<input type='password' name='${prefix}portal_password1' value='{$contact->portal_password}'>";
285 $form.="<input type='password' name='${prefix}portal_password' value='{$contact->portal_password}'>";
286 $form .= "<input name='${prefix}old_portal_password' type='hidden' size='25' value='{$contact->portal_password}' >";
288 $form.="<input type='password' name='${prefix}portal_password1' value=''>";
289 $form.="<input type='password' name='${prefix}portal_password' value=''>";
290 $form .= "<input name='${prefix}old_portal_password' type='hidden' size='25' value='' >";
295 <script type="text/javascript">
297 inputField : "{$prefix}jscal_field", daFormat : "$cal_dateformat", ifFormat : "$cal_dateformat", showsTime : false, button : "{$prefix}jscal_trigger", singleClick : true, step : 1, weekNumbers:false
304 $javascript = new javascript();
305 $javascript->setFormName($formname);
306 $javascript->setSugarBean($this->getContact());
307 $javascript->addField('email1','false',$prefix);
308 $javascript->addField('email2','false',$prefix);
309 $javascript->addRequiredFields($prefix);
311 $form .=$javascript->getScript();
312 $mod_strings = $temp_strings;
318 function getFormBody($prefix, $mod='', $formname=''){
319 if(!ACLController::checkAccess('Contacts', 'edit', true)){
323 $temp_strings = $mod_strings;
325 global $current_language;
326 $mod_strings = return_module_language($current_language, $mod);
329 global $current_user;
330 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
331 $lbl_first_name = $mod_strings['LBL_FIRST_NAME'];
332 $lbl_last_name = $mod_strings['LBL_LAST_NAME'];
333 $lbl_phone = $mod_strings['LBL_PHONE'];
334 $user_id = $current_user->id;
335 $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS'];
336 if ($formname == 'EmailEditView')
339 <input type="hidden" name="${prefix}record" value="">
340 <input type="hidden" name="${prefix}email2" value="">
341 <input type="hidden" name="${prefix}phone_work" value="">
342 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
344 <input name="${prefix}first_name" type="text" value="" size=10><br>
345 $lbl_last_name <span class="required">$lbl_required_symbol</span><br>
346 <input name='${prefix}last_name' type="text" value="" size=10><br>
347 $lbl_email_address <span class="required">$lbl_required_symbol</span><br>
348 <input name='${prefix}email1' type="text" value=""><br><br>
355 <input type="hidden" name="${prefix}record" value="">
356 <input type="hidden" name="${prefix}email2" value="">
357 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
359 <input name="${prefix}first_name" type="text" value=""><br>
360 $lbl_last_name <span class="required">$lbl_required_symbol</span><br>
361 <input name='${prefix}last_name' type="text" value=""><br>
363 <input name='${prefix}phone_work' type="text" value=""><br>
364 $lbl_email_address<br>
365 <input name='${prefix}email1' type="text" value=""><br><br>
371 $javascript = new javascript();
372 $javascript->setFormName($formname);
373 $javascript->setSugarBean($this->getContact());
374 $javascript->addField('email1','false',$prefix);
375 $javascript->addRequiredFields($prefix);
377 $form .=$javascript->getScript();
378 $mod_strings = $temp_strings;
382 function getForm($prefix, $mod=''){
383 if(!ACLController::checkAccess('Contacts', 'edit', true)){
387 global $current_language;
388 $mod_strings = return_module_language($current_language, $mod);
389 }else global $mod_strings;
392 $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE'];
393 $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY'];
394 $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL'];
397 $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']);
400 <form name="${prefix}ContactSave" onSubmit="return check_form('${prefix}ContactSave')" method="POST" action="index.php">
401 <input type="hidden" name="${prefix}module" value="Contacts">
402 <input type="hidden" name="${prefix}action" value="Save">
404 $the_form .= $this->getFormBody($prefix,'Contacts', "${prefix}ContactSave");
406 <input title="$lbl_save_button_title" accessKey="$lbl_save_button_key" class="button" type="submit" name="${prefix}button" value=" $lbl_save_button_label " >
410 $the_form .= get_left_form_footer();
411 $the_form .= get_validate_record_js();
419 function handleSave($prefix, $redirect=true, $useRequired=false){
420 global $theme, $current_user;
425 require_once('include/formbase.php');
429 $focus = $this->getContact();
431 if($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))){
435 if (!empty($_POST[$prefix.'new_reports_to_id'])) {
436 $focus->retrieve($_POST[$prefix.'new_reports_to_id']);
437 $focus->reports_to_id = $_POST[$prefix.'record'];
440 $focus = populateFromPost($prefix, $focus);
441 if( isset($_POST[$prefix.'old_portal_password']) && !empty($focus->portal_password) && $focus->portal_password != $_POST[$prefix.'old_portal_password']){
442 $focus->portal_password = User::getPasswordHash($focus->portal_password);
444 if (!isset($_POST[$prefix.'email_opt_out'])) $focus->email_opt_out = 0;
445 if (!isset($_POST[$prefix.'do_not_call'])) $focus->do_not_call = 0;
448 if(!$focus->ACLAccess('Save')){
449 ACLController::displayNoAccess(true);
452 if($_REQUEST['action'] != 'BusinessCard' && $_REQUEST['action'] != 'ConvertLead' && $_REQUEST['action'] != 'ConvertProspect')
455 if (!empty($_POST[$prefix.'sync_contact']) || !empty($focus->sync_contact)){
456 $focus->contacts_users_id = $current_user->id;
459 if (!isset($focus->users))
461 $focus->load_relationship('user_sync');
463 $focus->contacts_users_id = null;
464 $focus->user_sync->delete($focus->id, $current_user->id);
468 if (isset($GLOBALS['check_notify'])) {
469 $check_notify = $GLOBALS['check_notify'];
472 $check_notify = FALSE;
476 if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
478 $duplicateContacts = $this->checkForDuplicates($prefix);
479 if(isset($duplicateContacts)){
480 $location='module=Contacts&action=ShowDuplicates';
482 if(isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
483 $get .= '&inbound_email_id='.$_POST['inbound_email_id'];
486 // Bug 25311 - Add special handling for when the form specifies many-to-many relationships
487 if(isset($_POST['relate_to']) && !empty($_POST['relate_to'])) {
488 $get .= '&Contactsrelate_to='.$_POST['relate_to'];
490 if(isset($_POST['relate_id']) && !empty($_POST['relate_id'])) {
491 $get .= '&Contactsrelate_id='.$_POST['relate_id'];
494 //add all of the post fields to redirect get string
495 foreach ($focus->column_fields as $field)
497 if (!empty($focus->$field) && !is_object($focus->$field))
499 $get .= "&Contacts$field=".urlencode($focus->$field);
503 foreach ($focus->additional_column_fields as $field)
505 if (!empty($focus->$field))
507 $get .= "&Contacts$field=".urlencode($focus->$field);
511 if($focus->hasCustomFields()) {
512 foreach($focus->field_defs as $name=>$field) {
513 if (!empty($field['source']) && $field['source'] == 'custom_fields')
515 $get .= "&Contacts$name=".urlencode($focus->$name);
521 $emailAddress = new SugarEmailAddress();
522 $get .= $emailAddress->getFormBaseURL($focus);
525 //create list of suspected duplicate contact id's in redirect get string
527 foreach ($duplicateContacts as $contact)
529 $get .= "&duplicate[$i]=".$contact['id'];
533 //add return_module, return_action, and return_id to redirect get string
534 $get .= "&return_module=";
535 if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
536 else $get .= "Contacts";
537 $get .= "&return_action=";
538 if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
539 //else $get .= "DetailView";
540 if(!empty($_POST['return_id'])) $get .= "&return_id=".$_POST['return_id'];
541 if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
542 if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
544 // for InboundEmail flow
545 if(!empty($_POST['start'])) $get .= '&start='.$_POST['start'];
548 $_SESSION['SHOW_DUPLICATES'] = $get;
549 //now redirect the post to modules/Contacts/ShowDuplicates.php
550 if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1')
553 $json = getJSONobj();
554 echo $json->encode(array('status' => 'dupe', 'get' => $location));
556 else if(!empty($_REQUEST['ajax_load']))
558 echo "<script>SUGAR.ajaxUI.loadContent('index.php?$location');</script>";
561 if(!empty($_POST['to_pdf'])) $location .= '&to_pdf='.$_POST['to_pdf'];
562 header("Location: index.php?$location");
568 global $current_user;
569 if(is_admin($current_user)){
570 if (!isset($_POST[$prefix.'portal_active'])) $focus->portal_active = '0';
571 //if no password is set set account to inactive for portal
572 if(empty($_POST[$prefix.'portal_name']))$focus->portal_active = '0';
576 ///////////////////////////////////////////////////////////////////////////////
577 //// INBOUND EMAIL HANDLING
578 ///////////////////////////////////////////////////////////////////////////////
579 if(isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
580 // fake this case like it's already saved.
581 $focus->save($check_notify);
583 $email = new Email();
584 $email->retrieve($_REQUEST['inbound_email_id']);
585 $email->parent_type = 'Contacts';
586 $email->parent_id = $focus->id;
587 $email->assigned_user_id = $current_user->id;
588 $email->status = 'read';
590 $email->load_relationship('contacts');
591 $email->contacts->add($focus->id);
593 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);
596 //// END INBOUND EMAIL HANDLING
597 ///////////////////////////////////////////////////////////////////////////////
599 $focus->save($check_notify);
600 $return_id = $focus->id;
602 $GLOBALS['log']->debug("Saved record with id of ".$return_id);
604 if ($redirect && !empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
605 $json = getJSONobj();
606 echo $json->encode(array('status' => 'success',
608 $trackerManager = TrackerManager::getInstance();
609 $timeStamp = TimeDate::getInstance()->nowDb();
610 if($monitor = $trackerManager->getMonitor('tracker')){
611 $monitor->setValue('action', 'detailview');
612 $monitor->setValue('user_id', $GLOBALS['current_user']->id);
613 $monitor->setValue('module_name', 'Contacts');
614 $monitor->setValue('date_modified', $timeStamp);
615 $monitor->setValue('visible', 1);
617 if (!empty($this->bean->id)) {
618 $monitor->setValue('item_id', $return_id);
619 $monitor->setValue('item_summary', $focus->get_summary_text());
621 $trackerManager->saveMonitor($monitor, true, true);
626 if($redirect && isset($_POST['popup']) && $_POST['popup'] == 'true') {
628 if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
629 else $get .= 'Contacts';
631 if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
632 else $get .= 'Popup';
633 if(!empty($_POST['return_id'])) $get .= '&return_id='.$_POST['return_id'];
634 if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
635 if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
636 if(!empty($_POST['to_pdf'])) $get .= '&to_pdf='.$_POST['to_pdf'];
637 $get .= '&first_name=' . urlencode($focus->first_name);
638 $get .= '&last_name=' . urlencode($focus->last_name);
639 $get .= '&query=true';
640 header("Location: index.php?$get");
645 $this->handleRedirect($return_id);
651 function handleRedirect($return_id){
652 if(isset($_POST['return_module']) && $_POST['return_module'] != "") {
653 $return_module = $_POST['return_module'];
656 $return_module = "Contacts";
659 if(isset($_POST['return_action']) && $_POST['return_action'] != "") {
660 if($_REQUEST['return_module'] == 'Emails') {
661 $return_action = $_REQUEST['return_action'];
663 // if we create a new record "Save", we want to redirect to the DetailView
664 elseif($_REQUEST['action'] == "Save" && $_REQUEST['return_module'] != "Home") {
665 $return_action = 'DetailView';
667 // if we "Cancel", we go back to the list view.
668 $return_action = $_REQUEST['return_action'];
672 $return_action = "DetailView";
675 if(isset($_POST['return_id']) && $_POST['return_id'] != "") {
676 $return_id = $_POST['return_id'];
679 //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.
680 $redirect_url = "index.php?action=$return_action&module=$return_module&record=$return_id";
681 if(isset($_REQUEST['offset']) && empty($_REQUEST['duplicateSave'])) {
682 $redirect_url .= "&offset=".$_REQUEST['offset'];
685 if(!empty($_REQUEST['ajax_load'])){
686 echo "<script>SUGAR.ajaxUI.loadContent('$redirect_url');</script>\n";
689 header("Location: ". $redirect_url);
696 protected function getContact()
698 return new Contact();