/** * Saves a new Contact as well as any related items passed in. * * @return null */ protected function handleSave() { require_once 'modules/Campaigns/utils.php'; require_once "include/formbase.php"; $lead = false; if (!empty($_REQUEST['record'])) { $lead = new Lead(); $lead->retrieve($_REQUEST['record']); } global $beanList; $this->loadDefs(); $beans = array(); $selectedBeans = array(); $selects = array(); // Make sure the contact object is availible for relationships. $beans['Contacts'] = new Contact(); // Contacts if (!empty($_REQUEST['selectedContact'])) { $beans['Contacts']->retrieve($_REQUEST['selectedContact']); if (!empty($beans['Contacts']->id)) { $beans['Contacts']->new_with_id = false; unset($_REQUEST["convert_create_Contacts"]); unset($_POST["convert_create_Contacts"]); } } elseif (!empty($_REQUEST["convert_create_Contacts"]) && $_REQUEST["convert_create_Contacts"] != "false" && !isset($_POST['ContinueContact'])) { require_once 'modules/Contacts/ContactFormBase.php'; $contactForm = new ContactFormBase(); $duplicateContacts = $contactForm->checkForDuplicates('Contacts'); if (isset($duplicateContacts)) { echo $contactForm->buildTableForm($duplicateContacts, 'Contacts'); return; } $this->new_contact = true; } elseif (isset($_POST['ContinueContact'])) { $this->new_contact = true; } // Accounts if (!empty($_REQUEST['selectedAccount'])) { $_REQUEST['account_id'] = $_REQUEST['selectedAccount']; unset($_REQUEST["convert_create_Accounts"]); unset($_POST["convert_create_Accounts"]); } elseif (!empty($_REQUEST["convert_create_Accounts"]) && $_REQUEST["convert_create_Accounts"] != "false" && empty($_POST['ContinueAccount'])) { require_once 'modules/Accounts/AccountFormBase.php'; $accountForm = new AccountFormBase(); $duplicateAccounts = $accountForm->checkForDuplicates('Accounts'); if (isset($duplicateAccounts)) { echo $accountForm->buildTableForm($duplicateAccounts); return; } } foreach ($this->defs as $module => $vdef) { //Create a new record if "create" was selected if (!empty($_REQUEST["convert_create_{$module}"]) && $_REQUEST["convert_create_{$module}"] != "false") { //Save the new record $bean = $beanList[$module]; if (empty($beans[$module])) { $beans[$module] = new $bean(); } $this->populateNewBean($module, $beans[$module], $beans['Contacts'], $lead); // when creating a new contact, create the id for linking with other modules // and do not populate it with lead's old account_id if ($module == 'Contacts') { $beans[$module]->id = create_guid(); $beans[$module]->new_with_id = true; $beans[$module]->account_id = ''; } } else { if (!empty($vdef['ConvertLead']['select'])) { //Save the new record $select = $vdef['ConvertLead']['select']; $fieldDef = $beans['Contacts']->field_defs[$select]; if (!empty($fieldDef['id_name']) && !empty($_REQUEST[$fieldDef['id_name']])) { $beans['Contacts']->{$fieldDef}['id_name'] = $_REQUEST[$fieldDef['id_name']]; $selects[$module] = $_REQUEST[$fieldDef['id_name']]; if (!empty($_REQUEST[$select])) { $beans['Contacts']->{$select} = $_REQUEST[$select]; } // Bug 39268 - Add the existing beans to a list of beans we'll potentially add the lead's activities to $bean = loadBean($module); $bean->retrieve($_REQUEST[$fieldDef['id_name']]); $selectedBeans[$module] = $bean; // If we selected the Contact, just overwrite the $beans['Contacts'] if ($module == 'Contacts') { $beans[$module] = $bean; } } } } } $this->handleActivities($lead, $beans); // Bug 39268 - Add the lead's activities to the selected beans $this->handleActivities($lead, $selectedBeans); //link selected account to lead if it exists if (!empty($selectedBeans['Accounts'])) { $lead->account_id = $selectedBeans['Accounts']->id; } // link account to contact, if we picked an existing contact and created a new account if (!empty($beans['Accounts']->id) && !empty($beans['Contacts']->account_id) && $beans['Accounts']->id != $beans['Contacts']->account_id) { $beans['Contacts']->account_id = $beans['Accounts']->id; } // Saving beans with priorities. // Contacts and Accounts should be saved before lead activities to create correct relations $saveBeanPriority = array('Contacts', 'Accounts'); $tempBeans = array(); foreach ($saveBeanPriority as $name) { if (isset($beans[$name])) { $tempBeans[$name] = $beans[$name]; } } $beans = array_merge($tempBeans, $beans); unset($tempBeans); //Handle non-contacts relationships foreach ($beans as $bean) { if (!empty($lead)) { if (empty($bean->assigned_user_id)) { $bean->assigned_user_id = $lead->assigned_user_id; } $leadsRel = $this->findRelationship($bean, $lead); if (!empty($leadsRel)) { $bean->load_relationship($leadsRel); $relObject = $bean->{$leadsRel}->getRelationshipObject(); if ($relObject->relationship_type == "one-to-many" && $bean->{$leadsRel}->_get_bean_position()) { $id_field = $relObject->rhs_key; $lead->{$id_field} = $bean->id; } else { $bean->{$leadsRel}->add($lead->id); } } } //Special case code for opportunities->Accounts if ($bean->object_name == "Opportunity" && empty($bean->account_id)) { if (isset($beans['Accounts'])) { $bean->account_id = $beans['Accounts']->id; $bean->account_name = $beans['Accounts']->name; } else { if (!empty($selects['Accounts'])) { $bean->account_id = $selects['Accounts']; } } } //create meetings-users relationship if ($bean->object_name == "Meeting") { $bean = $this->setMeetingsUsersRelationship($bean); } $this->copyAddressFields($bean, $beans['Contacts']); $bean->save(); //if campaign id exists then there should be an entry in campaign_log table for the newly created contact: bug 44522 if (isset($lead->campaign_id) && $lead->campaign_id != null && $bean->object_name == "Contact") { campaign_log_lead_or_contact_entry($lead->campaign_id, $lead, $beans['Contacts'], 'contact'); } } if (!empty($lead)) { //Mark the original Lead converted $lead->status = "Converted"; $lead->converted = '1'; $lead->in_workflow = true; $lead->save(); } $this->displaySaveResults($beans); }
$encoded_contact_popup_request_data = $json->encode($popup_request_data); //Account require_once 'include/QuickSearchDefaults.php'; $qsd = QuickSearchDefaults::getQuickSearchDefaults(); $qsd->setFormName('BusinessCard'); $sqs_objects = array('BusinessCard_display_account_name' => $qsd->getQSParent()); $sqs_objects['BusinessCard_display_account_name']['populate_list'] = array('display_account_name', 'selectedAccount'); $quicksearch_js = '<script type="text/javascript" language="javascript"> sqs_objects = ' . $json->encode($sqs_objects) . '; addToValidateBinaryDependency(\'BusinessCard\', \'display_account_name\', \'alpha\', false, \'' . $app_strings['ERR_SQS_NO_MATCH_FIELD'] . $app_strings['LBL_ACCOUNT'] . '\', \'selectedAccount\' ); </script>'; $selectAccountButton = $quicksearch_js; $selectAccountButton .= "<div id='newaccountdivlink' style='display:inline' class='dataLabel'>{$mod_strings['LNK_SELECT_ACCOUNT']}: <input class='sqsEnabled' name='display_account_name' id='display_account_name' type=\"text\" value=\"\"><input name='selectedAccount' id='selectedAccount' type=\"hidden\" value=''> <input type='button' title=\"{$app_strings['LBL_SELECT_BUTTON_TITLE']}\" type=\"button\" class=\"button\" value='{$app_strings['LBL_SELECT_BUTTON_LABEL']}' name=btn1 LANGUAGE=javascript onclick='open_popup(\"Accounts\", 600, 400, \"\", true, false, {$encoded_contact_popup_request_data});'/> <input type='button' title=\"{$app_strings['LBL_CLEAR_BUTTON_TITLE']}\" accessKey=\"{$app_strings['LBL_CLEAR_BUTTON_KEY']}\" type=\"button\" class=\"button\" value='{$app_strings['LBL_CLEAR_BUTTON_LABEL']}' name=btn1 LANGUAGE=javascript onclick='document.forms[\"BusinessCard\"].selectedAccount.value=\"\";document.forms[\"BusinessCard\"].display_account_name.value=\"\"; '><br><b>{$app_strings['LBL_OR']}</b></div><br><br>"; $xtpl->assign('FORMHEADER', get_form_header($mod_strings['LNK_NEW_ACCOUNT'], '', '')); require_once 'modules/Accounts/AccountFormBase.php'; $accountForm = new AccountFormBase(); $xtpl->assign('CLASS', 'evenListRow'); $xtpl->assign('FORMBODY', $selectAccountButton . "<slot class='dataLabel'><input class='checkbox' type='checkbox' name='newaccount' onclick='document.forms[\"BusinessCard\"].selectedAccount.value=\"\";document.forms[\"BusinessCard\"].display_account_name.value=\"\";toggleDisplay(\"newaccountdiv\");'> " . $mod_strings['LNK_NEW_ACCOUNT'] . "</slot> <div id='newaccountdiv' style='display:none'>" . $accountForm->getWideFormBody('Accounts', 'Accounts', 'BusinessCard', '')); require_once 'modules/Notes/NoteFormBase.php'; $noteForm = new NoteFormBase(); $postform = "<div id='accountnotelink'><p><a href='javascript:toggleDisplay(\"accountnote\");'>{$mod_strings['LNK_NEW_NOTE']}</a></p></div>"; $postform .= '<div id="accountnote" style="display:none">' . $noteForm->getFormBody('AccountNotes', 'Notes', 'BusinessCard', 85) . '</div>'; $xtpl->assign('POSTFORM', $postform); $xtpl->parse("main.headlessform"); //OPPORTUNITTY $xtpl->assign('FORMHEADER', get_form_header($mod_strings['LNK_NEW_OPPORTUNITY'], '', '')); require_once 'modules/Opportunities/OpportunityFormBase.php'; $oppForm = new OpportunityFormBase(); $xtpl->assign('CLASS', 'evenListRow'); $xtpl->assign('FORMBODY', "<slot class='dataLabel'><input class='checkbox' type='checkbox' name='newopportunity' onclick='toggleDisplay(\"newoppdiv\");'> " . $mod_strings['LNK_NEW_OPPORTUNITY'] . "</slot><div id='newoppdiv' style='display:none'>" . $oppForm->getWideFormBody('Opportunities', 'Opportunities', 'BusinessCard', '', false)); require_once 'modules/Notes/NoteFormBase.php';
<?php if (!defined('sugarEntry') || !sugarEntry) { die('Not A Valid Entry Point'); } /* * Your installation or use of this SugarCRM file is subject to the applicable * terms available at * http://support.sugarcrm.com/06_Customer_Center/10_Master_Subscription_Agreements/. * If you do not agree to all of the applicable terms or do not have the * authority to bind the entity as an authorized representative, then do not * install or use this SugarCRM file. * * Copyright (C) SugarCRM Inc. All rights reserved. */ /********************************************************************************* * Description: Saves an Account record and then redirects the browser to the * defined return URL. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ require_once 'modules/Accounts/AccountFormBase.php'; $accountForm = new AccountFormBase(); $prefix = empty($_REQUEST['dup_checked']) ? '' : 'Accounts'; $accountForm->handleSave($prefix, true, false);
echo getClassicModuleTitle('Accounts', array($moduleName, $mod_strings['LBL_SAVE_ACCOUNT']), true); $xtpl = new XTemplate('modules/Accounts/ShowDuplicates.html'); $xtpl->assign("MOD", $mod_strings); $xtpl->assign("APP", $app_strings); $xtpl->assign("PRINT_URL", "index.php?" . $GLOBALS['request_string']); $xtpl->assign("MODULE", $_REQUEST['module']); if ($error_msg != '') { $xtpl->assign("ERROR", $error_msg); $xtpl->parse("main.error"); } if (isset($_REQUEST['popup']) && $_REQUEST['popup'] == 'true' || isset($_POST['popup']) && $_POST['popup'] == true) { insert_popup_header($theme); } $account = new Account(); require_once 'modules/Accounts/AccountFormBase.php'; $accountForm = new AccountFormBase(); $GLOBALS['check_notify'] = FALSE; $query = 'select id, name, website, billing_address_city from accounts where deleted=0 '; $duplicates = $_POST['duplicate']; $count = count($duplicates); if ($count > 0) { $query .= "and ("; $first = true; foreach ($duplicates as $duplicate_id) { if (!$first) { $query .= ' OR '; } $first = false; $query .= "id='{$duplicate_id}' "; } $query .= ')';
/********************************************************************************* * The contents of this file are subject to the SugarCRM Public License Version * 1.1.3 ("License"); You may not use this file except in compliance with the * License. You may obtain a copy of the License at http://www.sugarcrm.com/SPL * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * All copies of the Covered Code must include on each user interface screen: * (i) the "Powered by SugarCRM" logo and * (ii) the SugarCRM copyright notice * in the same form as they appear in the distribution. See full license for * requirements. * * The Original Code is: SugarCRM Open Source * The Initial Developer of the Original Code is SugarCRM, Inc. * Portions created by SugarCRM are Copyright (C) 2004-2006 SugarCRM, Inc.; * All Rights Reserved. * Contributor(s): ______________________________________. ********************************************************************************/ /********************************************************************************* * Description: Saves an Account record and then redirects the browser to the * defined return URL. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ require_once 'modules/Accounts/AccountFormBase.php'; $accountForm = new AccountFormBase(); $accountForm->handleSave('', true, false);
/** * Saves a new Contact as well as any related items passed in. * * @return null */ protected function handleSave() { require_once "include/formbase.php"; $lead = false; if (!empty($_REQUEST['record'])) { $lead = new Lead(); $lead->retrieve($_REQUEST['record']); } global $beanList; $this->loadDefs(); $beans = array(); $selectedBeans = array(); $selects = array(); //Make sure the contact object is availible for relationships. $beans['Contacts'] = new Contact(); $beans['Contacts']->id = create_guid(); $beans['Contacts']->new_with_id = true; // Bug 39287 - Check for Duplicates on selected modules before save if (!empty($_REQUEST['selectedContact'])) { $beans['Contacts']->retrieve($_REQUEST['selectedContact']); if (!empty($beans['Contacts']->id)) { $beans['Contacts']->new_with_id = false; unset($_REQUEST["convert_create_Contacts"]); unset($_POST["convert_create_Contacts"]); } } elseif (!empty($_REQUEST["convert_create_Contacts"]) && $_REQUEST["convert_create_Contacts"] != "false" && !isset($_POST['ContinueContact'])) { require_once 'modules/Contacts/ContactFormBase.php'; $contactForm = new ContactFormBase(); $duplicateContacts = $contactForm->checkForDuplicates('Contacts'); if (isset($duplicateContacts)) { echo $contactForm->buildTableForm($duplicateContacts, 'Contacts'); return; } } if (!empty($_REQUEST['selectedAccount'])) { $_REQUEST['account_id'] = $_REQUEST['selectedAccount']; unset($_REQUEST["convert_create_Accounts"]); unset($_POST["convert_create_Accounts"]); } elseif (!empty($_REQUEST["convert_create_Accounts"]) && $_REQUEST["convert_create_Accounts"] != "false" && empty($_POST['ContinueAccount'])) { require_once 'modules/Accounts/AccountFormBase.php'; $accountForm = new AccountFormBase(); $duplicateAccounts = $accountForm->checkForDuplicates('Accounts'); if (isset($duplicateAccounts)) { echo $accountForm->buildTableForm($duplicateAccounts); return; } } foreach ($this->defs as $module => $vdef) { //Create a new record if "create" was selected if (!empty($_REQUEST["convert_create_{$module}"]) && $_REQUEST["convert_create_{$module}"] != "false") { //Save the new record $bean = $beanList[$module]; if (empty($beans[$module])) { $beans[$module] = new $bean(); } $this->populateNewBean($module, $beans[$module], $beans['Contacts'], $lead); } else { if (!empty($vdef['ConvertLead']['select'])) { //Save the new record $select = $vdef['ConvertLead']['select']; $fieldDef = $beans['Contacts']->field_defs[$select]; if (!empty($fieldDef['id_name']) && !empty($_REQUEST[$fieldDef['id_name']])) { $beans['Contacts']->{$fieldDef}['id_name'] = $_REQUEST[$fieldDef['id_name']]; $selects[$module] = $_REQUEST[$fieldDef['id_name']]; if (!empty($_REQUEST[$select])) { $beans['Contacts']->{$select} = $_REQUEST[$select]; } // Bug 39268 - Add the existing beans to a list of beans we'll potentially add the lead's activities to $bean = loadBean($module); $bean->retrieve($_REQUEST[$fieldDef['id_name']]); $selectedBeans[$module] = $bean; } } } } $this->handleActivities($lead, $beans); // Bug 39268 - Add the lead's activities to the selected beans $this->handleActivities($lead, $selectedBeans); //link selected account to lead if it exists if (!empty($selectedBeans['Accounts'])) { $lead->account_id = $selectedBeans['Accounts']->id; } //Handle non-contacts relationships foreach ($beans as $bean) { if (!empty($lead)) { if (empty($bean->assigned_user_id)) { $bean->assigned_user_id = $lead->assigned_user_id; } $leadsRel = $this->findRelationship($bean, $lead); if (!empty($leadsRel)) { $bean->load_relationship($leadsRel); $relObject = $bean->{$leadsRel}->getRelationshipObject(); if ($relObject->relationship_type == "one-to-many" && $bean->{$leadsRel}->_get_bean_position()) { $id_field = $relObject->rhs_key; $lead->{$id_field} = $bean->id; } else { $bean->{$leadsRel}->add($lead->id); } } } //Special case code for opportunities->Accounts if ($bean->object_name == "Opportunity" && empty($bean->account_id)) { if (isset($beans['Accounts'])) { $bean->account_id = $beans['Accounts']->id; $bean->account_name = $beans['Accounts']->name; } else { if (!empty($selects['Accounts'])) { $bean->account_id = $selects['Accounts']; } } } $this->copyAddressFields($bean, $beans['Contacts']); $bean->save(); } if (!empty($lead)) { //Mark the original Lead converted $lead->status = "Converted"; $lead->converted = '1'; $lead->in_workflow = true; $lead->save(); } $this->displaySaveResults($beans); }
/** * Create HTML form to enter a new record with the minimum necessary fields. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. */ function get_new_record_form() { require_once 'modules/Accounts/AccountFormBase.php'; $accountForm = new AccountFormBase(); return $accountForm->getForm('', 'Accounts'); }
$sugar_smarty->assign('RELATED_RECORDS_HEADER', $app_strings['LBL_RELATED_RECORDS']); $Relateds = array(); $Related = array(); //Account /////////////////////////////////////// /// /// SETUP PARENT POPUP $popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'ConvertLead', 'field_to_name_array' => array('id' => 'selectedAccount', 'name' => 'display_account_name')); $json = getJSONobj(); $encoded_popup_request_data = $json->encode($popup_request_data); // /////////////////////////////////////// $selectAccountButton = "<div id='newaccountdivlink' style='display:inline'><b>{$mod_strings['LNK_SELECT_ACCOUNT']}</b> <input readonly='readonly' name='display_account_name' id='display_account_name' type=\"text\" value=\"\"><input name='selectedAccount' id='selectedAccount' type=\"hidden\" value=''> <input type='button' title=\"{$app_strings['LBL_SELECT_BUTTON_TITLE']}\" accessKey=\"{$app_strings['LBL_SELECT_BUTTON_KEY']}\" type=\"button\" class=\"button\" value='{$app_strings['LBL_SELECT_BUTTON_LABEL']}' name=btn1 onclick='open_popup(\"Accounts\", 600, 400, \"\", true, false, {$encoded_popup_request_data});'> <input type='button' title=\"{$app_strings['LBL_CLEAR_BUTTON_TITLE']}\" accessKey=\"{$app_strings['LBL_CLEAR_BUTTON_KEY']}\" type=\"button\" class=\"button\" value='{$app_strings['LBL_CLEAR_BUTTON_LABEL']}' name=btn1 LANGUAGE=javascript onclick='document.forms[\"ConvertLead\"].selectedAccount.value=\"\";document.forms[\"ConvertLead\"].display_account_name.value=\"\"; '><br><b>{$app_strings['LBL_OR']}</b></div>"; $Related['FORMHEADER'] = get_form_header($mod_strings['LNK_NEW_ACCOUNT'], '', ''); require_once 'modules/Accounts/AccountFormBase.php'; $accountForm = new AccountFormBase(); $Related['Class'] = 'evenListRow'; $Related['FORMBODY'] = $selectAccountButton . "<h5 class='dataLabel'><input class='checkbox' type='checkbox' name='newaccount' onclick='document.forms[\"ConvertLead\"].selectedAccount.value=\"\";document.forms[\"ConvertLead\"].display_account_name.value=\"\";toggleDisplay(\"newaccountdiv\");'> " . $mod_strings['LNK_NEW_ACCOUNT'] . "</h5><div id='newaccountdiv' style='display:none'>" . $accountForm->getWideFormBody('Accounts', 'Accounts', 'ConvertLead', $lead); //$Related['FORMFOOTER']=get_form_footer(); require_once 'modules/Notes/NoteFormBase.php'; $noteForm = new NoteFormBase(); $postform = "<h5 class='dataLabel'><input class='checkbox' type='checkbox' name='newaccountnote' onclick='toggleDisplay(\"accountnote\");'> {$mod_strings['LNK_NEW_NOTE']}</h5>"; $postform .= '<div id="accountnote" style="display:none">' . $noteForm->getFormBody('AccountNotes', 'Notes', 'ConvertLead', 85) . '</div><br>'; if (!empty($lead->account_name)) { $postform .= '<script>document.forms["ConvertLead"].newaccount.checked=true;toggleDisplay("newaccountdiv");</script>'; } $Related['POSTFORM'] = $postform; array_push($Relateds, $Related); //OPPORTUNITTY $Related['FORMHEADER'] = get_form_header($mod_strings['LNK_NEW_OPPORTUNITY'], '', ''); require_once 'modules/Opportunities/OpportunityFormBase.php';