Fixed many issues in output HTML code according to HTML 4.01 Transitional format.
[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(_($help_context = "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         if (key_in_foreign_table($selected_id, 'bom', 'workcentre_added'))
60         {
61                 display_error(_("Cannot delete this work centre because BOMs have been created referring to it."));
62                 return false;
63         }
64
65         if (key_in_foreign_table($selected_id, 'wo_requirements', 'workcentre'))        
66         {
67                 display_error(_("Cannot delete this work centre because work order requirements have been created referring to it."));
68                 return false;
69         }               
70         
71         return true;
72 }
73
74
75 //-----------------------------------------------------------------------------------
76
77 if ($Mode == 'Delete')
78 {
79
80         if (can_delete($selected_id))
81         {
82                 delete_work_centre($selected_id);
83                 display_notification(_('Selected work center has been deleted'));
84         }
85         $Mode = 'RESET';
86 }
87
88 if ($Mode == 'RESET')
89 {
90         $selected_id = -1;
91         $sav = get_post('show_inactive');
92         unset($_POST);
93         $_POST['show_inactive'] = $sav;
94 }
95 //-----------------------------------------------------------------------------------
96
97 $result = get_all_work_centres(check_value('show_inactive'));
98
99 start_form();
100 start_table(TABLESTYLE, "width='50%'");
101 $th = array(_("Name"), _("description"), "", "");
102 inactive_control_column($th);
103 table_header($th);
104
105 $k = 0;
106 while ($myrow = db_fetch($result)) 
107 {
108         
109         alt_table_row_color($k);        
110
111         label_cell($myrow["name"]);
112         label_cell($myrow["description"]);
113         inactive_control_cell($myrow["id"], $myrow["inactive"], 'workcentres', 'id');
114         edit_button_cell("Edit".$myrow['id'], _("Edit"));
115         delete_button_cell("Delete".$myrow['id'], _("Delete"));
116         end_row();
117 }
118
119 inactive_control_row($th);
120 end_table(1);
121 //-----------------------------------------------------------------------------------
122
123 start_table(TABLESTYLE2);
124
125 if ($selected_id != -1) 
126 {
127         if ($Mode == 'Edit') {
128                 //editing an existing status code
129                 $myrow = get_work_centre($selected_id);
130                 
131                 $_POST['name']  = $myrow["name"];
132                 $_POST['description']  = $myrow["description"];
133         }
134         hidden('selected_id', $selected_id);
135
136
137 text_row_ex(_("Name:"), 'name', 40);
138 text_row_ex(_("Description:"), 'description', 50);
139
140 end_table(1);
141
142 submit_add_or_update_center($selected_id == -1, '', 'both');
143
144 end_form();
145
146 //------------------------------------------------------------------------------------
147
148 end_page();
149
150 ?>