6 include($path_to_root . "/includes/session.inc");
8 page(_("Sales Groups"));
10 include($path_to_root . "/includes/ui.inc");
12 simple_page_mode(true);
14 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
19 if (strlen($_POST['description']) == 0)
22 display_error(_("The area description cannot be empty."));
23 set_focus('description');
26 if ($input_error != 1)
28 if ($selected_id != -1)
30 $sql = "UPDATE ".TB_PREF."groups SET description=".db_escape($_POST['description'])." WHERE id = '$selected_id'";
31 $note = _('Selected sales group has been updated');
35 $sql = "INSERT INTO ".TB_PREF."groups (description) VALUES (".db_escape($_POST['description']) . ")";
36 $note = _('New sales group has been added');
39 db_query($sql,"The sales group could not be updated or added");
40 display_notification($note);
45 if ($Mode == 'Delete')
50 // PREVENT DELETES IF DEPENDENT RECORDS IN 'debtors_master'
52 $sql= "SELECT COUNT(*) FROM ".TB_PREF."debtors_master WHERE group_no='$selected_id'";
53 $result = db_query($sql,"check failed");
54 $myrow = db_fetch_row($result);
58 display_error(_("Cannot delete this group because customers have been created using this group."));
60 if ($cancel_delete == 0)
62 $sql="DELETE FROM ".TB_PREF."groups WHERE id='" . $selected_id . "'";
63 db_query($sql,"could not delete sales group");
65 display_notification(_('Selected sales group has been deleted'));
66 } //end if Delete area
75 //-------------------------------------------------------------------------------------------------
77 $sql = "SELECT * FROM ".TB_PREF."groups ORDER BY description";
78 $result = db_query($sql,"could not get groups");
81 start_table("$table_style width=40%");
82 $th = array(_("Group Name"), "", "");
86 while ($myrow = db_fetch($result))
89 alt_table_row_color($k);
91 label_cell($myrow["description"]);
92 edit_button_cell("Edit".$myrow["id"], _("Edit"));
93 edit_button_cell("Delete".$myrow["id"], _("Delete"));
102 //-------------------------------------------------------------------------------------------------
106 start_table("$table_style2 width=40%");
108 if ($selected_id != -1)
110 if ($Mode == 'Edit') {
111 //editing an existing area
112 $sql = "SELECT * FROM ".TB_PREF."groups WHERE id='$selected_id'";
114 $result = db_query($sql,"could not get group");
115 $myrow = db_fetch($result);
117 $_POST['description'] = $myrow["description"];
119 hidden("selected_id", $selected_id);
122 text_row_ex(_("Group Name:"), 'description', 30);
126 submit_add_or_update_center($selected_id == -1, '', true);