Fixed many issues in output HTML code according to HTML 4.01 Transitional format.
[fa-stable.git] / sales / manage / sales_areas.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_SALESAREA';
13 $path_to_root = "../..";
14 include($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "Sales Areas"));
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 area 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_area($selected_id, $_POST['description']);
39                         $note = _('Selected sales area has been updated');
40         } 
41         else 
42         {
43                 add_sales_area($_POST['description']);
44                         $note = _('New sales area 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', 'area'))
60         {
61                 $cancel_delete = 1;
62                 display_error(_("Cannot delete this area because customer branches have been created using this area."));
63         } 
64         if ($cancel_delete == 0) 
65         {
66                 delete_sales_area($selected_id);
67
68                 display_notification(_('Selected sales area has been deleted'));
69         } //end if Delete area
70         $Mode = 'RESET';
71
72
73 if ($Mode == 'RESET')
74 {
75         $selected_id = -1;
76         $sav = get_post('show_inactive');
77         unset($_POST);
78         $_POST['show_inactive'] = $sav;
79 }
80
81 //-------------------------------------------------------------------------------------------------
82
83 $result = get_sales_areas(check_value('show_inactive'));
84
85 start_form();
86 start_table(TABLESTYLE, "width='30%'");
87
88 $th = array(_("Area Name"), "", "");
89 inactive_control_column($th);
90
91 table_header($th);
92 $k = 0; 
93
94 while ($myrow = db_fetch($result)) 
95 {
96         
97         alt_table_row_color($k);
98                 
99         label_cell($myrow["description"]);
100         
101         inactive_control_cell($myrow["area_code"], $myrow["inactive"], 'areas', 'area_code');
102
103         edit_button_cell("Edit".$myrow["area_code"], _("Edit"));
104         delete_button_cell("Delete".$myrow["area_code"], _("Delete"));
105         end_row();
106 }
107         
108 inactive_control_row($th);
109 end_table();
110 echo '<br>';
111
112 //-------------------------------------------------------------------------------------------------
113
114 start_table(TABLESTYLE2);
115
116 if ($selected_id != -1) 
117 {
118         if ($Mode == 'Edit') {
119                 //editing an existing area
120                 $myrow = get_sales_area($selected_id);
121
122                 $_POST['description']  = $myrow["description"];
123         }
124         hidden("selected_id", $selected_id);
125
126
127 text_row_ex(_("Area Name:"), 'description', 30); 
128
129 end_table(1);
130
131 submit_add_or_update_center($selected_id == -1, '', 'both');
132
133 end_form();
134
135 end_page();
136 ?>