Fixed record selection on pages using non-numeric selectors with simple_page_mode...
[fa-stable.git] / inventory / manage / item_units.php
1 <?php
2 $page_security = 11;
3 $path_to_root="../..";
4 include($path_to_root . "/includes/session.inc");
5
6 page(_("Units of Measure"));
7
8 include_once($path_to_root . "/includes/ui.inc");
9
10 include_once($path_to_root . "/inventory/includes/db/items_units_db.inc");
11
12 simple_page_mode(false);
13 //----------------------------------------------------------------------------------
14
15 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
16 {
17
18         //initialise no input errors assumed initially before we test
19         $input_error = 0;
20
21         if (strlen($_POST['abbr']) == 0)
22         {
23                 $input_error = 1;
24                 display_error(_("The unit of measure code cannot be empty."));
25                 set_focus('abbr');
26         }
27         if (strlen($_POST['description']) == 0)
28         {
29                 $input_error = 1;
30                 display_error(_("The unit of measure description cannot be empty."));
31                 set_focus('description');
32         }
33
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'));
38                 else
39                         display_notification(_('New unit has been added'));
40                 $Mode = 'RESET';
41         }
42 }
43
44 //----------------------------------------------------------------------------------
45
46 if ($Mode == 'Delete')
47 {
48
49         // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
50
51         if (item_unit_used($selected_id))
52         {
53                 display_error(_("Cannot delete this unit of measure because items have been created using this unit."));
54
55         }
56         else
57         {
58                 delete_item_unit($selected_id);
59                 display_notification(_('Selected unit has been deleted'));
60                 $Mode = 'RESET';
61         }
62 }
63
64 if ($Mode == 'RESET')
65 {
66         $selected_id = '';
67         unset($_POST);
68 }
69
70 //----------------------------------------------------------------------------------
71
72 $result = get_all_item_units();
73 start_form();
74 start_table("$table_style width=50%");
75 $th = array(_('Unit'), _('Description'), _('Decimals'), "", "");
76
77 table_header($th);
78 $k = 0; //row colour counter
79
80 while ($myrow = db_fetch($result))
81 {
82
83         alt_table_row_color($k);
84
85         label_cell($myrow["abbr"]);
86         label_cell($myrow["name"]);
87         label_cell(($myrow["decimals"]==-1?_("User Quantity Decimals"):$myrow["decimals"]));
88
89         edit_button_cell("Edit".$myrow[0], _("Edit"));
90         edit_button_cell("Delete".$myrow[0], _("Delete"));
91         end_row();
92 }
93
94 end_table();
95 end_form();
96 echo '<br>';
97
98 //----------------------------------------------------------------------------------
99
100 start_form();
101
102 start_table("class='tablestyle_noborder'");
103
104 if ($selected_id != '') 
105 {
106         if ($Mode == 'Edit') {
107                 //editing an existing item category
108
109                 $myrow = get_item_unit($selected_id);
110
111                 $_POST['abbr'] = $myrow["abbr"];
112                 $_POST['description']  = $myrow["name"];
113                 $_POST['decimals']  = $myrow["decimals"];
114         }
115         hidden('selected_id', $selected_id);
116 }
117 if ($selected_id != '' && item_unit_used($selected_id)) {
118     label_row(_("Unit Abbreviation:"), $_POST['abbr']);
119     hidden('abbr', $_POST['abbr']);
120 } else
121     text_row(_("Unit Abbreviation:"), 'abbr', null, 20, 20);
122 text_row(_("Descriptive Name:"), 'description', null, 40, 40);
123
124 number_list_row(_("Decimal Places:"), 'decimals', null, 0, 6, _("User Quantity Decimals"));
125
126 end_table(1);
127
128 submit_add_or_update_center($selected_id == '', '', true);
129
130 end_form();
131
132 end_page();
133
134 ?>