#!/usr/bin/perl
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
#
# Koha is free software; you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
#
# Koha 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 GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA 02111-1307 USA
use strict;
use CGI;
use C4::Auth;
use C4::Interface::CGI::Output;
use C4::Context;
use C4::Output;
use C4::Search;
use HTML::Template;
use C4::Authorities;
my $input = new CGI;
my $search_category=$input->param('search_category');
# $search_category=$input->param('category') unless $search_category;
#my $toponly = $input->param('toponly');
my $branch = $input->param('branch');
my $searchstring = $input->param('searchstring');
# $searchstring=~ s/\,//g;
my $id = $input->param('id');
my $offset=$input->param('offset');
my $father=$input->param('father');
my $reqsel="select category,stdlib,freelib from bibliothesaurus where id='$id'";
my $reqdel="delete from bibliothesaurus where id='$id'";
my $script_name="/cgi-bin/koha/admin/thesaurus.pl";
my $dbh = C4::Context->dbh;
my $authoritysep = C4::Context->preference("authoritysep");
my ($template, $borrowernumber, $cookie)
= get_template_and_user({template_name => "parameters/thesaurus.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => {parameters => 1},
debug => 1,
});
my $pagesize=20;
my $prevpage = $offset-$pagesize;
my $nextpage =$offset+$pagesize;
my $op = $input->param('op');
if ($op) {
$template->param(script_name => $script_name,
$op => 1); # we show only the TMPL_VAR names $op
} else {
$template->param(script_name => $script_name,
else => 1); # we show only the TMPL_VAR names $op
}
################## ADD_FORM ##################################
# called by default. Used to create form to add or modify a record
if ($op eq 'add_form') {
my $data;
if ($id) {
my $dbh = C4::Context->dbh;
my $sth=$dbh->prepare("select id,category,freelib,stdlib from bibliothesaurus where id='$id'");
$sth->execute;
$data=$sth->fetchrow_hashref;
$sth->finish;
} else {
$data->{'category'} = $input->param('category');
$data->{'stdlib'} = $input->param('stdlib');
}
if ($search_category) {
$template->param(action => "Modify thesaurus");
} else {
$template->param(action => "Add thesaurus");
}
$template->param(category => $data->{'category'},
stdlib => $data->{'stdlib'},
freelib => $data->{'freelib'},
id => $data->{'id'},
branch => $branch,
# toponly => $toponly,
search_category => $search_category,
searchstring => $searchstring,
offset => $offset,
father => $father,
);
if ($data->{'category'}) {
$template->param(category => "$data->{'category'}");
} else {
$template->param(category => "");
}
################## ADD_VALIDATE ##################################
# called by add_form, used to insert data in DB
} elsif ($op eq 'add_validate') {
my $dbh = C4::Context->dbh;
my $freelib = $input->param('freelib');
$freelib = $input->param('stdlib') unless ($input->param('freelib'));
newauthority($dbh,$input->param('category'),$input->param('father')." ".$input->param('stdlib'), $freelib,'',1,'');
print "Content-Type: text/html\n\n