0df22f8e903b5922f53706a852064ac51fff66f0
[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 if (isset($_GET['selected_id']))
14 {
15         $selected_id = $_GET['selected_id'];
16
17 else if (isset($_POST['selected_id']))
18 {
19         $selected_id = $_POST['selected_id'];
20 }
21
22 //----------------------------------------------------------------------------------
23
24 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM'])) 
25 {
26
27         //initialise no input errors assumed initially before we test
28         $input_error = 0;
29
30         if (strlen($_POST['abbr']) == 0) 
31         {
32                 $input_error = 1;
33                 display_error(_("The unit of measure code cannot be empty."));
34         }
35         if (strlen($_POST['description']) == 0) 
36         {
37                 $input_error = 1;
38                 display_error(_("The unit of measure description cannot be empty."));
39         }
40         if (!is_numeric($_POST['decimals'])) 
41         {
42                 $input_error = 1;
43                 display_error(_("The number of decimal places must be integer."));
44         }
45
46
47         if ($input_error !=1) {
48         write_item_unit(isset($selected_id) ? $selected_id : '', $_POST['abbr'], $_POST['description'], $_POST['decimals'] );
49                 meta_forward($_SERVER['PHP_SELF']); 
50         }
51 }
52
53 //---------------------------------------------------------------------------------- 
54
55 if (isset($_GET['delete'])) 
56 {
57
58         // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
59     
60         if (item_unit_used($selected_id))
61         {
62                 display_error(_("Cannot delete this unit of measure because items have been created using this units."));
63
64         } 
65         else 
66         {
67                 delete_item_unit($selected_id);
68                 meta_forward($_SERVER['PHP_SELF']);             
69         }
70 }
71
72 //----------------------------------------------------------------------------------
73
74 $result = get_all_item_units();
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"]);
89
90         edit_link_cell(SID."selected_id=$myrow[0]");
91         delete_link_cell(SID."selected_id=$myrow[0]&delete=yes");
92         end_row();
93 }
94
95 end_table();
96
97 //----------------------------------------------------------------------------------
98
99 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Unit of Measure"));
100
101 start_form();
102
103 start_table("class='tablestyle_noborder'");
104
105 if (isset($selected_id)) 
106 {
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
118 if (isset($selected_id) && item_unit_used($selected_id)) {
119     label_row(_("Unit Abbreviation:"), $_POST['abbr']);
120     hidden('abbr', $_POST['abbr']);
121 } else
122     text_row(_("Unit Abbreviation:"), 'abbr', null, 20, 20);
123 text_row(_("Descriptive Name:"), 'description', null, 40, 40);  
124 text_row(_("Decimal Places:"), 'decimals', null, 40, 40);  
125
126 end_table(1);
127
128 submit_add_or_update_center(!isset($selected_id));
129
130 end_form();
131
132 end_page();
133
134 ?>