5 include($path_to_root . "/includes/session.inc");
7 page(_("Units of Measure"));
9 include_once($path_to_root . "/includes/ui.inc");
11 include_once($path_to_root . "/inventory/includes/db/items_units_db.inc");
13 if (isset($_GET['selected_id']))
15 $selected_id = $_GET['selected_id'];
17 else if (isset($_POST['selected_id']))
19 $selected_id = $_POST['selected_id'];
22 //----------------------------------------------------------------------------------
24 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
27 //initialise no input errors assumed initially before we test
30 if (strlen($_POST['abbr']) == 0)
33 display_error(_("The unit of measure code cannot be empty."));
35 if (strlen($_POST['description']) == 0)
38 display_error(_("The unit of measure description cannot be empty."));
40 if (!is_numeric($_POST['decimals']))
43 display_error(_("The number of decimal places must be integer."));
47 if ($input_error !=1) {
48 write_item_unit(isset($selected_id) ? $selected_id : '', $_POST['abbr'], $_POST['description'], $_POST['decimals'] );
49 meta_forward($_SERVER['PHP_SELF']);
53 //----------------------------------------------------------------------------------
55 if (isset($_GET['delete']))
58 // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
60 if (item_unit_used($selected_id))
62 display_error(_("Cannot delete this unit of measure because items have been created using this units."));
67 delete_item_unit($selected_id);
68 meta_forward($_SERVER['PHP_SELF']);
72 //----------------------------------------------------------------------------------
74 $result = get_all_item_units();
75 start_table("$table_style width=50%");
76 $th = array(_('Unit'), _('Description'), _('Decimals'), "", "");
79 $k = 0; //row colour counter
81 while ($myrow = db_fetch($result))
84 alt_table_row_color($k);
86 label_cell($myrow["abbr"]);
87 label_cell($myrow["name"]);
88 label_cell($myrow["decimals"]);
90 edit_link_cell(SID."selected_id=$myrow[0]");
91 delete_link_cell(SID."selected_id=$myrow[0]&delete=yes");
97 //----------------------------------------------------------------------------------
99 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Unit of Measure"));
103 start_table("class='tablestyle_noborder'");
105 if (isset($selected_id))
107 //editing an existing item category
109 $myrow = get_item_unit($selected_id);
111 $_POST['abbr'] = $myrow["abbr"];
112 $_POST['description'] = $myrow["name"];
113 $_POST['decimals'] = $myrow["decimals"];
115 hidden('selected_id', $selected_id);
118 if (isset($selected_id) && item_unit_used($selected_id)) {
119 label_row(_("Unit Abbreviation:"), $_POST['abbr']);
120 hidden('abbr', $_POST['abbr']);
122 text_row(_("Unit Abbreviation:"), 'abbr', null, 20, 20);
123 text_row(_("Descriptive Name:"), 'description', null, 40, 40);
124 text_row(_("Decimal Places:"), 'decimals', null, 3, 3);
128 submit_add_or_update_center(!isset($selected_id));