Fixed many issues in output HTML code according to HTML 4.01 Transitional format.
[fa-stable.git] / sales / manage / sales_groups.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_SALESGROUP';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "Sales Groups"));
17
18 include($path_to_root . "/includes/ui.inc");
19
20 simple_page_mode(true);
21
22 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
23 {
24
25         $input_error = 0;
26
27         if (strlen($_POST['description']) == 0) 
28         {
29                 $input_error = 1;
30                 display_error(_("The sales group description cannot be empty."));
31                 set_focus('description');
32         }
33
34         if ($input_error != 1)
35         {
36         if ($selected_id != -1) 
37         {
38                 update_sales_group($selected_id, $_POST['description']);
39                         $note = _('Selected sales group has been updated');
40         } 
41         else 
42         {
43                 add_sales_group($_POST['description']);
44                         $note = _('New sales group has been added');
45         }
46     
47                 display_notification($note);            
48                 $Mode = 'RESET';
49         }
50
51
52 if ($Mode == 'Delete')
53 {
54
55         $cancel_delete = 0;
56
57         // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtors_master'
58
59         if (key_in_foreign_table($selected_id, 'cust_branch', 'group_no'))
60         {
61                 $cancel_delete = 1;
62                 display_error(_("Cannot delete this group because customers have been created using this group."));
63         } 
64         if ($cancel_delete == 0) 
65         {
66                 delete_sales_group($selected_id);
67                 display_notification(_('Selected sales group has been deleted'));
68         } //end if Delete group
69         $Mode = 'RESET';
70
71
72 if ($Mode == 'RESET')
73 {
74         $selected_id = -1;
75         $sav = get_post('show_inactive');
76         unset($_POST);
77         if ($sav) $_POST['show_inactive'] = 1;
78 }
79 //-------------------------------------------------------------------------------------------------
80
81 $result = get_sales_groups(check_value('show_inactive'));
82
83 start_form();
84 start_table(TABLESTYLE, "width='30%'");
85 $th = array(_("ID"), _("Group Name"), "", "");
86 inactive_control_column($th);
87
88 table_header($th);
89 $k = 0; 
90
91 while ($myrow = db_fetch($result)) 
92 {
93         
94         alt_table_row_color($k);
95                 
96         label_cell($myrow["id"]);
97         label_cell($myrow["description"]);
98         inactive_control_cell($myrow["id"], $myrow["inactive"], 'groups', 'id');
99         edit_button_cell("Edit".$myrow["id"], _("Edit"));
100         delete_button_cell("Delete".$myrow["id"], _("Delete"));
101         end_row();
102 }
103
104 inactive_control_row($th);
105 end_table(1);
106
107 //-------------------------------------------------------------------------------------------------
108
109 start_table(TABLESTYLE2);
110
111 if ($selected_id != -1) 
112 {
113         if ($Mode == 'Edit') {
114                 //editing an existing group
115                 $myrow = get_sales_group($selected_id);
116
117                 $_POST['description']  = $myrow["description"];
118         }
119         hidden("selected_id", $selected_id);
120         label_row(_("ID"), $myrow["id"]);
121
122
123 text_row_ex(_("Group Name:"), 'description', 30); 
124
125 end_table(1);
126
127 submit_add_or_update_center($selected_id == -1, '', 'both');
128
129 end_form();
130
131 end_page();
132 ?>