5 include($path_to_root . "/includes/session.inc");
7 page(_("Item Categories"));
9 include_once($path_to_root . "/includes/ui.inc");
11 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
13 if (isset($_GET['selected_id']))
15 $selected_id = strtoupper($_GET['selected_id']);
17 else if (isset($_POST['selected_id']))
19 $selected_id = strtoupper($_POST['selected_id']);
22 //----------------------------------------------------------------------------------
24 if (isset($_POST['ADD_ITEM']) || isset($_POST['UPDATE_ITEM']))
27 //initialise no input errors assumed initially before we test
30 if (strlen($_POST['description']) == 0)
33 display_error(_("The item category description cannot be empty."));
38 if (isset($selected_id))
40 update_item_category($selected_id, $_POST['description']);
44 add_item_category($_POST['description']);
46 meta_forward($_SERVER['PHP_SELF']);
50 //----------------------------------------------------------------------------------
52 if (isset($_GET['delete']))
55 // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
56 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE category_id='$selected_id'";
57 $result = db_query($sql, "could not query stock master");
58 $myrow = db_fetch_row($result);
61 display_error(_("Cannot delete this item category because items have been created using this item category."));
66 delete_item_category($selected_id);
67 meta_forward($_SERVER['PHP_SELF']);
71 //----------------------------------------------------------------------------------
73 $sql = "SELECT * FROM ".TB_PREF."stock_category";
74 $result = db_query($sql, "could not get stock categories");
76 start_table("$table_style width=30%");
77 $th = array(_("Name"), "", "");
79 $k = 0; //row colour counter
81 while ($myrow = db_fetch($result))
84 alt_table_row_color($k);
86 label_cell($myrow["description"]);
87 edit_link_cell(SID."selected_id=$myrow[0]");
88 delete_link_cell(SID."selected_id=$myrow[0]&delete=yes");
94 //----------------------------------------------------------------------------------
96 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Item Category"));
100 start_table("class='tablestyle_noborder'");
102 if (isset($selected_id))
104 //editing an existing item category
106 $myrow = get_item_category($selected_id);
108 $_POST['category_id'] = $myrow["category_id"];
109 $_POST['description'] = $myrow["description"];
111 hidden('selected_id', $selected_id);
112 hidden('category_id', $_POST['category_id']);
115 text_row(_("Category Name:"), 'description', null, 30, 30);
119 submit_add_or_update_center(!isset($selected_id));