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");
16 page(_($help_context = "Sales Areas"));
18 include($path_to_root . "/includes/ui.inc");
20 simple_page_mode(true);
22 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
27 if (strlen($_POST['description']) == 0)
30 display_error(_("The area description cannot be empty."));
31 set_focus('description');
34 if ($input_error != 1)
36 if ($selected_id != -1)
38 update_sales_area($selected_id, $_POST['description']);
39 $note = _('Selected sales area has been updated');
43 add_sales_area($_POST['description']);
44 $note = _('New sales area has been added');
47 display_notification($note);
52 if ($Mode == 'Delete')
57 // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtors_master'
59 if (key_in_foreign_table($selected_id, 'cust_branch', 'area'))
62 display_error(_("Cannot delete this area because customer branches have been created using this area."));
64 if ($cancel_delete == 0)
66 delete_sales_area($selected_id);
68 display_notification(_('Selected sales area has been deleted'));
69 } //end if Delete area
76 $sav = get_post('show_inactive');
78 $_POST['show_inactive'] = $sav;
81 //-------------------------------------------------------------------------------------------------
83 $result = get_sales_areas(check_value('show_inactive'));
86 start_table(TABLESTYLE, "width='30%'");
88 $th = array(_("Area Name"), "", "");
89 inactive_control_column($th);
94 while ($myrow = db_fetch($result))
97 alt_table_row_color($k);
99 label_cell($myrow["description"]);
101 inactive_control_cell($myrow["area_code"], $myrow["inactive"], 'areas', 'area_code');
103 edit_button_cell("Edit".$myrow["area_code"], _("Edit"));
104 delete_button_cell("Delete".$myrow["area_code"], _("Delete"));
108 inactive_control_row($th);
112 //-------------------------------------------------------------------------------------------------
114 start_table(TABLESTYLE2);
116 if ($selected_id != -1)
118 if ($Mode == 'Edit') {
119 //editing an existing area
120 $myrow = get_sales_area($selected_id);
122 $_POST['description'] = $myrow["description"];
124 hidden("selected_id", $selected_id);
127 text_row_ex(_("Area Name:"), 'description', 30);
131 submit_add_or_update_center($selected_id == -1, '', 'both');