query($query);
$i=-1;
while(($row=$db->fetchByAssoc($result)) != null) {
$i++;
$rows[$i] = $row;
}
if ($i==-1) return null;
return $rows;
}
return null;
}
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 = sizeof($rows[0]) * 2 + 1;
if ($action != 'ShowDuplicates')
{
$form = "
EOQ;
$the_form .= get_left_form_footer();
$the_form .= get_validate_record_js();
return $the_form;
}
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(new Account());
$javascript->addRequiredFields($prefix);
$form .=$javascript->getScript();
$mod_strings = $temp_strings;
return $form;
}
function getWideFormBody($prefix, $mod='',$formname='', $contact=''){
if(!ACLController::checkAccess('Accounts', 'edit', true)){
return '';
}
if(empty($contact)){
$contact = new Contact();
}
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 = new Account();
$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 .= <<
$lbl_account_name $lbl_required_symbol |
{$mod_strings['LBL_DESCRIPTION']} |
|
|
$lbl_phone |
|
$lbl_website |
|
EOQ;
//carry forward custom lead fields common to accounts during Lead Conversion
$tempAccount = new Account();
if (method_exists($contact, 'convertCustomFieldsForm')) $contact->convertCustomFieldsForm($form, $tempAccount, $prefix);
unset($tempAccount);
$form .= <<
EOQ;
$javascript = new javascript();
$javascript->setFormName($formname);
$javascript->setSugarBean(new Account());
$javascript->addRequiredFields($prefix);
$form .=$javascript->getScript();
$mod_strings = $temp_strings;
return $form;
}
function handleSave($prefix,$redirect=true, $useRequired=false){
require_once('include/formbase.php');
$focus = new Account();
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
$get .= '&return_module=';
if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
else $get .= 'Accounts';
$get .= '&return_action=';
if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
//else $get .= 'DetailView';
if(!empty($_POST['return_id'])) $get .= '&return_id='.$_POST['return_id'];
if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
$_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));
}
else if(!empty($_REQUEST['ajax_load']))
{
echo "";
}
else {
if(!empty($_POST['to_pdf']))
$location .= '&to_pdf='.$_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') {
$get = '&module=';
if(!empty($_POST['return_module'])) $get .= $_POST['return_module'];
else $get .= 'Accounts';
$get .= '&action=';
if(!empty($_POST['return_action'])) $get .= $_POST['return_action'];
else $get .= 'Popup';
if(!empty($_POST['return_id'])) $get .= '&return_id='.$_POST['return_id'];
if(!empty($_POST['popup'])) $get .= '&popup='.$_POST['popup'];
if(!empty($_POST['create'])) $get .= '&create='.$_POST['create'];
if(!empty($_POST['to_pdf'])) $get .= '&to_pdf='.$_POST['to_pdf'];
$get .= '&name=' . $focus->name;
$get .= '&query=true';
header("Location: index.php?$get");
return;
}
if($redirect){
handleRedirect($return_id,'Accounts');
}else{
return $focus;
}
}
}
?>