/** * 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); }
$xtpl->assign("MODULE", $_REQUEST['module']); if ($error_msg != '') { $xtpl->assign("ERROR", $error_msg); $xtpl->parse("main.error"); } if (isset($_POST['handle']) && $_POST['handle'] == 'Save') { require_once 'modules/Contacts/ContactFormBase.php'; $contactForm = new ContactFormBase(); require_once 'modules/Accounts/AccountFormBase.php'; $accountForm = new AccountFormBase(); require_once 'modules/Opportunities/OpportunityFormBase.php'; $oppForm = new OpportunityFormBase(); if (!isset($_POST['selectedContact']) && !isset($_POST['ContinueContact'])) { $duplicateContacts = $contactForm->checkForDuplicates('Contacts'); if (isset($duplicateContacts)) { $formBody = $contactForm->buildTableForm($duplicateContacts); $xtpl->assign('FORMBODY', $formBody); $xtpl->parse('main.formnoborder'); $xtpl->parse('main'); $xtpl->out('main'); return; } } if (empty($_POST['selectedAccount']) && empty($_POST['ContinueAccount'])) { $duplicateAccounts = $accountForm->checkForDuplicates('Accounts'); if (isset($duplicateAccounts)) { $xtpl->assign('FORMBODY', $accountForm->buildTableForm($duplicateAccounts)); $xtpl->parse('main.formnoborder'); $xtpl->parse('main'); $xtpl->out('main'); return;
/** * 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); }
$xtpl->assign("ERROR", $error_msg); $xtpl->parse("main.error"); } if (isset($_POST['handle']) && $_POST['handle'] == 'Save') { require_once 'modules/Contacts/Contact.php'; require_once 'modules/Contacts/ContactFormBase.php'; $contactForm = new ContactFormBase(); require_once 'modules/Accounts/AccountFormBase.php'; $accountForm = new AccountFormBase(); require_once 'modules/Opportunities/Opportunity.php'; require_once 'modules/Opportunities/OpportunityFormBase.php'; $oppForm = new OpportunityFormBase(); if (!isset($_POST['selectedContact']) && !isset($_POST['ContinueContact'])) { $duplicateContacts = $contactForm->checkForDuplicates('Contacts'); if (isset($duplicateContacts)) { $xtpl->assign('FORMBODY', $contactForm->buildTableForm($duplicateContacts)); $xtpl->parse('main.formnoborder'); $xtpl->parse('main'); $xtpl->out('main'); return; } } if (empty($_POST['selectedAccount']) && empty($_POST['ContinueAccount'])) { $duplicateAccounts = $accountForm->checkForDuplicates('Accounts'); if (isset($duplicateAccounts)) { $xtpl->assign('FORMBODY', $accountForm->buildTableForm($duplicateAccounts)); $xtpl->parse('main.formnoborder'); $xtpl->parse('main'); $xtpl->out('main'); return; }
$linked_beans[] = $lead->get_linked_beans('meetings', 'Meeting'); $linked_beans[] = $lead->get_linked_beans('emails', 'Email'); $GLOBALS['check_notify'] = FALSE; foreach ($_POST as $k => $v) { if (is_array($v)) { $val = encodeMultienumValue($_POST[$k]); $_POST[$k] = $val; } } $formbody = array(); $sugar_smarty->assign('SAVE_BUTTON_DISPLAY', 'style="display:none;"'); $sugar_smarty->assign('CANCEL_BUTTON_DISPLAY', 'style="display:none;"'); if (!isset($_POST['selectedContact']) && !isset($_POST['ContinueContact'])) { $duplicateContacts = $contactForm->checkForDuplicates('Contacts'); if (isset($duplicateContacts)) { $sugar_smarty->assign('DUPLICATEFORMBODY', $contactForm->buildTableForm($duplicateContacts, 'Contacts')); $selected_menu = 'form'; echo $sugar_smarty->fetch('modules/Leads/ConvertLead.tpl'); return; } } if (isset($_POST['newaccount']) && $_POST['newaccount'] == 'on' && empty($_POST['selectedAccount']) && empty($_POST['ContinueAccount'])) { $duplicateAccounts = $accountForm->checkForDuplicates('Accounts'); if (isset($duplicateAccounts)) { $sugar_smarty->assign('DUPLICATEFORMBODY', $accountForm->buildTableForm($duplicateAccounts)); $selected_menu = 'form'; echo $sugar_smarty->fetch('modules/Leads/ConvertLead.tpl'); return; } } if (isset($_POST['newopportunity']) && $_POST['newopportunity'] == 'on' && !isset($_POST['selectedOpportunity']) && !isset($_POST['ContinueOpportunity'])) {