X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=admin%2Fauth_tag_structure.pl;h=b66cbff017051c3701dfcd55db2c493a4a1ed5fc;hb=3d84f4b9b3a11f32b37f27478de0ee6c5d9d37e4;hp=31b510a875dc08a35baa9c8fd01b7cf8fda5764b;hpb=ce9f504c7903d7431c8e18754f18ddf5bca2727a;p=koha.git diff --git a/admin/auth_tag_structure.pl b/admin/auth_tag_structure.pl index 31b510a875..b66cbff017 100755 --- a/admin/auth_tag_structure.pl +++ b/admin/auth_tag_structure.pl @@ -5,37 +5,37 @@ # # 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 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 3 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. +# 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., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . -use strict; -#use warnings; FIXME - Bug 2505 -use CGI; +use Modern::Perl; +use CGI qw ( -utf8 ); use C4::Auth; use C4::Koha; use C4::Context; use C4::Output; use C4::Context; +use Koha::Authority::Types; # retrieve parameters my $input = new CGI; my $authtypecode = $input->param('authtypecode') || ''; # set to select framework my $existingauthtypecode = $input->param('existingauthtypecode') || ''; # set when we have to create a new framework (in authtype) by copying an old one (in existingauthtype) -# my $authtypeinfo = getauthtypeinfo($authtype); my $searchfield = $input->param('searchfield') || 0; -my $offset = $input->param('offset') || 0; +my $offset = $input->param('offset'); +$offset = 0 if not defined $offset or $offset < 0; my $op = $input->param('op') || ''; $searchfield =~ s/\,//g; @@ -46,24 +46,15 @@ my $dbh = C4::Context->dbh; # open template my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "admin/auth_tag_structure.tmpl", + = get_template_and_user({template_name => "admin/auth_tag_structure.tt", query => $input, type => "intranet", authnotrequired => 0, - flagsrequired => {parameters => 'parameters_remaining_permissions'}, + flagsrequired => {parameters => 'manage_marc_frameworks'}, debug => 1, }); -# get authtype list -my $authtypes = getauthtypes; -my @authtypesloop = (); -foreach my $thisauthtype ( sort keys %{$authtypes} ) { - push @authtypesloop, - { value => $thisauthtype, - selected => $thisauthtype eq $authtypecode, - authtypetext => $authtypes->{$thisauthtype}->{'authtypetext'}, - }; -} +my $authority_types = Koha::Authority::Types->search( {}, { order_by => ['authtypecode'] } ); my $sth; # check that authtype framework is defined in auth_tag_structure if we are on a default action @@ -83,7 +74,7 @@ if (!$op or $op eq 'authtype_create_confirm') { } } $template->param(script_name => $script_name); -$template->param(authtypeloop => \@authtypesloop); +$template->param(authority_types => $authority_types ); if ($op && $op ne 'authtype_create_confirm') { $template->param($op => 1); } else { @@ -100,29 +91,11 @@ if ($op eq 'add_form') { $sth->execute($searchfield,$authtypecode); $data=$sth->fetchrow_hashref; } - my $sth = $dbh->prepare("select distinct category from authorised_values"); - $sth->execute; - my @authorised_values; - push @authorised_values,""; - while ((my $category) = $sth->fetchrow_array) { - push @authorised_values, $category; - } - my $authorised_value = CGI::scrolling_list(-name=>'authorised_value', - -id=>'authorised_value', - -values=> \@authorised_values, - -size=>1, - -tabindex=>'', - -multiple=>0, - -default => $data->{'authorised_value'}, - ); if ($searchfield) { - $template->param(action => "Modify tag", - searchfield => "$searchfield"); + $template->param('searchfield' => $searchfield); $template->param('heading_modify_tag_p' => 1); } else { - $template->param(action => "Add tag", - searchfield => ""); $template->param('heading_add_tag_p' => 1); } $template->param('use_heading_flags_p' => 1); @@ -130,7 +103,7 @@ if ($op eq 'add_form') { libopac => $data->{'libopac'}, repeatable => "".$data->{'repeatable'}, mandatory => "".$data->{'mandatory'}, - authorised_value => $authorised_value, + authorised_value => $data->{authorised_value}, authtypecode => $authtypecode, ); # END $OP eq ADD_FORM @@ -143,33 +116,31 @@ if ($op eq 'add_form') { my $repeatable = $input->param('repeatable') ? 1 : 0; my $mandatory = $input->param('mandatory') ? 1 : 0; my $authorised_value = $input->param('authorised_value'); - unless (C4::Context->config('demo') eq 1) { - if ($input->param('modif')) { - $sth=$dbh->prepare("UPDATE auth_tag_structure SET tagfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, authorised_value=? WHERE authtypecode=? AND tagfield=?"); - $sth->execute( - $tagfield, - $liblibrarian, - $libopac, - $repeatable, - $mandatory, - $authorised_value, - $authtypecode, - $tagfield, - ); - } else { - $sth=$dbh->prepare("INSERT INTO auth_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,authtypecode) VALUES (?,?,?,?,?,?,?)"); - $sth->execute( - $tagfield, - $liblibrarian, - $libopac, - $repeatable, - $mandatory, - $authorised_value, - $authtypecode - ); - } + if ($input->param('modif')) { + $sth=$dbh->prepare("UPDATE auth_tag_structure SET tagfield=?, liblibrarian=?, libopac=?, repeatable=?, mandatory=?, authorised_value=? WHERE authtypecode=? AND tagfield=?"); + $sth->execute( + $tagfield, + $liblibrarian, + $libopac, + $repeatable, + $mandatory, + $authorised_value, + $authtypecode, + $tagfield, + ); + } else { + $sth=$dbh->prepare("INSERT INTO auth_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,authtypecode) VALUES (?,?,?,?,?,?,?)"); + $sth->execute( + $tagfield, + $liblibrarian, + $libopac, + $repeatable, + $mandatory, + $authorised_value, + $authtypecode + ); } - print "Content-Type: text/html\n\nparam('tagfield')."&authtypecode=$authtypecode\">"; + print $input->redirect("/cgi-bin/koha/admin/auth_tag_structure.pl?searchfield=$tagfield&authtypecode=$authtypecode"); exit; # END $OP eq ADD_VALIDATE ################## DELETE_CONFIRM ################################## @@ -186,13 +157,10 @@ 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') { - unless (C4::Context->config('demo') eq 1) { - my $sth = $dbh->prepare("delete from auth_tag_structure where tagfield=? and authtypecode=?"); - $sth->execute($searchfield,$authtypecode); - my $sth = $dbh->prepare("delete from auth_subfield_structure where tagfield=? and authtypecode=?"); - $sth->execute($searchfield,$authtypecode); - } - print "Content-Type: text/html\n\nparam('tagfield')."&authtypecode=$authtypecode\">"; + $dbh->do(q|delete from auth_tag_structure where tagfield=? and authtypecode=?|, undef, $searchfield, $authtypecode); + $dbh->do(q|delete from auth_subfield_structure where tagfield=? and authtypecode=?|, undef, $searchfield, $authtypecode); + my $tagfield = $input->param('tagfield'); + print $input->redirect("/cgi-bin/koha/admin/auth_tag_structure.pl?searchfield=$tagfield&authtypecode=$authtypecode"); exit; # END $OP eq DELETE_CONFIRMED ################## ITEMTYPE_CREATE ################################## @@ -229,9 +197,6 @@ if ($op eq 'add_form') { $row_data{repeatable} = $results->[$i]{'repeatable'}; $row_data{mandatory} = $results->[$i]{'mandatory'}; $row_data{authorised_value} = $results->[$i]{'authorised_value'}; - $row_data{subfield_link} = "auth_subfields_structure.pl?tagfield=" . $results->[$i]{'tagfield'} . "&authtypecode=" . $authtypecode; - $row_data{edit} = "$script_name?op=add_form&searchfield=" . $results->[$i]{'tagfield'} . "&authtypecode=" . $authtypecode; - $row_data{delete} = "$script_name?op=delete_confirm&searchfield=" . $results->[$i]{'tagfield'} . "&authtypecode=" . $authtypecode; push(@loop_data, \%row_data); } $template->param(loop => \@loop_data, @@ -274,6 +239,7 @@ sub StringSearch { sub duplicate_auth_framework { my ($newauthtype,$oldauthtype) = @_; # warn "TO $newauthtype FROM $oldauthtype"; + my $dbh = C4::Context->dbh; my $sth = $dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from auth_tag_structure where authtypecode=?"); $sth->execute($oldauthtype); my $sth_insert = $dbh->prepare("insert into auth_tag_structure (tagfield, liblibrarian, libopac, repeatable, mandatory, authorised_value, authtypecode) values (?,?,?,?,?,?,?)");