e5a72f95bd982f7480d5f3050949cef90df7557f
[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                 set_focus('abbr');
35         }
36         if (strlen($_POST['description']) == 0)
37         {
38                 $input_error = 1;
39                 display_error(_("The unit of measure description cannot be empty."));
40                 set_focus('description');
41         }
42
43         if ($input_error !=1) {
44         write_item_unit(isset($selected_id) ? $selected_id : '', $_POST['abbr'], $_POST['description'], $_POST['decimals'] );
45                 meta_forward($_SERVER['PHP_SELF']);
46         }
47 }
48
49 //----------------------------------------------------------------------------------
50
51 if (isset($_GET['delete']))
52 {
53
54         // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
55
56         if (item_unit_used($selected_id))
57         {
58                 display_error(_("Cannot delete this unit of measure because items have been created using this unit."));
59
60         }
61         else
62         {
63                 delete_item_unit($selected_id);
64                 meta_forward($_SERVER['PHP_SELF']);
65         }
66 }
67
68 //----------------------------------------------------------------------------------
69
70 $result = get_all_item_units();
71 start_table("$table_style width=50%");
72 $th = array(_('Unit'), _('Description'), _('Decimals'), "", "");
73
74 table_header($th);
75 $k = 0; //row colour counter
76
77 while ($myrow = db_fetch($result))
78 {
79
80         alt_table_row_color($k);
81
82         label_cell($myrow["abbr"]);
83         label_cell($myrow["name"]);
84         label_cell(($myrow["decimals"]==-1?_("User Quantity Decimals"):$myrow["decimals"]));
85
86         edit_link_cell(SID."selected_id=$myrow[0]");
87         delete_link_cell(SID."selected_id=$myrow[0]&delete=yes");
88         end_row();
89 }
90
91 end_table();
92
93 //----------------------------------------------------------------------------------
94
95 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Unit of Measure"));
96
97 start_form();
98
99 start_table("class='tablestyle_noborder'");
100
101 if (isset($selected_id))
102 {
103         //editing an existing item category
104
105         $myrow = get_item_unit($selected_id);
106
107         $_POST['abbr'] = $myrow["abbr"];
108         $_POST['description']  = $myrow["name"];
109         $_POST['decimals']  = $myrow["decimals"];
110
111         hidden('selected_id', $selected_id);
112 }
113
114 if (isset($selected_id) && item_unit_used($selected_id)) {
115     label_row(_("Unit Abbreviation:"), $_POST['abbr']);
116     hidden('abbr', $_POST['abbr']);
117 } else
118     text_row(_("Unit Abbreviation:"), 'abbr', null, 20, 20);
119 text_row(_("Descriptive Name:"), 'description', null, 40, 40);
120
121 number_list_row(_("Decimal Places:"), 'decimals', null, 0, 6, _("User Quantity Decimals"));
122
123 end_table(1);
124
125 submit_add_or_update_center(!isset($selected_id));
126
127 end_form();
128
129 end_page();
130
131 ?>