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."));
34 set_focus('description');
39 if (isset($selected_id))
41 update_item_category($selected_id, $_POST['description']);
45 add_item_category($_POST['description']);
47 meta_forward($_SERVER['PHP_SELF']);
51 //----------------------------------------------------------------------------------
53 if (isset($_GET['delete']))
56 // PREVENT DELETES IF DEPENDENT RECORDS IN 'stock_master'
57 $sql= "SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE category_id='$selected_id'";
58 $result = db_query($sql, "could not query stock master");
59 $myrow = db_fetch_row($result);
62 display_error(_("Cannot delete this item category because items have been created using this item category."));
67 delete_item_category($selected_id);
68 meta_forward($_SERVER['PHP_SELF']);
72 //----------------------------------------------------------------------------------
74 $sql = "SELECT * FROM ".TB_PREF."stock_category";
75 $result = db_query($sql, "could not get stock categories");
77 start_table("$table_style width=30%");
78 $th = array(_("Name"), "", "");
80 $k = 0; //row colour counter
82 while ($myrow = db_fetch($result))
85 alt_table_row_color($k);
87 label_cell($myrow["description"]);
88 edit_link_cell(SID."selected_id=$myrow[0]");
89 delete_link_cell(SID."selected_id=$myrow[0]&delete=yes");
95 //----------------------------------------------------------------------------------
97 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Item Category"));
101 start_table("class='tablestyle_noborder'");
103 if (isset($selected_id))
105 //editing an existing item category
107 $myrow = get_item_category($selected_id);
109 $_POST['category_id'] = $myrow["category_id"];
110 $_POST['description'] = $myrow["description"];
112 hidden('selected_id', $selected_id);
113 hidden('category_id', $_POST['category_id']);
116 text_row(_("Category Name:"), 'description', null, 30, 30);
120 submit_add_or_update_center(!isset($selected_id));