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