Fixed many issues in output HTML code according to HTML 4.01 Transitional format.
[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 function key_in_crm_contacts($id) // extra function for testing foreign concatenated key. Joe 02.09.2013.
56 {
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);
61         return $contacts[0];
62 }
63
64 if ($Mode == 'Delete')
65 {
66         $cancel_delete = 0;
67
68         if (key_in_crm_contacts($selected_id))
69         {
70                 $cancel_delete = 1;
71                 display_error(_("Cannot delete this category because there are contacts related to it."));
72         } 
73         if ($cancel_delete == 0) 
74         {
75                 delete_crm_category($selected_id);
76
77                 display_notification(_('Category has been deleted'));
78         }
79         $Mode = 'RESET';
80 }
81
82 if ($Mode == 'RESET')
83 {
84         $selected_id = -1;
85         $sav = get_post('show_inactive');
86         unset($_POST);
87         $_POST['show_inactive'] = $sav;
88 }
89
90 //-------------------------------------------------------------------------------------------------
91
92 $result = get_crm_categories(check_value('show_inactive'));
93
94 start_form();
95 start_table(TABLESTYLE, "width='70%'");
96
97 $th = array(_("Category Type"), _("Category Subtype"), _("Short Name"), _("Description"),  "", "&nbsp;");
98 inactive_control_column($th);
99
100 table_header($th);
101 $k = 0; 
102
103 while ($myrow = db_fetch($result)) 
104 {
105         
106         alt_table_row_color($k);
107                 
108         label_cell($myrow["type"]);
109         label_cell($myrow["action"]);
110         label_cell($myrow["name"]);
111         label_cell($myrow["description"]);
112         
113         inactive_control_cell($myrow["id"], $myrow["inactive"], 'crm_categories', 'id');
114
115         edit_button_cell("Edit".$myrow["id"], _("Edit"));
116         if ($myrow["system"])
117                 label_cell('');
118         else
119                 delete_button_cell("Delete".$myrow["id"], _("Delete"));
120         end_row();
121 }
122         
123 inactive_control_row($th);
124 end_table(1);
125
126 //-------------------------------------------------------------------------------------------------
127 start_table(TABLESTYLE2);
128
129 if ($selected_id != -1) 
130 {
131         if ($Mode == 'Edit') {
132                 //editing an existing area
133                 $myrow = get_crm_category($selected_id);
134
135                 $_POST['name']  = $myrow["name"];
136                 $_POST['type']  = $myrow["type"];
137                 $_POST['subtype']  = $myrow["action"];
138                 $_POST['description']  = $myrow["description"];
139         }
140         hidden("selected_id", $selected_id);
141
142
143 if ($Mode == 'Edit' && $myrow['system']) {
144         label_row(_("Contact Category Type:"), $_POST['type']);
145         label_row(_("Contact Category Subtype:"), $_POST['subtype']);
146 } else {
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); 
150 }
151
152 text_row_ex(_("Category Short Name:"), 'name', 30); 
153 textarea_row(_("Category Description:"), 'description', null, 60,4);
154
155 end_table(1);
156
157 submit_add_or_update_center($selected_id == -1, '', 'both');
158
159 end_form();
160
161 end_page();
162 ?>