4474dc976f35c2d79bdc3c466cf9f2613a20ec08
[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                 set_focus('description');
35         }
36
37         if ($input_error !=1)
38         {
39         if (isset($selected_id)) 
40         {
41                     update_item_category($selected_id, $_POST['description']);                  
42         } 
43         else 
44         {
45                     add_item_category($_POST['description']);
46         }
47                 meta_forward($_SERVER['PHP_SELF']); 
48         }
49 }
50
51 //---------------------------------------------------------------------------------- 
52
53 if (isset($_GET['delete'])) 
54 {
55
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);
60         if ($myrow[0] > 0) 
61         {
62                 display_error(_("Cannot delete this item category because items have been created using this item category."));
63
64         } 
65         else 
66         {
67                 delete_item_category($selected_id);
68                 meta_forward($_SERVER['PHP_SELF']);             
69         }
70 }
71
72 //----------------------------------------------------------------------------------
73
74 $sql = "SELECT * FROM ".TB_PREF."stock_category";
75 $result = db_query($sql, "could not get stock categories");
76
77 start_table("$table_style width=30%");
78 $th = array(_("Name"), "", "");
79 table_header($th);
80 $k = 0; //row colour counter
81
82 while ($myrow = db_fetch($result)) 
83 {
84         
85         alt_table_row_color($k);
86
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");
90         end_row();
91 }
92
93 end_table();
94
95 //----------------------------------------------------------------------------------
96
97 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Item Category"));
98
99 start_form();
100
101 start_table("class='tablestyle_noborder'");
102
103 if (isset($selected_id)) 
104 {
105         //editing an existing item category
106
107         $myrow = get_item_category($selected_id);
108
109         $_POST['category_id'] = $myrow["category_id"];
110         $_POST['description']  = $myrow["description"];
111
112         hidden('selected_id', $selected_id);
113         hidden('category_id', $_POST['category_id']);
114 }
115
116 text_row(_("Category Name:"), 'description', null, 30, 30);  
117
118 end_table(1);
119
120 submit_add_or_update_center(!isset($selected_id));      
121
122 end_form();
123
124 end_page();
125
126 ?>