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 simple_page_mode(false);
14 //----------------------------------------------------------------------------------
16 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
19 //initialise no input errors assumed initially before we test
22 if (strlen($_POST['abbr']) == 0)
25 display_error(_("The unit of measure code cannot be empty."));
28 if (strlen($_POST['description']) == 0)
31 display_error(_("The unit of measure description cannot be empty."));
32 set_focus('description');
35 if ($input_error !=1) {
36 write_item_unit($selected_id, $_POST['abbr'], $_POST['description'], $_POST['decimals'] );
37 if($selected_id != '')
38 display_notification(_('Selected unit has been updated'));
40 display_notification(_('New unit has been added'));
45 //----------------------------------------------------------------------------------
47 if ($Mode == 'Delete')
50 // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
52 if (item_unit_used($selected_id))
54 display_error(_("Cannot delete this unit of measure because items have been created using this unit."));
59 delete_item_unit($selected_id);
60 display_notification(_('Selected unit has been deleted'));
71 //----------------------------------------------------------------------------------
73 $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"]==-1?_("User Quantity Decimals"):$myrow["decimals"]));
90 edit_button_cell("Edit".$myrow[0], _("Edit"));
91 edit_button_cell("Delete".$myrow[0], _("Delete"));
99 //----------------------------------------------------------------------------------
103 start_table("class='tablestyle_noborder'");
105 if ($selected_id != '')
107 if ($Mode == 'Edit') {
108 //editing an existing item category
110 $myrow = get_item_unit($selected_id);
112 $_POST['abbr'] = $myrow["abbr"];
113 $_POST['description'] = $myrow["name"];
114 $_POST['decimals'] = $myrow["decimals"];
116 hidden('selected_id', $selected_id);
119 if ($selected_id != '' && item_unit_used($selected_id)) {
120 label_row(_("Unit Abbreviation:"), $_POST['abbr']);
121 hidden('abbr', $_POST['abbr']);
123 text_row(_("Unit Abbreviation:"), 'abbr', null, 20, 20);
124 text_row(_("Descriptive Name:"), 'description', null, 40, 40);
126 number_list_row(_("Decimal Places:"), 'decimals', null, 0, 6, _("User Quantity Decimals"));
130 submit_add_or_update_center($selected_id == '', '', true);