db = DBManagerFactory::getInstance(); } public function checkForDuplicates($prefix) { require_once('include/formbase.php'); $query = ''; $name = !empty($_POST[$prefix . 'name']) ? $_POST[$prefix . 'name'] : ''; $shippingAddressCity = !empty($_POST[$prefix . 'shipping_address_city']) ? $_POST[$prefix . 'shipping_address_city'] : ''; $billingAddressCity = !empty($_POST[$prefix . 'billing_address_city']) ? $_POST[$prefix . 'billing_address_city'] : ''; $baseQuery = 'SELECT id, name, website, billing_address_city FROM accounts WHERE deleted != 1 AND '; if (!empty($name)) { $nameQuoted = $this->db->quoted($name . '%'); $query = $baseQuery ." name LIKE " . $nameQuoted; } if (!empty($billingAddressCity) || !empty($shippingAddressCity)) { $tempQuery = ''; if (!empty($billingAddressCity)) { $billingAddressCityQuoted = $this->db->quoted($billingAddressCity . '%'); $tempQuery .= "billing_address_city LIKE " . $billingAddressCityQuoted; } if (!empty($shippingAddressCity)) { $shippingAddressCityQuoted = $this->db->quoted($shippingAddressCity . '%'); $tempQuery .= (empty($tempQuery)) ?: ' OR '; $tempQuery .= "shipping_address_city LIKE " . $shippingAddressCityQuoted; } $query .= (empty($query)) ? $baseQuery : ' AND '; $query .= ' ('. $tempQuery . ' ) '; } if (!empty($query)) { $rows = array(); $db = DBManagerFactory::getInstance(); $result = $db->query($query); $i=-1; while (($row=$db->fetchByAssoc($result)) != null) { $i++; $rows[$i] = $row; } if ($i==-1) { return null; } return $rows; } return null; } public function buildTableForm($rows, $mod='Accounts') { if (!ACLController::checkAccess('Accounts', 'edit', true)) { return ''; } global $action; if (!empty($mod)) { global $current_language; $mod_strings = return_module_language($current_language, $mod); } else { global $mod_strings; } global $app_strings; $cols = count($rows[0]) * 2 + 1; if ($action != 'ShowDuplicates') { $form = "
"; $form .= '
'.$mod_strings['MSG_DUPLICATE']. '
'; unset($_POST['selectedAccount']); } else { $form = '
'.$mod_strings['MSG_SHOW_DUPLICATES']. '
'; } if (isset($_POST['return_action']) && $_POST['return_action'] == 'SubPanelViewer') { $_POST['return_action'] = 'DetailView'; } if (isset($_POST['return_action']) && $_POST['return_action'] == 'DetailView' && empty($_REQUEST['return_id'])) { unset($_POST['return_action']); } $form .= ""; if ($action != 'ShowDuplicates') { $form .= ""; } require_once('include/formbase.php'); $form .= getPostToForm(); if (isset($rows[0])) { foreach ($rows[0] as $key=>$value) { if ($key != 'id') { $form .= ""; } } $form .= ""; } $rowColor = 'oddListRowS1'; require_once 'include/portability/RouteConverter.php'; $routeConverter = new RouteConverter(); foreach ($rows as $row) { $form .= ""; if ($action != 'ShowDuplicates') { $form .= "\n"; } foreach ($row as $key=>$value) { if ($key != 'id') { if (isset($_POST['popup']) && $_POST['popup']==true) { $form .= "\n"; } else { $link = 'index.php?module=Accounts&action=DetailView&record='.$row['id']; if ($routeConverter->isLegacyRoute($link)) { $link = $routeConverter->generateUiLink($link); } $form .= "\n"; } } } if ($rowColor == 'evenListRowS1') { $rowColor = 'oddListRowS1'; } else { $rowColor = 'evenListRowS1'; } $form .= ""; } $form .= "
"; // handle buttons if ($action == 'ShowDuplicates') { $return_action = 'ListView'; // cn: bug 6658 - hardcoded return action break popup -> create -> duplicate -> cancel $return_action = (isset($_REQUEST['return_action']) && !empty($_REQUEST['return_action'])) ? $_REQUEST['return_action'] : $return_action; $form .= "\n"; if (!empty($_REQUEST['return_module']) && !empty($_REQUEST['return_action']) && !empty($_REQUEST['return_id'])) { $form .= ""; } elseif (!empty($_POST['return_module']) && !empty($_POST['return_action'])) { $form .= ""; } else { $form .= ""; } } else { $form .= "\n"; } $form .= "
 ". $mod_strings[$mod_strings['db_'.$key]]. "
[${app_strings['LBL_SELECT_BUTTON_LABEL']}]  $value$value
"; // handle buttons if ($action == 'ShowDuplicates') { $return_action = 'ListView'; // cn: bug 6658 - hardcoded return action break popup -> create -> duplicate -> cancel $return_action = (isset($_REQUEST['return_action']) && !empty($_REQUEST['return_action'])) ? $_REQUEST['return_action'] : $return_action; $form .= "\n"; if (!empty($_REQUEST['return_module']) && !empty($_REQUEST['return_action']) && !empty($_REQUEST['return_id'])) { $form .= ""; } elseif (!empty($_POST['return_module']) && !empty($_POST['return_action'])) { $form .= ""; } else { $form .= ""; } } else { $form .= "\n"; } $form .= "
"; return $form; } public function getForm($prefix, $mod='', $form='') { if (!ACLController::checkAccess('Accounts', 'edit', true)) { return ''; } if (!empty($mod)) { global $current_language; $mod_strings = return_module_language($current_language, $mod); } else { global $mod_strings; } global $app_strings; $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']; $the_form = get_left_form_header($mod_strings['LBL_NEW_FORM_TITLE']); $the_form .= << EOQ; $the_form .= $this->getFormBody($prefix, $mod, $prefix."AccountSave"); $the_form .= <<

EOQ; $the_form .= get_left_form_footer(); $the_form .= get_validate_record_js(); return $the_form; } public function getFormBody($prefix, $mod='', $formname='') { if (!ACLController::checkAccess('Accounts', 'edit', true)) { return ''; } global $mod_strings; $temp_strings = $mod_strings; if (!empty($mod)) { global $current_language; $mod_strings = return_module_language($current_language, $mod); } global $app_strings; global $current_user; $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL']; $lbl_account_name = $mod_strings['LBL_ACCOUNT_NAME']; $lbl_phone = $mod_strings['LBL_PHONE']; $lbl_website = $mod_strings['LBL_WEBSITE']; $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']; $user_id = $current_user->id; $form = << EOQ; $form .= "$lbl_account_name $lbl_required_symbol

"; $form .= "$lbl_phone

"; $form .= "$lbl_website

"; $form .='

'; $javascript = new javascript(); $javascript->setFormName($formname); $javascript->setSugarBean(BeanFactory::newBean('Accounts')); $javascript->addRequiredFields($prefix); $form .=$javascript->getScript(); $mod_strings = $temp_strings; return $form; } public function getWideFormBody($prefix, $mod='', $formname='', $contact='') { if (!ACLController::checkAccess('Accounts', 'edit', true)) { return ''; } if (empty($contact)) { $contact = BeanFactory::newBean('Contacts'); } global $mod_strings; $temp_strings = $mod_strings; if (!empty($mod)) { global $current_language; $mod_strings = return_module_language($current_language, $mod); } global $app_strings; global $current_user; $account = BeanFactory::newBean('Accounts'); $lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL']; $lbl_account_name = $mod_strings['LBL_ACCOUNT_NAME']; $lbl_phone = $mod_strings['LBL_PHONE']; $lbl_website = $mod_strings['LBL_WEBSITE']; if (isset($contact->assigned_user_id)) { $user_id=$contact->assigned_user_id; } else { $user_id = $current_user->id; } //Retrieve Email address and set email1, email2 $sugarEmailAddress = new SugarEmailAddress(); $sugarEmailAddress->handleLegacyRetrieve($contact); if (!isset($contact->email1)) { $contact->email1 = ''; } if (!isset($contact->email2)) { $contact->email2 = ''; } if (!isset($contact->email_opt_out)) { $contact->email_opt_out = ''; } $form=""; $default_desc=""; if (!empty($contact->description)) { $default_desc=$contact->description; } $form .= << EOQ; //carry forward custom lead fields common to accounts during Lead Conversion $tempAccount = BeanFactory::newBean('Accounts'); if (method_exists($contact, 'convertCustomFieldsForm')) { $contact->convertCustomFieldsForm($form, $tempAccount, $prefix); } unset($tempAccount); $form .= << EOQ; $javascript = new javascript(); $javascript->setFormName($formname); $javascript->setSugarBean(BeanFactory::newBean('Accounts')); $javascript->addRequiredFields($prefix); $form .=$javascript->getScript(); $mod_strings = $temp_strings; return $form; } public function handleSave($prefix, $redirect=true, $useRequired=false) { require_once('include/formbase.php'); $focus = BeanFactory::newBean('Accounts'); if ($useRequired && !checkRequired($prefix, array_keys($focus->required_fields))) { return null; } $focus = populateFromPost($prefix, $focus); if (isset($GLOBALS['check_notify'])) { $check_notify = $GLOBALS['check_notify']; } else { $check_notify = false; } if (empty($_POST['record']) && empty($_POST['dup_checked'])) { $duplicateAccounts = $this->checkForDuplicates($prefix); if (isset($duplicateAccounts)) { $location='module=Accounts&action=ShowDuplicates'; $get = ''; // Bug 25311 - Add special handling for when the form specifies many-to-many relationships if (isset($_POST['relate_to']) && !empty($_POST['relate_to'])) { $get .= '&Accountsrelate_to='.$_POST['relate_to']; } if (isset($_POST['relate_id']) && !empty($_POST['relate_id'])) { $get .= '&Accountsrelate_id='.$_POST['relate_id']; } //add all of the post fields to redirect get string foreach ($focus->column_fields as $field) { if (!empty($focus->$field) && !is_object($focus->$field)) { $get .= "&Accounts$field=".urlencode($focus->$field); } } foreach ($focus->additional_column_fields as $field) { if (!empty($focus->$field)) { $get .= "&Accounts$field=".urlencode($focus->$field); } } if ($focus->hasCustomFields()) { foreach ($focus->field_defs as $name=>$field) { if (!empty($field['source']) && $field['source'] == 'custom_fields') { $get .= "&Accounts$name=".urlencode($focus->$name); } } } $emailAddress = new SugarEmailAddress(); $get .= $emailAddress->getFormBaseURL($focus); //create list of suspected duplicate account id's in redirect get string $i=0; foreach ($duplicateAccounts as $account) { $get .= "&duplicate[$i]=".$account['id']; $i++; } //add return_module, return_action, and return_id to redirect get string $urlData = array('return_module' => 'Accounts', 'return_action' => ''); foreach (array('return_module', 'return_action', 'return_id', 'popup', 'create') as $var) { if (!empty($_POST[$var])) { $urlData[$var] = $_POST[$var]; } } $get .= "&".http_build_query($urlData); $_SESSION['SHOW_DUPLICATES'] = $get; //now redirect the post to modules/Accounts/ShowDuplicates.php if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { ob_clean(); $json = getJSONobj(); echo $json->encode(array('status' => 'dupe', 'get' => $location)); } elseif (!empty($_REQUEST['ajax_load'])) { echo ""; } else { if (!empty($_POST['to_pdf'])) { $location .= '&to_pdf='.urlencode($_POST['to_pdf']); } header("Location: index.php?$location"); } return null; } } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } $focus->save($check_notify); $return_id = $focus->id; $GLOBALS['log']->debug("Saved record with id of ".$return_id); if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') { $json = getJSONobj(); echo $json->encode(array('status' => 'success', 'get' => '')); $trackerManager = TrackerManager::getInstance(); $timeStamp = TimeDate::getInstance()->nowDb(); if ($monitor = $trackerManager->getMonitor('tracker')) { $monitor->setValue('action', 'detailview'); $monitor->setValue('user_id', $GLOBALS['current_user']->id); $monitor->setValue('module_name', 'Accounts'); $monitor->setValue('date_modified', $timeStamp); $monitor->setValue('visible', 1); if (!empty($this->bean->id)) { $monitor->setValue('item_id', $return_id); $monitor->setValue('item_summary', $focus->get_summary_text()); } $trackerManager->saveMonitor($monitor, true, true); } return null; } if (isset($_POST['popup']) && $_POST['popup'] == 'true') { $urlData = array("query" => true, "name" => $focus->name, "module" => 'Accounts', 'action' => 'Popup'); if (!empty($_POST['return_module'])) { $urlData['module'] = $_POST['return_module']; } if (!empty($_POST['return_action'])) { $urlData['action'] = $_POST['return_action']; } foreach (array('return_id', 'popup', 'create', 'to_pdf') as $var) { if (!empty($_POST[$var])) { $urlData[$var] = $_POST[$var]; } } header("Location: index.php?".http_build_query($urlData)); return; } if ($redirect) { handleRedirect($return_id, 'Accounts'); } else { return $focus; } } }
$lbl_account_name $lbl_required_symbol {$mod_strings['LBL_DESCRIPTION']}
$lbl_phone
$lbl_website