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 ***********************************************************************/
13 $path_to_root="../..";
14 include($path_to_root . "/includes/session.inc");
16 page(_("Item Categories"));
18 include_once($path_to_root . "/includes/ui.inc");
20 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
22 simple_page_mode(true);
23 //----------------------------------------------------------------------------------
25 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
28 //initialise no input errors assumed initially before we test
31 if (strlen($_POST['description']) == 0)
34 display_error(_("The item category description cannot be empty."));
35 set_focus('description');
40 if ($selected_id != -1)
42 update_item_category($selected_id, $_POST['description']);
43 display_notification(_('Selected item category has been updated'));
47 add_item_category($_POST['description']);
48 display_notification(_('New item category has been added'));
54 //----------------------------------------------------------------------------------
56 if ($Mode == 'Delete')
59 // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
60 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE category_id=".db_escape($selected_id);
61 $result = db_query($sql, "could not query stock master");
62 $myrow = db_fetch_row($result);
65 display_error(_("Cannot delete this item category because items have been created using this item category."));
69 delete_item_category($selected_id);
70 display_notification(_('Selected item category has been deleted'));
80 //----------------------------------------------------------------------------------
82 $sql = "SELECT * FROM ".TB_PREF."stock_category";
83 $result = db_query($sql, "could not get stock categories");
86 start_table("$table_style width=30%");
87 $th = array(_("Name"), "", "");
89 $k = 0; //row colour counter
91 while ($myrow = db_fetch($result))
94 alt_table_row_color($k);
96 label_cell($myrow["description"]);
97 edit_button_cell("Edit".$myrow[0], _("Edit"));
98 delete_button_cell("Delete".$myrow[0], _("Delete"));
105 //----------------------------------------------------------------------------------
109 start_table($table_style2);
111 if ($selected_id != -1)
113 if ($Mode == 'Edit') {
114 //editing an existing item category
115 $myrow = get_item_category($selected_id);
117 $_POST['category_id'] = $myrow["category_id"];
118 $_POST['description'] = $myrow["description"];
120 hidden('selected_id', $selected_id);
121 hidden('category_id');
124 text_row(_("Category Name:"), 'description', null, 30, 30);
128 submit_add_or_update_center($selected_id == -1, '', true);