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 function key_in_crm_contacts($id) // extra function for testing foreign concatenated key. Joe 02.09.2013.
57 $row = get_crm_category($id);
58 $sql = "SELECT COUNT(*) FROM ".TB_PREF."crm_contacts WHERE type='".$row['type']."' AND action='".$row['action']."'";
59 $result = db_query($sql, "check relations for crm_contacts failed");
60 $contacts = db_fetch($result);
64 if ($Mode == 'Delete')
68 if (key_in_crm_contacts($selected_id))
71 display_error(_("Cannot delete this category because there are contacts related to it."));
73 if ($cancel_delete == 0)
75 delete_crm_category($selected_id);
77 display_notification(_('Category has been deleted'));
85 $sav = get_post('show_inactive');
87 $_POST['show_inactive'] = $sav;
90 //-------------------------------------------------------------------------------------------------
92 $result = get_crm_categories(check_value('show_inactive'));
95 start_table(TABLESTYLE, "width=70%");
97 $th = array(_("Category Type"), _("Category Subtype"), _("Short Name"), _("Description"), "", " ");
98 inactive_control_column($th);
103 while ($myrow = db_fetch($result))
106 alt_table_row_color($k);
108 label_cell($myrow["type"]);
109 label_cell($myrow["action"]);
110 label_cell($myrow["name"]);
111 label_cell($myrow["description"]);
113 inactive_control_cell($myrow["id"], $myrow["inactive"], 'crm_categories', 'id');
115 edit_button_cell("Edit".$myrow["id"], _("Edit"));
116 if ($myrow["system"])
119 delete_button_cell("Delete".$myrow["id"], _("Delete"));
123 inactive_control_row($th);
126 //-------------------------------------------------------------------------------------------------
127 start_table(TABLESTYLE2);
129 if ($selected_id != -1)
131 if ($Mode == 'Edit') {
132 //editing an existing area
133 $myrow = get_crm_category($selected_id);
135 $_POST['name'] = $myrow["name"];
136 $_POST['type'] = $myrow["type"];
137 $_POST['subtype'] = $myrow["action"];
138 $_POST['description'] = $myrow["description"];
140 hidden("selected_id", $selected_id);
143 if ($Mode == 'Edit' && $myrow['system']) {
144 label_row(_("Contact Category Type:"), $_POST['type']);
145 label_row(_("Contact Category Subtype:"), $_POST['subtype']);
147 // crm_category_type_list_row(_("Contact Category Type:"), 'type', null, _('Other'));
148 text_row_ex(_("Contact Category Type:"), 'type', 30);
149 text_row_ex(_("Contact Category Subtype:"), 'subtype', 30);
152 text_row_ex(_("Category Short Name:"), 'name', 30);
153 textarea_row(_("Category Description:"), 'description', null, 60,4);
157 submit_add_or_update_center($selected_id == -1, '', 'both');