} /********************************************************************************* * 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: TODO: To be written. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ require_once 'modules/Contacts/ContactFormBase.php'; $contactForm = new ContactFormBase(); $contactForm->handleSave('', true, false);
/** * 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("MOD", $mod_strings); $xtpl->assign("APP", $app_strings); $xtpl->assign("IMAGE_PATH", $image_path); $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') { insert_popup_header($theme); } require_once 'modules/Contacts/Contact.php'; $contact = new Contact(); require_once 'modules/Contacts/ContactFormBase.php'; $contactForm = new ContactFormBase(); $GLOBALS['check_notify'] = FALSE; $query = 'select id,first_name, last_name, title, email1, email2 from contacts where deleted=0 '; $duplicates = $_GET['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 .= ')';
$xtpl->parse('main.row'); $xtpl->parse('main'); $xtpl->out('main'); } else { //CONTACT $xtpl->assign('FORMHEADER', $mod_strings['LNK_NEW_CONTACT']); $xtpl->parse("main.startform"); $xtpl->parse("main.savebegin"); require_once 'modules/Contacts/ContactFormBase.php'; $xtpl->assign('OPPNEEDSACCOUNT', $mod_strings['NTC_OPPORTUNITY_REQUIRES_ACCOUNT']); if ($sugar_config['require_accounts']) { $xtpl->assign('CHECKOPPORTUNITY', "&& checkOpportunity()"); } else { $xtpl->assign('CHECKOPPORTUNITY', ""); } $contactForm = new ContactFormBase(); $xtpl->assign('FORMBODY', $contactForm->getWideFormBody('Contacts', 'Contacts', 'BusinessCard', '', false)); $xtpl->assign('TABLECLASS', 'edit view'); $xtpl->assign('CLASS', 'dataLabel'); require_once 'modules/Notes/NoteFormBase.php'; $noteForm = new NoteFormBase(); $postform = "<h5 class='dataLabel'><input class='checkbox' type='checkbox' name='newcontactnote' onclick='toggleDisplay(\"contactnote\");'> {$mod_strings['LNK_NEW_NOTE']}</h5>"; $postform .= '<div id="contactnote" style="display:none">' . $noteForm->getFormBody('ContactNotes', 'Notes', 'BusinessCard', 85) . '</div>'; $xtpl->assign('POSTFORM', $postform); $xtpl->parse("main.form"); $xtpl->assign('HEADER', $app_strings['LBL_RELATED_RECORDS']); $xtpl->parse("main.hrrow"); $popup_request_data = array('call_back_function' => 'set_return', 'form_name' => 'BusinessCard', 'field_to_name_array' => array('id' => 'selectedAccount', 'name' => 'display_account_name')); $json = getJSONobj(); $encoded_contact_popup_request_data = $json->encode($popup_request_data); //Account
/** * 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/Contacts/ContactFormBase.php'; $form = new ContactFormBase(); return $form->getForm(''); }
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License along with * this program; if not, see http://www.gnu.org/licenses or write to the Free * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301 USA. * * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * SugarCRM" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by SugarCRM". ********************************************************************************/ /********************************************************************************* * Description: TODO: To be written. * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc. * All Rights Reserved. * Contributor(s): ______________________________________.. ********************************************************************************/ require_once 'modules/Contacts/ContactFormBase.php'; $contactForm = new ContactFormBase(); $prefix = empty($_REQUEST['dup_checked']) ? '' : 'Contacts'; $contactForm->handleSave($prefix, true, false);
/** * */ function process_page_for_address() { global $theme; global $mod_strings; global $app_strings; global $currentModule; global $sugar_version, $sugar_config; $output_html = ''; $where = ''; $where = $this->_get_where_clause(); $formBase = new ContactFormBase(); if (isset($_REQUEST['doAction']) && $_REQUEST['doAction'] == 'save') { $formBase->handleSave('', false, true); } $first_name = empty($_REQUEST['first_name']) ? '' : $_REQUEST['first_name']; $last_name = empty($_REQUEST['last_name']) ? '' : $_REQUEST['last_name']; $account_name = empty($_REQUEST['account_name']) ? '' : $_REQUEST['account_name']; $request_data = empty($_REQUEST['request_data']) ? '' : $_REQUEST['request_data']; $hide_clear_button = empty($_REQUEST['hide_clear_button']) ? false : true; $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE']; $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY']; $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL']; // TODO: cleanup the construction of $addform $formbody = $formBase->getFormBody('', '', 'EmailEditView'); $addform = '<table><tr><td nowrap="nowrap" valign="top">' . str_replace('<br>', '</td><td nowrap="nowrap" valign="top"> ', $formbody) . '</td></tr></table>' . '<input type="hidden" name="action" value="Popup" />'; $formSave = <<<EOQ \t\t<input type="submit" name="button" class="button" title="{$lbl_save_button_title}" accesskey="{$lbl_save_button_key}" value=" {$lbl_save_button_label} " /> \t\t<input type="button" name="button" class="button" title="{$app_strings['LBL_CANCEL_BUTTON_TITLE']}" accesskey="{$app_strings['LBL_CANCEL_BUTTON_KEY']}" value="{$app_strings['LBL_CANCEL_BUTTON_LABEL']}" onclick="toggleDisplay('addform');" /> EOQ; $createContact = <<<EOQ \t\t<input type="button" id="showAdd" name="showAdd" class="button" value="{$mod_strings['LNK_NEW_CONTACT']}" onclick="toggleDisplay('addform');" /> EOQ; $addformheader = get_form_header($mod_strings['LNK_NEW_CONTACT'], $formSave, false); $button = "<form action='index.php' method='post' name='form' id='form'>\n"; if (!$hide_clear_button) { $button .= "<input type='button' name='button' class='button' onclick=\"send_back('','');\" title='" . $app_strings['LBL_CLEAR_BUTTON_TITLE'] . "' accesskey='" . $app_strings['LBL_CLEAR_BUTTON_KEY'] . "' value=' " . $app_strings['LBL_CLEAR_BUTTON_LABEL'] . " ' />\n"; } $button .= "<input type='submit' name='button' class='button' onclick=\"window.close();\" title='" . $app_strings['LBL_CANCEL_BUTTON_TITLE'] . "' accesskey='" . $app_strings['LBL_CANCEL_BUTTON_KEY'] . "' value=' " . $app_strings['LBL_CANCEL_BUTTON_LABEL'] . " ' />\n"; $button .= "</form>\n"; $form = new XTemplate('modules/Contacts/Address_picker.html'); $form->assign('MOD', $mod_strings); $form->assign('APP', $app_strings); $form->assign('ADDFORMHEADER', $addformheader); $form->assign('ADDFORM', $addform); $form->assign('THEME', $theme); $form->assign('MODULE_NAME', $currentModule); $form->assign('FIRST_NAME', $first_name); $form->assign('LAST_NAME', $last_name); $form->assign('ACCOUNT_NAME', $account_name); $form->assign('request_data', $request_data); // fill in for mass update $button = "<input type='hidden' name='module' value='Contacts'>" . "<input type='hidden' id='form_action' name='action' value='CloseContactAddressPopup'>" . "<input type='hidden' name='massupdate' value='true'>" . "<input type='hidden' name='delete' value='false'>" . "<input type='hidden' name='mass' value='Array'>" . "<input type='hidden' name='Update' value='Update'>"; if (isset($_REQUEST['mass']) && is_array($_REQUEST['mass'])) { foreach (array_unique($_REQUEST['mass']) as $record) { $button .= "<input style='display: none' checked type='checkbox' name='mass[]' value='{$record}'>\n"; } } $button .= "<input type='hidden' name='query' value='true'>"; $button .= "<input type='hidden' name='saved_associated_data' value=''>"; $button .= "<input type='hidden' name='close_window' value='true'>"; $button .= "<input type='hidden' name='html' value='change_address'>"; $button .= "<input type='hidden' name='account_name' value='{$account_name}'>"; // Added ID attribute to each element to use getElementById. To give ID attribute to an element is a good practice. $button .= "<span style='display: none'><textarea name='primary_address_street' id='primary_address_street'>" . str_replace("<br>", "\n", $_REQUEST["primary_address_street"]) . "</textarea></span>"; $button .= "<input type='hidden' name='primary_address_city' id='primary_address_city' value='" . $_REQUEST["primary_address_city"] . "'>"; $button .= "<input type='hidden' name='primary_address_state' id='primary_address_state' value='" . $_REQUEST["primary_address_state"] . "'>"; $button .= "<input type='hidden' name='primary_address_postalcode' id='primary_address_postalcode' value='" . $_REQUEST["primary_address_postalcode"] . "'>"; $button .= "<input type='hidden' name='primary_address_country' id='primary_address_country' value='" . $_REQUEST["primary_address_country"] . "'>"; // Adding an onclick event to remove address for alternate address, as user has selected copy address to primary address $button .= "<input title='" . $mod_strings['LBL_COPY_ADDRESS_CHECKED_PRIMARY'] . "' class='button' LANGUAGE=javascript type='submit' name='button' value=' " . $mod_strings['LBL_COPY_ADDRESS_CHECKED_PRIMARY'] . " ' onclick='clearAddress(\"alt\");'>\n"; // Adding a new block of code copy the address to alternate address for contacts $button .= "<span style='display: none'><textarea name='alt_address_street' id='alt_address_street'>" . str_replace("<br>", "\n", $_REQUEST["primary_address_street"]) . "</textarea></span>"; $button .= "<input type='hidden' name='alt_address_city' id='alt_address_city' value='" . $_REQUEST["primary_address_city"] . "'>"; $button .= "<input type='hidden' name='alt_address_state' id='alt_address_state' value='" . $_REQUEST["primary_address_state"] . "'>"; $button .= "<input type='hidden' name='alt_address_postalcode' id='alt_address_postalcode' value='" . $_REQUEST["primary_address_postalcode"] . "'>"; $button .= "<input type='hidden' name='alt_address_country' id='alt_address_country' value='" . $_REQUEST["primary_address_country"] . "'>"; // Adding an onclick event to remove address for primary address, as user has selected copy address to alternate address // NOTE => You need to change the label as as per SugarCRM way.. $button .= "<input title='" . $mod_strings['LBL_COPY_ADDRESS_CHECKED_ALT'] . "' class='button' LANGUAGE=javascript type='submit' name='button' value=' " . $mod_strings['LBL_COPY_ADDRESS_CHECKED_ALT'] . " ' onclick='clearAddress(\"primary\");'>\n"; $button .= "<input title='" . $app_strings['LBL_CANCEL_BUTTON_TITLE'] . "' accessKey='" . $app_strings['LBL_CANCEL_BUTTON_KEY'] . "' class='button' LANGUAGE=javascript onclick=\"window.close()\" type='submit' name='button' value=' " . $app_strings['LBL_CANCEL_BUTTON_LABEL'] . " '>\n"; ob_start(); insert_popup_header($theme); $output_html .= ob_get_contents(); ob_end_clean(); // Reset the sections that are already in the page so that they do not print again later. $form->reset('main.SearchHeader'); // create the listview $seed_bean = new Contact(); $ListView = new ListView(); $ListView->show_export_button = false; $ListView->process_for_popups = true; $ListView->show_delete_button = false; $ListView->show_select_menu = false; $ListView->setXTemplate($form); $ListView->setHeaderTitle($mod_strings['LBL_LIST_FORM_TITLE']); $ListView->setHeaderText($button); $ListView->setQuery($where, '', '', 'CONTACT'); $ListView->setModStrings($mod_strings); ob_start(); $ListView->processListViewMulti($seed_bean, 'main', 'CONTACT'); $output_html .= ob_get_contents(); ob_end_clean(); // Regular Expression to override sListView $exp = '/sListView.save_checks/si'; $change = 'save_checks'; $output_html = preg_replace(array($exp), array($change), $output_html); $output_html .= <<<EOJS <script type="text/javascript"> <!-- // Function to clear address according to the buttons clicked. function clearAddress(key) { document.getElementById(key+"_address_street").value = ""; document.getElementById(key+"_address_city").value = ""; document.getElementById(key+"_address_state").value = ""; document.getElementById(key+"_address_postalcode").value = ""; document.getElementById(key+"_address_country").value = ""; } checked_items = Array(); inputs_array = document.MassUpdate.elements; for(wp = 0 ; wp < inputs_array.length; wp++) { if(inputs_array[wp].name == "mass[]" && inputs_array[wp].style.display == "none") { checked_items.push(inputs_array[wp].value); } } for(i in checked_items) { for(wp = 0 ; wp < inputs_array.length; wp++) { if(inputs_array[wp].name == "mass[]" && inputs_array[wp].value == checked_items[i]) { inputs_array[wp].checked = true; } } } --> </script> EOJS; $output_html .= insert_popup_footer(); return $output_html; }
/** * 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); }
echo $sugar_smarty->fetch('modules/Leads/ConvertLead.tpl'); } else { $lead = new Lead(); $lead->retrieve($_REQUEST['record']); $sugar_smarty->assign('RECORD', $_REQUEST['record']); $sugar_smarty->assign('TABLECLASS', 'edit view'); //CONTACT $sugar_smarty->assign('FORMHEADER', $mod_strings['LNK_NEW_CONTACT']); $sugar_smarty->assign('OPPNEEDSACCOUNT', $mod_strings['NTC_OPPORTUNITY_REQUIRES_ACCOUNT']); if ($sugar_config['require_accounts']) { $sugar_smarty->assign('CHECKOPPORTUNITY', "&& checkOpportunity()"); } else { $sugar_smarty->assign('CHECKOPPORTUNITY', ""); } require_once 'modules/Contacts/ContactFormBase.php'; $contactForm = new ContactFormBase(); $sugar_smarty->assign('FORMBODY', $contactForm->getWideFormBody('Contacts', 'Contacts', 'ConvertLead', $lead, false)); //$sugar_smarty->assign('FORMFOOTER',get_form_footer()); $sugar_smarty->assign('CLASS', 'dataLabel'); require_once 'modules/Notes/NoteFormBase.php'; $noteForm = new NoteFormBase(); $postform = "<h5 class='dataLabel'><input class='checkbox' type='checkbox' name='newcontactnote' onclick='toggleDisplay(\"contactnote\");'> {$mod_strings['LNK_NEW_NOTE']}</h5>"; $postform .= '<div id="contactnote" style="display:none">' . $noteForm->getFormBody('ContactNotes', 'Notes', 'ConvertLead', 80) . '</div>'; $sugar_smarty->assign('POSTFORM', $postform); $sugar_smarty->assign('RELATED_RECORDS_HEADER', $app_strings['LBL_RELATED_RECORDS']); $Relateds = array(); $Related = array(); //Account /////////////////////////////////////// /// /// SETUP PARENT POPUP
sugar_die("Missing 'form' parameter"); } $the_javascript = "<script type='text/javascript' language='JavaScript'>\n"; $the_javascript .= "function set_return(contact_id, contact_email,contact_name,contact_display) {\n"; $the_javascript .= "\twindow.opener.set_current_parent(contact_id,contact_email,contact_name,contact_display);\n"; $the_javascript .= "}\n"; $the_javascript .= "</script>\n"; $button = "<form action='index.php' method='post' name='form' id='form'>\n"; $button .= "<input title='" . $app_strings['LBL_CLEAR_BUTTON_TITLE'] . "' accessKey='" . $app_strings['LBL_CLEAR_BUTTON_KEY'] . "' class='button' LANGUAGE=javascript onclick=\"window.opener.clear_email_addresses(); window.close()\" type='submit' name='button' value=' " . $app_strings['LBL_CLEAR_BUTTON_LABEL'] . " '>\n"; $button .= "<input title='" . $app_strings['LBL_CANCEL_BUTTON_TITLE'] . "' accessKey='" . $app_strings['LBL_CANCEL_BUTTON_KEY'] . "' class='button' LANGUAGE=javascript onclick=\"window.close()\" type='submit' name='button' value=' " . $app_strings['LBL_CANCEL_BUTTON_LABEL'] . " '>\n"; $button .= "</form>\n"; //$form->assign('INPUT_VALUE_NAME',$_REQUEST['input_value_name']); //$form->assign('INPUT_VALUE_ID',$_REQUEST['input_value_id']); $form->assign("SET_RETURN_JS", $the_javascript); require_once 'modules/Contacts/ContactFormBase.php'; $formBase = new ContactFormBase(); if (isset($_REQUEST['doAction']) && $_REQUEST['doAction'] == 'save') { $formBase->handleSave('', false, true); } $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE']; $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY']; $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL']; $formbody = $formBase->getFormBody('', '', $_REQUEST['form']); $formbody = '<table><tr><td nowrap valign="top">' . str_replace('<br>', '</td><td nowrap valign="top"> ', $formbody) . '</td></tr></table>'; $formSave = <<<EOQ <input title='{$lbl_save_button_title}' accessKey='{$lbl_save_button_key}' class='button' type='submit' name='button' value=' {$lbl_save_button_label} ' > <input title='{$app_strings['LBL_CANCEL_BUTTON_TITLE']}' accessKey='{$app_strings['LBL_CANCEL_BUTTON_KEY']}' class='button' onClick="toggleDisplay('addform');" type='button' name='button' value='{$app_strings['LBL_CANCEL_BUTTON_LABEL']}' > EOQ; $createContact = <<<EOQ <input class='button' type='button' name='showAdd' value='{$mod_strings['LNK_NEW_CONTACT']}' onClick='toggleDisplay("addform");'> EOQ; $form->assign("CREATECONTACT", $createContact);
/** * */ function process_page_for_address() { global $theme; global $mod_strings; global $app_strings; global $currentModule; global $sugar_version, $sugar_config; $output_html = ''; $where = ''; $where = $this->_get_where_clause(); $image_path = 'themes/' . $theme . '/images/'; $formBase = new ContactFormBase(); if (isset($_REQUEST['doAction']) && $_REQUEST['doAction'] == 'save') { $formBase->handleSave('', false, true); } $first_name = empty($_REQUEST['first_name']) ? '' : $_REQUEST['first_name']; $last_name = empty($_REQUEST['last_name']) ? '' : $_REQUEST['last_name']; $account_name = empty($_REQUEST['account_name']) ? '' : $_REQUEST['account_name']; $request_data = empty($_REQUEST['request_data']) ? '' : $_REQUEST['request_data']; $hide_clear_button = empty($_REQUEST['hide_clear_button']) ? false : true; $lbl_save_button_title = $app_strings['LBL_SAVE_BUTTON_TITLE']; $lbl_save_button_key = $app_strings['LBL_SAVE_BUTTON_KEY']; $lbl_save_button_label = $app_strings['LBL_SAVE_BUTTON_LABEL']; // TODO: cleanup the construction of $addform $formbody = $formBase->getFormBody('', '', 'EmailEditView'); $addform = '<table><tr><td nowrap="nowrap" valign="top">' . str_replace('<br>', '</td><td nowrap="nowrap" valign="top"> ', $formbody) . '</td></tr></table>' . '<input type="hidden" name="action" value="Popup" />'; $formSave = <<<EOQ \t\t<input type="submit" name="button" class="button" title="{$lbl_save_button_title}" accesskey="{$lbl_save_button_key}" value=" {$lbl_save_button_label} " /> \t\t<input type="button" name="button" class="button" title="{$app_strings['LBL_CANCEL_BUTTON_TITLE']}" accesskey="{$app_strings['LBL_CANCEL_BUTTON_KEY']}" value="{$app_strings['LBL_CANCEL_BUTTON_LABEL']}" onclick="toggleDisplay('addform');" /> EOQ; $createContact = <<<EOQ \t\t<input type="button" name="showAdd" class="button" value="{$mod_strings['LNK_NEW_CONTACT']}" onclick="toggleDisplay('addform');" /> EOQ; $addformheader = get_form_header($mod_strings['LNK_NEW_CONTACT'], $formSave, false); $button = "<form action='index.php' method='post' name='form' id='form'>\n"; if (!$hide_clear_button) { $button .= "<input type='button' name='button' class='button' onclick=\"send_back('','');\" title='" . $app_strings['LBL_CLEAR_BUTTON_TITLE'] . "' accesskey='" . $app_strings['LBL_CLEAR_BUTTON_KEY'] . "' value=' " . $app_strings['LBL_CLEAR_BUTTON_LABEL'] . " ' />\n"; } $button .= "<input type='submit' name='button' class='button' onclick=\"window.close();\" title='" . $app_strings['LBL_CANCEL_BUTTON_TITLE'] . "' accesskey='" . $app_strings['LBL_CANCEL_BUTTON_KEY'] . "' value=' " . $app_strings['LBL_CANCEL_BUTTON_LABEL'] . " ' />\n"; $button .= "</form>\n"; $form = new XTemplate('modules/Contacts/Address_picker.html'); $form->assign('MOD', $mod_strings); $form->assign('APP', $app_strings); //$form->assign('CREATECONTACT', $createContact); $form->assign('ADDFORMHEADER', $addformheader); $form->assign('ADDFORM', $addform); $form->assign('THEME', $theme); $form->assign('MODULE_NAME', $currentModule); $form->assign('FIRST_NAME', $first_name); $form->assign('LAST_NAME', $last_name); $form->assign('ACCOUNT_NAME', $account_name); $form->assign('request_data', $request_data); // fill in for mass update $button = "<input type='hidden' name='module' value='Contacts'><input type='hidden' id='form_action' name='action' value='index'><input type='hidden' name='massupdate' value='true'><input type='hidden' name='delete' value='false'><input type='hidden' name='mass' value='Array'><input type='hidden' name='Update' value='Update'>"; if (isset($_REQUEST['mass']) && is_array($_REQUEST['mass'])) { foreach (array_unique($_REQUEST['mass']) as $record) { $button .= "<input style='display: none' checked type='checkbox' name='mass[]' value='{$record}'>\n"; } } $button .= "<input type='hidden' name='saved_associated_data' value=''>"; $button .= "<input type='hidden' name='query' value='true'>"; $button .= "<input type='hidden' name='close_window' value='true'>"; $button .= "<input type='hidden' name='html' value='change_address'>"; $button .= "<input type='hidden' name='account_name' value='{$account_name}'>"; $button .= "<span style='display: none'><textarea name='primary_address_street'>" . str_replace("<br>", "\n", $_REQUEST["primary_address_street"]) . "</textarea></span>"; $button .= "<input type='hidden' name='primary_address_city' value='" . $_REQUEST["primary_address_city"] . "'>"; $button .= "<input type='hidden' name='primary_address_state' value='" . $_REQUEST["primary_address_state"] . "'>"; $button .= "<input type='hidden' name='primary_address_postalcode' value='" . $_REQUEST["primary_address_postalcode"] . "'>"; $button .= "<input type='hidden' name='primary_address_country' value='" . $_REQUEST["primary_address_country"] . "'>"; $button .= "<input type='hidden' name='Contacts_CONTACT_offset' value=''>"; $button .= "<input title='" . $mod_strings['LBL_COPY_ADDRESS_CHECKED'] . "' class='button' LANGUAGE=javascript type='submit' name='button' value=' " . $mod_strings['LBL_COPY_ADDRESS_CHECKED'] . " '>\n"; $button .= "<input title='" . $app_strings['LBL_CANCEL_BUTTON_TITLE'] . "' accessKey='" . $app_strings['LBL_CANCEL_BUTTON_KEY'] . "' class='button' LANGUAGE=javascript onclick=\"window.close()\" type='submit' name='button' value=' " . $app_strings['LBL_CANCEL_BUTTON_LABEL'] . " '>\n"; ob_start(); insert_popup_header($theme); $output_html .= ob_get_contents(); ob_end_clean(); //$output_html .= get_form_header($mod_strings['LBL_SEARCH_FORM_TITLE'], '', false); //$form->parse('main.SearchHeader'); //$output_html .= $form->text('main.SearchHeader'); $output_html .= get_form_footer(); // Reset the sections that are already in the page so that they do not print again later. $form->reset('main.SearchHeader'); // create the listview $seed_bean = new Contact(); $ListView = new ListView(); $ListView->show_export_button = false; $ListView->setXTemplate($form); $ListView->setHeaderTitle($mod_strings['LBL_LIST_FORM_TITLE']); $ListView->setHeaderText($button); $ListView->setQuery($where, '', '', 'CONTACT'); $ListView->setModStrings($mod_strings); // Added $ListView->process_for_popups = true; ob_start(); $ListView->processListViewMulti($seed_bean, 'main', 'CONTACT'); $output_html .= ob_get_contents(); ob_end_clean(); // The following is a regular expression filter that will convert the nested <a>...</a> tags // for the Next and Previous button links. The regular expression has 7 placeholder fields // Given sample HTML as follows /* ------------------------------------- <a href="/maint_4_5_0/index.php?module=Contacts&action=Popup&query=true&account_name=360 Vacations 723351&html=change_address&primary_address_street=111 Silicon Valley Road&primary_address_city=Ohio&primary_address_state=CA&primary_address_postalcode=53430&primary_address_country=USA&mode=undefined&create=undefined&metadata=undefined&Contacts_CONTACT_offset=20" onclick="javascript:return sListView.save_checks(20, \'Contacts_CONTACT_offset\')" class="listViewPaginationLinkS1">Next <img src=\'themes/GoldenGate/images/next.gif\' width=\'8\' height=\'11\' alt=\'Next\' border=\'0\' align=\'absmiddle\'></a> <a href="/maint_4_5_0/index.php?module=Contacts&action=Popup&query=true&account_name=360 Vacations 723351&html=change_address&primary_address_street=111 Silicon Valley Road&primary_address_city=Ohio&primary_address_state=CA&primary_address_postalcode=53430&primary_address_country=USA&mode=undefined&create=undefined&metadata=undefined&Contacts_CONTACT_offset=-100" onclick="javascript:return sListView.save_checks(980, \'Contacts_CONTACT_offset\')" class="listViewPaginationLinkS1">End <img src=\'themes/GoldenGate/images/end.gif\' width=\'13\' height=\'11\' alt=\'End\' border=\'0\' align=\'absmiddle\'> </a> -------------------------------------- The resulting preg_replace call should create Array of matches: [1] => Array ( [0] => 20 ) [2] => Array ( [0] => Next ) [3] => Array ( [0] => <img src='themes/GoldenGate/images/next.gif' width='8' height='11' alt='Next' border='0' align='absmiddle'> ) [4] => Array ( [0] => ) [5] => Array ( [0] => 980 ) [6] => Array ( [0] => End ) [7] => Array ( [0] => <img src='themes/GoldenGate/images/end.gif' width='13' height='11' alt='End' border='0' align='absmiddle'> ) */ $exp = '/<a.*?checks\\((\\d+),.*?>(.*?)(<img.*>).*<\\/a>(.*?)<a.*?checks\\((\\d+),.*?>(.*?)(<img.*>).*<\\/a>/Ui'; $change = '<a class="listViewPaginationLinkS1" onclick="javascript:save_checks(${1}, \'Contacts_CONTACT_offset\');" href="#"> ${2}${3}</a>${4}<a class="listViewPaginationLinkS1" onclick="javascript:save_checks(${5}, \'Contacts_CONTACT_offset\');" href="#">${6}${7}</a>'; $output_html = preg_replace(array($exp), array($change), $output_html); $output_html .= '<script> checked_items = Array(); inputs_array = document.MassUpdate.elements; for(wp = 0 ; wp < inputs_array.length; wp++) { if(inputs_array[wp].name == "mass[]" && inputs_array[wp].style.display == "none") { checked_items.push(inputs_array[wp].value); } } for(i in checked_items) { for(wp = 0 ; wp < inputs_array.length; wp++) { if(inputs_array[wp].name == "mass[]" && inputs_array[wp].value == checked_items[i]) { inputs_array[wp].checked = true; } } } </script>'; $output_html .= get_form_footer(); $output_html .= insert_popup_footer(); return $output_html; }