2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM 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 class ContactFormBase {
48 function checkForDuplicates($prefix){
50 require_once('include/formbase.php');
52 $focus = new Contact();
54 $baseQuery = 'SELECT id, first_name, last_name, title FROM contacts where deleted = 0 AND ';
55 if(!empty($_POST[$prefix.'first_name']) && !empty($_POST[$prefix.'last_name'])){
56 $query = $baseQuery ." first_name LIKE '". $_POST[$prefix.'first_name'] . "%' AND last_name = '". $_POST[$prefix.'last_name'] ."'";
58 $query = $baseQuery ." last_name = '". $_POST[$prefix.'last_name'] ."'";
63 $result = $db->query($query);
64 while (($row = $db->fetchByAssoc($result)) != null) {
65 if(!isset($rows[$row['id']])) {
73 while(isset($_POST['emailAddress' . $count])) {
74 $emailStr .= ",'" . strtoupper(trim($_POST['emailAddress' . $count++])) . "'";
78 $emailStr = substr($emailStr, 1);
79 $query = 'SELECT DISTINCT er.bean_id AS id FROM email_addr_bean_rel er, ' .
80 'email_addresses ea WHERE ea.id = er.email_address_id ' .
81 'AND ea.deleted = 0 AND er.deleted = 0 AND er.bean_module = \'Contacts\' ' .
82 'AND email_address_caps IN (' . $emailStr . ')';
83 $result = $db->query($query);
84 while (($row= $db->fetchByAssoc($result)) != null) {
85 if(!isset($rows[$row['id']])) {
86 $query2 = "SELECT id, first_name, last_name, title FROM contacts WHERE deleted = 0 AND id = '" . $row['id'] . "'";
87 $result2 = $db->query($query2);
88 $r = $db->fetchByAssoc($result2);
89 if(isset($r['id']) && !array_key_exists('id', $r)) {
96 return !empty($rows) ? $rows : null;
99 function buildTableForm($rows, $mod=''){
102 global $current_language;
103 $mod_strings = return_module_language($current_language, $mod);
104 }else global $mod_strings;
106 $cols = sizeof($rows[0]) * 2 + 1;
107 if ($action != 'ShowDuplicates')
109 $form = '<table width="100%"><tr><td>'.$mod_strings['MSG_DUPLICATE']. '</td></tr><tr><td height="20"></td></tr></table>';
110 $form .= "<form action='index.php' method='post' name='dupContacts'>
111 <input type='hidden' name='selectedContact' value=''>";
112 $form .= getPostToForm('/emailAddress(PrimaryFlag|OptOutFlag|InvalidFlag)?[0-9]*?$/', true);
117 $form = '<table width="100%"><tr><td>'.$mod_strings['MSG_SHOW_DUPLICATES']. '</td></tr><tr><td height="20"></td></tr></table>';
119 $form .= "<table width='100%' cellpadding='0' cellspacing='0' class='list view' border='0'><tr class='pagination'><td colspan='$cols'><table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td>";
120 if ($action == 'ShowDuplicates')
122 $form .= "<input title='${app_strings['LBL_SAVE_BUTTON_TITLE']}' accessKey='${app_strings['LBL_SAVE_BUTTON_KEY']}' class='button' onclick=\"this.form.action.value='Save';\" type='submit' name='button' value=' ${app_strings['LBL_SAVE_BUTTON_LABEL']} '>\n";
123 if (!empty($_REQUEST['return_module']) && !empty($_REQUEST['return_action']) && !empty($_REQUEST['return_id']))
124 $form .= "<input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}' accessKey='${app_strings['LBL_CANCEL_BUTTON_KEY']}' class='button' onclick=\"this.form.module.value=".$_REQUEST['return_module'].";this.form.action.value=".$_REQUEST['return_action'].";this.form.record.value=".$_REQUEST['return_id']."'\" type='submit' name='button' value=' ${app_strings['LBL_CANCEL_BUTTON_LABEL']} '>";
125 else if (!empty($_POST['return_module']) && !empty($_POST['return_action']))
126 $form .= "<input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}' accessKey='${app_strings['LBL_CANCEL_BUTTON_KEY']}' class='button' onclick=\"this.form.module.value=".$_POST['return_module'].";this.form.action.value=". $_POST['return_action'].";'\" type='submit' name='button' value=' ${app_strings['LBL_CANCEL_BUTTON_LABEL']} '>";
128 $form .= "<input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}' accessKey='${app_strings['LBL_CANCEL_BUTTON_KEY']}' class='button' onclick=\"this.form.action.value='ListView';\" type='submit' type='submit' name='button' value=' ${app_strings['LBL_CANCEL_BUTTON_LABEL']} '>";
132 $form .= "<input type='submit' class='button' name='ContinueContact' value='${mod_strings['LNK_NEW_CONTACT']}'>";
134 $form .= "</td></tr></table></td></tr><tr>";
135 if ($action != 'ShowDuplicates')
137 $form .= "<td scope='col'> </td>";
140 require_once('include/formbase.php');
142 if(isset($_POST['return_action']) && $_POST['return_action'] == 'SubPanelViewer') {
143 $_POST['return_action'] = 'DetailView';
146 if(isset($_POST['return_action']) && $_POST['return_action'] == 'DetailView' && empty($_REQUEST['return_id'])) {
147 unset($_POST['return_action']);
150 $form .= getPostToForm();
153 foreach ($rows[0] as $key=>$value){
155 $form .= "<td scope='col' >". $mod_strings[$mod_strings['db_'.$key]]. "</td>";
160 $rowColor = 'oddListRowS1';
161 foreach($rows as $row){
163 $form .= "<tr class='$rowColor'>";
164 if ($action != 'ShowDuplicates')
166 $form .= "<td width='1%' nowrap='nowrap'><a href='#' onClick=\"document.forms['dupContacts'].selectedContact.value='${row['id']}';document.forms['dupContacts'].submit() \">[${app_strings['LBL_SELECT_BUTTON_LABEL']}]</a> </td>\n";
170 foreach ($row as $key=>$value){
172 if(isset($_POST['popup']) && $_POST['popup']==true){
173 $form .= "<td scope='row'><a href='#' onclick=\"window.opener.location='index.php?module=Contacts&action=DetailView&record=${row['id']}'\">$value</a></td>\n";
176 $form .= "<td scope='row'><a target='_blank' href='index.php?module=Contacts&action=DetailView&record=${row['id']}'>$value</a></td>\n";
179 $form .= "<td><a target='_blank' href='index.php?module=Contacts&action=DetailView&record=${row['id']}'>$value</a></td>\n";
184 if($rowColor == 'evenListRowS1'){
185 $rowColor = 'oddListRowS1';
187 $rowColor = 'evenListRowS1';
191 $form .= "<tr class='pagination'><td colspan='$cols'><table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td>";
192 if ($action == 'ShowDuplicates')
194 $form .= "<input title='${app_strings['LBL_SAVE_BUTTON_TITLE']}' accessKey='${app_strings['LBL_SAVE_BUTTON_KEY']}' class='button' onclick=\"this.form.action.value='Save';\" type='submit' name='button' value=' ${app_strings['LBL_SAVE_BUTTON_LABEL']} '>\n";
195 if (!empty($_REQUEST['return_module']) && !empty($_REQUEST['return_action']) && !empty($_REQUEST['return_id']))
196 $form .= "<input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}' accessKey='${app_strings['LBL_CANCEL_BUTTON_KEY']}' class='button' onclick=\"this.form.module.value=".$_REQUEST['return_module'].";this.form.action.value=".$_REQUEST['return_action'].";this.form.record.value=".$_REQUEST['return_id']."'\" type='submit' name='button' value=' ${app_strings['LBL_CANCEL_BUTTON_LABEL']} '>";
197 else if (!empty($_POST['return_module']) && !empty($_POST['return_action']))
198 $form .= "<input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}' accessKey='${app_strings['LBL_CANCEL_BUTTON_KEY']}' class='button' onclick=\"this.form.module.value=".$_POST['return_module'].";this.form.action.value=". $_POST['return_action'].";'\" type='submit' name='button' value=' ${app_strings['LBL_CANCEL_BUTTON_LABEL']} '>";
200 $form .= "<input title='${app_strings['LBL_CANCEL_BUTTON_TITLE']}' accessKey='${app_strings['LBL_CANCEL_BUTTON_KEY']}' class='button' onclick=\"this.form.action.value='ListView';\" type='submit' type='submit' name='button' value=' ${app_strings['LBL_CANCEL_BUTTON_LABEL']} '>";
204 $form .= "<input type='submit' class='button' name='ContinueContact' value='${mod_strings['LNK_NEW_CONTACT']}'></form>";
206 $form .= "</td></tr></table></td></tr></table>";
214 function getWideFormBody($prefix, $mod='',$formname='', $contact = '', $portal = true){
216 if(!ACLController::checkAccess('Contacts', 'edit', true)){
221 $contact = new Contact();
225 $temp_strings = $mod_strings;
227 global $current_language;
228 $mod_strings = return_module_language($current_language, $mod);
231 global $current_user;
232 global $app_list_strings;
233 $primary_address_country_options = get_select_options_with_id($app_list_strings['countries_dom'], $contact->primary_address_country);
234 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
235 $lbl_first_name = $mod_strings['LBL_FIRST_NAME'];
236 $lbl_last_name = $mod_strings['LBL_LAST_NAME'];
237 $lbl_phone = $mod_strings['LBL_OFFICE_PHONE'];
238 $lbl_address = $mod_strings['LBL_PRIMARY_ADDRESS'];
240 if (isset($contact->assigned_user_id)) {
241 $user_id=$contact->assigned_user_id;
243 $user_id = $current_user->id;
246 //Retrieve Email address and set email1, email2
247 $sugarEmailAddress = new SugarEmailAddress();
248 $sugarEmailAddress->handleLegacyRetrieve($contact);
249 if(!isset($contact->email1)){
250 $contact->email1 = '';
252 if(!isset($contact->email2)){
253 $contact->email2 = '';
255 if(!isset($contact->email_opt_out)){
256 $contact->email_opt_out = '';
258 $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS'];
259 $salutation_options=get_select_options_with_id($app_list_strings['salutation_dom'], $contact->salutation);
261 if (isset($contact->lead_source)) {
262 $lead_source_options=get_select_options_with_id($app_list_strings['lead_source_dom'], $contact->lead_source);
264 $lead_source_options=get_select_options_with_id($app_list_strings['lead_source_dom'], '');
270 if ($formname == 'ConvertProspect') {
271 $lead_source_label = "<td scope='row'> </td>";
272 $lead_source_field = "<td > </td>";
274 $lead_source_label = "<td scope='row' nowrap>${mod_strings['LBL_LEAD_SOURCE']}</td>";
275 $lead_source_field = "<td ><select name='${prefix}lead_source'>$lead_source_options</select></td>";
281 if(!empty($_REQUEST['birthdate'])){
282 $birthdate=$_REQUEST['birthdate'];
286 $jsCalendarImage = SugarThemeRegistry::current()->getImageURL('jscalendar.gif');
287 $ntc_date_format = $timedate->get_user_date_format();
288 $cal_dateformat = $timedate->get_cal_date_format();
289 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
292 <input type="hidden" name="${prefix}record" value="">
293 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
294 <table border='0' celpadding="0" cellspacing="0" width='100%'>
296 <td nowrap scope='row'>$lbl_first_name</td>
297 <td scope='row'>$lbl_last_name <span class="required">$lbl_required_symbol</span></td>
298 <td scope='row' nowrap>${mod_strings['LBL_TITLE']}</td>
299 <td scope='row' nowrap>${mod_strings['LBL_DEPARTMENT']}</td>
302 <td ><select name='${prefix}salutation'>$salutation_options</select> <input name="${prefix}first_name" type="text" value="{$contact->first_name}"></td>
303 <td ><input name='${prefix}last_name' type="text" value="{$contact->last_name}"></td>
304 <td nowrap><input name='${prefix}title' type="text" value="{$contact->title}"></td>
305 <td nowrap><input name='${prefix}department' type="text" value="{$contact->department}"></td>
308 <td nowrap colspan='4' scope='row'>$lbl_address</td>
312 <td nowrap colspan='4' ><textarea cols='80' rows='2' name='${prefix}primary_address_street'>{$contact->primary_address_street}</textarea></td>
316 <td scope='row'>${mod_strings['LBL_CITY']}</td>
317 <td scope='row'>${mod_strings['LBL_STATE']}</td>
318 <td scope='row'>${mod_strings['LBL_POSTAL_CODE']}</td>
319 <td scope='row'>${mod_strings['LBL_COUNTRY']}</td>
323 <td ><input name='${prefix}primary_address_city' maxlength='100' value='{$contact->primary_address_city}'></td>
324 <td ><input name='${prefix}primary_address_state' maxlength='100' value='{$contact->primary_address_state}'></td>
325 <td ><input name='${prefix}primary_address_postalcode' maxlength='100' value='{$contact->primary_address_postalcode}'></td>
326 <td ><input name='${prefix}primary_address_country' maxlength='100' value='{$contact->primary_address_country}'></td>
331 <td nowrap scope='row'>$lbl_phone</td>
332 <td nowrap scope='row'>${mod_strings['LBL_MOBILE_PHONE']}</td>
333 <td nowrap scope='row'>${mod_strings['LBL_FAX_PHONE']}</td>
334 <td nowrap scope='row'>${mod_strings['LBL_HOME_PHONE']}</td>
338 <td nowrap ><input name='${prefix}phone_work' type="text" value="{$contact->phone_work}"></td>
339 <td nowrap ><input name='${prefix}phone_mobile' type="text" value="{$contact->phone_mobile}"></td>
340 <td nowrap ><input name='${prefix}phone_fax' type="text" value="{$contact->phone_fax}"></td>
341 <td nowrap ><input name='${prefix}phone_home' type="text" value="{$contact->phone_home}"></td>
345 <td scope='row' nowrap>${mod_strings['LBL_OTHER_PHONE']}</td>
348 <td scope="row">${mod_strings['LBL_BIRTHDATE']} </td>
353 <td nowrap><input name='${prefix}phone_other' type="text" value="{$contact->phone_other}"></td>
357 <input name='{$prefix}birthdate' onblur="parseDate(this, '$cal_dateformat');" size='12' maxlength='10' id='${prefix}jscal_field' type="text" value="{$birthdate}">
358 <img src="{$jsCalendarImage}" alt="{$app_strings['LBL_ENTER_DATE']}" id="${prefix}jscal_trigger" align="absmiddle">
364 $form .= $sugarEmailAddress->getEmailAddressWidgetEditView($contact->id, $_REQUEST['action']=='ConvertLead'?'Leads':'Contacts', false, 'include/SugarEmailAddress/templates/forWideFormBodyView.tpl');
366 require_once('include/SugarFields/Fields/Text/SugarFieldText.php');
367 $sugarfield = new SugarFieldText('Text');
368 $description_text = $sugarfield->getClassicEditView('description', $contact->description, $prefix, true);
372 <td nowrap colspan='4' scope='row'>${mod_strings['LBL_DESCRIPTION']}</td>
375 <td nowrap colspan='4' >{$description_text}</td>
381 //carry forward custom lead fields common to contacts during Lead Conversion
382 $tempContact = new Contact();
384 if (method_exists($contact, 'convertCustomFieldsForm')) $contact->convertCustomFieldsForm($form, $tempContact, $prefix);
390 <input type='hidden' name='${prefix}alt_address_street' value='{$contact->alt_address_street}'>
391 <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}'>
392 <input type='hidden' name='${prefix}do_not_call' value='{$contact->do_not_call}'>
393 <input type='hidden' name='${prefix}email_opt_out' value='{$contact->email_opt_out}'>
396 if ($portal == true){
397 if (isset($contact->portal_name)) {
398 $form.="<input type='hidden' name='${prefix}portal_name' value='{$contact->portal_name}'>";
400 $form.="<input type='hidden' name='${prefix}portal_name' value=''>";
402 if (isset($contact->portal_app)) {
403 $form.="<input type='hidden' name='${prefix}portal_app' value='{$contact->portal_app}'>";
405 $form.="<input type='hidden' name='${prefix}portal_app' value=''>";
409 if(!empty($contact->portal_name) && !empty($contact->portal_app)){
410 $form .= "<input name='${prefix}portal_active' type='hidden' size='25' value='1' >";
413 if(isset($contact->portal_password)){
414 $form.="<input type='password' name='${prefix}portal_password1' value='{$contact->portal_password}'>";
415 $form.="<input type='password' name='${prefix}portal_password' value='{$contact->portal_password}'>";
416 $form .= "<input name='${prefix}old_portal_password' type='hidden' size='25' value='{$contact->portal_password}' >";
418 $form.="<input type='password' name='${prefix}portal_password1' value=''>";
419 $form.="<input type='password' name='${prefix}portal_password' value=''>";
420 $form .= "<input name='${prefix}old_portal_password' type='hidden' size='25' value='' >";
425 <script type="text/javascript">
427 inputField : "{$prefix}jscal_field", daFormat : "$cal_dateformat", ifFormat : "$cal_dateformat", showsTime : false, button : "{$prefix}jscal_trigger", singleClick : true, step : 1, weekNumbers:false
434 $javascript = new javascript();
435 $javascript->setFormName($formname);
436 $javascript->setSugarBean(new Contact());
437 $javascript->addField('email1','false',$prefix);
438 $javascript->addField('email2','false',$prefix);
439 $javascript->addRequiredFields($prefix);
441 $form .=$javascript->getScript();
442 $mod_strings = $temp_strings;
448 function getFormBody($prefix, $mod='', $formname=''){
449 if(!ACLController::checkAccess('Contacts', 'edit', true)){
453 $temp_strings = $mod_strings;
455 global $current_language;
456 $mod_strings = return_module_language($current_language, $mod);
459 global $current_user;
460 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
461 $lbl_first_name = $mod_strings['LBL_FIRST_NAME'];
462 $lbl_last_name = $mod_strings['LBL_LAST_NAME'];
463 $lbl_phone = $mod_strings['LBL_PHONE'];
464 $user_id = $current_user->id;
465 $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS'];
466 if ($formname == 'EmailEditView')
469 <input type="hidden" name="${prefix}record" value="">
470 <input type="hidden" name="${prefix}email2" value="">
471 <input type="hidden" name="${prefix}phone_work" value="">
472 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
474 <input name="${prefix}first_name" type="text" value="" size=10><br>
475 $lbl_last_name <span class="required">$lbl_required_symbol</span><br>
476 <input name='${prefix}last_name' type="text" value="" size=10><br>
477 $lbl_email_address <span class="required">$lbl_required_symbol</span><br>
478 <input name='${prefix}email1' type="text" value=""><br><br>
485 <input type="hidden" name="${prefix}record" value="">
486 <input type="hidden" name="${prefix}email2" value="">
487 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
489 <input name="${prefix}first_name" type="text" value=""><br>
490 $lbl_last_name <span class="required">$lbl_required_symbol</span><br>
491 <input name='${prefix}last_name' type="text" value=""><br>
493 <input name='${prefix}phone_work' type="text" value=""><br>
494 $lbl_email_address<br>
495 <input name='${prefix}email1' type="text" value=""><br><br>
501 $javascript = new javascript();
502 $javascript->setFormName($formname);
503 $javascript->setSugarBean(new Contact());
504 $javascript->addField('email1','false',$prefix);
505 $javascript->addRequiredFields($prefix);
507 $form .=$javascript->getScript();
508 $mod_strings = $temp_strings;
512 function getForm($prefix, $mod=''){
513 if(!ACLController::checkAccess('Contacts', 'edit', true)){
517 global $current_language;
518 $mod_strings = return_module_language($current_language, $mod);
519 }else global $mod_strings;
522 $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE'];
523 $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY'];
524 $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL'];
527 $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']);
530 <form name="${prefix}ContactSave" onSubmit="return check_form('${prefix}ContactSave')" method="POST" action="index.php">
531 <input type="hidden" name="${prefix}module" value="Contacts">
532 <input type="hidden" name="${prefix}action" value="Save">
534 $the_form .= $this->getFormBody($prefix,'Contacts', "${prefix}ContactSave");
536 <input title="$lbl_save_button_title" accessKey="$lbl_save_button_key" class="button" type="submit" name="${prefix}button" value=" $lbl_save_button_label " >
540 $the_form .= get_left_form_footer();
541 $the_form .= get_validate_record_js();
549 function handleSave($prefix, $redirect=true, $useRequired=false){
550 global $theme, $current_user;
555 require_once('include/formbase.php');
559 $focus = new Contact();
561 if($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))){
565 if (!empty($_POST[$prefix.'new_reports_to_id'])) {
566 $focus->retrieve($_POST[$prefix.'new_reports_to_id']);
567 $focus->reports_to_id = $_POST[$prefix.'record'];
570 $focus = populateFromPost($prefix, $focus);
571 if(!empty($focus->portal_password) && $focus->portal_password != $_POST[$prefix.'old_portal_password']){
572 $focus->portal_password = md5($focus->portal_password);
574 if (!isset($_POST[$prefix.'email_opt_out'])) $focus->email_opt_out = 0;
575 if (!isset($_POST[$prefix.'do_not_call'])) $focus->do_not_call = 0;
578 if(!$focus->ACLAccess('Save')){
579 ACLController::displayNoAccess(true);
582 if($_REQUEST['action'] != 'BusinessCard' && $_REQUEST['action'] != 'ConvertLead' && $_REQUEST['action'] != 'ConvertProspect')
585 if (!empty($_POST[$prefix.'sync_contact'])){
586 $focus->contacts_users_id = $current_user->id;
589 if (!isset($focus->users))
591 $focus->load_relationship('user_sync');
593 $focus->contacts_users_id = null;
594 $focus->user_sync->delete($focus->id, $current_user->id);
598 if (isset($GLOBALS['check_notify'])) {
599 $check_notify = $GLOBALS['check_notify'];
602 $check_notify = FALSE;
606 if (empty($_POST['record']) && empty($_POST['dup_checked'])) {
608 $duplicateContacts = $this->checkForDuplicates($prefix);
609 if(isset($duplicateContacts)){
610 $location='module=Contacts&action=ShowDuplicates';
612 if(isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
613 $get .= '&inbound_email_id='.$_POST['inbound_email_id'];
616 //add all of the post fields to redirect get string
617 foreach ($focus->column_fields as $field)
619 if (!empty($focus->$field) && !is_object($focus->$field))
621 $get .= "&Contacts$field=".urlencode($focus->$field);
625 foreach ($focus->additional_column_fields as $field)
627 if (!empty($focus->$field))
629 $get .= "&Contacts$field=".urlencode($focus->$field);
633 if($focus->hasCustomFields()) {
634 foreach($focus->field_defs as $name=>$field) {
635 if (!empty($field['source']) && $field['source'] == 'custom_fields')
637 $get .= "&Contacts$name=".urlencode($focus->$name);
643 $emailAddress = new SugarEmailAddress();
644 $get .= $emailAddress->getFormBaseURL($focus);
647 //create list of suspected duplicate contact id's in redirect get string
649 foreach ($duplicateContacts as $contact)
651 $get .= "&duplicate[$i]=".$contact['id'];
655 //add return_module, return_action, and return_id to redirect get string
656 $get .= "&return_module=";
657 if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
658 else $get .= "Contacts";
659 $get .= "&return_action=";
660 if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
661 //else $get .= "DetailView";
662 if(!empty($_POST['return_id'])) $get .= "&return_id=".$_POST['return_id'];
663 if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
664 if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
666 // for InboundEmail flow
667 if(!empty($_POST['start'])) $get .= '&start='.$_POST['start'];
669 //now redirect the post to modules/Contacts/ShowDuplicates.php
670 if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1')
673 $json = getJSONobj();
674 $_SESSION['SHOW_DUPLICATES'] = $get;
675 echo $json->encode(array('status' => 'dupe', 'get' => $location . $get));
677 if(!empty($_POST['to_pdf'])) $location .= '&to_pdf='.$_POST['to_pdf'];
678 $_SESSION['SHOW_DUPLICATES'] = $get;
679 header("Location: index.php?$location");
685 global $current_user;
686 if(is_admin($current_user)){
687 if (!isset($_POST[$prefix.'portal_active'])) $focus->portal_active = '0';
688 //if no password is set set account to inactive for portal
689 if(empty($_POST[$prefix.'portal_name']))$focus->portal_active = '0';
693 ///////////////////////////////////////////////////////////////////////////////
694 //// INBOUND EMAIL HANDLING
695 ///////////////////////////////////////////////////////////////////////////////
696 if(isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
697 // fake this case like it's already saved.
698 $focus->save($check_notify);
700 $email = new Email();
701 $email->retrieve($_REQUEST['inbound_email_id']);
702 $email->parent_type = 'Contacts';
703 $email->parent_id = $focus->id;
704 $email->assigned_user_id = $current_user->id;
705 $email->status = 'read';
707 $email->load_relationship('contacts');
708 $email->contacts->add($focus->id);
710 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);
713 //// END INBOUND EMAIL HANDLING
714 ///////////////////////////////////////////////////////////////////////////////
716 $focus->save($check_notify);
717 $return_id = $focus->id;
719 $GLOBALS['log']->debug("Saved record with id of ".$return_id);
721 if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
722 $json = getJSONobj();
723 echo $json->encode(array('status' => 'success',
725 $trackerManager = TrackerManager::getInstance();
726 $timeStamp = gmdate($GLOBALS['timedate']->get_db_date_time_format());
727 if($monitor = $trackerManager->getMonitor('tracker')){
728 $monitor->setValue('action', 'detailview');
729 $monitor->setValue('user_id', $GLOBALS['current_user']->id);
730 $monitor->setValue('module_name', 'Contacts');
731 $monitor->setValue('date_modified', $timeStamp);
732 $monitor->setValue('visible', 1);
734 if (!empty($this->bean->id)) {
735 $monitor->setValue('item_id', $return_id);
736 $monitor->setValue('item_summary', $focus->get_summary_text());
738 $trackerManager->saveMonitor($monitor, true, true);
743 if(isset($_POST['popup']) && $_POST['popup'] == 'true') {
745 if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
746 else $get .= 'Contacts';
748 if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
749 else $get .= 'Popup';
750 if(!empty($_POST['return_id'])) $get .= '&return_id='.$_POST['return_id'];
751 if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
752 if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
753 if(!empty($_POST['to_pdf'])) $get .= '&to_pdf='.$_POST['to_pdf'];
754 $get .= '&first_name=' . urlencode($focus->first_name);
755 $get .= '&last_name=' . urlencode($focus->last_name);
756 $get .= '&query=true';
757 header("Location: index.php?$get");
762 $this->handleRedirect($return_id);
768 function handleRedirect($return_id){
769 if(isset($_POST['return_module']) && $_POST['return_module'] != "") {
770 $return_module = $_POST['return_module'];
773 $return_module = "Contacts";
776 if(isset($_POST['return_action']) && $_POST['return_action'] != "") {
777 if($_REQUEST['return_module'] == 'Emails') {
778 $return_action = $_REQUEST['return_action'];
780 // if we create a new record "Save", we want to redirect to the DetailView
781 elseif($_REQUEST['action'] == "Save" && $_REQUEST['return_module'] != "Home") {
782 $return_action = 'DetailView';
784 // if we "Cancel", we go back to the list view.
785 $return_action = $_REQUEST['return_action'];
789 $return_action = "DetailView";
792 if(isset($_POST['return_id']) && $_POST['return_id'] != "") {
793 $return_id = $_POST['return_id'];
796 header("Location: index.php?action=$return_action&module=$return_module&record=$return_id");