X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=blobdiff_plain;f=admin%2Fshipping_companies.php;h=f83fad5a7ee521d90c6cc363e79bfbcba7418666;hb=2bb32c39a0dc02afea9a67053d03d4b148114d5d;hp=7d4e530c7cb0a424742928a86d821c1a15f11a42;hpb=da8311619dd73feae101d246a1957b972e00cbd2;p=fa-stable.git diff --git a/admin/shipping_companies.php b/admin/shipping_companies.php index 7d4e530c..f83fad5a 100644 --- a/admin/shipping_companies.php +++ b/admin/shipping_companies.php @@ -1,22 +1,22 @@ . +***********************************************************************/ +$page_security = 'SA_SHIPPING'; $path_to_root=".."; include($path_to_root . "/includes/session.inc"); -page(_("Shipping Company")); +page(_($help_context = "Shipping Company")); include($path_to_root . "/includes/ui.inc"); +include($path_to_root . "/admin/db/shipping_db.inc"); - -if (isset($_GET['selected_id'])) -{ - $selected_id = $_GET['selected_id']; -} -else if (isset($_POST['selected_id'])) -{ - $selected_id = $_POST['selected_id']; -} - +simple_page_mode(true); //---------------------------------------------------------------------------------------------- function can_process() @@ -24,51 +24,36 @@ function can_process() if (strlen($_POST['shipper_name']) == 0) { display_error(_("The shipping company name cannot be empty.")); + set_focus('shipper_name'); return false; } return true; } //---------------------------------------------------------------------------------------------- - -if (isset($_POST['ADD_ITEM']) && can_process()) +if ($Mode=='ADD_ITEM' && can_process()) { - - $sql = "INSERT INTO ".TB_PREF."shippers (shipper_name, contact, phone, address) - VALUES ('" . $_POST['shipper_name'] . "', '" . - $_POST['contact'] . "', '" . - $_POST['phone'] . "', '" . - $_POST['address'] . "')"; - - db_query($sql,"The Shipping Company could not be added"); - meta_forward($_SERVER['PHP_SELF']); + add_shipper($_POST['shipper_name'], $_POST['contact'], $_POST['phone'], $_POST['phone2'], $_POST['address']); + display_notification(_('New shipping company has been added')); + $Mode = 'RESET'; } //---------------------------------------------------------------------------------------------- -if (isset($_POST['UPDATE_ITEM']) && can_process()) +if ($Mode=='UPDATE_ITEM' && can_process()) { - - $sql = "UPDATE ".TB_PREF."shippers SET shipper_name='" . $_POST['shipper_name'] . "' , - contact ='" . $_POST['contact'] . "' , - phone ='" . $_POST['phone'] . "' , - address ='" . $_POST['address'] . "' - WHERE shipper_id = $selected_id"; - - db_query($sql,"The shipping company could not be updated"); - meta_forward($_SERVER['PHP_SELF']); + update_shipper($selected_id, $_POST['shipper_name'], $_POST['contact'], $_POST['phone'], $_POST['phone2'], $_POST['address']); + display_notification(_('Selected shipping company has been updated')); + $Mode = 'RESET'; } //---------------------------------------------------------------------------------------------- -if (isset($_GET['delete'])) +if ($Mode == 'Delete') { // PREVENT DELETES IF DEPENDENT RECORDS IN 'sales_orders' - $sql= "SELECT COUNT(*) FROM ".TB_PREF."sales_orders WHERE ship_via='$selected_id'"; - $result = db_query($sql,"check failed"); - $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + if (key_in_foreign_table($selected_id, 'sales_orders', 'ship_via')) { $cancel_delete = 1; display_error(_("Cannot delete this shipping company because sales orders have been created using this shipper.")); @@ -76,32 +61,35 @@ if (isset($_GET['delete'])) else { // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtor_trans' - - $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtor_trans WHERE ship_via='$selected_id'"; - $result = db_query($sql,"check failed"); - $myrow = db_fetch_row($result); - if ($myrow[0] > 0) + if (key_in_foreign_table($selected_id, 'debtor_trans', 'ship_via')) { $cancel_delete = 1; display_error(_("Cannot delete this shipping company because invoices have been created using this shipping company.")); } else { - $sql="DELETE FROM ".TB_PREF."shippers WHERE shipper_id=$selected_id"; - db_query($sql,"could not delete shipper"); - - meta_forward($_SERVER['PHP_SELF']); + delete_shipper($selected_id); + display_notification(_('Selected shipping company has been deleted')); } } + $Mode = 'RESET'; } +if ($Mode == 'RESET') +{ + $selected_id = -1; + $sav = get_post('show_inactive'); + unset($_POST); + $_POST['show_inactive'] = $sav; +} //---------------------------------------------------------------------------------------------- -$sql = "SELECT * FROM ".TB_PREF."shippers ORDER BY shipper_id"; -$result = db_query($sql,"could not get shippers"); +$result = get_shippers(check_value('show_inactive')); -start_table($table_style); -$th = array(_("Name"), _("Contact Person"), _("Phone Number"), _("Address"), "", ""); +start_form(); +start_table(TABLESTYLE); +$th = array(_("Name"), _("Contact Person"), _("Phone Number"), _("Secondary Phone"), _("Address"), "", ""); +inactive_control_column($th); table_header($th); $k = 0; //row colour counter @@ -112,36 +100,34 @@ while ($myrow = db_fetch($result)) label_cell($myrow["shipper_name"]); label_cell($myrow["contact"]); label_cell($myrow["phone"]); + label_cell($myrow["phone2"]); label_cell($myrow["address"]); - edit_link_cell("selected_id=".$myrow[0]); - delete_link_cell("selected_id=".$myrow[0]."&delete=1"); + inactive_control_cell($myrow["shipper_id"], $myrow["inactive"], 'shippers', 'shipper_id'); + edit_button_cell("Edit".$myrow["shipper_id"], _("Edit")); + delete_button_cell("Delete".$myrow["shipper_id"], _("Delete")); end_row(); } -end_table(); +inactive_control_row($th); +end_table(1); //---------------------------------------------------------------------------------------------- -hyperlink_no_params($_SERVER['PHP_SELF'], _("New Shipping Company")); - -start_form(); - -start_table($table_style2); +start_table(TABLESTYLE2); -if (isset($selected_id)) +if ($selected_id != -1) { - //editing an existing Shipper - - $sql = "SELECT * FROM ".TB_PREF."shippers WHERE shipper_id=$selected_id"; + if ($Mode == 'Edit') { + //editing an existing Shipper - $result = db_query($sql, "could not get shipper"); - $myrow = db_fetch($result); - - $_POST['shipper_name'] = $myrow["shipper_name"]; - $_POST['contact'] = $myrow["contact"]; - $_POST['phone'] = $myrow["phone"]; - $_POST['address'] = $myrow["address"]; + $myrow = get_shipper($selected_id); + $_POST['shipper_name'] = $myrow["shipper_name"]; + $_POST['contact'] = $myrow["contact"]; + $_POST['phone'] = $myrow["phone"]; + $_POST['phone2'] = $myrow["phone2"]; + $_POST['address'] = $myrow["address"]; + } hidden('selected_id', $selected_id); } @@ -149,14 +135,15 @@ text_row_ex(_("Name:"), 'shipper_name', 40); text_row_ex(_("Contact Person:"), 'contact', 30); -text_row_ex(_("Phone Number:"), 'phone', 20); +text_row_ex(_("Phone Number:"), 'phone', 32, 30); + +text_row_ex(_("Secondary Phone Number:"), 'phone2', 32, 30); text_row_ex(_("Address:"), 'address', 50); end_table(1); -submit_add_or_update_center(!isset($selected_id)); +submit_add_or_update_center($selected_id == -1, '', 'both'); end_form(); end_page(); -?>