4 include($path_to_root . "/includes/session.inc");
6 page(_("Units of Measure"));
8 include_once($path_to_root . "/includes/ui.inc");
10 include_once($path_to_root . "/inventory/includes/db/items_units_db.inc");
12 simple_page_mode(false);
13 //----------------------------------------------------------------------------------
15 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
18 //initialise no input errors assumed initially before we test
21 if (strlen($_POST['abbr']) == 0)
24 display_error(_("The unit of measure code cannot be empty."));
27 if (strlen($_POST['description']) == 0)
30 display_error(_("The unit of measure description cannot be empty."));
31 set_focus('description');
34 if ($input_error !=1) {
35 write_item_unit(htmlentities($selected_id), $_POST['abbr'], $_POST['description'], $_POST['decimals'] );
36 if($selected_id != '')
37 display_notification(_('Selected unit has been updated'));
39 display_notification(_('New unit has been added'));
44 //----------------------------------------------------------------------------------
46 if ($Mode == 'Delete')
49 // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
51 if (item_unit_used($selected_id))
53 display_error(_("Cannot delete this unit of measure because items have been created using this unit."));
58 delete_item_unit($selected_id);
59 display_notification(_('Selected unit has been deleted'));
70 //----------------------------------------------------------------------------------
72 $result = get_all_item_units();
74 start_table("$table_style width=50%");
75 $th = array(_('Unit'), _('Description'), _('Decimals'), "", "");
78 $k = 0; //row colour counter
80 while ($myrow = db_fetch($result))
83 alt_table_row_color($k);
85 label_cell($myrow["abbr"]);
86 label_cell($myrow["name"]);
87 label_cell(($myrow["decimals"]==-1?_("User Quantity Decimals"):$myrow["decimals"]));
89 edit_button_cell("Edit".$myrow[0], _("Edit"));
90 edit_button_cell("Delete".$myrow[0], _("Delete"));
98 //----------------------------------------------------------------------------------
102 start_table("class='tablestyle_noborder'");
104 if ($selected_id != '')
106 if ($Mode == 'Edit') {
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);
117 if ($selected_id != '' && item_unit_used($selected_id)) {
118 label_row(_("Unit Abbreviation:"), $_POST['abbr']);
119 hidden('abbr', $_POST['abbr']);
121 text_row(_("Unit Abbreviation:"), 'abbr', null, 20, 20);
122 text_row(_("Descriptive Name:"), 'description', null, 40, 40);
124 number_list_row(_("Decimal Places:"), 'decimals', null, 0, 6, _("User Quantity Decimals"));
128 submit_add_or_update_center($selected_id == '', '', true);