*** empty log message ***
[fa-stable.git] / inventory / manage / item_categories.php
1 <?php
2
3 $page_security = 11;
4 $path_to_root="../..";
5 include($path_to_root . "/includes/session.inc");
6
7 page(_("Item Categories"));
8
9 include_once($path_to_root . "/includes/ui.inc");
10
11 include_once($path_to_root . "/inventory/includes/inventory_db.inc");
12
13 if (isset($_GET['selected_id']))
14 {
15         $selected_id = strtoupper($_GET['selected_id']);
16
17 else if (isset($_POST['selected_id']))
18 {
19         $selected_id = strtoupper($_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['description']) == 0) 
31         {
32                 $input_error = 1;
33                 display_error(_("The item category description cannot be empty."));
34         }
35
36         if ($input_error !=1)
37         {
38         if (isset($selected_id)) 
39         {
40                     update_item_category($selected_id, $_POST['description']);                  
41         } 
42         else 
43         {
44                     add_item_category($_POST['description']);
45         }
46                 meta_forward($_SERVER['PHP_SELF']); 
47         }
48 }
49
50 //---------------------------------------------------------------------------------- 
51
52 if (isset($_GET['delete'])) 
53 {
54
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);
59         if ($myrow[0] > 0) 
60         {
61                 display_error(_("Cannot delete this item category because items have been created using this item category."));
62
63         } 
64         else 
65         {
66                 delete_item_category($selected_id);
67                 meta_forward($_SERVER['PHP_SELF']);             
68         }
69 }
70
71 //----------------------------------------------------------------------------------
72
73 $sql = "SELECT * FROM ".TB_PREF."stock_category";
74 $result = db_query($sql, "could not get stock categories");
75
76 start_table("$table_style width=30%");
77 $th = array(_("Name"), "", "");
78 table_header($th);
79 $k = 0; //row colour counter
80
81 while ($myrow = db_fetch($result)) 
82 {
83         
84         alt_table_row_color($k);
85
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");
89         end_row();
90 }
91
92 end_table();
93
94 //----------------------------------------------------------------------------------
95
96 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Item Category"));
97
98 start_form();
99
100 start_table("class='tablestyle_noborder'");
101
102 if (isset($selected_id)) 
103 {
104         //editing an existing item category
105
106         $myrow = get_item_category($selected_id);
107
108         $_POST['category_id'] = $myrow["category_id"];
109         $_POST['description']  = $myrow["description"];
110
111         hidden('selected_id', $selected_id);
112         hidden('category_id', $_POST['category_id']);
113 }
114
115 text_row(_("Category Name:"), 'description', null, 30, 30);  
116
117 end_table(1);
118
119 submit_add_or_update_center(!isset($selected_id));      
120
121 end_form();
122
123 end_page();
124
125 ?>