[0004212] Work Order Entry: fixed error when voided WO refence is reused.
[fa-stable.git] / admin / tags.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 $path_to_root = "..";
13 include($path_to_root . "/includes/session.inc");
14 include_once($path_to_root . "/includes/types.inc"); // For tag constants
15 include_once($path_to_root . "/admin/db/tags_db.inc");
16 include($path_to_root . "/includes/ui.inc");
17
18 // Set up page security based on what type of tags we're working with
19 if (@$_GET['type'] == "account" || get_post('type') == TAG_ACCOUNT) {
20         $page_security = 'SA_GLACCOUNTTAGS';
21 } else if(@$_GET['type'] == "dimension" || get_post('type') == TAG_DIMENSION) {
22         $page_security = 'SA_DIMTAGS';
23 }
24
25 // We use $_POST['type'] throughout this script, so convert $_GET vars
26 // if $_POST['type'] is not set.
27 if (!isset($_POST['type'])) {
28         if ($_GET['type'] == "account")
29                 $_POST['type'] = TAG_ACCOUNT;
30         elseif ($_GET['type'] == "dimension")
31                 $_POST['type'] = TAG_DIMENSION;
32         else
33                 die(_("Unspecified tag type"));
34 }
35
36 // Set up page based on what type of tags we're working with
37 switch ($_POST['type']) {
38         case TAG_ACCOUNT:
39                 // Account tags
40                 $_SESSION['page_title'] = _($help_context = "Account Tags");
41                 break;
42         case TAG_DIMENSION:
43                 // Dimension tags
44                 $_SESSION['page_title'] = _($help_context = "Dimension Tags");
45 }
46
47 page($_SESSION['page_title']);
48
49 simple_page_mode(true);
50
51 //-----------------------------------------------------------------------------------
52
53 function can_process() 
54 {
55         if (strlen($_POST['name']) == 0) 
56         {
57                 display_error( _("The tag name cannot be empty."));
58                 set_focus('name');
59                 return false;
60         }
61         return true;
62 }
63
64 //-----------------------------------------------------------------------------------
65
66 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM') 
67 {
68         if (can_process()) 
69         {
70         if ($selected_id != -1) 
71         {
72                 if( $ret = update_tag($selected_id, $_POST['name'], $_POST['description']))
73                                 display_notification(_('Selected tag settings have been updated'));
74         } 
75         else 
76         {
77                 if( $ret = add_tag($_POST['type'], $_POST['name'], $_POST['description']))
78                                 display_notification(_('New tag has been added'));
79         }
80                 if ($ret) $Mode = 'RESET';
81         }
82 }
83
84 //-----------------------------------------------------------------------------------
85
86 function can_delete($selected_id)
87 {
88         if ($selected_id == -1)
89                 return false;
90         $result = get_records_associated_with_tag($selected_id);
91         
92         if (db_num_rows($result) > 0)   
93         {
94                 display_error(_("Cannot delete this tag because records have been created referring to it."));
95                 return false;
96         }
97
98         return true;
99 }
100
101
102 //-----------------------------------------------------------------------------------
103
104 if ($Mode == 'Delete')
105 {
106         if (can_delete($selected_id))
107         {
108                 delete_tag($selected_id);
109                 display_notification(_('Selected tag has been deleted'));
110         }
111         $Mode = 'RESET';
112 }
113
114 //-----------------------------------------------------------------------------------
115
116 if ($Mode == 'RESET')
117 {
118         $selected_id = -1;
119         $_POST['name'] = $_POST['description'] = '';
120 }
121
122 //-----------------------------------------------------------------------------------
123
124 $result = get_tags($_POST['type'], check_value('show_inactive'));
125
126 start_form();
127 start_table(TABLESTYLE);
128 $th = array(_("Tag Name"), _("Tag Description"), "", "");
129 inactive_control_column($th);
130 table_header($th);
131
132 $k = 0;
133 while ($myrow = db_fetch($result)) 
134 {
135         alt_table_row_color($k);
136
137         label_cell($myrow['name']);
138         label_cell($myrow['description']);
139         inactive_control_cell($myrow["id"], $myrow["inactive"], 'tags', 'id');
140         edit_button_cell("Edit".$myrow["id"], _("Edit"));
141         delete_button_cell("Delete".$myrow["id"], _("Delete"));
142         end_row();
143 }
144
145 inactive_control_row($th);
146 end_table(1);
147
148 //-----------------------------------------------------------------------------------
149
150 start_table(TABLESTYLE2);
151
152 if ($selected_id != -1) // We've selected a tag 
153 {
154         if ($Mode == 'Edit') {
155                 // Editing an existing tag
156                 $myrow = get_tag($selected_id);
157         
158                 $_POST['name'] = $myrow["name"];
159                 $_POST['description'] = $myrow["description"];
160         }
161         // Note the selected tag
162         hidden('selected_id', $selected_id);
163 }
164         
165 text_row_ex(_("Tag Name:"), 'name', 15, 30);
166 text_row_ex(_("Tag Description:"), 'description', 40, 60);
167 hidden('type');
168
169 end_table(1);
170
171 submit_add_or_update_center($selected_id == -1, '', 'both');
172
173 end_form();
174
175 //------------------------------------------------------------------------------------
176
177 end_page();
178