Changed license type to GPLv3 in top of files
[fa-stable.git] / inventory / manage / item_categories.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 11;
13 $path_to_root="../..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_("Item Categories"));
17
18 include_once($path_to_root . "/includes/ui.inc");
19
20 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
21
22 simple_page_mode(true);
23 //----------------------------------------------------------------------------------
24
25 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
26 {
27
28         //initialise no input errors assumed initially before we test
29         $input_error = 0;
30
31         if (strlen($_POST['description']) == 0) 
32         {
33                 $input_error = 1;
34                 display_error(_("The item category description cannot be empty."));
35                 set_focus('description');
36         }
37
38         if ($input_error !=1)
39         {
40         if ($selected_id != -1) 
41         {
42                     update_item_category($selected_id, $_POST['description']);                  
43                         display_notification(_('Selected item category has been updated'));
44         } 
45         else 
46         {
47                     add_item_category($_POST['description']);
48                         display_notification(_('New item category has been added'));
49         }
50                 $Mode = 'RESET';
51         }
52 }
53
54 //---------------------------------------------------------------------------------- 
55
56 if ($Mode == 'Delete')
57 {
58
59         // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
60         $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE category_id='$selected_id'";
61         $result = db_query($sql, "could not query stock master");
62         $myrow = db_fetch_row($result);
63         if ($myrow[0] > 0) 
64         {
65                 display_error(_("Cannot delete this item category because items have been created using this item category."));
66         } 
67         else 
68         {
69                 delete_item_category($selected_id);
70                 display_notification(_('Selected item category has been deleted'));
71         }
72         $Mode = 'RESET';
73 }
74
75 if ($Mode == 'RESET')
76 {
77         $selected_id = -1;
78         unset($_POST);
79 }
80 //----------------------------------------------------------------------------------
81
82 $sql = "SELECT * FROM ".TB_PREF."stock_category";
83 $result = db_query($sql, "could not get stock categories");
84
85 start_form();
86 start_table("$table_style width=30%");
87 $th = array(_("Name"), "", "");
88 table_header($th);
89 $k = 0; //row colour counter
90
91 while ($myrow = db_fetch($result)) 
92 {
93         
94         alt_table_row_color($k);
95
96         label_cell($myrow["description"]);
97         edit_button_cell("Edit".$myrow[0], _("Edit"));
98         delete_button_cell("Delete".$myrow[0], _("Delete"));
99         end_row();
100 }
101
102 end_table();
103 end_form();
104 echo '<br>';
105 //----------------------------------------------------------------------------------
106
107 start_form();
108
109 start_table($table_style2);
110
111 if ($selected_id != -1) 
112 {
113         if ($Mode == 'Edit') {
114                 //editing an existing item category
115                 $myrow = get_item_category($selected_id);
116
117                 $_POST['category_id'] = $myrow["category_id"];
118                 $_POST['description']  = $myrow["description"];
119         }
120         hidden('selected_id', $selected_id);
121         hidden('category_id');
122 }
123
124 text_row(_("Category Name:"), 'description', null, 30, 30);  
125
126 end_table(1);
127
128 submit_add_or_update_center($selected_id == -1, '', true);
129
130 end_form();
131
132 end_page();
133
134 ?>