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 ***********************************************************************/
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 = '$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='$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='" . $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
83 //-------------------------------------------------------------------------------------------------
85 $sql = "SELECT * FROM ".TB_PREF."groups ORDER BY description";
86 $result = db_query($sql,"could not get groups");
89 start_table("$table_style width=30%");
90 $th = array(_("Group Name"), "", "");
94 while ($myrow = db_fetch($result))
97 alt_table_row_color($k);
99 label_cell($myrow["description"]);
100 edit_button_cell("Edit".$myrow["id"], _("Edit"));
101 delete_button_cell("Delete".$myrow["id"], _("Delete"));
110 //-------------------------------------------------------------------------------------------------
114 start_table($table_style2);
116 if ($selected_id != -1)
118 if ($Mode == 'Edit') {
119 //editing an existing area
120 $sql = "SELECT * FROM ".TB_PREF."groups WHERE id='$selected_id'";
122 $result = db_query($sql,"could not get group");
123 $myrow = db_fetch($result);
125 $_POST['description'] = $myrow["description"];
127 hidden("selected_id", $selected_id);
130 text_row_ex(_("Group Name:"), 'description', 30);
134 submit_add_or_update_center($selected_id == -1, '', true);