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_CRMCATEGORY';
14 include($path_to_root . "/includes/session.inc");
15 include_once($path_to_root . "/includes/db/crm_contacts_db.inc");
17 page(_($help_context = "Contact Categories"));
19 include($path_to_root . "/includes/ui.inc");
21 simple_page_mode(true);
23 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
28 if (strlen($_POST['description']) == 0)
31 display_error(_("Category description cannot be empty."));
32 set_focus('description');
35 if ($input_error != 1)
37 if ($selected_id != -1)
39 update_crm_category($selected_id, get_post('type'), get_post('subtype'),
40 get_post('name'), get_post('description'));
41 $note = _('Selected contact category has been updated');
45 add_crm_category(get_post('type'), get_post('subtype'), get_post('name'),
46 get_post('description'));
47 $note = _('New contact category has been added');
50 display_notification($note);
55 if ($Mode == 'Delete')
59 if (key_in_foreign_table($selected_id, 'crm_relations', 'category_id'))
62 display_error(_("Cannot delete this category because there are contacts related to it."));
64 if ($cancel_delete == 0)
66 delete_crm_category($selected_id);
68 display_notification(_('Category has been deleted'));
76 $sav = get_post('show_inactive');
78 $_POST['show_inactive'] = $sav;
81 //-------------------------------------------------------------------------------------------------
83 $result = get_crm_categories(check_value('show_inactive'));
86 start_table(TABLESTYLE, "width=50%");
88 $th = array(_("Type id"), _("Action id"), _("Short Name"), _("Description"), "", " ");
89 inactive_control_column($th);
94 while ($myrow = db_fetch($result))
97 alt_table_row_color($k);
99 label_cell($myrow["type"]);
100 label_cell($myrow["action"]);
101 label_cell($myrow["name"]);
102 label_cell($myrow["description"]);
104 inactive_control_cell($myrow["id"], $myrow["inactive"], 'areas', 'id');
106 edit_button_cell("Edit".$myrow["id"], _("Edit"));
107 if ($myrow["system"])
110 delete_button_cell("Delete".$myrow["id"], _("Delete"));
114 inactive_control_row($th);
117 //-------------------------------------------------------------------------------------------------
118 start_table(TABLESTYLE2);
120 if ($selected_id != -1)
122 if ($Mode == 'Edit') {
123 //editing an existing area
124 $myrow = get_crm_category($selected_id);
126 $_POST['name'] = $myrow["name"];
127 $_POST['type'] = $myrow["type"];
128 $_POST['subtype'] = $myrow["action"];
129 $_POST['description'] = $myrow["description"];
131 hidden("selected_id", $selected_id);
134 if ($Mode == 'Edit' && $myrow['system']) {
135 label_row(_("Contact Category Type:"), $_POST['type']);
136 label_row(_("Contact Category Subtype:"), $_POST['subtype']);
138 // crm_category_type_list_row(_("Contact Category Type:"), 'type', null, _('Other'));
139 text_row_ex(_("Contact Category Type:"), 'type', 30);
140 text_row_ex(_("Contact Category Subtype:"), 'subtype', 30);
143 text_row_ex(_("Category Short Name:"), 'name', 30);
144 textarea_row(_("Category Description:"), 'description', null, 60,4);
148 submit_add_or_update_center($selected_id == -1, '', 'both');