New framework handling. New koha_attr table for mapping MARC to koha
[koha-ffzg.git] / admin / thesaurus.pl
index 0bfbef9..f7b1f11 100755 (executable)
 
 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::Context;
 use C4::Authorities;
 
 my $input = new CGI;
 my $search_category=$input->param('search_category');
-$search_category=$input->param('category') unless $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;
+$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 $reqsel="";
 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 = gettemplate("parameters/thesaurus.tmpl",0);
+my ($template, $borrowernumber, $cookie)
+    = get_template_and_user({template_name => "admin/thesaurus.tmpl",
+                            query => $input,
+                            type => "intranet",
+                            authnotrequired => 0,
+                            flagsrequired => {parameters => 1},
+                            debug => 1,
+                            });
+
 my $pagesize=20;
 
 my $prevpage = $offset-$pagesize;
@@ -64,8 +72,8 @@ 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;
+               my $sth=$dbh->prepare("select id,category,freelib,stdlib from bibliothesaurus where id=?");
+               $sth->execute($id);
                $data=$sth->fetchrow_hashref;
                $sth->finish;
        } else {
@@ -73,9 +81,9 @@ if ($op eq 'add_form') {
                $data->{'stdlib'} = $input->param('stdlib');
        }
        if ($search_category) {
-               $template->param(action => "Modify authorised value");
+               $template->param(action => "Modify thesaurus");
        } else {
-               $template->param(action => "Add authorised value");
+               $template->param(action => "Add thesaurus");
        }
        $template->param(category => $data->{'category'},
                                                        stdlib => $data->{'stdlib'},
@@ -94,18 +102,28 @@ if ($op eq 'add_form') {
                $template->param(category => "<input type=text name=\"category\" size=8 maxlength=8>");
        }
 ################## ADD_VALIDATE ##################################
-# called by add_form, used to insert/modify data in DB
+# called by add_form, used to insert data in DB
 } elsif ($op eq 'add_validate') {
        my $dbh = C4::Context->dbh;
-       newauthority($dbh,$input->param('category'),$input->param('stdlib'), $input->param('freelib'),'',1,'');
+       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<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$offset\"></html>";
        exit;
+################## MOD_VALIDATE ##################################
+# called by add_form, used to modify data in DB
+} elsif ($op eq 'mod_validate') {
+       my $dbh = C4::Context->dbh;
+       my $freelib = $input->param('freelib');
+       modauthority($dbh,$id,$freelib);
+       print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?branch=$branch&search_category=$search_category&offset=$offset&searchstring=".CGI::escapeHTML($searchstring)."\"></html>";
+       exit;
 ################## DELETE_CONFIRM ##################################
 # called by default form, used to confirm deletion of data in DB
 } elsif ($op eq 'delete_confirm') {
        my $dbh = C4::Context->dbh;
-       my $sth=$dbh->prepare($reqsel);
-       $sth->execute;
+       my $sth=$dbh->prepare("select category,stdlib,freelib from bibliothesaurus where id=?");
+       $sth->execute($id);
        my $data=$sth->fetchrow_hashref;
        $sth->finish;
        $template->param(search_category => $search_category,
@@ -117,10 +135,6 @@ if ($op eq 'add_form') {
 ################## DELETE_CONFIRMED ##################################
 # called by delete_confirm, used to effectively confirm deletion of data in DB
 } elsif ($op eq 'delete_confirmed') {
-#      my $dbh = C4::Context->dbh;
-#      my $sth=$dbh->prepare($reqdel);
-#      $sth->execute;
-#      $sth->finish;
        &delauthority($id);
        print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=thesaurus.pl?search_category=$search_category&searchstring=$searchstring\"></html>";
        exit;
@@ -242,11 +256,11 @@ if ($op eq 'add_form') {
                                                        branch => $branch,
                                                        father => $father);
        if ($offset>0) {
-               $template->param(previous => "<a href=$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$prevpage>&lt;&lt; Prev</a>");
+               $template->param(previous => "$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$prevpage");
        }
        if ($pagesize<$count) {
-               $template->param(next => "<a href=$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$nextpage>Next &gt;&gt;</a>");
+               $template->param(next => "$script_name?branch=$branch&search_category=$search_category&searchstring=$searchstring&offset=$nextpage");
        }
 } #---- END $OP eq DEFAULT
 
-print "Content-Type: text/html\n\n", $template->output;
+output_html_with_http_headers $input, $cookie, $template->output;