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_once($path_to_root . "/includes/types.inc"); // For tag constants
15 // Set up page security based on what type of tags we're working with
16 if ($_GET['type'] == "account" || $_POST['type'] == TAG_ACCOUNT) {
17 $page_security = 'SA_GLACCOUNTTAGS';
18 } else if($_GET['type'] == "dimension" || $_POST['type'] == TAG_DIMENSION) {
19 $page_security = 'SA_DIMTAGS';
22 include($path_to_root . "/includes/session.inc"); // Define session before using $_SESSION
24 if (!isset($page_security)) {
25 // If GET & POST don't have the info, try getting it from the session.
26 $page_security = $_SESSION['tags_page_security'];
28 $_SESSION['tags_page_security'] = $page_security;
30 // We use $_POST['type'] throughout this script, so convert $_GET vars
31 // if $_POST['type'] is not set.
32 if (!isset($_POST['type'])) {
33 if ($_GET['type'] == "account")
34 $_POST['type'] = TAG_ACCOUNT;
35 elseif ($_GET['type'] == "dimension")
36 $_POST['type'] = TAG_DIMENSION;
38 die(_("Unspecified tag type"));
41 // Set up page based on what type of tags we're working with
42 // TODO: Set $_SESSION['sel_app'] to be relevant app (see /includes/page/header.inc::page_header()
43 switch ($_POST['type']) {
46 $_SESSION['page_title'] = _("Account Tags");
50 $_SESSION['page_title'] = _("Dimension Tags");
53 page($_SESSION['page_title']);
54 include_once($path_to_root . "/admin/db/tags_db.inc");
56 include($path_to_root . "/includes/ui.inc");
58 simple_page_mode(true);
60 //-----------------------------------------------------------------------------------
62 function can_process()
64 if (strlen($_POST['name']) == 0)
66 display_error( _("The tag name cannot be empty."));
73 //-----------------------------------------------------------------------------------
75 if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
79 if ($selected_id != -1)
81 if( $ret = update_tag($selected_id, $_POST['name'], $_POST['description']))
82 display_notification(_('Selected tag settings have been updated'));
86 if( $ret = add_tag($_POST['type'], $_POST['name'], $_POST['description']))
87 display_notification(_('New tag has been added'));
89 if ($ret) $Mode = 'RESET';
93 //-----------------------------------------------------------------------------------
95 function can_delete($selected_id)
97 if ($selected_id == -1)
99 $result = get_records_associated_with_tag($selected_id);
101 if (db_num_rows($result) > 0)
103 display_error(_("Cannot delete this tag because records have been created referring to it."));
111 //-----------------------------------------------------------------------------------
113 if ($Mode == 'Delete')
115 if (can_delete($selected_id))
117 delete_tag($selected_id);
118 display_notification(_('Selected tag has been deleted'));
123 //-----------------------------------------------------------------------------------
125 if ($Mode == 'RESET')
128 $_POST['name'] = $_POST['description'] = '';
131 //-----------------------------------------------------------------------------------
133 $result = get_tags($_POST['type'], check_value('show_inactive'));
136 start_table($table_style);
137 $th = array(_("Tag Name"), _("Tag Description"), "", "");
138 inactive_control_column($th);
142 while ($myrow = db_fetch($result))
144 alt_table_row_color($k);
146 label_cell($myrow['name']);
147 label_cell($myrow['description']);
148 inactive_control_cell($myrow["id"], $myrow["inactive"], 'tags', 'id');
149 edit_button_cell("Edit".$myrow["id"], _("Edit"));
150 delete_button_cell("Delete".$myrow["id"], _("Delete"));
154 inactive_control_row($th);
157 //-----------------------------------------------------------------------------------
159 start_table($table_style2);
161 if ($selected_id != -1) // We've selected a tag
163 if ($Mode == 'Edit') {
164 // Editing an existing tag
165 $myrow = get_tag($selected_id);
167 $_POST['name'] = $myrow["name"];
168 $_POST['description'] = $myrow["description"];
170 // Note the selected tag
171 hidden('selected_id', $selected_id);
174 text_row_ex(_("Tag Name:"), 'name', 15, 30);
175 text_row_ex(_("Tag Description:"), 'description', 40, 60);
180 submit_add_or_update_center($selected_id == -1, '', 'both');
184 //------------------------------------------------------------------------------------