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."));
36 if (strlen($_POST['description']) == 0)
39 display_error(_("The unit of measure description cannot be empty."));
40 set_focus('description');
43 if ($input_error !=1) {
44 write_item_unit(isset($selected_id) ? $selected_id : '', $_POST['abbr'], $_POST['description'], $_POST['decimals'] );
45 meta_forward($_SERVER['PHP_SELF']);
49 //----------------------------------------------------------------------------------
51 if (isset($_GET['delete']))
54 // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
56 if (item_unit_used($selected_id))
58 display_error(_("Cannot delete this unit of measure because items have been created using this unit."));
63 delete_item_unit($selected_id);
64 meta_forward($_SERVER['PHP_SELF']);
68 //----------------------------------------------------------------------------------
70 $result = get_all_item_units();
71 start_table("$table_style width=50%");
72 $th = array(_('Unit'), _('Description'), _('Decimals'), "", "");
75 $k = 0; //row colour counter
77 while ($myrow = db_fetch($result))
80 alt_table_row_color($k);
82 label_cell($myrow["abbr"]);
83 label_cell($myrow["name"]);
84 label_cell(($myrow["decimals"]==-1?_("User Quantity Decimals"):$myrow["decimals"]));
86 edit_link_cell(SID."selected_id=$myrow[0]");
87 delete_link_cell(SID."selected_id=$myrow[0]&delete=yes");
93 //----------------------------------------------------------------------------------
95 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Unit of Measure"));
99 start_table("class='tablestyle_noborder'");
101 if (isset($selected_id))
103 //editing an existing item category
105 $myrow = get_item_unit($selected_id);
107 $_POST['abbr'] = $myrow["abbr"];
108 $_POST['description'] = $myrow["name"];
109 $_POST['decimals'] = $myrow["decimals"];
111 hidden('selected_id', $selected_id);
114 if (isset($selected_id) && item_unit_used($selected_id)) {
115 label_row(_("Unit Abbreviation:"), $_POST['abbr']);
116 hidden('abbr', $_POST['abbr']);
118 text_row(_("Unit Abbreviation:"), 'abbr', null, 20, 20);
119 text_row(_("Descriptive Name:"), 'description', null, 40, 40);
121 number_list_row(_("Decimal Places:"), 'decimals', null, 0, 6, _("User Quantity Decimals"));
125 submit_add_or_update_center(!isset($selected_id));