Switch to new access levels system
[fa-stable.git] / manufacturing / manage / work_centres.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_WORKCENTRES';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_("Work Centres"));
17
18 include($path_to_root . "/manufacturing/includes/manufacturing_db.inc");
19
20 include($path_to_root . "/includes/ui.inc");
21
22 simple_page_mode(true);
23 //-----------------------------------------------------------------------------------
24
25 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
26 {
27
28         //initialise no input errors assumed initially before we test
29         $input_error = 0;
30
31         if (strlen($_POST['name']) == 0) 
32         {
33                 $input_error = 1;
34                 display_error(_("The work centre name cannot be empty."));
35                 set_focus('name');
36         }
37
38         if ($input_error != 1) 
39         {
40                 
41         if ($selected_id != -1) 
42         {
43                 update_work_centre($selected_id, $_POST['name'], $_POST['description']);
44                         display_notification(_('Selected work center has been updated'));
45         } 
46         else 
47         {
48                 add_work_centre($_POST['name'], $_POST['description']);
49                         display_notification(_('New work center has been added'));
50         }
51                 $Mode = 'RESET';
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 ($Mode == 'Delete')
84 {
85
86         if (can_delete($selected_id))
87         {
88                 delete_work_centre($selected_id);
89                 display_notification(_('Selected work center has been deleted'));
90         }
91         $Mode = 'RESET';
92 }
93
94 if ($Mode == 'RESET')
95 {
96         $selected_id = -1;
97         $sav = get_post('show_inactive');
98         unset($_POST);
99         $_POST['show_inactive'] = $sav;
100 }
101 //-----------------------------------------------------------------------------------
102
103 $result = get_all_work_centres(check_value('show_inactive'));
104
105 start_form();
106 start_table("$table_style width=50%");
107 $th = array(_("Name"), _("description"), "", "");
108 inactive_control_column($th);
109 table_header($th);
110
111 $k = 0;
112 while ($myrow = db_fetch($result)) 
113 {
114         
115         alt_table_row_color($k);        
116
117         label_cell($myrow["name"]);
118         label_cell($myrow["description"]);
119         inactive_control_cell($myrow["id"], $myrow["inactive"], 'workcentres', 'id');
120         edit_button_cell("Edit".$myrow['id'], _("Edit"));
121         delete_button_cell("Delete".$myrow['id'], _("Delete"));
122         end_row();
123 }
124
125 inactive_control_row($th);
126 end_table(1);
127 //-----------------------------------------------------------------------------------
128
129 start_table($table_style2);
130
131 if ($selected_id != -1) 
132 {
133         if ($Mode == 'Edit') {
134                 //editing an existing status code
135                 $myrow = get_work_centre($selected_id);
136                 
137                 $_POST['name']  = $myrow["name"];
138                 $_POST['description']  = $myrow["description"];
139         }
140         hidden('selected_id', $selected_id);
141
142
143 text_row_ex(_("Name:"), 'name', 40);
144 text_row_ex(_("Description:"), 'description', 50);
145
146 end_table(1);
147
148 submit_add_or_update_center($selected_id == -1, '', 'both');
149
150 end_form();
151
152 //------------------------------------------------------------------------------------
153
154 end_page();
155
156 ?>