Topic: Variables display but empty values sent to database
When the script below is called with a transaction id (trans_id) as well as a link_id and a batch_ref, everything displays as it should. Both top and bottom tables.
When "Add new" is clicked, the database table 0_batch_link should have the new link added.
Even though the new link variables display correctly in the bottom table, the added row in the database contains no data other than the auto-incremented record id.
I need a fresh pair of eyes to see what is missing. Any assistance much appreciated.
neholtz
NOTE: I have tried with both the local variables and the $_POST variables with the same result.
<?php
/*===================================================================\
| FrontBatchProcessing |
|--------------------------------------------------------------------|
| Copyright (C) 2019 NEH Systems |
| Date: 07-March-2019 |
| Description: FrontAccounting Transaction Batch Control Module |
| Released under GNU GPL License. |
| |
\===================================================================*/
$page_security = 'SA_VIEWLNKS';
$path_to_root = '../../..';
$module_root = $path_to_root . "/modules/BatchControl";
include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/ui.inc");
include_once($path_to_root . "/includes/date_functions.inc");
include_once($module_root . "/includes/batches_db.inc");
add_access_extensions();
$js = "";
if ($SysPrefs->use_popup_windows)
$js .= get_js_open_window(720, 640);
if (user_use_date_picker())
$js .= get_js_date_picker();
page(_($help_context = "Batch Control"));
simple_page_mode(true);
$link_id = '';
$batch_ref = '';
$trans_id = '';
//-----------------------------------------------------------------------------
// code to display items in batch_links table when called from batch_control
// the top table displays for both viewing links and also for adding new links
// if no items in the batch_links table, then display appropriate message
if (isset($_GET['link_id']) && !empty($_GET['link_id'])) // from batch_control
{
$link_id = $_GET['link_id'];
$result = get_links($link_id); // function in BatchControl/includes
if (!$result)
{
$msg = "No Linked Transactions Found."; // new batch without links
display_note($msg, 2, 2, "");
hyperlink_back(1);
}
else
{
start_table(TABLESTYLE);
$th = array(_("Batch ID"), _("Reference"), _("Transaction ID"), "", "");
inactive_control_column($th);
table_header($th);
$i = 0;
$k = 0;
while($row = db_fetch($result))
{
alt_table_row_color($k);
$i++;
label_cell($row['link_id']);
label_cell($row['batch_ref']);
label_cell($row['trans_id']);
edit_button_cell("Edit".$row["link_id"], _("Edit"));
delete_button_cell("Delete".$row["link_id"], _("Delete"));
end_row();
}
$num = count($row)-1;
end_table(1);
$msg = $i . " Linked Transactions Found.";
display_note($msg, $br=1, $br2=1, $extra="");
hyperlink_back(1);
}
}
//-----------------------------------------------------------------------------
// displays the bottom table if view_links has been called from batch_control
// with a trans_id to be added to the batch_links table - new link is displayed
//
if (isset($_GET['trans_id']) && !empty($_GET['trans_id']))
{
$trans_id = $_GET['trans_id'];
if (isset($_GET['batch_ref']) && !empty($_GET['batch_ref']))
$batch_ref = $_GET['batch_ref'];
$_POST['link_id'] = $link_id;
$_POST['batch_ref'] = $batch_ref;
$_POST['trans_id'] = $trans_id;
start_form();
start_table(TABLESTYLE2);
$th = array(_("Batch ID"), _("Reference"), _("Transaction ID"), "", "");
inactive_control_column($th);
table_header($th);
start_row();
echo "<td>" . $_POST['link_id'] . "</td><td>" . $_POST['batch_ref'] .
"</td><td>" . $_POST['trans_id'] . "</td><td></td><td></td>";
end_row();
br(1);
end_table(1);
$msg = "Transaction " . $_POST['trans_id'] . " will be added to Batch " .
$_POST['link_id'] . " " . $_POST['batch_ref'];
display_note($msg, 1, 1, "");
submit_add_or_update_center($selected_id == -1, '', 'both');
end_form();
end_page();
}
//-----------------------------------------------------------------------------
// functions
//-----------------------------------------------------------------------------
function can_process()
{
global $selected_id;
if (isset($_POST['link_id']) && strlen($_POST['link_id']) < 3)
{
display_error(_("Invalid Link ID."));
return false;
}
elseif (isset($_POST['batch_ref']) && strlen($_POST['batch_ref']) < 15)
{
display_error(_("Incomplete Batch Reference."));
return false;
}
elseif (isset($_POST['trans_id']) && strlen($_POST['trans_id']) < 7)
{
display_error(_("Invalid Trans ID."));
return false;
}
return true;
}
//-----------------------------------------------------------------------------
if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
{
if ($Mode=='ADD_ITEM' && can_process())
{
// function in BatchControl/includes
create_new_link($link_id, $batch_ref, $trans_id);
display_notification(_('New transaction link added to selected batch'));
$Mode = 'RESET';
}
else
{
// will decide after consult whether editing and/or deletion allowed
}
}