Changed API for input/lists functions, added empty hints when needed
[fa-stable.git] / manufacturing / manage / work_centres.php
1 <?php
2
3 $page_security = 3;
4 $path_to_root="../..";
5 include($path_to_root . "/includes/session.inc");
6
7 page(_("Work Centres"));
8
9 include($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
10
11 include($path_to_root . "/includes/ui.inc");
12
13 if (isset($_GET['selected_id']))
14 {
15         $selected_id = $_GET['selected_id'];
16
17 elseif(isset($_POST['selected_id']))
18 {
19         $selected_id = $_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['name']) == 0) 
31         {
32                 $input_error = 1;
33                 display_error(_("The work centre name cannot be empty."));
34                 set_focus('name');
35         }
36
37         if ($input_error != 1) 
38         {
39                 
40         if (isset($selected_id)) 
41         {
42                 
43                 update_work_centre($selected_id, $_POST['name'], $_POST['description']);
44     
45         } 
46         else 
47         {
48     
49                 add_work_centre($_POST['name'], $_POST['description']);
50         }
51                 meta_forward($_SERVER['PHP_SELF']);     
52         }
53
54
55 //-----------------------------------------------------------------------------------
56
57 function can_delete($selected_id)
58 {
59         $sql= "SELECT COUNT(*) FROM ".TB_PREF."bom WHERE workcentre_added='$selected_id'";      
60         $result = db_query($sql, "check can delete work centre");
61         $myrow = db_fetch_row($result);
62         if ($myrow[0] > 0) 
63         {
64                 display_error(_("Cannot delete this work centre because BOMs have been created referring to it."));
65                 return false;
66         }
67         
68         $sql= "SELECT COUNT(*) FROM ".TB_PREF."wo_requirements WHERE workcentre='$selected_id'";
69         $result = db_query($sql, "check can delete work centre");
70         $myrow = db_fetch_row($result);
71         if ($myrow[0] > 0) 
72         {
73                 display_error(_("Cannot delete this work centre because work order requirements have been created referring to it."));
74                 return false;
75         }               
76         
77         return true;
78 }
79
80
81 //-----------------------------------------------------------------------------------
82
83 if (isset($_GET['delete'])) 
84 {
85
86         if (can_delete($selected_id))
87         {
88                 delete_work_centre($selected_id);
89                 meta_forward($_SERVER['PHP_SELF']);             
90         }
91 }
92
93 //-----------------------------------------------------------------------------------
94
95 $result = get_all_work_centres();
96
97 start_table("$table_style width=50%");
98 $th = array(_("Name"), _("description"), "", "");
99 table_header($th);
100
101 $k = 0;
102 while ($myrow = db_fetch($result)) 
103 {
104         
105         alt_table_row_color($k);        
106
107         label_cell($myrow["name"]);
108         label_cell($myrow["description"]);
109         edit_link_cell("selected_id=" . $myrow["id"]);
110         delete_link_cell("selected_id=" . $myrow["id"]. "&delete=1");
111         end_row();
112 }
113
114 end_table();
115
116 //-----------------------------------------------------------------------------------
117
118 hyperlink_no_params($_SERVER['PHP_SELF'], _("New Work Centre"));
119
120 start_form();
121
122 start_table($table_style2);
123
124 if (isset($selected_id)) 
125 {
126         //editing an existing status code
127
128         $myrow = get_work_centre($selected_id);
129
130         $_POST['name']  = $myrow["name"];
131         $_POST['description']  = $myrow["description"];
132
133         hidden('selected_id', $selected_id);
134
135
136 text_row_ex(_("Name:"), 'name', 40);
137 text_row_ex(_("Description:"), 'description', 50);
138
139 end_table(1);
140
141 submit_add_or_update_center(!isset($selected_id));
142
143 end_form();
144
145 //------------------------------------------------------------------------------------
146
147 end_page();
148
149 ?>