MARC authorities management (1st draft)

This commit is contained in:
tipaul 2004-05-28 08:23:03 +00:00
parent 8e8230f792
commit a9f96d62d6
3 changed files with 771 additions and 0 deletions

304
admin/auth_subfields_structure.pl Executable file
View file

@ -0,0 +1,304 @@
#!/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 C4::Output;
use C4::Interface::CGI::Output;
use C4::Auth;
use CGI;
use C4::Search;
use C4::Context;
use HTML::Template;
sub StringSearch {
my ($env,$searchstring,$authtypecode)=@_;
my $dbh = C4::Context->dbh;
$searchstring=~ s/\'/\\\'/g;
my @data=split(' ',$searchstring);
my $count=@data;
my $sth=$dbh->prepare("Select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,seealso,authorised_value,value_builder from auth_subfield_structure where (tagfield like ? and authtypecode=?) order by tagfield");
$sth->execute("$searchstring%",$authtypecode);
my @results;
my $cnt=0;
while (my $data=$sth->fetchrow_hashref){
push(@results,$data);
$cnt ++;
}
$sth->finish;
$dbh->disconnect;
return ($cnt,\@results);
}
my $input = new CGI;
my $tagfield=$input->param('tagfield');
my $tagsubfield=$input->param('tagsubfield');
my $authtypecode=$input->param('authtypecode');
my $pkfield="tagfield";
my $offset=$input->param('offset');
my $script_name="/cgi-bin/koha/admin/auth_subfields_structure.pl";
my ($template, $borrowernumber, $cookie)
= get_template_and_user({template_name => "parameters/auth_subfields_structure.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => {parameters => 1},
debug => 1,
});
my $pagesize=30;
my $op = $input->param('op');
$tagfield=~ s/\,//g;
if ($op) {
$template->param(script_name => $script_name,
tagfield =>$tagfield,
authtypecode => $authtypecode,
$op => 1); # we show only the TMPL_VAR names $op
} else {
$template->param(script_name => $script_name,
tagfield =>$tagfield,
authtypecode => $authtypecode,
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;
my $dbh = C4::Context->dbh;
my $more_subfields = $input->param("more_subfields")+1;
# build authorised value list
my $sth2 = $dbh->prepare("select distinct category from authorised_values");
$sth2->execute;
my @authorised_values;
push @authorised_values,"";
while ((my $category) = $sth2->fetchrow_array) {
push @authorised_values, $category;
}
push (@authorised_values,"branches");
push (@authorised_values,"itemtypes");
# build value_builder list
my @value_builder=('');
opendir(DIR, "../value_builder") || die "can't opendir ../value_builder: $!";
while (my $line = readdir(DIR)) {
if ($line =~ /\.pl$/) {
push (@value_builder,$line);
}
}
closedir DIR;
# build values list
my $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,seealso,authorised_value,value_builder from auth_subfield_structure where tagfield=? and authtypecode=?"); # and tagsubfield='$tagsubfield'");
$sth->execute($tagfield,$authtypecode);
my @loop_data = ();
my $toggle="white";
my $i=0;
while ($data =$sth->fetchrow_hashref) {
my %row_data; # get a fresh hash for the row data
if ($toggle eq 'white'){
$toggle="#ffffcc";
} else {
$toggle="white";
}
$row_data{tab} = CGI::scrolling_list(-name=>'tab',
-values=>['-1','0','1','2','3','4','5','6','7','8','9'],
-labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
'2' =>'2','3'=>'3','4'=>'4',
'5' =>'5','6'=>'6','7'=>'7',
'8' =>'8','9'=>'9',
},
-default=>$data->{'tab'},
-size=>1,
-multiple=>0,
);
$row_data{tagsubfield} =$data->{'tagsubfield'}."<input type='hidden' name='tagsubfield' value='".$data->{'tagsubfield'}."'>";
$row_data{liblibrarian} = CGI::escapeHTML($data->{'liblibrarian'});
$row_data{libopac} = CGI::escapeHTML($data->{'libopac'});
$row_data{seealso} = CGI::escapeHTML($data->{'seealso'});
$row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
-values=> \@authorised_values,
-default=>$data->{'authorised_value'},
-size=>1,
-multiple=>0,
);
$row_data{value_builder} = CGI::scrolling_list(-name=>'value_builder',
-values=> \@value_builder,
-default=>$data->{'value_builder'},
-size=>1,
-multiple=>0,
);
$row_data{repeatable} = CGI::checkbox("repeatable$i",$data->{'repeatable'}?'checked':'',1,'');
$row_data{mandatory} = CGI::checkbox("mandatory$i",$data->{'mandatory'}?'checked':'',1,'');
$row_data{bgcolor} = $toggle;
push(@loop_data, \%row_data);
$i++;
}
# add more_subfields empty lines for add if needed
for (my $i=1;$i<=$more_subfields;$i++) {
my %row_data; # get a fresh hash for the row data
$row_data{tab} = CGI::scrolling_list(-name=>'tab',
-values=>['-1','0','1','2','3','4','5','6','7','8','9'],
-labels => {'-1' =>'ignore','0'=>'0','1'=>'1',
'2' =>'2','3'=>'3','4'=>'4',
'5' =>'5','6'=>'6','7'=>'7',
'8' =>'8','9'=>'9',
},
-default=>"",
-size=>1,
-multiple=>0,
);
$row_data{tagsubfield} = "<input type=\"text\" name=\"tagsubfield\" value=\"".$data->{'tagsubfield'}."\" size=\"3\" maxlength=\"1\">";
$row_data{liblibrarian} = "";
$row_data{libopac} = "";
$row_data{seealso} = "";
$row_data{repeatable} = CGI::checkbox('repeatable','',1,'');
$row_data{mandatory} = CGI::checkbox('mandatory','',1,'');
$row_data{authorised_value} = CGI::scrolling_list(-name=>'authorised_value',
-values=> \@authorised_values,
-size=>1,
-multiple=>0,
);
$row_data{bgcolor} = $toggle;
push(@loop_data, \%row_data);
}
$template->param('use-heading-flags-p' => 1);
$template->param('heading-edit-subfields-p' => 1);
$template->param(action => "Edit subfields",
tagfield => "<input type=\"hidden\" name=\"tagfield\" value=\"$tagfield\">$tagfield",
loop => \@loop_data,
more_subfields => $more_subfields,
more_tag => $tagfield);
# END $OP eq ADD_FORM
################## ADD_VALIDATE ##################################
# called by add_form, used to insert/modify data in DB
} elsif ($op eq 'add_validate') {
my $dbh = C4::Context->dbh;
$template->param(tagfield => "$input->param('tagfield')");
my $sth=$dbh->prepare("replace auth_subfield_structure (tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,seealso,authorised_value,value_builder,authtypecode)
values (?,?,?,?,?,?,?,?,?,?,?)");
my @tagsubfield = $input->param('tagsubfield');
my @liblibrarian = $input->param('liblibrarian');
my @libopac = $input->param('libopac');
my @tab = $input->param('tab');
my @seealso = $input->param('seealso');
my @authorised_values = $input->param('authorised_value');
my @value_builder =$input->param('value_builder');
for (my $i=0; $i<= $#tagsubfield ; $i++) {
my $tagfield =$input->param('tagfield');
my $tagsubfield =$tagsubfield[$i];
$tagsubfield="@" unless $tagsubfield;
my $liblibrarian =$liblibrarian[$i];
my $libopac =$libopac[$i];
my $repeatable =$input->param("repeatable$i")?1:0;
my $mandatory =$input->param("mandatory$i")?1:0;
my $tab =$tab[$i];
my $seealso =$seealso[$i];
my $authorised_value =$authorised_values[$i];
my $value_builder=$value_builder[$i];
if ($liblibrarian) {
unless (C4::Context->config('demo') eq 1) {
$sth->execute ($tagfield,
$tagsubfield,
$liblibrarian,
$libopac,
$repeatable,
$mandatory,
$tab,
$seealso,
$authorised_value,
$value_builder,$authtypecode);
}
}
}
$sth->finish;
print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
exit;
# END $OP eq ADD_VALIDATE
################## 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("select tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,tab,authorised_value,value_builder from auth_subfield_structure where tagfield=? and tagsubfield=? and itemtype=?");
$sth->execute($tagfield,$tagsubfield);
my $data=$sth->fetchrow_hashref;
$sth->finish;
$template->param(liblibrarian => $data->{'liblibrarian'},
tagsubfield => $data->{'tagsubfield'},
delete_link => $script_name,
tagfield =>$tagfield,
tagsubfield => $tagsubfield,
authtypecode => $authtypecode,
);
# END $OP eq DELETE_CONFIRM
################## 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;
unless (C4::Context->config('demo') eq 1) {
my $sth=$dbh->prepare("delete from auth_subfield_structure where tagfield=? and tagsubfield=? and authtypecode=?");
$sth->execute($tagfield,$tagsubfield,$authtypecode);
$sth->finish;
}
print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_subfields_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
exit;
$template->param(tagfield => $tagfield);
# END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
my $env;
my ($count,$results)=StringSearch($env,$tagfield,$authtypecode);
my $toggle="white";
my @loop_data = ();
for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
if ($toggle eq 'white'){
$toggle="#ffffcc";
} else {
$toggle="white";
}
my %row_data; # get a fresh hash for the row data
$row_data{tagfield} = $results->[$i]{'tagfield'};
$row_data{tagsubfield} = $results->[$i]{'tagsubfield'};
$row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
$row_data{repeatable} = $results->[$i]{'repeatable'};
$row_data{mandatory} = $results->[$i]{'mandatory'};
$row_data{tab} = $results->[$i]{'tab'};
$row_data{seealso} = $results->[$i]{'seealso'};
$row_data{authorised_value} = $results->[$i]{'authorised_value'};
$row_data{value_builder} = $results->[$i]{'value_builder'};
$row_data{delete} = "$script_name?op=delete_confirm&amp;tagfield=$tagfield&amp;tagsubfield=".$results->[$i]{'tagsubfield'}."&authtypecode=$authtypecode";
$row_data{bgcolor} = $toggle;
push(@loop_data, \%row_data);
}
$template->param(loop => \@loop_data);
$template->param(edit => "<a href=\"$script_name?op=add_form&amp;tagfield=$tagfield&authtypecode=$authtypecode\">");
if ($offset>0) {
my $prevpage = $offset-$pagesize;
$template->param(prev =>"<a href=\"$script_name?offset=$prevpage&amp;tagfield=$tagfield&authtypecode=$authtypecode\">");
}
if ($offset+$pagesize<$count) {
my $nextpage =$offset+$pagesize;
$template->param(next => "<a href=\"$script_name?offset=$nextpage&amp;tagfield=$tagfield&authtypecode=$authtypecode\">");
}
} #---- END $OP eq DEFAULT
output_html_with_http_headers $input, $cookie, $template->output;

296
admin/auth_tag_structure.pl Executable file
View file

@ -0,0 +1,296 @@
#!/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::Koha;
use C4::Context;
use C4::Output;
use C4::Interface::CGI::Output;
use C4::Search;
use C4::Context;
use HTML::Template;
# retrieve parameters
my $input = new CGI;
my $authtypecode = $input->param('authtypecode'); # set to select framework
$authtypecode="" unless $authtypecode;
my $existingauthtypecode = $input->param('existingauthtypecode'); # set when we have to create a new framework (in authtype) by copying an old one (in existingauthtype)
$existingauthtypecode = "" unless $existingauthtypecode;
# my $authtypeinfo = getauthtypeinfo($authtype);
my $searchfield=$input->param('searchfield');
$searchfield=0 unless $searchfield;
$searchfield=~ s/\,//g;
my $offset=$input->param('offset');
my $op = $input->param('op');
my $pagesize=20;
my $script_name="/cgi-bin/koha/admin/auth_tag_structure.pl";
my $dbh = C4::Context->dbh;
# open template
my ($template, $loggedinuser, $cookie)
= get_template_and_user({template_name => "parameters/auth_tag_structure.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => {parameters => 1},
debug => 1,
});
# get authtype list
my $authtypes = getauthtypes;
my @authtypesloop;
foreach my $thisauthtype (keys %$authtypes) {
my $selected = 1 if $thisauthtype eq $authtypecode;
my %row =(value => $thisauthtype,
selected => $selected,
authtypetext => $authtypes->{$thisauthtype}->{'authtypetext'},
);
push @authtypesloop, \%row;
}
my $sth;
# check that authtype framework is defined in auth_tag_structure if we are on a default action
if (!$op or $op eq 'authtype_create_confirm') {
warn "IN";
$sth=$dbh->prepare("select count(*) from auth_tag_structure where authtypecode=?");
$sth->execute($authtypecode);
my ($authtypeexist) = $sth->fetchrow;
if ($authtypeexist) {
} else {
# if authtype does not exists, then OP must be changed to "create authtype" if we are not on the way to create it
# (op = authtyp_create_confirm)
if ($op eq "authtype_create_confirm") {
duplicate_auth_framework($authtypecode, $existingauthtypecode);
} else {
$op = "authtype_create";
}
}
}
$template->param(authtypeloop => \@authtypesloop);
if ($op && $op ne 'authtype_create_confirm') {
$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') {
#---- if primkey exists, it's a modify action, so read values to modify...
my $data;
if ($searchfield) {
$sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from auth_tag_structure where tagfield=? and authtypecode=?");
$sth->execute($searchfield,$authtypecode);
$data=$sth->fetchrow_hashref;
$sth->finish;
}
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',
-values=> \@authorised_values,
-size=>1,
-multiple=>0,
-default => $data->{'authorised_value'},
);
if ($searchfield) {
$template->param(action => "Modify tag",
searchfield => "<input type=\"hidden\" name=\"tagfield\" value=\"$searchfield\" />$searchfield");
$template->param('heading-modify-tag-p' => 1);
} else {
$template->param(action => "Add tag",
searchfield => "<input type=\"text\" name=\"tagfield\" size=\"5\" maxlength=\"3\" />");
$template->param('heading-add-tag-p' => 1);
}
$template->param('use-heading-flags-p' => 1);
$template->param(liblibrarian => $data->{'liblibrarian'},
libopac => $data->{'libopac'},
repeatable => CGI::checkbox('repeatable',$data->{'repeatable'}?'checked':'',1,''),
mandatory => CGI::checkbox('mandatory',$data->{'mandatory'}?'checked':'',1,''),
authorised_value => $authorised_value,
authtypecode => $authtypecode,
);
# END $OP eq ADD_FORM
################## ADD_VALIDATE ##################################
# called by add_form, used to insert/modify data in DB
} elsif ($op eq 'add_validate') {
$sth=$dbh->prepare("replace auth_tag_structure (tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value,authtypecode) values (?,?,?,?,?,?,?)");
my $tagfield =$input->param('tagfield');
my $liblibrarian = $input->param('liblibrarian');
my $libopac =$input->param('libopac');
my $repeatable =$input->param('repeatable');
my $mandatory =$input->param('mandatory');
my $authorised_value =$input->param('authorised_value');
unless (C4::Context->config('demo') eq 1) {
$sth->execute($tagfield,
$liblibrarian,
$libopac,
$repeatable?1:0,
$mandatory?1:0,
$authorised_value,
$authtypecode
);
}
$sth->finish;
print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=auth_tag_structure.pl?tagfield=$tagfield&authtypecode=$authtypecode\"></html>";
exit;
# END $OP eq ADD_VALIDATE
################## DELETE_CONFIRM ##################################
# called by default form, used to confirm deletion of data in DB
} elsif ($op eq 'delete_confirm') {
$sth=$dbh->prepare("select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from auth_tag_structure where tagfield=?");
$sth->execute($searchfield);
my $data=$sth->fetchrow_hashref;
$sth->finish;
$template->param(liblibrarian => $data->{'liblibrarian'},
searchfield => $searchfield,
);
# END $OP eq DELETE_CONFIRM
################## 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) {
$dbh->do("delete from auth_tag_structure where tagfield='$searchfield'");
$dbh->do("delete from auth_subfield_structure where tagfield='$searchfield'");
}
# END $OP eq DELETE_CONFIRMED
################## ITEMTYPE_CREATE ##################################
# called automatically if an unexisting authtypecode is selected
} elsif ($op eq 'authtype_create') {
$sth = $dbh->prepare("select count(*),auth_tag_structure.authtypecode,authtypetext from auth_tag_structure,auth_types where auth_types.authtypecode=auth_tag_structure.authtypecode group by auth_tag_structure.authtypecode");
$sth->execute;
my @existingauthtypeloop;
while (my ($tot,$thisauthtype,$authtypetext) = $sth->fetchrow) {
if ($tot>0) {
my %line = ( value => $thisauthtype,
authtypetext => $authtypetext,
);
push @existingauthtypeloop,\%line;
}
}
$template->param(existingauthtypeloop => \@existingauthtypeloop,
authtypecode => $authtypecode,
);
################## DEFAULT ##################################
} else { # DEFAULT
# here, $op can be unset or set to "authtype_create_confirm".
warn "authtype : $authtypecode";
if ($searchfield ne '') {
$template->param(searchfield => $searchfield);
}
my $env;
my ($count,$results)=StringSearch($env,$searchfield,$authtypecode);
my $toggle="white";
my @loop_data = ();
for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
if ($toggle eq 'white'){
$toggle="#ffffcc";
} else {
$toggle="white";
}
my %row_data; # get a fresh hash for the row data
$row_data{tagfield} = $results->[$i]{'tagfield'};
$row_data{liblibrarian} = $results->[$i]{'liblibrarian'};
$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&amp;searchfield=".$results->[$i]{'tagfield'}."&authtypecode=".$authtypecode;
$row_data{delete} = "$script_name?op=delete_confirm&amp;searchfield=".$results->[$i]{'tagfield'}."&authtypecode=".$authtypecode;
$row_data{bgcolor} = $toggle;
push(@loop_data, \%row_data);
}
$template->param(loop => \@loop_data,
authtypecode => $authtypecode,
);
if ($offset>0) {
my $prevpage = $offset-$pagesize;
$template->param(isprevpage => $offset,
prevpage=> $prevpage,
searchfield => $searchfield,
script_name => $script_name,
);
}
if ($offset+$pagesize<$count) {
my $nextpage =$offset+$pagesize;
$template->param(nextpage =>$nextpage,
searchfield => $searchfield,
script_name => $script_name,
);
}
} #---- END $OP eq DEFAULT
$template->param(loggeninuser => $loggedinuser);
output_html_with_http_headers $input, $cookie, $template->output;
#
# the sub used for searches
#
sub StringSearch {
my ($env,$searchstring,$authtypecode)=@_;
my $dbh = C4::Context->dbh;
$searchstring=~ s/\'/\\\'/g;
my @data=split(' ',$searchstring);
my $count=@data;
my $sth=$dbh->prepare("Select tagfield,liblibrarian,libopac,repeatable,mandatory,authorised_value from auth_tag_structure where (tagfield >= ? and authtypecode=?) order by tagfield");
$sth->execute($data[0], $authtypecode);
my @results;
while (my $data=$sth->fetchrow_hashref){
push(@results,$data);
}
# $sth->execute;
$sth->finish;
return (scalar(@results),\@results);
}
#
# the sub used to duplicate a framework from an existing one in MARC parameters tables.
#
sub duplicate_auth_framework {
my ($newauthtype,$oldauthtype) = @_;
warn "TO $newauthtype FROM $oldauthtype";
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 (?,?,?,?,?,?,?)");
while ( my ($tagfield,$liblibrarian,$libopac,$repeatable,$mandatory,$authorised_value) = $sth->fetchrow) {
$sth_insert->execute($tagfield,$liblibrarian,$libopac,$repeatable,$mandatory,$authorised_value,$newauthtype);
}
$sth = $dbh->prepare("select authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,thesaurus_category,value_builder,seealso from auth_subfield_structure where authtypecode=?");
$sth->execute($oldauthtype);
$sth_insert = $dbh->prepare("insert into auth_subfield_structure (authtypecode,tagfield,tagsubfield,liblibrarian,libopac,repeatable,mandatory,kohafield,tab,authorised_value,thesaurus_category,value_builder,seealso) values (?,?,?,?,?,?,?,?,?,?,?,?,?)");
while ( my ($authtypecode, $tagfield, $tagsubfield, $liblibrarian, $libopac, $repeatable, $mandatory, $kohafield, $tab, $authorised_value, $thesaurus_category, $value_builder, $seealso) = $sth->fetchrow) {
$sth_insert->execute($newauthtype, $tagfield, $tagsubfield, $liblibrarian, $libopac, $repeatable, $mandatory, $kohafield, $tab, $authorised_value, $thesaurus_category, $value_builder, $seealso);
}
}

171
admin/authtypes.pl Executable file
View file

@ -0,0 +1,171 @@
#!/usr/bin/perl
# NOTE: 4-character tabs
#written 20/02/2002 by paul.poulain@free.fr
# This software is placed under the gnu General Public License, v2 (http://www.gnu.org/licenses/gpl.html)
# 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::Context;
use C4::Output;
use C4::Search;
use C4::Auth;
use C4::Interface::CGI::Output;
use HTML::Template;
sub StringSearch {
my ($env,$searchstring,$type)=@_;
my $dbh = C4::Context->dbh;
$searchstring=~ s/\'/\\\'/g;
my @data=split(' ',$searchstring);
my $count=@data;
my $sth=$dbh->prepare("Select * from auth_types where (authtypecode like ?) order by authtypecode");
$sth->execute("$data[0]%");
my @results;
while (my $data=$sth->fetchrow_hashref){
push(@results,$data);
}
# $sth->execute;
$sth->finish;
return (scalar(@results),\@results);
}
my $input = new CGI;
my $searchfield=$input->param('authtypecode');
my $offset=$input->param('offset');
my $script_name="/cgi-bin/koha/admin/authtypes.pl";
my $authtypecode=$input->param('authtypecode');
my $pagesize=20;
my $op = $input->param('op');
$searchfield=~ s/\,//g;
my ($template, $borrowernumber, $cookie)
= get_template_and_user({template_name => "parameters/authtypes.tmpl",
query => $input,
type => "intranet",
authnotrequired => 0,
flagsrequired => {parameters => 1},
debug => 1,
});
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') {
#start the page and read in includes
#---- if primkey exists, it's a modify action, so read values to modify...
my $data;
if ($authtypecode) {
my $dbh = C4::Context->dbh;
my $sth=$dbh->prepare("select authtypecode,authtypetext,auth_tag_to_report from auth_types where authtypecode=?");
$sth->execute($authtypecode);
$data=$sth->fetchrow_hashref;
$sth->finish;
}
$template->param(authtypecode => $authtypecode,
authtypetext => $data->{'authtypetext'},
auth_tag_to_report => $data->{'auth_tag_to_report'},
);
;
# END $OP eq ADD_FORM
################## ADD_VALIDATE ##################################
# called by add_form, used to insert/modify data in DB
} elsif ($op eq 'add_validate') {
my $dbh = C4::Context->dbh;
my $sth=$dbh->prepare("replace auth_types (authtypecode,authtypetext,auth_tag_to_report) values (?,?,?)");
$sth->execute($input->param('authtypecode'),$input->param('authtypetext'),$input->param('auth_tag_to_report'));
$sth->finish;
print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authtypes.pl\"></html>";
exit;
# END $OP eq ADD_VALIDATE
################## DELETE_CONFIRM ##################################
# called by default form, used to confirm deletion of data in DB
} elsif ($op eq 'delete_confirm') {
#start the page and read in includes
my $dbh = C4::Context->dbh;
# Check both categoryitem and biblioitems, see Bug 199
my $total = 0;
for my $table ('auth_tag_structure') {
my $sth=$dbh->prepare("select count(*) as total from $table where authtypecode=?");
$sth->execute($authtypecode);
$total += $sth->fetchrow_hashref->{total};
$sth->finish;
}
my $sth=$dbh->prepare("select authtypecode,authtypetext from authtypes where authtypecode=?");
$sth->execute($authtypecode);
my $data=$sth->fetchrow_hashref;
$sth->finish;
$template->param(authtypecode => $authtypecode,
authtypetext => $data->{'authtypetext'},
total => $total);
# END $OP eq DELETE_CONFIRM
################## DELETE_CONFIRMED ##################################
# called by delete_confirm, used to effectively confirm deletion of data in DB
} elsif ($op eq 'delete_confirmed') {
#start the page and read in includes
my $dbh = C4::Context->dbh;
my $authtypecode=uc($input->param('authtypecode'));
my $sth=$dbh->prepare("delete from auth_types where authtypecode=?");
$sth->execute($authtypecode);
$sth->finish;
print "Content-Type: text/html\n\n<META HTTP-EQUIV=Refresh CONTENT=\"0; URL=authtypes.pl\"></html>";
exit;
# END $OP eq DELETE_CONFIRMED
################## DEFAULT ##################################
} else { # DEFAULT
my $env;
my ($count,$results)=StringSearch($env,$searchfield,'web');
my $toggle="white";
my @loop_data;
for (my $i=$offset; $i < ($offset+$pagesize<$count?$offset+$pagesize:$count); $i++){
my %row_data;
if ($toggle eq 'white'){
$row_data{toggle}="#ffffcc";
} else {
$row_data{toggle}="white";
}
$row_data{authtypecode} = $results->[$i]{'authtypecode'};
$row_data{authtypetext} = $results->[$i]{'authtypetext'};
$row_data{auth_tag_to_report} = $results->[$i]{'auth_tag_to_report'};
push(@loop_data, \%row_data);
}
$template->param(loop => \@loop_data);
if ($offset>0) {
my $prevpage = $offset-$pagesize;
$template->param(previous => "$script_name?offset=".$prevpage);
}
if ($offset+$pagesize<$count) {
my $nextpage =$offset+$pagesize;
$template->param(next => "$script_name?offset=".$nextpage);
}
} #---- END $OP eq DEFAULT
output_html_with_http_headers $input, $cookie, $template->output;
# Local Variables:
# tab-width: 4
# End: