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 // 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';
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
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'];
27 $_SESSION['tags_page_security'] = $page_security;
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;
37 die(_("Unspecified tag type"));
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']) {
45 $_SESSION['page_title'] = _("Account Tags");
49 $_SESSION['page_title'] = _("Dimension Tags");
52 page($_SESSION['page_title']);
53 include_once($path_to_root . "/admin/db/tags_db.inc");
55 include($path_to_root . "/includes/ui.inc");
57 simple_page_mode(true);
59 //-----------------------------------------------------------------------------------
61 function can_process()
63 if (strlen($_POST['name']) == 0)
65 display_error( _("The tag name cannot be empty."));
72 //-----------------------------------------------------------------------------------
74 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
78 if ($selected_id != -1)
80 if( $ret = update_tag($selected_id, $_POST['name'], $_POST['description']))
81 display_notification(_('Selected tag settings have been updated'));
85 if( $ret = add_tag($_POST['type'], $_POST['name'], $_POST['description']))
86 display_notification(_('New tag has been added'));
88 if ($ret) $Mode = 'RESET';
92 //-----------------------------------------------------------------------------------
94 function can_delete($selected_id)
96 if ($selected_id == -1)
98 $result = get_records_associated_with_tag($selected_id);
100 if (db_num_rows($result) > 0)
102 display_error(_("Cannot delete this tag because records have been created referring to it."));
110 //-----------------------------------------------------------------------------------
112 if ($Mode == 'Delete')
114 if (can_delete($selected_id))
116 delete_tag($selected_id);
117 display_notification(_('Selected tag has been deleted'));
122 //-----------------------------------------------------------------------------------
124 if ($Mode == 'RESET')
127 $_POST['name'] = $_POST['description'] = '';
130 //-----------------------------------------------------------------------------------
132 $result = get_tags($_POST['type'], check_value('show_inactive'));
135 start_table($table_style);
136 $th = array(_("Tag Name"), _("Tag Description"), "", "");
137 inactive_control_column($th);
141 while ($myrow = db_fetch($result))
143 alt_table_row_color($k);
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"));
153 inactive_control_row($th);
156 //-----------------------------------------------------------------------------------
158 start_table($table_style2);
160 if ($selected_id != -1) // We've selected a tag
162 if ($Mode == 'Edit') {
163 // Editing an existing tag
164 $myrow = get_tag($selected_id);
166 $_POST['name'] = $myrow["name"];
167 $_POST['description'] = $myrow["description"];
169 // Note the selected tag
170 hidden('selected_id', $selected_id);
173 text_row_ex(_("Tag Name:"), 'name', 15, 30);
174 text_row_ex(_("Tag Description:"), 'description', 40, 60);
179 submit_add_or_update_center($selected_id == -1, '', 'both');
183 //------------------------------------------------------------------------------------