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 ***********************************************************************/
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");
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';
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;
33 die(_("Unspecified tag type"));
36 // Set up page based on what type of tags we're working with
37 switch ($_POST['type']) {
40 $_SESSION['page_title'] = _($help_context = "Account Tags");
44 $_SESSION['page_title'] = _($help_context = "Dimension Tags");
47 page($_SESSION['page_title']);
49 simple_page_mode(true);
51 //-----------------------------------------------------------------------------------
53 function can_process()
55 if (strlen($_POST['name']) == 0)
57 display_error( _("The tag name cannot be empty."));
64 //-----------------------------------------------------------------------------------
66 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
70 if ($selected_id != -1)
72 if( $ret = update_tag($selected_id, $_POST['name'], $_POST['description']))
73 display_notification(_('Selected tag settings have been updated'));
77 if( $ret = add_tag($_POST['type'], $_POST['name'], $_POST['description']))
78 display_notification(_('New tag has been added'));
80 if ($ret) $Mode = 'RESET';
84 //-----------------------------------------------------------------------------------
86 function can_delete($selected_id)
88 if ($selected_id == -1)
90 $result = get_records_associated_with_tag($selected_id);
92 if (db_num_rows($result) > 0)
94 display_error(_("Cannot delete this tag because records have been created referring to it."));
102 //-----------------------------------------------------------------------------------
104 if ($Mode == 'Delete')
106 if (can_delete($selected_id))
108 delete_tag($selected_id);
109 display_notification(_('Selected tag has been deleted'));
114 //-----------------------------------------------------------------------------------
116 if ($Mode == 'RESET')
119 $_POST['name'] = $_POST['description'] = '';
122 //-----------------------------------------------------------------------------------
124 $result = get_tags($_POST['type'], check_value('show_inactive'));
127 start_table(TABLESTYLE);
128 $th = array(_("Tag Name"), _("Tag Description"), "", "");
129 inactive_control_column($th);
133 while ($myrow = db_fetch($result))
135 alt_table_row_color($k);
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"));
145 inactive_control_row($th);
148 //-----------------------------------------------------------------------------------
150 start_table(TABLESTYLE2);
152 if ($selected_id != -1) // We've selected a tag
154 if ($Mode == 'Edit') {
155 // Editing an existing tag
156 $myrow = get_tag($selected_id);
158 $_POST['name'] = $myrow["name"];
159 $_POST['description'] = $myrow["description"];
161 // Note the selected tag
162 hidden('selected_id', $selected_id);
165 text_row_ex(_("Tag Name:"), 'name', 15, 30);
166 text_row_ex(_("Tag Description:"), 'description', 40, 60);
171 submit_add_or_update_center($selected_id == -1, '', 'both');
175 //------------------------------------------------------------------------------------