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 = 'EcmFkVatTables') {
if (!ACLController::checkAccess('EcmFkVatTables', 'edit', true)) {
return '';
}
// dump(1);exit;
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('EcmFkVatTables', '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_ecmFkVatTable_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_ecmFkVatTable_name $lbl_required_symbol
";
$form .= "$lbl_phone
";
$form .= "$lbl_website
";
$form .='';
$javascript = new javascript();
$javascript->setFormName($formname);
$javascript->setSugarBean(new EcmFkVatTable());
$javascript->addRequiredFields($prefix);
$form .=$javascript->getScript();
$mod_strings = $temp_strings;
return $form;
}
function getWideFormBody($prefix, $mod = '', $formname = '', $contact = '') {
if (!ACLController::checkAccess('EcmFkVatTables', '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;
$ecmFkVatTable = new EcmFkVatTable();
$lbl_required_symbol = $app_strings['LBL_REQUIRED_SYMBOL'];
$lbl_ecmFkVatTable_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_ecmFkVatTable_name $lbl_required_symbol |
{$mod_strings['LBL_DESCRIPTION']} |
|
|
| $lbl_phone |
|
| $lbl_website |
|
EOQ;
//carry forward custom lead fields common to ecmFkVatTables during Lead Conversion
$tempEcmFkVatTable = new EcmFkVatTable();
if (method_exists($contact, 'convertCustomFieldsForm'))
$contact->convertCustomFieldsForm($form, $tempEcmFkVatTable, $prefix);
unset($tempEcmFkVatTable);
$form .= <<
EOQ;
$javascript = new javascript();
$javascript->setFormName($formname);
$javascript->setSugarBean(new EcmFkVatTable());
$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 EcmFkVatTable();
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'])) {
$duplicateEcmFkVatTables = $this->checkForDuplicates($prefix);
if (isset($duplicateEcmFkVatTables)) {
$location = 'module=EcmFkVatTables&action=ShowDuplicates';
$get = '';
//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 .= "&EcmFkVatTables$field=" . urlencode($focus->$field);
}
}
foreach ($focus->additional_column_fields as $field) {
if (!empty($focus->$field)) {
$get .= "&EcmFkVatTables$field=" . urlencode($focus->$field);
}
}
if ($focus->hasCustomFields()) {
foreach ($focus->field_defs as $name => $field) {
if (!empty($field['source']) && $field['source'] == 'custom_fields') {
$get .= "&EcmFkVatTables$name=" . urlencode($focus->$name);
}
}
}
$emailAddress = new SugarEmailAddress();
$get .= $emailAddress->getFormBaseURL($focus);
//create list of suspected duplicate ecmFkVatTable id's in redirect get string
$i = 0;
foreach ($duplicateEcmFkVatTables as $ecmFkVatTable) {
$get .= "&duplicate[$i]=" . $ecmFkVatTable['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 .= 'EcmFkVatTables';
$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'];
//now redirect the post to modules/EcmFkVatTables/ShowDuplicates.php
if (!empty($_POST['is_ajax_call']) && $_POST['is_ajax_call'] == '1') {
ob_clean();
$json = getJSONobj();
$_SESSION['SHOW_DUPLICATES'] = $get;
echo $json->encode(array('status' => 'dupe', 'get' => $location . $get));
} else {
if (!empty($_POST['to_pdf']))
$location .= '&to_pdf=' . $_POST['to_pdf'];
$_SESSION['SHOW_DUPLICATES'] = $get;
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 = gmdate($GLOBALS['timedate']->get_db_date_time_format());
if ($monitor = $trackerManager->getMonitor('tracker')) {
$monitor->setValue('action', 'detailview');
$monitor->setValue('user_id', $GLOBALS['current_user']->id);
$monitor->setValue('module_name', 'EcmFkVatTables');
$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 .= 'EcmFkVatTables';
$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, 'EcmFkVatTables');
} else {
return $focus;
}
}
}