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