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