1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
|
<?php
/**********************************************************************
Copyright (C) FrontAccounting, LLC.
Released under the terms of the GNU General Public License, GPL,
as published by the Free Software Foundation, either version 3
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
***********************************************************************/
$path_to_root = "..";
include($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/includes/types.inc"); // For tag constants
include_once($path_to_root . "/admin/db/tags_db.inc");
include($path_to_root . "/includes/ui.inc");
// Set up page security based on what type of tags we're working with
if (@$_GET['type'] == "account" || get_post('type') == TAG_ACCOUNT) {
$page_security = 'SA_GLACCOUNTTAGS';
} else if(@$_GET['type'] == "dimension" || get_post('type') == TAG_DIMENSION) {
$page_security = 'SA_DIMTAGS';
}
// We use $_POST['type'] throughout this script, so convert $_GET vars
// if $_POST['type'] is not set.
if (!isset($_POST['type'])) {
if ($_GET['type'] == "account")
$_POST['type'] = TAG_ACCOUNT;
elseif ($_GET['type'] == "dimension")
$_POST['type'] = TAG_DIMENSION;
else
die(_("Unspecified tag type"));
}
// Set up page based on what type of tags we're working with
switch ($_POST['type']) {
case TAG_ACCOUNT:
// Account tags
$_SESSION['page_title'] = _($help_context = "Account Tags");
break;
case TAG_DIMENSION:
// Dimension tags
$_SESSION['page_title'] = _($help_context = "Dimension Tags");
}
page($_SESSION['page_title']);
simple_page_mode(true);
//-----------------------------------------------------------------------------------
function can_process()
{
if (strlen($_POST['name']) == 0)
{
display_error( _("The tag name cannot be empty."));
set_focus('name');
return false;
}
return true;
}
//-----------------------------------------------------------------------------------
if ($Mode=='ADD_ITEM' || $Mode=='UPDATE_ITEM')
{
if (can_process())
{
if ($selected_id != -1)
{
if( $ret = update_tag($selected_id, $_POST['name'], $_POST['description']))
display_notification(_('Selected tag settings have been updated'));
}
else
{
if( $ret = add_tag($_POST['type'], $_POST['name'], $_POST['description']))
display_notification(_('New tag has been added'));
}
if ($ret) $Mode = 'RESET';
}
}
//-----------------------------------------------------------------------------------
function can_delete($selected_id)
{
if ($selected_id == -1)
return false;
$result = get_records_associated_with_tag($selected_id);
if (db_num_rows($result) > 0)
{
display_error(_("Cannot delete this tag because records have been created referring to it."));
return false;
}
return true;
}
//-----------------------------------------------------------------------------------
if ($Mode == 'Delete')
{
if (can_delete($selected_id))
{
delete_tag($selected_id);
display_notification(_('Selected tag has been deleted'));
}
$Mode = 'RESET';
}
//-----------------------------------------------------------------------------------
if ($Mode == 'RESET')
{
$selected_id = -1;
$_POST['name'] = $_POST['description'] = '';
}
//-----------------------------------------------------------------------------------
$result = get_tags($_POST['type'], check_value('show_inactive'));
start_form();
start_table($table_style);
$th = array(_("Tag Name"), _("Tag Description"), "", "");
inactive_control_column($th);
table_header($th);
$k = 0;
while ($myrow = db_fetch($result))
{
alt_table_row_color($k);
label_cell($myrow['name']);
label_cell($myrow['description']);
inactive_control_cell($myrow["id"], $myrow["inactive"], 'tags', 'id');
edit_button_cell("Edit".$myrow["id"], _("Edit"));
delete_button_cell("Delete".$myrow["id"], _("Delete"));
end_row();
}
inactive_control_row($th);
end_table(1);
//-----------------------------------------------------------------------------------
start_table($table_style2);
if ($selected_id != -1) // We've selected a tag
{
if ($Mode == 'Edit') {
// Editing an existing tag
$myrow = get_tag($selected_id);
$_POST['name'] = $myrow["name"];
$_POST['description'] = $myrow["description"];
}
// Note the selected tag
hidden('selected_id', $selected_id);
}
text_row_ex(_("Tag Name:"), 'name', 15, 30);
text_row_ex(_("Tag Description:"), 'description', 40, 60);
hidden('type');
end_table(1);
submit_add_or_update_center($selected_id == -1, '', 'both');
end_form();
//------------------------------------------------------------------------------------
end_page();
?>
|