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 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'] ."'";
60 if(!empty($_POST[$prefix.'record'])) {
61 $query .= " AND id != '". $_POST[$prefix.'record'] ."'";
66 $result = $db->query($query);
67 while (($row = $db->fetchByAssoc($result)) != null) {
68 if(!isset($rows[$row['id']])) {
76 while(isset($_POST['emailAddress' . $count])) {
77 $emailStr .= ",'" . strtoupper(trim($_POST['emailAddress' . $count++])) . "'";
81 $emailStr = substr($emailStr, 1);
82 $query = 'SELECT DISTINCT er.bean_id AS id FROM email_addr_bean_rel er, ' .
83 'email_addresses ea WHERE ea.id = er.email_address_id ' .
84 'AND ea.deleted = 0 AND er.deleted = 0 AND er.bean_module = \'Contacts\' ' .
85 'AND email_address_caps IN (' . $emailStr . ')';
86 $result = $db->query($query);
87 while (($row= $db->fetchByAssoc($result)) != null) {
88 if(!isset($rows[$row['id']])) {
89 $query2 = "SELECT id, first_name, last_name, title FROM contacts WHERE deleted = 0 AND id = '" . $row['id'] . "'";
90 $result2 = $db->query($query2);
91 $r = $db->fetchByAssoc($result2);
92 if(isset($r['id']) && !array_key_exists('id', $r)) {
99 return !empty($rows) ? $rows : null;
102 function buildTableForm($rows, $mod=''){
105 global $current_language;
106 $mod_strings = return_module_language($current_language, $mod);
107 }else global $mod_strings;
109 $cols = sizeof($rows[0]) * 2 + 1;
110 if ($action != 'ShowDuplicates')
112 $form = '<table width="100%"><tr><td>'.$mod_strings['MSG_DUPLICATE']. '</td></tr><tr><td height="20"></td></tr></table>';
113 $form .= "<form action='index.php' method='post' name='dupContacts'>
114 <input type='hidden' name='selectedContact' value=''>";
115 $form .= getPostToForm('/emailAddress(PrimaryFlag|OptOutFlag|InvalidFlag)?[0-9]*?$/', true);
120 $form = '<table width="100%"><tr><td>'.$mod_strings['MSG_SHOW_DUPLICATES']. '</td></tr><tr><td height="20"></td></tr></table>';
122 $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>";
123 if ($action == 'ShowDuplicates')
125 $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";
126 if (!empty($_REQUEST['return_module']) && !empty($_REQUEST['return_action']) && !empty($_REQUEST['return_id']))
127 $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']} '>";
128 else if (!empty($_POST['return_module']) && !empty($_POST['return_action']))
129 $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']} '>";
131 $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']} '>";
135 $form .= "<input type='submit' class='button' name='ContinueContact' value='${mod_strings['LNK_NEW_CONTACT']}'>";
137 $form .= "</td></tr></table></td></tr><tr>";
138 if ($action != 'ShowDuplicates')
140 $form .= "<td scope='col'> </td>";
143 require_once('include/formbase.php');
145 if(isset($_POST['return_action']) && $_POST['return_action'] == 'SubPanelViewer') {
146 $_POST['return_action'] = 'DetailView';
149 if(isset($_POST['return_action']) && $_POST['return_action'] == 'DetailView' && empty($_REQUEST['return_id'])) {
150 unset($_POST['return_action']);
153 $form .= getPostToForm();
156 foreach ($rows[0] as $key=>$value){
158 $form .= "<td scope='col' >". $mod_strings[$mod_strings['db_'.$key]]. "</td>";
163 $rowColor = 'oddListRowS1';
164 foreach($rows as $row){
166 $form .= "<tr class='$rowColor'>";
167 if ($action != 'ShowDuplicates')
169 $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";
173 foreach ($row as $key=>$value){
175 if(isset($_POST['popup']) && $_POST['popup']==true){
176 $form .= "<td scope='row'><a href='#' onclick=\"window.opener.location='index.php?module=Contacts&action=DetailView&record=${row['id']}'\">$value</a></td>\n";
179 $form .= "<td scope='row'><a target='_blank' href='index.php?module=Contacts&action=DetailView&record=${row['id']}'>$value</a></td>\n";
182 $form .= "<td><a target='_blank' href='index.php?module=Contacts&action=DetailView&record=${row['id']}'>$value</a></td>\n";
187 if($rowColor == 'evenListRowS1'){
188 $rowColor = 'oddListRowS1';
190 $rowColor = 'evenListRowS1';
194 $form .= "<tr class='pagination'><td colspan='$cols'><table width='100%' cellspacing='0' cellpadding='0' border='0'><tr><td>";
195 if ($action == 'ShowDuplicates')
197 $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";
198 if (!empty($_REQUEST['return_module']) && !empty($_REQUEST['return_action']) && !empty($_REQUEST['return_id']))
199 $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']} '>";
200 else if (!empty($_POST['return_module']) && !empty($_POST['return_action']))
201 $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']} '>";
203 $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']} '>";
207 $form .= "<input type='submit' class='button' name='ContinueContact' value='${mod_strings['LNK_NEW_CONTACT']}'></form>";
209 $form .= "</td></tr></table></td></tr></table>";
217 function getWideFormBody($prefix, $mod='',$formname='', $contact = '', $portal = true){
219 if(!ACLController::checkAccess('Contacts', 'edit', true)){
224 $contact = new Contact();
228 $temp_strings = $mod_strings;
230 global $current_language;
231 $mod_strings = return_module_language($current_language, $mod);
234 global $current_user;
235 global $app_list_strings;
236 $primary_address_country_options = get_select_options_with_id($app_list_strings['countries_dom'], $contact->primary_address_country);
237 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
238 $lbl_first_name = $mod_strings['LBL_FIRST_NAME'];
239 $lbl_last_name = $mod_strings['LBL_LAST_NAME'];
240 $lbl_phone = $mod_strings['LBL_OFFICE_PHONE'];
241 $lbl_address = $mod_strings['LBL_PRIMARY_ADDRESS'];
243 if (isset($contact->assigned_user_id)) {
244 $user_id=$contact->assigned_user_id;
246 $user_id = $current_user->id;
249 //Retrieve Email address and set email1, email2
250 $sugarEmailAddress = new SugarEmailAddress();
251 $sugarEmailAddress->handleLegacyRetrieve($contact);
252 if(!isset($contact->email1)){
253 $contact->email1 = '';
255 if(!isset($contact->email2)){
256 $contact->email2 = '';
258 if(!isset($contact->email_opt_out)){
259 $contact->email_opt_out = '';
261 $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS'];
262 $salutation_options=get_select_options_with_id($app_list_strings['salutation_dom'], $contact->salutation);
264 if (isset($contact->lead_source)) {
265 $lead_source_options=get_select_options_with_id($app_list_strings['lead_source_dom'], $contact->lead_source);
267 $lead_source_options=get_select_options_with_id($app_list_strings['lead_source_dom'], '');
273 if ($formname == 'ConvertProspect') {
274 $lead_source_label = "<td scope='row'> </td>";
275 $lead_source_field = "<td > </td>";
277 $lead_source_label = "<td scope='row' nowrap>${mod_strings['LBL_LEAD_SOURCE']}</td>";
278 $lead_source_field = "<td ><select name='${prefix}lead_source'>$lead_source_options</select></td>";
284 if(!empty($_REQUEST['birthdate'])){
285 $birthdate=$_REQUEST['birthdate'];
289 $jsCalendarImage = SugarThemeRegistry::current()->getImageURL('jscalendar.gif');
290 $ntc_date_format = $timedate->get_user_date_format();
291 $cal_dateformat = $timedate->get_cal_date_format();
292 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
295 <input type="hidden" name="${prefix}record" value="">
296 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
297 <table border='0' celpadding="0" cellspacing="0" width='100%'>
299 <td nowrap scope='row'>$lbl_first_name</td>
300 <td scope='row'>$lbl_last_name <span class="required">$lbl_required_symbol</span></td>
301 <td scope='row' nowrap>${mod_strings['LBL_TITLE']}</td>
302 <td scope='row' nowrap>${mod_strings['LBL_DEPARTMENT']}</td>
305 <td ><select name='${prefix}salutation'>$salutation_options</select> <input name="${prefix}first_name" type="text" value="{$contact->first_name}"></td>
306 <td ><input name='${prefix}last_name' type="text" value="{$contact->last_name}"></td>
307 <td nowrap><input name='${prefix}title' type="text" value="{$contact->title}"></td>
308 <td nowrap><input name='${prefix}department' type="text" value="{$contact->department}"></td>
311 <td nowrap colspan='4' scope='row'>$lbl_address</td>
315 <td nowrap colspan='4' ><textarea cols='80' rows='2' name='${prefix}primary_address_street'>{$contact->primary_address_street}</textarea></td>
319 <td scope='row'>${mod_strings['LBL_CITY']}</td>
320 <td scope='row'>${mod_strings['LBL_STATE']}</td>
321 <td scope='row'>${mod_strings['LBL_POSTAL_CODE']}</td>
322 <td scope='row'>${mod_strings['LBL_COUNTRY']}</td>
326 <td ><input name='${prefix}primary_address_city' maxlength='100' value='{$contact->primary_address_city}'></td>
327 <td ><input name='${prefix}primary_address_state' maxlength='100' value='{$contact->primary_address_state}'></td>
328 <td ><input name='${prefix}primary_address_postalcode' maxlength='100' value='{$contact->primary_address_postalcode}'></td>
329 <td ><input name='${prefix}primary_address_country' maxlength='100' value='{$contact->primary_address_country}'></td>
334 <td nowrap scope='row'>$lbl_phone</td>
335 <td nowrap scope='row'>${mod_strings['LBL_MOBILE_PHONE']}</td>
336 <td nowrap scope='row'>${mod_strings['LBL_FAX_PHONE']}</td>
337 <td nowrap scope='row'>${mod_strings['LBL_HOME_PHONE']}</td>
341 <td nowrap ><input name='${prefix}phone_work' type="text" value="{$contact->phone_work}"></td>
342 <td nowrap ><input name='${prefix}phone_mobile' type="text" value="{$contact->phone_mobile}"></td>
343 <td nowrap ><input name='${prefix}phone_fax' type="text" value="{$contact->phone_fax}"></td>
344 <td nowrap ><input name='${prefix}phone_home' type="text" value="{$contact->phone_home}"></td>
348 <td scope='row' nowrap>${mod_strings['LBL_OTHER_PHONE']}</td>
351 <td scope="row">${mod_strings['LBL_BIRTHDATE']} </td>
356 <td nowrap><input name='${prefix}phone_other' type="text" value="{$contact->phone_other}"></td>
360 <input name='{$prefix}birthdate' onblur="parseDate(this, '$cal_dateformat');" size='12' maxlength='10' id='${prefix}jscal_field' type="text" value="{$birthdate}">
361 <img src="{$jsCalendarImage}" alt="{$app_strings['LBL_ENTER_DATE']}" id="${prefix}jscal_trigger" align="absmiddle">
367 $form .= $sugarEmailAddress->getEmailAddressWidgetEditView($contact->id, $_REQUEST['action']=='ConvertLead'?'Leads':'Contacts', false, 'include/SugarEmailAddress/templates/forWideFormBodyView.tpl');
369 require_once('include/SugarFields/Fields/Text/SugarFieldText.php');
370 $sugarfield = new SugarFieldText('Text');
371 $description_text = $sugarfield->getClassicEditView('description', $contact->description, $prefix, true);
375 <td nowrap colspan='4' scope='row'>${mod_strings['LBL_DESCRIPTION']}</td>
378 <td nowrap colspan='4' >{$description_text}</td>
384 //carry forward custom lead fields common to contacts during Lead Conversion
385 $tempContact = new Contact();
387 if (method_exists($contact, 'convertCustomFieldsForm')) $contact->convertCustomFieldsForm($form, $tempContact, $prefix);
393 <input type='hidden' name='${prefix}alt_address_street' value='{$contact->alt_address_street}'>
394 <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}'>
395 <input type='hidden' name='${prefix}do_not_call' value='{$contact->do_not_call}'>
396 <input type='hidden' name='${prefix}email_opt_out' value='{$contact->email_opt_out}'>
399 if ($portal == true){
400 if (isset($contact->portal_name)) {
401 $form.="<input type='hidden' name='${prefix}portal_name' value='{$contact->portal_name}'>";
403 $form.="<input type='hidden' name='${prefix}portal_name' value=''>";
405 if (isset($contact->portal_app)) {
406 $form.="<input type='hidden' name='${prefix}portal_app' value='{$contact->portal_app}'>";
408 $form.="<input type='hidden' name='${prefix}portal_app' value=''>";
412 if(!empty($contact->portal_name) && !empty($contact->portal_app)){
413 $form .= "<input name='${prefix}portal_active' type='hidden' size='25' value='1' >";
416 if(isset($contact->portal_password)){
417 $form.="<input type='password' name='${prefix}portal_password1' value='{$contact->portal_password}'>";
418 $form.="<input type='password' name='${prefix}portal_password' value='{$contact->portal_password}'>";
419 $form .= "<input name='${prefix}old_portal_password' type='hidden' size='25' value='{$contact->portal_password}' >";
421 $form.="<input type='password' name='${prefix}portal_password1' value=''>";
422 $form.="<input type='password' name='${prefix}portal_password' value=''>";
423 $form .= "<input name='${prefix}old_portal_password' type='hidden' size='25' value='' >";
428 <script type="text/javascript">
430 inputField : "{$prefix}jscal_field", daFormat : "$cal_dateformat", ifFormat : "$cal_dateformat", showsTime : false, button : "{$prefix}jscal_trigger", singleClick : true, step : 1, weekNumbers:false
437 $javascript = new javascript();
438 $javascript->setFormName($formname);
439 $javascript->setSugarBean(new Contact());
440 $javascript->addField('email1','false',$prefix);
441 $javascript->addField('email2','false',$prefix);
442 $javascript->addRequiredFields($prefix);
444 $form .=$javascript->getScript();
445 $mod_strings = $temp_strings;
451 function getFormBody($prefix, $mod='', $formname=''){
452 if(!ACLController::checkAccess('Contacts', 'edit', true)){
456 $temp_strings = $mod_strings;
458 global $current_language;
459 $mod_strings = return_module_language($current_language, $mod);
462 global $current_user;
463 $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
464 $lbl_first_name = $mod_strings['LBL_FIRST_NAME'];
465 $lbl_last_name = $mod_strings['LBL_LAST_NAME'];
466 $lbl_phone = $mod_strings['LBL_PHONE'];
467 $user_id = $current_user->id;
468 $lbl_email_address = $mod_strings['LBL_EMAIL_ADDRESS'];
469 if ($formname == 'EmailEditView')
472 <input type="hidden" name="${prefix}record" value="">
473 <input type="hidden" name="${prefix}email2" value="">
474 <input type="hidden" name="${prefix}phone_work" value="">
475 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
477 <input name="${prefix}first_name" type="text" value="" size=10><br>
478 $lbl_last_name <span class="required">$lbl_required_symbol</span><br>
479 <input name='${prefix}last_name' type="text" value="" size=10><br>
480 $lbl_email_address <span class="required">$lbl_required_symbol</span><br>
481 <input name='${prefix}email1' type="text" value=""><br><br>
488 <input type="hidden" name="${prefix}record" value="">
489 <input type="hidden" name="${prefix}email2" value="">
490 <input type="hidden" name="${prefix}assigned_user_id" value='${user_id}'>
492 <input name="${prefix}first_name" type="text" value=""><br>
493 $lbl_last_name <span class="required">$lbl_required_symbol</span><br>
494 <input name='${prefix}last_name' type="text" value=""><br>
496 <input name='${prefix}phone_work' type="text" value=""><br>
497 $lbl_email_address<br>
498 <input name='${prefix}email1' type="text" value=""><br><br>
504 $javascript = new javascript();
505 $javascript->setFormName($formname);
506 $javascript->setSugarBean(new Contact());
507 $javascript->addField('email1','false',$prefix);
508 $javascript->addRequiredFields($prefix);
510 $form .=$javascript->getScript();
511 $mod_strings = $temp_strings;
515 function getForm($prefix, $mod=''){
516 if(!ACLController::checkAccess('Contacts', 'edit', true)){
520 global $current_language;
521 $mod_strings = return_module_language($current_language, $mod);
522 }else global $mod_strings;
525 $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE'];
526 $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY'];
527 $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL'];
530 $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']);
533 <form name="${prefix}ContactSave" onSubmit="return check_form('${prefix}ContactSave')" method="POST" action="index.php">
534 <input type="hidden" name="${prefix}module" value="Contacts">
535 <input type="hidden" name="${prefix}action" value="Save">
537 $the_form .= $this->getFormBody($prefix,'Contacts', "${prefix}ContactSave");
539 <input title="$lbl_save_button_title" accessKey="$lbl_save_button_key" class="button" type="submit" name="${prefix}button" value=" $lbl_save_button_label " >
543 $the_form .= get_left_form_footer();
544 $the_form .= get_validate_record_js();
552 function handleSave($prefix, $redirect=true, $useRequired=false){
553 global $theme, $current_user;
558 require_once('include/formbase.php');
562 $focus = new Contact();
564 if($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))){
568 if (!empty($_POST[$prefix.'new_reports_to_id'])) {
569 $focus->retrieve($_POST[$prefix.'new_reports_to_id']);
570 $focus->reports_to_id = $_POST[$prefix.'record'];
573 $focus = populateFromPost($prefix, $focus);
574 if( isset($_POST[$prefix.'old_portal_password']) && !empty($focus->portal_password) && $focus->portal_password != $_POST[$prefix.'old_portal_password']){
575 $focus->portal_password = md5($focus->portal_password);
577 if (!isset($_POST[$prefix.'email_opt_out'])) $focus->email_opt_out = 0;
578 if (!isset($_POST[$prefix.'do_not_call'])) $focus->do_not_call = 0;
581 if(!$focus->ACLAccess('Save')){
582 ACLController::displayNoAccess(true);
585 if($_REQUEST['action'] != 'BusinessCard' && $_REQUEST['action'] != 'ConvertLead' && $_REQUEST['action'] != 'ConvertProspect')
588 if (!empty($_POST[$prefix.'sync_contact'])){
589 $focus->contacts_users_id = $current_user->id;
592 if (!isset($focus->users))
594 $focus->load_relationship('user_sync');
596 $focus->contacts_users_id = null;
597 $focus->user_sync->delete($focus->id, $current_user->id);
601 if (isset($GLOBALS['check_notify'])) {
602 $check_notify = $GLOBALS['check_notify'];
605 $check_notify = FALSE;
609 if (empty($_POST['dup_checked'])) {
611 $duplicateContacts = $this->checkForDuplicates($prefix);
612 if(isset($duplicateContacts)){
613 $location='module=Contacts&action=ShowDuplicates';
615 if(isset($_POST['inbound_email_id']) && !empty($_POST['inbound_email_id'])) {
616 $get .= '&inbound_email_id='.$_POST['inbound_email_id'];
619 // Bug 25311 - Add special handling for when the form specifies many-to-many relationships
620 if(isset($_POST['relate_to']) && !empty($_POST['relate_to'])) {
621 $get .= '&Contactsrelate_to='.$_POST['relate_to'];
623 if(isset($_POST['relate_id']) && !empty($_POST['relate_id'])) {
624 $get .= '&Contactsrelate_id='.$_POST['relate_id'];
627 //add all of the post fields to redirect get string
628 foreach ($focus->column_fields as $field)
630 if (!empty($focus->$field) && !is_object($focus->$field))
632 $get .= "&Contacts$field=".urlencode($focus->$field);
636 foreach ($focus->additional_column_fields as $field)
638 if (!empty($focus->$field))
640 $get .= "&Contacts$field=".urlencode($focus->$field);
644 if($focus->hasCustomFields()) {
645 foreach($focus->field_defs as $name=>$field) {
646 if (!empty($field['source']) && $field['source'] == 'custom_fields')
648 $get .= "&Contacts$name=".urlencode($focus->$name);
654 $emailAddress = new SugarEmailAddress();
655 $get .= $emailAddress->getFormBaseURL($focus);
658 //create list of suspected duplicate contact id's in redirect get string
660 foreach ($duplicateContacts as $contact)
662 $get .= "&duplicate[$i]=".$contact['id'];
666 //add return_module, return_action, and return_id to redirect get string
667 $get .= "&return_module=";
668 if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
669 else $get .= "Contacts";
670 $get .= "&return_action=";
671 if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
672 //else $get .= "DetailView";
673 if(!empty($_POST['return_id'])) $get .= "&return_id=".$_POST['return_id'];
674 if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
675 if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
677 // for InboundEmail flow
678 if(!empty($_POST['start'])) $get .= '&start='.$_POST['start'];
681 $_SESSION['SHOW_DUPLICATES'] = $get;
682 //now redirect the post to modules/Contacts/ShowDuplicates.php
683 if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1')
686 $json = getJSONobj();
687 echo $json->encode(array('status' => 'dupe', 'get' => $location));
689 else if(!empty($_REQUEST['ajax_load']))
691 echo "<script>SUGAR.ajaxUI.loadContent('index.php?$location');</script>";
694 if(!empty($_POST['to_pdf'])) $location .= '&to_pdf='.$_POST['to_pdf'];
695 header("Location: index.php?$location");
701 global $current_user;
702 if(is_admin($current_user) && isset($_POST[$prefix.'portal_name_verified'])){
703 if (!isset($_POST[$prefix.'portal_active'])) $focus->portal_active = '0';
704 //if no password is set set account to inactive for portal
705 if(empty($_POST[$prefix.'portal_name']))$focus->portal_active = '0';
709 ///////////////////////////////////////////////////////////////////////////////
710 //// INBOUND EMAIL HANDLING
711 ///////////////////////////////////////////////////////////////////////////////
712 if(isset($_REQUEST['inbound_email_id']) && !empty($_REQUEST['inbound_email_id'])) {
713 // fake this case like it's already saved.
714 $focus->save($check_notify);
716 $email = new Email();
717 $email->retrieve($_REQUEST['inbound_email_id']);
718 $email->parent_type = 'Contacts';
719 $email->parent_id = $focus->id;
720 $email->assigned_user_id = $current_user->id;
721 $email->status = 'read';
723 $email->load_relationship('contacts');
724 $email->contacts->add($focus->id);
726 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);
729 //// END INBOUND EMAIL HANDLING
730 ///////////////////////////////////////////////////////////////////////////////
732 $focus->save($check_notify);
733 $return_id = $focus->id;
735 $GLOBALS['log']->debug("Saved record with id of ".$return_id);
737 if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
738 $json = getJSONobj();
739 echo $json->encode(array('status' => 'success',
741 $trackerManager = TrackerManager::getInstance();
742 $timeStamp = TimeDate::getInstance()->nowDb();
743 if($monitor = $trackerManager->getMonitor('tracker')){
744 $monitor->setValue('action', 'detailview');
745 $monitor->setValue('user_id', $GLOBALS['current_user']->id);
746 $monitor->setValue('module_name', 'Contacts');
747 $monitor->setValue('date_modified', $timeStamp);
748 $monitor->setValue('visible', 1);
750 if (!empty($this->bean->id)) {
751 $monitor->setValue('item_id', $return_id);
752 $monitor->setValue('item_summary', $focus->get_summary_text());
754 $trackerManager->saveMonitor($monitor, true, true);
759 if(isset($_POST['popup']) && $_POST['popup'] == 'true') {
761 if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
762 else $get .= 'Contacts';
764 if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
765 else $get .= 'Popup';
766 if(!empty($_POST['return_id'])) $get .= '&return_id='.$_POST['return_id'];
767 if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
768 if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
769 if(!empty($_POST['to_pdf'])) $get .= '&to_pdf='.$_POST['to_pdf'];
770 $get .= '&first_name=' . urlencode($focus->first_name);
771 $get .= '&last_name=' . urlencode($focus->last_name);
772 $get .= '&query=true';
773 header("Location: index.php?$get");
778 $this->handleRedirect($return_id);
784 function handleRedirect($return_id){
785 if(isset($_POST['return_module']) && $_POST['return_module'] != "") {
786 $return_module = $_POST['return_module'];
789 $return_module = "Contacts";
792 if(isset($_POST['return_action']) && $_POST['return_action'] != "") {
793 if($_REQUEST['return_module'] == 'Emails') {
794 $return_action = $_REQUEST['return_action'];
796 // if we create a new record "Save", we want to redirect to the DetailView
797 elseif($_REQUEST['action'] == "Save" && $_REQUEST['return_module'] != "Home") {
798 $return_action = 'DetailView';
800 // if we "Cancel", we go back to the list view.
801 $return_action = $_REQUEST['return_action'];
805 $return_action = "DetailView";
808 if(isset($_POST['return_id']) && $_POST['return_id'] != "") {
809 $return_id = $_POST['return_id'];
812 //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.
813 $redirect_url = "index.php?action=$return_action&module=$return_module&record=$return_id";
814 if(isset($_REQUEST['offset']) && empty($_REQUEST['duplicateSave'])) {
815 $redirect_url .= "&offset=".$_REQUEST['offset'];
818 if(!empty($_REQUEST['ajax_load'])){
819 echo "<script>SUGAR.ajaxUI.loadContent('$redirect_url');</script>\n";
822 header("Location: ". $redirect_url);