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");
16 page(_($help_context = "Sales Groups"));
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_group($selected_id, $_POST['description']);
39 $note = _('Selected sales group has been updated');
43 add_sales_group($_POST['description']);
44 $note = _('New sales group 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', 'group_no'))
62 display_error(_("Cannot delete this group because customers have been created using this group."));
64 if ($cancel_delete == 0)
66 delete_sales_group($selected_id);
67 display_notification(_('Selected sales group has been deleted'));
68 } //end if Delete area
75 $sav = get_post('show_inactive');
77 if ($sav) $_POST['show_inactive'] = 1;
79 //-------------------------------------------------------------------------------------------------
81 $result = get_sales_groups(check_value('show_inactive'));
84 start_table(TABLESTYLE, "width=30%");
85 $th = array(_("Group Name"), "", "");
86 inactive_control_column($th);
91 while ($myrow = db_fetch($result))
94 alt_table_row_color($k);
96 label_cell($myrow["description"]);
97 inactive_control_cell($myrow["id"], $myrow["inactive"], 'groups', 'id');
98 edit_button_cell("Edit".$myrow["id"], _("Edit"));
99 delete_button_cell("Delete".$myrow["id"], _("Delete"));
103 inactive_control_row($th);
106 //-------------------------------------------------------------------------------------------------
108 start_table(TABLESTYLE2);
110 if ($selected_id != -1)
112 if ($Mode == 'Edit') {
113 //editing an existing area
114 $myrow = get_sales_group($selected_id);
116 $_POST['description'] = $myrow["description"];
118 hidden("selected_id", $selected_id);
121 text_row_ex(_("Group Name:"), 'description', 30);
125 submit_add_or_update_center($selected_id == -1, '', 'both');