From e7e930ab39d40b81a19bae1e267a4c4917e7d52c Mon Sep 17 00:00:00 2001 From: tipaul Date: Thu, 10 Jun 2004 08:28:40 +0000 Subject: [PATCH] MARC authority management (continued) --- C4/AuthoritiesMarc.pm | 213 +++++++++++++++++- C4/Biblio.pm | 11 +- C4/Koha.pm | 13 +- authorities/auth_finder.pl | 164 ++++++++++++++ authorities/authorities-home.pl | 142 +----------- authorities/authorities.pl | 56 +++-- authorities/detail.pl | 183 +++++++++++++++ .../default/en/authorities/auth_finder.tmpl | 37 +++ .../en/authorities/authorities-home.tmpl | 155 +------------ .../default/en/authorities/authorities.tmpl | 2 +- .../default/en/authorities/detail.tmpl | 48 ++++ .../en/authorities/searchresultlist.tmpl | 62 +++++ .../default/en/intranet-main.tmpl | 14 +- .../parameters/auth_subfields_structure.tmpl | 5 +- .../default/en/parameters/authtypes.tmpl | 7 + .../parameters/marc_subfields_structure.tmpl | 4 +- updater/updatedatabase | 22 +- 17 files changed, 816 insertions(+), 322 deletions(-) create mode 100755 authorities/auth_finder.pl create mode 100755 authorities/detail.pl create mode 100644 koha-tmpl/intranet-tmpl/default/en/authorities/auth_finder.tmpl create mode 100644 koha-tmpl/intranet-tmpl/default/en/authorities/detail.tmpl create mode 100644 koha-tmpl/intranet-tmpl/default/en/authorities/searchresultlist.tmpl diff --git a/C4/AuthoritiesMarc.pm b/C4/AuthoritiesMarc.pm index 7c69ae0750..c244d60a27 100644 --- a/C4/AuthoritiesMarc.pm +++ b/C4/AuthoritiesMarc.pm @@ -20,6 +20,7 @@ use strict; require Exporter; use C4::Context; use C4::Database; +use C4::Koha; use MARC::Record; use vars qw($VERSION @ISA @EXPORT); @@ -30,8 +31,8 @@ $VERSION = 0.01; @ISA = qw(Exporter); @EXPORT = qw( &AUTHgettagslib - &MARCfindsubfield - &MARCfind_frameworkcode + &AUTHfindsubfield + &AUTHfind_authtypecode &AUTHaddauthority &AUTHmodauthority @@ -39,6 +40,8 @@ $VERSION = 0.01; &AUTHaddsubfield &AUTHgetauthority + &authoritysearch + &MARCmodsubfield &AUTHhtml2marc &AUTHaddword @@ -46,12 +49,209 @@ $VERSION = 0.01; &char_decode ); +sub authoritysearch { + my ($dbh, $tags, $and_or, $excluding, $operator, $value, $offset,$length,$authtypecode) = @_; + # build the sql request. She will look like : + # select m1.bibid + # from auth_subfield_table as m1, auth_subfield_table as m2 + # where m1.authid=m2.authid and + # (m1.subfieldvalue like "Des%" and m2.subfieldvalue like "27%") + + # "Normal" statements + my @normal_tags = (); + my @normal_and_or = (); + my @normal_operator = (); + my @normal_value = (); + # Extracts the NOT statements from the list of statements + for(my $i = 0 ; $i <= $#{$value} ; $i++) + { + if(@$operator[$i] eq "contains") # if operator is contains, splits the words in separate requests + { + foreach my $word (split(/ /, @$value[$i])) + { + unless (C4::Context->stopwords->{uc($word)}) { #it's NOT a stopword => use it. Otherwise, ignore + my $tag = substr(@$tags[$i],0,3); + my $subf = substr(@$tags[$i],3,1); + push @normal_tags, @$tags[$i]; + push @normal_and_or, "and"; # assumes "foo" and "bar" if "foo bar" is entered + push @normal_operator, @$operator[$i]; + push @normal_value, $word; + } + } + } + else + { + push @normal_tags, @$tags[$i]; + push @normal_and_or, @$and_or[$i]; + push @normal_operator, @$operator[$i]; + push @normal_value, @$value[$i]; + } + } + + # Finds the basic results without the NOT requests + my ($sql_tables, $sql_where1, $sql_where2) = create_request($dbh,\@normal_tags, \@normal_and_or, \@normal_operator, \@normal_value); + + my $sth; + if ($sql_where2) { + $sth = $dbh->prepare("select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where2 and ($sql_where1)"); + warn "Q2 : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where2 and ($sql_where1)"; + } else { + $sth = $dbh->prepare("select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1"); + warn "Q : select distinct m1.authid from auth_header,$sql_tables where m1.authid=auth_header.authid and auth_header.authtypecode=? and $sql_where1"; + } + $sth->execute($authtypecode); + my @result = (); + + while (my ($authid) = $sth->fetchrow) { + warn "AUTH: $authid"; + push @result,$authid; + } + + # we have authid list. Now, loads summary from [offset] to [offset]+[length] + my $counter = $offset; + my @finalresult = (); + my $oldline; + while (($counter <= $#result) && ($counter <= ($offset + $length))) { + warn "HERE"; + # get MARC::Record of the authority + my $record = AUTHgetauthority($dbh,$result[$counter]); + # then build the summary + my $authtypecode = AUTHfind_authtypecode($dbh,$result[$counter]); + my $authref = getauthtype($authtypecode); + my $summary = $authref->{summary}; + my @fields = $record->fields(); + foreach my $field (@fields) { + my $tag = $field->tag(); + if ($tag<10) { + } else { + my @subf = $field->subfields; + for my $i (0..$#subf) { + my $subfieldcode = $subf[$i][0]; + my $subfieldvalue = $subf[$i][1]; + my $tagsubf = $tag.$subfieldcode; + $summary =~ s/\[(.?.?.?)$tagsubf(.*?)]/$1$subfieldvalue\[$1$tagsubf$2]$2$3/g; + } + } + } + $summary =~ s/\[(.*?)]//g; + $summary =~ s/\n/
/g; + # then add a line for the template loop + my %newline; + $newline{summary} = $summary; + $newline{authid} = $result[$counter]; + push @finalresult, \%newline; + my $nbresults = $#result + 1; + return (\@finalresult, $nbresults); + } +} + +# Creates the SQL Request + +sub create_request { + my ($dbh,$tags, $and_or, $operator, $value) = @_; + + my $sql_tables; # will contain marc_subfield_table as m1,... + my $sql_where1; # will contain the "true" where + my $sql_where2 = "("; # will contain m1.authid=m2.authid + my $nb_active=0; # will contain the number of "active" entries. and entry is active is a value is provided. + my $nb_table=1; # will contain the number of table. ++ on each entry EXCEPT when an OR is provided. + + for(my $i=0; $i<=@$value;$i++) { + if (@$value[$i]) { + $nb_active++; + if ($nb_active==1) { + if (@$operator[$i] eq "start") { + $sql_tables .= "auth_subfield_table as m$nb_table,"; + $sql_where1 .= "(m1.subfieldvalue like ".$dbh->quote("@$value[$i]%"); + if (@$tags[$i]) { + $sql_where1 .=" and m1.tag+m1.subfieldcode in (@$tags[$i])"; + } + $sql_where1.=")"; + } elsif (@$operator[$i] eq "contains") { + $sql_tables .= "auth_word as m$nb_table,"; + $sql_where1 .= "(m1.word like ".$dbh->quote("@$value[$i]%"); + if (@$tags[$i]) { + $sql_where1 .=" and m1.tag+m1.subfieldid in (@$tags[$i])"; + } + $sql_where1.=")"; + } else { + $sql_tables .= "auth_subfield_table as m$nb_table,"; + $sql_where1 .= "(m1.subfieldvalue @$operator[$i] ".$dbh->quote("@$value[$i]"); + if (@$tags[$i]) { + $sql_where1 .=" and m1.tag+m1.subfieldcode in (@$tags[$i])"; + } + $sql_where1.=")"; + } + } else { + if (@$operator[$i] eq "start") { + $nb_table++; + $sql_tables .= "auth_subfield_table as m$nb_table,"; + $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue like ".$dbh->quote("@$value[$i]%"); + if (@$tags[$i]) { + $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldcode in (@$tags[$i])"; + } + $sql_where1.=")"; + $sql_where2 .= "m1.authid=m$nb_table.authid and "; + } elsif (@$operator[$i] eq "contains") { + if (@$and_or[$i] eq 'and') { + $nb_table++; + $sql_tables .= "auth_word as m$nb_table,"; + $sql_where1 .= "@$and_or[$i] (m$nb_table.word like ".$dbh->quote("@$value[$i]%"); + if (@$tags[$i]) { + $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldid in(@$tags[$i])"; + } + $sql_where1.=")"; + $sql_where2 .= "m1.authid=m$nb_table.authid and "; + } else { + $sql_where1 .= "@$and_or[$i] (m$nb_table.word like ".$dbh->quote("@$value[$i]%"); + if (@$tags[$i]) { + $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldid in (@$tags[$i])"; + } + $sql_where1.=")"; + $sql_where2 .= "m1.authid=m$nb_table.authid and "; + } + } else { + $nb_table++; + $sql_tables .= "auth_subfield_table as m$nb_table,"; + $sql_where1 .= "@$and_or[$i] (m$nb_table.subfieldvalue @$operator[$i] ".$dbh->quote(@$value[$i]); + if (@$tags[$i]) { + $sql_where1 .=" and m$nb_table.tag+m$nb_table.subfieldcode in (@$tags[$i])"; + } + $sql_where2 .= "m1.authid=m$nb_table.authid and "; + $sql_where1.=")"; + } + } + } + } + + if($sql_where2 ne "(") # some datas added to sql_where2, processing + { + $sql_where2 = substr($sql_where2, 0, (length($sql_where2)-5)); # deletes the trailing ' and ' + $sql_where2 .= ")"; + } + else # no sql_where2 statement, deleting '(' + { + $sql_where2 = ""; + } + chop $sql_tables; # deletes the trailing ',' + return ($sql_tables, $sql_where1, $sql_where2); +} + + +sub AUTHfind_authtypecode { + my ($dbh,$authid) = @_; + my $sth = $dbh->prepare("select authtypecode from auth_header where authid=?"); + $sth->execute($authid); + my ($authtypecode) = $sth->fetchrow; + return $authtypecode; +} + sub AUTHgettagslib { my ($dbh,$forlibrarian,$authtypecode)= @_; - warn "AUTH : $authtypecode"; +# warn "AUTH : $authtypecode"; $authtypecode="" unless $authtypecode; - warn "AUTH : $authtypecode"; +# warn "AUTH : $authtypecode"; my $sth; my $libfield = ($forlibrarian eq 1)? 'liblibrarian' : 'libopac'; # check that framework exists @@ -171,7 +371,7 @@ sub AUTHgetauthority { my $record = MARC::Record->new(); #---- TODO : the leader is missing $record->leader(' '); - my $sth=$dbh->prepare("select authid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink + my $sth=$dbh->prepare("select authid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue from auth_subfield_table where authid=? order by tag,tagorder,subfieldcode "); @@ -558,6 +758,9 @@ Paul POULAIN paul.poulain@free.fr # $Id$ # $Log$ +# Revision 1.2 2004/06/10 08:29:01 tipaul +# MARC authority management (continued) +# # Revision 1.1 2004/06/07 07:35:01 tipaul # MARC authority management package # diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 415e23198d..c51749c187 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -240,24 +240,24 @@ sub MARCgettagslib { $res->{$tag}->{repeatable}=$repeatable; } - $sth=$dbh->prepare("select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder,kohafield,seealso,hidden,isurl from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"); + $sth=$dbh->prepare("select tagfield,tagsubfield,$libfield as lib,tab, mandatory, repeatable,authorised_value,authtypecode,value_builder,kohafield,seealso,hidden,isurl from marc_subfield_structure where frameworkcode=? order by tagfield,tagsubfield"); $sth->execute($frameworkcode); my $subfield; my $authorised_value; - my $thesaurus_category; + my $authtypecode; my $value_builder; my $kohafield; my $seealso; my $hidden; my $isurl; - while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$thesaurus_category,$value_builder,$kohafield,$seealso,$hidden,$isurl) = $sth->fetchrow) { + while ( ($tag, $subfield, $lib, $tab, $mandatory, $repeatable,$authorised_value,$authtypecode,$value_builder,$kohafield,$seealso,$hidden,$isurl) = $sth->fetchrow) { $res->{$tag}->{$subfield}->{lib}=$lib; $res->{$tag}->{$subfield}->{tab}=$tab; $res->{$tag}->{$subfield}->{mandatory}=$mandatory; $res->{$tag}->{$subfield}->{repeatable}=$repeatable; $res->{$tag}->{$subfield}->{authorised_value}=$authorised_value; - $res->{$tag}->{$subfield}->{thesaurus_category}=$thesaurus_category; + $res->{$tag}->{$subfield}->{authtypecode}=$authtypecode; $res->{$tag}->{$subfield}->{value_builder}=$value_builder; $res->{$tag}->{$subfield}->{kohafield}=$kohafield; $res->{$tag}->{$subfield}->{seealso}=$seealso; @@ -2191,6 +2191,9 @@ Paul POULAIN paul.poulain@free.fr # $Id$ # $Log$ +# Revision 1.92 2004/06/10 08:29:01 tipaul +# MARC authority management (continued) +# # Revision 1.91 2004/06/03 10:03:01 tipaul # * frameworks and itemtypes are independant # * in the MARC editor, showing the + to duplicate a tag only if the tag is repeatable diff --git a/C4/Koha.pm b/C4/Koha.pm index e6da0640a0..61a3d554d6 100644 --- a/C4/Koha.pm +++ b/C4/Koha.pm @@ -59,7 +59,7 @@ Koha.pm provides many functions for Koha scripts. &getprinters &getprinter &getitemtypes &getitemtypeinfo &getframeworks &getframeworkinfo - &getauthtypes + &getauthtypes &getauthtype $DEBUG); use vars qw(); @@ -322,6 +322,17 @@ sub getauthtypes { return (\%authtypes); } +sub getauthtype { + my ($authtypecode) = @_; +# returns a reference to a hash of references to authtypes... + my %authtypes; + my $dbh = C4::Context->dbh; + my $sth=$dbh->prepare("select * from auth_types where authtypecode=?"); + $sth->execute($authtypecode); + my $res=$sth->fetchrow_hashref; + return $res; +} + =head2 getframework $frameworks = &getframework(); diff --git a/authorities/auth_finder.pl b/authorities/auth_finder.pl new file mode 100755 index 0000000000..f27b8d3023 --- /dev/null +++ b/authorities/auth_finder.pl @@ -0,0 +1,164 @@ +#!/usr/bin/perl +# WARNING: 4-character tab stops here + +# 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; +require Exporter; +use CGI; +use C4::Auth; +use HTML::Template; +use C4::Context; +use C4::Search; +use C4::Auth; +use C4::Output; +use C4::Interface::CGI::Output; +use C4::AuthoritiesMarc; +use C4::SearchMarc; +use C4::Catalogue; +use C4::Koha; # XXX subfield_is_koha_internal_p + +my $query=new CGI; +my $op = $query->param('op'); +my $authtypecode = $query->param('authtypecode'); +my $dbh = C4::Context->dbh; + +my $startfrom=$query->param('startfrom'); +$startfrom=0 if(!defined $startfrom); +my ($template, $loggedinuser, $cookie); +my $resultsperpage; + +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; +} + +if ($op eq "do_search") { + my @marclist = $query->param('marclist'); + my @and_or = $query->param('and_or'); + my @excluding = $query->param('excluding'); + my @operator = $query->param('operator'); + my @value = $query->param('value'); + + $resultsperpage= $query->param('resultsperpage'); + $resultsperpage = 19 if(!defined $resultsperpage); + my $orderby = $query->param('orderby'); + + # builds tag and subfield arrays + my @tags; + + my ($results,$total) = authoritysearch($dbh, \@tags,\@and_or, + \@excluding, \@operator, \@value, + $startfrom*$resultsperpage, $resultsperpage,$orderby); + + ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "authorities/auth_finder.tmpl", + query => $query, + type => 'intranet', + authnotrequired => 0, + flagsrequired => {borrowers => 1}, + flagsrequired => {catalogue => 1}, + debug => 1, + }); + + # multi page display gestion + my $displaynext=0; + my $displayprev=$startfrom; + if(($total - (($startfrom+1)*($resultsperpage))) > 0 ){ + $displaynext = 1; + } + + my @field_data = (); + + + for(my $i = 0 ; $i <= $#marclist ; $i++) + { + push @field_data, { term => "marclist", val=>$marclist[$i] }; + push @field_data, { term => "and_or", val=>$and_or[$i] }; + push @field_data, { term => "excluding", val=>$excluding[$i] }; + push @field_data, { term => "operator", val=>$operator[$i] }; + push @field_data, { term => "value", val=>$value[$i] }; + } + + my @numbers = (); + + if ($total>$resultsperpage) + { + for (my $i=1; $i<$total/$resultsperpage+1; $i++) + { + if ($i<16) + { + my $highlight=0; + ($startfrom==($i-1)) && ($highlight=1); + push @numbers, { number => $i, + highlight => $highlight , + searchdata=> \@field_data, + startfrom => ($i-1)}; + } + } + } + + my $from = $startfrom*$resultsperpage+1; + my $to; + + if($total < (($startfrom+1)*$resultsperpage)) + { + $to = $total; + } else { + $to = (($startfrom+1)*$resultsperpage); + } + $template->param(result => $results, + startfrom=> $startfrom, + displaynext=> $displaynext, + displayprev=> $displayprev, + resultsperpage => $resultsperpage, + startfromnext => $startfrom+1, + startfromprev => $startfrom-1, + searchdata=>\@field_data, + total=>$total, + from=>$from, + to=>$to, + numbers=>\@numbers, + ); + +} else { + ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "authorities/auth_finder.tmpl", + query => $query, + type => 'intranet', + authnotrequired => 0, + flagsrequired => {catalogue => 1}, + debug => 1, + }); + +} + +$template->param(authtypesloop => \@authtypesloop); + +# Print the page +output_html_with_http_headers $query, $cookie, $template->output; + +# Local Variables: +# tab-width: 4 +# End: diff --git a/authorities/authorities-home.pl b/authorities/authorities-home.pl index 3b3d78be8c..3737e434c8 100755 --- a/authorities/authorities-home.pl +++ b/authorities/authorities-home.pl @@ -33,63 +33,6 @@ use C4::SearchMarc; use C4::Catalogue; use C4::Koha; # XXX subfield_is_koha_internal_p -# Creates the list of active tags using the active MARC configuration -sub create_marclist { - my $dbh = C4::Context->dbh; - my $tagslib = AUTHgettagslib($dbh,1); - my @marcarray; - push @marcarray,""; - my $widest_menu_item_width = 0; - for (my $pass = 1; $pass <= 2; $pass += 1) - { - for (my $tabloop = 0; $tabloop<=9;$tabloop++) - { - my $separator_inserted_p = 0; # FIXME... should not use!! - foreach my $tag (sort(keys (%{$tagslib}))) - { - foreach my $subfield (sort(keys %{$tagslib->{$tag}})) - { - next if subfield_is_koha_internal_p($subfield); - next unless ($tagslib->{$tag}->{$subfield}->{tab} eq $tabloop); - my $menu_item = "$tag$subfield - $tagslib->{$tag}->{$subfield}->{lib}"; - if ($pass == 1) - { - $widest_menu_item_width = length $menu_item if($widest_menu_item_width < length $menu_item); - } else { - if (!$separator_inserted_p) - { - my $w = int(($widest_menu_item_width - 3 + 0.5)/2); - my $s = ('-' x ($w * 4/5)); - push @marcarray, "$s $tabloop $s"; - $separator_inserted_p = 1; - } - push @marcarray, $menu_item; - } - } - } - } - } - return \@marcarray; -} - -# Creates a scrolling list with the associated default value. -# Using more than one scrolling list in a CGI assigns the same default value to all the -# scrolling lists on the page !?!? That's why this function was written. -sub create_scrolling_list { - my ($params) = @_; - my $scrollist = sprintf("\n"; - - return $scrollist; -} - my $query=new CGI; my $op = $query->param('op'); my $authtypecode = $query->param('authtypecode'); @@ -108,7 +51,6 @@ foreach my $thisauthtype (keys %$authtypes) { selected => $selected, authtypetext => $authtypes->{$thisauthtype}{'authtypetext'}, ); - warn "X = $authtypes->{$thisauthtype}{'authtypetext'}"; push @authtypesloop, \%row; } @@ -121,30 +63,14 @@ if ($op eq "do_search") { $resultsperpage= $query->param('resultsperpage'); $resultsperpage = 19 if(!defined $resultsperpage); - my $orderby = $query->param('orderby'); - - # builds tag and subfield arrays my @tags; - foreach my $marc (@marclist) { - if ($marc) { - my ($tag,$subfield) = MARCfind_marc_from_kohafield($dbh,$marc); - if ($tag) { - push @tags,$dbh->quote("$tag$subfield"); - } else { - push @tags, $dbh->quote(substr($marc,0,4)); - } - } else { - push @tags, ""; - } - } - findseealso($dbh,\@tags); - my ($results,$total) = catalogsearch($dbh, \@tags,\@and_or, + my ($results,$total) = authoritysearch($dbh, \@tags,\@and_or, \@excluding, \@operator, \@value, - $startfrom*$resultsperpage, $resultsperpage,$orderby); - + $startfrom*$resultsperpage, $resultsperpage,$authtypecode); + warn "R : $results"; ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "authorities/authorities-home.tmpl", + = get_template_and_user({template_name => "authorities/searchresultlist.tmpl", query => $query, type => 'intranet', authnotrequired => 0, @@ -199,7 +125,8 @@ if ($op eq "do_search") { } else { $to = (($startfrom+1)*$resultsperpage); } - $template->param(result => $results, + $template->param(result => $results) if $results; + $template->param( startfrom=> $startfrom, displaynext=> $displaynext, displayprev=> $displayprev, @@ -296,64 +223,7 @@ else { flagsrequired => {catalogue => 1}, debug => 1, }); - #$template->param(loggedinuser => $loggedinuser); - - my $marcarray = create_marclist(); - - my $marclist = CGI::scrolling_list(-name=>"marclist", - -values=> $marcarray, - -size=>1, - -multiple=>0, - -onChange => "sql_update()", - ); - - my @statements = (); - - # Considering initial search with 3 criterias - push @statements, { "marclist" => $marclist, "first" => 1 }; - push @statements, { "marclist" => $marclist, "first" => 0 }; - push @statements, { "marclist" => $marclist, "first" => 0 }; - my $sth=$dbh->prepare("Select itemtype,description from itemtypes order by description"); - $sth->execute; - my @itemtype; - my %itemtypes; - push @itemtype, ""; - $itemtypes{''} = ""; - while (my ($value,$lib) = $sth->fetchrow_array) { - push @itemtype, $value; - $itemtypes{$value}=$lib; - } - - my $CGIitemtype=CGI::scrolling_list( -name => 'value', - -values => \@itemtype, - -labels => \%itemtypes, - -size => 1, - -multiple => 0 ); - $sth->finish; - - my @branches; - my @select_branch; - my %select_branches; - my ($count2,@branches)=branches(); - push @select_branch, ""; - $select_branches{''} = ""; - for (my $i=0;$i<$count2;$i++){ - push @select_branch, $branches[$i]->{'branchcode'};# - $select_branches{$branches[$i]->{'branchcode'}} = $branches[$i]->{'branchname'}; - } - my $CGIbranch=CGI::scrolling_list( -name => 'value', - -values => \@select_branch, - -labels => \%select_branches, - -size => 1, - -multiple => 0 ); - $sth->finish; - - $template->param("statements" => \@statements, - "nbstatements" => 3, - CGIitemtype => $CGIitemtype, - CGIbranch => $CGIbranch, - ); } $template->param(authtypesloop => \@authtypesloop); diff --git a/authorities/authorities.pl b/authorities/authorities.pl index 98c2470d36..391a42efbe 100755 --- a/authorities/authorities.pl +++ b/authorities/authorities.pl @@ -172,6 +172,7 @@ sub build_tabs ($$$$) { my @loop_data = (); foreach my $tag (sort(keys (%{$tagslib}))) { my $indicator; +# warn "TAG : $tag => ".$tagslib->{$tag}->{lib}."//"; # if MARC::Record is not empty => use it as master loop, then add missing subfields that should be in the tab. # if MARC::Record is empty => use tab as master loop. if ($record ne -1 && $record->field($tag)) { @@ -285,9 +286,11 @@ my $error = $input->param('error'); my $authid=$input->param('authid'); # if authid exists, it's a modif, not a new authority. my $z3950 = $input->param('z3950'); my $op = $input->param('op'); +# warn "OP : $op"; my $authtypecode = $input->param('authtypecode'); my $dbh = C4::Context->dbh; $authtypecode = &AUTHfind_authtypecode($dbh,$authid) if $authid; +# warn "authtypecode : $authtypecode && authid = $authid"; my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "authorities/authorities.tmpl", query => $input, @@ -300,11 +303,11 @@ my ($template, $loggedinuser, $cookie) $tagslib = AUTHgettagslib($dbh,1,$authtypecode); my $record=-1; my $encoding=""; -$record = AUTHgetauth($dbh,$authid) if ($authid); +$record = AUTHgetauthority($dbh,$authid) if ($authid); $is_a_modif=0; -my ($oldbiblionumtagfield,$oldbiblionumtagsubfield); -my ($oldbiblioitemnumtagfield,$oldbiblioitemnumtagsubfield,$bibitem,$oldbiblioitemnumber); +# my ($oldbiblionumtagfield,$oldbiblionumtagsubfield); +# my ($oldbiblioitemnumtagfield,$oldbiblioitemnumtagsubfield,$bibitem,$oldbiblioitemnumber); if ($authid) { $is_a_modif=1; # if it's a modif, retrieve old biblio and bibitem numbers for the future modification of old-DB. @@ -331,6 +334,7 @@ if ($op eq "add") { } my $record = AUTHhtml2marc($dbh,\@tags,\@subfields,\@values,%indicators); # MARC::Record built => now, record in DB + warn "IN ADD : ".$record->as_formatted(); if ($is_a_modif) { AUTHmodauthority($dbh,$record,$authid,$authtypecode); } else { @@ -384,30 +388,40 @@ if ($op eq "add") { build_tabs ($template, $record, $dbh,$encoding); build_hidden_data; $template->param( - authid => $authid, - oldbiblionumtagfield => $oldbiblionumtagfield, - oldbiblionumtagsubfield => $oldbiblionumtagsubfield, - oldbiblioitemnumtagfield => $oldbiblioitemnumtagfield, - oldbiblioitemnumtagsubfield => $oldbiblioitemnumtagsubfield, - oldbiblioitemnumber => $oldbiblioitemnumber ); + authid => $authid,); +# oldbiblionumtagfield => $oldbiblionumtagfield, +# oldbiblionumtagsubfield => $oldbiblionumtagsubfield, +# oldbiblioitemnumtagfield => $oldbiblioitemnumtagfield, +# oldbiblioitemnumtagsubfield => $oldbiblioitemnumtagsubfield, +# oldbiblioitemnumber => $oldbiblioitemnumber ); } elsif ($op eq "delete") { #------------------------------------------------------------------------------------------------------------------------------ &AUTHdelauthority($dbh,$authid); } -#------------------------------------------------------------------------------------------------------------------------------ -#------------------------------------------------------------------------------------------------------------------------------ -# MAIN -#------------------------------------------------------------------------------------------------------------------------------ + build_tabs ($template, $record, $dbh,$encoding); build_hidden_data; $template->param( authid => $authid, - oldbiblionumtagfield => $oldbiblionumtagfield, - oldbiblionumtagsubfield => $oldbiblionumtagsubfield, - oldbiblioitemnumtagfield => $oldbiblioitemnumtagfield, - oldbiblioitemnumtagsubfield => $oldbiblioitemnumtagsubfield, - oldbiblioitemnumber => $oldbiblioitemnumber ); -$template->param( - authtypecode => $authtypecode, - ); +# oldbiblionumtagfield => $oldbiblionumtagfield, +# oldbiblionumtagsubfield => $oldbiblionumtagsubfield, +# oldbiblioitemnumtagfield => $oldbiblioitemnumtagfield, +# # oldbiblioitemnumtagsubfield => $oldbiblioitemnumtagsubfield, +# oldbiblioitemnumber => $oldbiblioitemnumber, + authtypecode => $authtypecode, + ); + + 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'}, + ); + warn "X = $authtypes->{$thisauthtype}{'authtypetext'}"; + push @authtypesloop, \%row; +} + +$template->param(authtypesloop => \@authtypesloop); output_html_with_http_headers $input, $cookie, $template->output; \ No newline at end of file diff --git a/authorities/detail.pl b/authorities/detail.pl new file mode 100755 index 0000000000..4e7d0e23c1 --- /dev/null +++ b/authorities/detail.pl @@ -0,0 +1,183 @@ +#!/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 + +=head1 NAME + +etail.pl : script to show an authority in MARC format + +=head1 SYNOPSIS + + +=head1 DESCRIPTION + +This script needs an authid + +It shows the authority in a (nice) MARC format depending on authority MARC +parameters tables. + +=head1 FUNCTIONS + +=over 2 + +=cut + + +use strict; +require Exporter; +use C4::AuthoritiesMarc; +use C4::Auth; +use C4::Context; +use C4::Output; +use C4::Interface::CGI::Output; +use CGI; +use C4::Search; +use MARC::Record; +use C4::Koha; +# use C4::Biblio; +# use C4::Catalogue; +use HTML::Template; + +my $query=new CGI; + +my $dbh=C4::Context->dbh; + +my $authid = $query->param('authid'); +my $authtypecode = &AUTHfind_authtypecode($dbh,$authid); +my $tagslib = &AUTHgettagslib($dbh,1,$authtypecode); + +my $record =AUTHgetauthority($dbh,$authid); +# open template +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "authorities/detail.tmpl", + query => $query, + type => "intranet", + authnotrequired => 0, + flagsrequired => {catalogue => 1}, + debug => 1, + }); + +# fill arrays +my @loop_data =(); +my $tag; +# loop through each tab 0 through 9 +# for (my $tabloop = 0; $tabloop<=10;$tabloop++) { +# loop through each tag + my @fields = $record->fields(); + my @loop_data =(); + foreach my $field (@fields) { + my @subfields_data; + # if tag <10, there's no subfield, use the "@" trick + if ($field->tag()<10) { +# next if ($tagslib->{$field->tag()}->{'@'}->{tab} ne $tabloop); + next if ($tagslib->{$field->tag()}->{'@'}->{hidden}); + my %subfield_data; + $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{'@'}->{lib}; + $subfield_data{marc_value}=$field->data(); + $subfield_data{marc_subfield}='@'; + $subfield_data{marc_tag}=$field->tag(); + push(@subfields_data, \%subfield_data); + } else { + my @subf=$field->subfields; + # loop through each subfield + for my $i (0..$#subf) { + $subf[$i][0] = "@" unless $subf[$i][0]; +# next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne $tabloop); + next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{hidden}); + my %subfield_data; + $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{$subf[$i][0]}->{lib}; + if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{isurl}) { + $subfield_data{marc_value}="$subf[$i][1]"; + } else { + $subfield_data{marc_value}=$subf[$i][1]; + } + $subfield_data{marc_subfield}=$subf[$i][0]; + $subfield_data{marc_tag}=$field->tag(); + push(@subfields_data, \%subfield_data); + } + } + if ($#subfields_data>=0) { + my %tag_data; + $tag_data{tag}=$field->tag().' -'. $tagslib->{$field->tag()}->{lib}; + $tag_data{subfield} = \@subfields_data; + push (@loop_data, \%tag_data); + } + } + $template->param("0XX" =>\@loop_data); +# } +# now, build item tab ! +# the main difference is that datas are in lines and not in columns : thus, we build the first, then the values... +# loop through each tag +# warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary +# then construct template. +# my @fields = $record->fields(); +# my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code +# my @big_array; +# foreach my $field (@fields) { +# next if ($field->tag()<10); +# my @subf=$field->subfields; +# my %this_row; +# # loop through each subfield +# for my $i (0..$#subf) { +# next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10); +# $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib}; +# $this_row{$subf[$i][0]} =$subf[$i][1]; +# } +# if (%this_row) { +# push(@big_array, \%this_row); +# } +# } +# #fill big_row with missing datas +# foreach my $subfield_code (keys(%witness)) { +# for (my $i=0;$i<=$#big_array;$i++) { +# $big_array[$i]{$subfield_code}=" " unless ($big_array[$i]{$subfield_code}); +# } +# } +# # now, construct template ! +# my @item_value_loop; +# my @header_value_loop; +# for (my $i=0;$i<=$#big_array; $i++) { +# my $items_data; +# foreach my $subfield_code (keys(%witness)) { +# $items_data .="".$big_array[$i]{$subfield_code}.""; +# } +# my %row_data; +# $row_data{item_value} = $items_data; +# push(@item_value_loop,\%row_data); +# } +# foreach my $subfield_code (keys(%witness)) { +# my %header_value; +# $header_value{header_value} = $witness{$subfield_code}; +# push(@header_value_loop, \%header_value); +# } + +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; +} + +$template->param(authid => $authid, + authtypesloop => \@authtypesloop); +output_html_with_http_headers $query, $cookie, $template->output; + diff --git a/koha-tmpl/intranet-tmpl/default/en/authorities/auth_finder.tmpl b/koha-tmpl/intranet-tmpl/default/en/authorities/auth_finder.tmpl new file mode 100644 index 0000000000..6c04533999 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/default/en/authorities/auth_finder.tmpl @@ -0,0 +1,37 @@ + +
+ +

Authority search

+ +
+ + + "> +
+

Search on

+

+ + +

+

+ + "> + + + + +

+

+ +

+
+
+
+ + diff --git a/koha-tmpl/intranet-tmpl/default/en/authorities/authorities-home.tmpl b/koha-tmpl/intranet-tmpl/default/en/authorities/authorities-home.tmpl index aebf46eba0..5f065dd90c 100644 --- a/koha-tmpl/intranet-tmpl/default/en/authorities/authorities-home.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/authorities/authorities-home.tmpl @@ -10,161 +10,28 @@

Search on

- - - - - - -

-

- - - - - - -

-

- - - - - -

-

- - - - - - -

-
-
-

Search on

-

- - - - - - + +

- + + "> + - -

-

- - - - - -

-

- - - - - - -

- -
-
-

More fields

- -

- - - - - value=""> -

- -

- -

- Warning : the "contains" statement does NOT work if you enter 2 or less letters -
-
-

-

- -
-

-

Results per page : - - Ordered by -

- Suggestions

- - diff --git a/koha-tmpl/intranet-tmpl/default/en/authorities/authorities.tmpl b/koha-tmpl/intranet-tmpl/default/en/authorities/authorities.tmpl index aa674692ab..c56a3e9670 100644 --- a/koha-tmpl/intranet-tmpl/default/en/authorities/authorities.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/authorities/authorities.tmpl @@ -134,7 +134,7 @@ function Check(f) { alertString2 += "\n- "+ total_missing_mandatory_subfields +_(" mandatory fields empty (see bold subfields)"); alert(alertString2); } else { - document.forms[0].submit(); + document.forms[1].submit(); } } function Dopop(link,i) { diff --git a/koha-tmpl/intranet-tmpl/default/en/authorities/detail.tmpl b/koha-tmpl/intranet-tmpl/default/en/authorities/detail.tmpl new file mode 100644 index 0000000000..fd12f74e61 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/default/en/authorities/detail.tmpl @@ -0,0 +1,48 @@ + +/includes/marc-editor.css"> +
+

Authority number :

+ "> + //images/fileopen.png"> + + + //images/edittrash.png"> + + ')" class="button authority"> + Print + +
+ +
+ +

+ +

+ +

+ + +

+ + +
+ + + + diff --git a/koha-tmpl/intranet-tmpl/default/en/authorities/searchresultlist.tmpl b/koha-tmpl/intranet-tmpl/default/en/authorities/searchresultlist.tmpl new file mode 100644 index 0000000000..a3a937e882 --- /dev/null +++ b/koha-tmpl/intranet-tmpl/default/en/authorities/searchresultlist.tmpl @@ -0,0 +1,62 @@ + +
+

Authority search results

+ +
+ + + + + + + + + + + +
Authority #Author
">
+
+ +
+ diff --git a/koha-tmpl/intranet-tmpl/default/en/intranet-main.tmpl b/koha-tmpl/intranet-tmpl/default/en/intranet-main.tmpl index 44c9924958..8669db86f4 100644 --- a/koha-tmpl/intranet-tmpl/default/en/intranet-main.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/intranet-main.tmpl @@ -32,7 +32,7 @@ if(!x && document.getElementById) x=document.getElementById(n); return x; } function SetOn(item) { - for(i=1;i<=6;i++) { + for(i=1;i<=7;i++) { SetOff(i); } if (!(layer = MM_findObj('Hint' + item))) return; @@ -113,10 +113,14 @@ All the system reports
+

Authorities

+ Authorities management & searches +
+

Parameters

Alter Koha System preferences
-
+

Circulation

Work at the front desk on Issues and returns using only a barcode reader and a mouse
@@ -125,13 +129,15 @@ Catalogue
- Circulation
+ Circulation
Members
+ Authorities
+ Reports
- Parameters
+ Parameters
diff --git a/koha-tmpl/intranet-tmpl/default/en/parameters/auth_subfields_structure.tmpl b/koha-tmpl/intranet-tmpl/default/en/parameters/auth_subfields_structure.tmpl index dc3f4cc02c..d56e88868d 100644 --- a/koha-tmpl/intranet-tmpl/default/en/parameters/auth_subfields_structure.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/parameters/auth_subfields_structure.tmpl @@ -34,7 +34,7 @@ " size=40 maxlength=80>

-

(ignore means that the subfield is NOT managed by Koha)

+

hidden (subfield is managed, but hidden. -should be filled by a plugin or thesaurus-)

URL (if checked, it means that the subfield is an URL and can be clicked

@@ -103,8 +103,7 @@ subfield ignored - Tab :, - Repeatable, Not repeatable, + Managed, Repeatable, Not repeatable, Mandatory, Not mandatory, see also : , hidden, diff --git a/koha-tmpl/intranet-tmpl/default/en/parameters/authtypes.tmpl b/koha-tmpl/intranet-tmpl/default/en/parameters/authtypes.tmpl index 20a9183dbc..02694ffdcb 100644 --- a/koha-tmpl/intranet-tmpl/default/en/parameters/authtypes.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/parameters/authtypes.tmpl @@ -73,6 +73,10 @@ function Check(f) {

+

+ + +

"> Enter here the number of the tag that will be reported in the biblio (subfield by subfield). For example, in UNIMARC, enter 200 to report every 200 subfield in the 70x biblio

@@ -112,6 +116,7 @@ function Check(f) { Code Description + summary Tag reported   Edit @@ -121,6 +126,7 @@ function Check(f) {   Default framework   +   MARC structure     @@ -130,6 +136,7 @@ function Check(f) { + " class="button parameters" >MARC structure ?op=add_form&authtypecode=">/images/fileopen.png" width=32 hspace=0 vspace=0 border=0> diff --git a/koha-tmpl/intranet-tmpl/default/en/parameters/marc_subfields_structure.tmpl b/koha-tmpl/intranet-tmpl/default/en/parameters/marc_subfields_structure.tmpl index de43e47426..17d18c8b7f 100644 --- a/koha-tmpl/intranet-tmpl/default/en/parameters/marc_subfields_structure.tmpl +++ b/koha-tmpl/intranet-tmpl/default/en/parameters/marc_subfields_structure.tmpl @@ -42,7 +42,7 @@

URL (if checked, it means that the subfield is an URL and can be clicked

- or thesaurus: + or thesaurus: or plugin:

@@ -116,7 +116,7 @@ hidden, is an url, Auth value :, - Thesaurus :, + Authority :, Plugin :, diff --git a/updater/updatedatabase b/updater/updatedatabase index 3d6b314e96..46e0a87b2c 100755 --- a/updater/updatedatabase +++ b/updater/updatedatabase @@ -212,6 +212,7 @@ my %requiretables = ( authtypecode char(10) not NULL, authtypetext char(255) not NULL, auth_tag_to_report char(3) not NULL, + summary text not NULL, PRIMARY KEY (authtypecode) )", biblio_framework => "( @@ -261,7 +262,6 @@ my %requiretables = ( subfieldcode char(1) NOT NULL default '', subfieldorder tinyint(4) NOT NULL default '1', subfieldvalue varchar(255) default NULL, - valuebloblink bigint(20) default NULL, PRIMARY KEY (subfieldid), KEY authid (authid), KEY tag (tag), @@ -1111,6 +1111,23 @@ if ($items{'bulk'} eq "varchar(30)") { $sti->execute; } +# changing the marc_subfield_structure table around... +my %marc_subfield_structure; + +$sth = $dbh->prepare("show columns from marc_subfield_structure"); +$sth->execute; +while ( my ( $column, $type, $null, $key, $default, $extra ) = $sth->fetchrow ) +{ + $marc_subfield_structure{$column} = $type; +} + +if ($marc_subfield_structure{thesaurus_category}) { + print " changing thesaurus_category in marc_subfield_structure table\n"; + my $sti = + $dbh->prepare("ALTER TABLE marc_subfield_structure CHANGE `thesaurus_category` `authtypecode` VARCHAR(10 ) DEFAULT NULL"); + $sti->execute; +} + # # creating index in issuingrules if needed # @@ -1183,6 +1200,9 @@ $sth->finish; exit; # $Log$ +# Revision 1.83 2004/06/10 08:32:02 tipaul +# MARC authority management (continued) +# # Revision 1.82 2004/06/03 12:46:58 tipaul # * frameworks and itemtypes are independant # -- 2.39.5