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(_("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 $sql = "UPDATE ".TB_PREF."groups SET description=".db_escape($_POST['description'])." WHERE id = ".db_escape($selected_id);
39 $note = _('Selected sales group has been updated');
43 $sql = "INSERT INTO ".TB_PREF."groups (description) VALUES (".db_escape($_POST['description']) . ")";
44 $note = _('New sales group has been added');
47 db_query($sql,"The sales group could not be updated or added");
48 display_notification($note);
53 if ($Mode == 'Delete')
58 // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtors_master'
60 $sql= "SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE group_no=".db_escape($selected_id);
61 $result = db_query($sql,"check failed");
62 $myrow = db_fetch_row($result);
66 display_error(_("Cannot delete this group because customers have been created using this group."));
68 if ($cancel_delete == 0)
70 $sql="DELETE FROM ".TB_PREF."groups WHERE id=".db_escape($selected_id);
71 db_query($sql,"could not delete sales group");
73 display_notification(_('Selected sales group has been deleted'));
74 } //end if Delete area
81 $sav = get_post('show_inactive');
83 if ($sav) $_POST['show_inactive'] = 1;
85 //-------------------------------------------------------------------------------------------------
87 $sql = "SELECT * FROM ".TB_PREF."groups";
88 if (!check_value('show_inactive')) $sql .= " WHERE !inactive";
89 $sql .= " ORDER BY description";
90 $result = db_query($sql,"could not get groups");
93 start_table("$table_style width=30%");
94 $th = array(_("Group Name"), "", "");
95 inactive_control_column($th);
100 while ($myrow = db_fetch($result))
103 alt_table_row_color($k);
105 label_cell($myrow["description"]);
106 inactive_control_cell($myrow["id"], $myrow["inactive"], 'groups', 'id');
107 edit_button_cell("Edit".$myrow["id"], _("Edit"));
108 delete_button_cell("Delete".$myrow["id"], _("Delete"));
112 inactive_control_row($th);
117 //-------------------------------------------------------------------------------------------------
119 start_table($table_style2);
121 if ($selected_id != -1)
123 if ($Mode == 'Edit') {
124 //editing an existing area
125 $sql = "SELECT * FROM ".TB_PREF."groups WHERE id=".db_escape($selected_id);
127 $result = db_query($sql,"could not get group");
128 $myrow = db_fetch($result);
130 $_POST['description'] = $myrow["description"];
132 hidden("selected_id", $selected_id);
135 text_row_ex(_("Group Name:"), 'description', 30);
139 submit_add_or_update_center($selected_id == -1, '', 'both');