Feature 5388: Print Invoices (documents) list gets too long. Fixed by default 180...
[fa-stable.git] / admin / crm_categories.php
1 <?php
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';
13 $path_to_root = '..';
14 include($path_to_root . "/includes/session.inc");
15 include_once($path_to_root . "/includes/db/crm_contacts_db.inc");
16
17 page(_($help_context = "Contact Categories"));
18
19 include($path_to_root . "/includes/ui.inc");
20
21 simple_page_mode(true);
22
23 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
24 {
25
26         $input_error = 0;
27
28         if (strlen($_POST['description']) == 0) 
29         {
30                 $input_error = 1;
31                 display_error(_("Category description cannot be empty."));
32                 set_focus('description');
33         }
34
35         if ($input_error != 1)
36         {
37         if ($selected_id != -1) 
38         {
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');
42         } 
43         else 
44         {
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');
48         }
49
50                 display_notification($note);
51                 $Mode = 'RESET';
52         }
53
54
55 if ($Mode == 'Delete')
56 {
57         $cancel_delete = 0;
58
59         if (is_crm_category_used($selected_id))
60         {
61                 $cancel_delete = 1;
62                 display_error(_("Cannot delete this category because there are contacts related to it."));
63         } 
64         if ($cancel_delete == 0) 
65         {
66                 delete_crm_category($selected_id);
67
68                 display_notification(_('Category has been deleted'));
69         }
70         $Mode = 'RESET';
71 }
72
73 if ($Mode == 'RESET')
74 {
75         $selected_id = -1;
76         $sav = get_post('show_inactive');
77         unset($_POST);
78         $_POST['show_inactive'] = $sav;
79 }
80
81 //-------------------------------------------------------------------------------------------------
82
83 $result = get_crm_categories(check_value('show_inactive'));
84
85 start_form();
86 start_table(TABLESTYLE, "width='70%'");
87
88 $th = array(_("Category Type"), _("Category Subtype"), _("Short Name"), _("Description"),  "", "&nbsp;");
89 inactive_control_column($th);
90
91 table_header($th);
92 $k = 0; 
93
94 while ($myrow = db_fetch($result)) 
95 {
96         
97         alt_table_row_color($k);
98                 
99         label_cell($myrow["type"]);
100         label_cell($myrow["action"]);
101         label_cell($myrow["name"]);
102         label_cell($myrow["description"]);
103         
104         inactive_control_cell($myrow["id"], $myrow["inactive"], 'crm_categories', 'id');
105
106         edit_button_cell("Edit".$myrow["id"], _("Edit"));
107         if ($myrow["system"])
108                 label_cell('');
109         else
110                 delete_button_cell("Delete".$myrow["id"], _("Delete"));
111         end_row();
112 }
113         
114 inactive_control_row($th);
115 end_table(1);
116
117 //-------------------------------------------------------------------------------------------------
118 start_table(TABLESTYLE2);
119
120 if ($selected_id != -1) 
121 {
122         if ($Mode == 'Edit') {
123                 //editing an existing area
124                 $myrow = get_crm_category($selected_id);
125
126                 $_POST['name']  = $myrow["name"];
127                 $_POST['type']  = $myrow["type"];
128                 $_POST['subtype']  = $myrow["action"];
129                 $_POST['description']  = $myrow["description"];
130         }
131         hidden("selected_id", $selected_id);
132
133
134 if ($Mode == 'Edit' && $myrow['system']) {
135         label_row(_("Contact Category Type:"), $_POST['type']);
136         label_row(_("Contact Category Subtype:"), $_POST['subtype']);
137 } else {
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); 
141 }
142
143 text_row_ex(_("Category Short Name:"), 'name', 30); 
144 textarea_row(_("Category Description:"), 'description', null, 60, 4);
145
146 end_table(1);
147
148 submit_add_or_update_center($selected_id == -1, '', 'both');
149
150 end_form();
151
152 end_page();