From e928ba3e059fb0c40496b3c72c5e9117c8acaadb Mon Sep 17 00:00:00 2001 From: tgarip1957 Date: Fri, 1 Sep 2006 15:45:01 +0000 Subject: [PATCH] MARCXML only. No more MARC record. No more non-marc handling Install LibXML or Expat for fast parsing. either will work Bug in addbiblio when adding authorities fixed --- cataloguing/addbiblio-nomarc.pl | 68 ----- cataloguing/addbiblio.pl | 423 ++++++++++++++++++-------------- cataloguing/additem-nomarc.pl | 220 ----------------- cataloguing/additem.pl | 386 ++++++++++++++++++----------- cataloguing/keywordsearch.pl | 123 ---------- cataloguing/savebiblio.pl | 57 ----- cataloguing/saveitem.pl | 95 ------- cataloguing/thesaurus_popup.pl | 126 ---------- cataloguing/websitesearch.pl | 119 --------- 9 files changed, 481 insertions(+), 1136 deletions(-) delete mode 100755 cataloguing/addbiblio-nomarc.pl delete mode 100755 cataloguing/additem-nomarc.pl delete mode 100755 cataloguing/keywordsearch.pl delete mode 100755 cataloguing/savebiblio.pl delete mode 100755 cataloguing/saveitem.pl delete mode 100755 cataloguing/thesaurus_popup.pl delete mode 100755 cataloguing/websitesearch.pl diff --git a/cataloguing/addbiblio-nomarc.pl b/cataloguing/addbiblio-nomarc.pl deleted file mode 100755 index 58787fe491..0000000000 --- a/cataloguing/addbiblio-nomarc.pl +++ /dev/null @@ -1,68 +0,0 @@ -#!/usr/bin/perl - -# $Id$ - -# -# TODO -# -# Add info on biblioitems and items already entered as you enter new ones -# - -# 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 - -# $Log$ -# Revision 1.1 2006/01/17 16:40:54 tipaul -# moving acqui.simple directory to cataloguing, as acqui.simple contains cataloguing scripts... -# -# Revision 1.3 2005/05/04 08:45:22 tipaul -# synch'ing 2.2 and head -# -# Revision 1.2.4.1 2005/03/25 12:52:42 tipaul -# needs "editcatalogue" flag, not "catalogue" -# -# Revision 1.2 2003/05/09 23:47:22 rangi -# This script is now templated -# 3 more to go i think -# - -use CGI; -use strict; -use C4::Output; -use HTML::Template; -use C4::Auth; -use C4::Interface::CGI::Output; - -my $input = new CGI; -my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { - template_name => "acqui.simple/addbiblio-nomarc.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { editcatalogue => 1 }, - debug => 1, - } -); - -my $error = $input->param('error'); - -$template->param( - ERROR => $error, -); - -output_html_with_http_headers $input, $cookie, $template->output; diff --git a/cataloguing/addbiblio.pl b/cataloguing/addbiblio.pl index d2a412bb3e..5278b6f116 100755 --- a/cataloguing/addbiblio.pl +++ b/cataloguing/addbiblio.pl @@ -25,60 +25,24 @@ use C4::Auth; use C4::Output; use C4::Interface::CGI::Output; use C4::Biblio; -use C4::Search; -use C4::SearchMarc; # also includes Biblio.pm, SearchMarc is used to FindDuplicate +use C4::Search; # also includes Biblio.pm, Search is used to FindDuplicate use C4::Context; -use C4::Log; use C4::Koha; # XXX subfield_is_koha_internal_p -use HTML::Template; -use MARC::File::USMARC; -use MARC::File::XML; - +use MARC::Record; +use Encode; use vars qw( $tagslib); use vars qw( $authorised_values_sth); use vars qw( $is_a_modif ); - +my $input = new CGI; +my $z3950 = $input->param('z3950'); +#my $logstatus=C4::Context->preference('Activate_log'); +my $xml; my $itemtype; # created here because it can be used in build_authorized_values_list sub -=item find_value - - ($indicators, $value) = find_value($tag, $subfield, $record,$encoding); - -Find the given $subfield in the given $tag in the given -MARC::Record $record. If the subfield is found, returns -the (indicators, value) pair; otherwise, (undef, undef) is -returned. - -=cut - -sub find_value { - my ($tagfield,$insubfield,$record,$encoding) = @_; - my @result; - my $indicator; - if ($tagfield <10) { - if ($record->field($tagfield)) { - push @result, $record->field($tagfield)->data(); - } else { - push @result,""; - } - } else { - foreach my $field ($record->field($tagfield)) { - my @subfields = $field->subfields(); - foreach my $subfield (@subfields) { - if (@$subfield[0] eq $insubfield) { - push @result,@$subfield[1]; - $indicator = $field->indicator(1).$field->indicator(2); - } - } - } - } - return($indicator,@result); -} - =item MARCfindbreeding - $record = MARCfindbreeding($dbh, $breedingid); + $record = MARCfindbreeding($dbh, $breedingid,$frameworkcode); Look up the breeding farm with database handle $dbh, for the record with id $breedingid. If found, returns the decoded @@ -88,17 +52,36 @@ Returns as second parameter the character encoding. =cut sub MARCfindbreeding { - my ($dbh,$id) = @_; - my $sth = $dbh->prepare("select file,marc,encoding from marc_breeding where id=?"); + my ($dbh,$id,$oldbiblionumber) = @_; + my $sth = $dbh->prepare("select marc,encoding from marc_breeding where id=?"); $sth->execute($id); - my ($file,$marc,$encoding) = $sth->fetchrow; + my ($marc,$encoding) = $sth->fetchrow; + $sth->finish; if ($marc) { my $record = MARC::File::USMARC::decode($marc); if (ref($record) eq undef) { return -1; - } else { - return $record,$encoding; + } + +##Delete biblionumber tag in case a similar tag is used in imported MARC + my ( $tagfield, $tagsubfield ) =MARCfind_marc_from_kohafield("biblionumber","biblios"); + my $old_field = $record->field($tagfield); + $record->delete_field($old_field); + ##add the old biblionumber if a modif but coming from breedingfarm + if ($oldbiblionumber){ + my $newfield; + if ($tagfield<10){ + $newfield = MARC::Field->new($tagfield, $oldbiblionumber); + }else{ + $newfield = MARC::Field->new($tagfield, '', '', "$tagsubfield" => $oldbiblionumber); + } + $record->insert_fields_ordered($newfield); } + my $xml= $record->as_xml_record(); + $xml=Encode::encode('utf8',$xml); + my $xmlhash=XML_xml2hash_onerecord($xml); + return $xmlhash,$encoding; + } return -1; } @@ -164,10 +147,11 @@ sub build_authorized_values_list ($$$$$) { builds the entry for a subfield. =cut sub create_input () { - my ($tag,$subfield,$value,$i,$tabloop,$rec,$authorised_values_sth) = @_; + my ($tag,$subfield,$value,$i,$tabloop,$rec,$authorised_values_sth,$id) = @_; $value =~ s/"/"/g; my $dbh = C4::Context->dbh; my %subfield_data; + $subfield_data{id}=$id; $subfield_data{tag}=$tag; $subfield_data{subfield}=$subfield; $subfield_data{marc_lib}="".$tagslib->{$tag}->{$subfield}->{lib}.""; @@ -175,15 +159,14 @@ sub create_input () { $subfield_data{tag_mandatory}=$tagslib->{$tag}->{mandatory}; $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory}; $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable}; - $subfield_data{kohafield}=$tagslib->{$tag}->{$subfield}->{kohafield}; $subfield_data{index} = $i; - $subfield_data{visibility} = "display:none" unless (($tagslib->{$tag}->{$subfield}->{hidden}%2==0) or $value ne ''); #check parity - # it's an authorised field + $subfield_data{visibility} = "display:none" if (substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) gt "0") ; #check parity if ($tagslib->{$tag}->{$subfield}->{authorised_value}) { $subfield_data{marc_value}= build_authorized_values_list($tag, $subfield, $value, $dbh,$authorised_values_sth); # it's a thesaurus / authority field } elsif ($tagslib->{$tag}->{$subfield}->{authtypecode}) { - $subfield_data{marc_value}=" {$tag}->{$subfield}->{authtypecode}."&index=$i',$i)\">..."; + + $subfield_data{marc_value}=" {$tag}->{$subfield}->{authtypecode}."&index=$id',$id);\">..."; # it's a plugin field } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) { # opening plugin. Just check wether we are on a developper computer on a production one @@ -196,29 +179,31 @@ sub create_input () { require $plugin; my $extended_param = plugin_parameters($dbh,$rec,$tagslib,$i,$tabloop); my ($function_name,$javascript) = plugin_javascript($dbh,$rec,$tagslib,$i,$tabloop); - $subfield_data{marc_value}=" ... $javascript"; + $subfield_data{marc_value}=" ... $javascript"; # it's an hidden field } elsif ($tag eq '') { - $subfield_data{marc_value}=""; - } elsif ($tagslib->{$tag}->{$subfield}->{'hidden'}) { - $subfield_data{marc_value}=""; + $subfield_data{marc_value}=""; + } elsif (substr($tagslib->{$tag}->{$subfield}->{'hidden'},2,1) gt "1") { + + $subfield_data{marc_value}=""; # it's a standard field } else { if (length($value) >100) { - $subfield_data{marc_value}=""; + $subfield_data{marc_value}=""; } else { - $subfield_data{marc_value}=""; #" + $subfield_data{marc_value}=""; #" } } return \%subfield_data; } -sub build_tabs ($$$$) { - my($template, $record, $dbh,$encoding) = @_; +sub build_tabs ($$$;$){ + my($template, $xmlhash, $dbh,$addedfield) = @_; # fill arrays my @loop_data =(); my $tag; my $i=0; +my $id=100; my $authorised_values_sth = $dbh->prepare("select authorised_value,lib from authorised_values where category=? order by lib"); @@ -228,49 +213,69 @@ sub build_tabs ($$$$) { my @loop_data = (); foreach my $tag (sort(keys (%{$tagslib}))) { my $indicator; - # 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) || $tag eq '000')) { - my @fields; - if ($tag ne '000') { - @fields = $record->field($tag); - } else { - push @fields,$record->leader(); - } - foreach my $field (@fields) { - my @subfields_data; - if ($tag<10) { - my ($value,$subfield); - if ($tag ne '000') { - $value=$field->data(); - $subfield="@"; - } else { - $value = $field; - $subfield='@'; - } - next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop); - next if ($tagslib->{$tag}->{$subfield}->{kohafield} eq 'biblio.biblionumber'); - push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth)); - $i++; - } else { - my @subfields=$field->subfields(); - foreach my $subfieldcount (0..$#subfields) { - my $subfield=$subfields[$subfieldcount][0]; - my $value=$subfields[$subfieldcount][1]; - next if (length $subfield !=1); + # 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 ($xmlhash) { + #### + my @subfields_data; + my %definedsubfields; + my $hiddenrequired; + my ($ind1,$ind2); + my $biblio=$xmlhash->{'datafield'}; + my $controlfields=$xmlhash->{'controlfield'}; + my $leader=$xmlhash->{'leader'}; + if ($tag>9){ + foreach my $data (@$biblio){ + if ($data->{'tag'} eq $tag){ + $ind1=" "; + $ind2=" "; + foreach my $subfield ( $data->{'subfield'}){ + foreach my $code ( @$subfield){ + if (@$subfield>1){$hiddenrequired=1;} + my $subfield=$code->{'code'} ; + my $value=$code->{'content'}; + $definedsubfields{$tag}{$code->{'code'}}=1 ; next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop); - push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$record,$authorised_values_sth)); + push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$xmlhash,$authorised_values_sth,$id)); $i++; - } + } + } + $ind1=$data->{'ind1'}; + $ind2= $data->{'ind2'}; + } + } + }else{ + if ($tag eq "000" || $tag eq "LDR"){ + my $subfield="@"; + my $value=$leader->[0] if $leader->[0]; + $definedsubfields{$tag}{'@'}=1; + next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop); + push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$xmlhash,$authorised_values_sth,$id)); + $i++; + }else{ + foreach my $control (@$controlfields){ + if ($control->{'tag'} eq $tag){ + my $subfield="@"; + my $value=$control->{'content'} ; + $definedsubfields{$tag}{'@'}=1; + next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop); + push(@subfields_data, &create_input($tag,$subfield,$value,$i,$tabloop,$xmlhash,$authorised_values_sth,$id)); + $i++; } -# now, loop again to add parameter subfield that are not in the MARC::Record + } + } + }##tag >9 + + + ##### + + # now, loop again to add parameter subfield that are not in the MARC::Record foreach my $subfield (sort( keys %{$tagslib->{$tag}})) { next if (length $subfield !=1); next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop); - next if ($tag<10); - next if (($tagslib->{$tag}->{$subfield}->{hidden}<=-4) or ($tagslib->{$tag}->{$subfield}->{hidden}>=5) ); #check for visibility flag - next if (defined($field->subfield($subfield))); - push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth)); + next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) gt "1") ); #check for visibility flag + next if ($definedsubfields{$tag}{$subfield} ); + push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$xmlhash,$authorised_values_sth,$id)); $i++; } if ($#subfields_data >= 0) { @@ -278,38 +283,62 @@ sub build_tabs ($$$$) { $tag_data{tag} = $tag; $tag_data{tag_lib} = $tagslib->{$tag}->{lib}; $tag_data{repeatable} = $tagslib->{$tag}->{repeatable}; - $tag_data{indicator} = $record->field($tag)->indicator(1). $record->field($tag)->indicator(2) if ($tag>=10); + $tag_data{indicator} = $ind1.$ind2 if ($tag>=10); $tag_data{subfield_loop} = \@subfields_data; if ($tag<10) { - $tag_data{fixedfield} = 1; - } + $tag_data{fixedfield} = 1; + } push (@loop_data, \%tag_data); } + + # If there is more than 1 field, add an empty hidden field as separator. - if ($#fields >=1 && $#loop_data >=0 && $loop_data[$#loop_data]->{'tag'} eq $tag) { + if ($hiddenrequired && $#loop_data >=0 && $loop_data[$#loop_data]->{'tag'} eq $tag) { my @subfields_data; my %tag_data; - push(@subfields_data, &create_input('','','',$i,$tabloop,$record,$authorised_values_sth)); + push(@subfields_data, &create_input('','','',$i,$tabloop,$xmlhash,$authorised_values_sth,$id)); $tag_data{tag} = ''; $tag_data{tag_lib} = ''; $tag_data{indicator} = ''; $tag_data{subfield_loop} = \@subfields_data; if ($tag<10) { - $tag_data{fixedfield} = 1; - } + $tag_data{fixedfield} = 1; + } push (@loop_data, \%tag_data); $i++; } - } + if ($addedfield eq $tag) { + my %tag_data; + my @subfields_data; + foreach my $subfield (sort( keys %{$tagslib->{$tag}})) { + next if (length $subfield !=1); + next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop); + next if ($tag<10); + next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) gt "1") ); #check for visibility flag + push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$xmlhash,$authorised_values_sth,$id)); + $i++; + } + $tag_data{tag} = $tag; + $tag_data{tag_lib} = $tagslib->{$tag}->{lib}; + $tag_data{repeatable} = $tagslib->{$tag}->{repeatable}; + $tag_data{indicator} = $ind1.$ind2 if ($tag>=10); + $tag_data{subfield_loop} = \@subfields_data; + if ($tag<10) { + $tag_data{fixedfield} = 1; + } + push (@loop_data, \%tag_data); + $i++; + } + # if breeding is empty } else { my @subfields_data; foreach my $subfield (sort(keys %{$tagslib->{$tag}})) { next if (length $subfield !=1); - next if (($tagslib->{$tag}->{$subfield}->{hidden}<=-5) or ($tagslib->{$tag}->{$subfield}->{hidden}>=4) ); #check for visibility flag + next if ((substr($tagslib->{$tag}->{$subfield}->{hidden},2,1) gt "1") ); #check for visibility flag next if ($tagslib->{$tag}->{$subfield}->{tab} ne $tabloop); - push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$record,$authorised_values_sth)); + push(@subfields_data, &create_input($tag,$subfield,'',$i,$tabloop,$xmlhash,$authorised_values_sth,$id)); $i++; } if ($#subfields_data >= 0) { @@ -321,12 +350,13 @@ sub build_tabs ($$$$) { $tag_data{subfield_loop} = \@subfields_data; $tag_data{tagfirstsubfield} = $tag_data{subfield_loop}[0]; if ($tag<10) { - $tag_data{fixedfield} = 1; - } + $tag_data{fixedfield} = 1; + } push (@loop_data, \%tag_data); } } - } + $id++; + } $template->param($tabloop."XX" =>\@loop_data); } } @@ -352,7 +382,7 @@ sub build_hidden_data () { $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib}; $subfield_data{marc_mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory}; $subfield_data{marc_repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable}; - $subfield_data{marc_value}=""; + $subfield_data{marc_value}=""; push(@loop_data, \%subfield_data); $i++ } @@ -365,21 +395,21 @@ sub build_hidden_data () { #========================= my $input = new CGI; my $error = $input->param('error'); -my $biblionumber=$input->param('biblionumber'); # if biblionumber exists, it's a modif, not a new biblio. -if (!$biblionumber){ - $biblionumber=$input->param('oldbiblionumber'); - warn "OLDBIBLIONUMBER".$biblionumber; - } +my $oldbiblionumber=$input->param('oldbiblionumber'); # if bib exists, it's a modif, not a new biblio. my $breedingid = $input->param('breedingid'); my $z3950 = $input->param('z3950'); my $op = $input->param('op'); +my $duplicateok = $input->param('duplicateok'); + my $frameworkcode = $input->param('frameworkcode'); my $dbh = C4::Context->dbh; +my $biblionumber; + +$biblionumber=$oldbiblionumber if $oldbiblionumber; -$frameworkcode = &MARCfind_frameworkcode($dbh,$biblionumber) if ($biblionumber and not ($frameworkcode)); $frameworkcode='' if ($frameworkcode eq 'Default'); my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "acqui.simple/addbiblio.tmpl", + = get_template_and_user({template_name => "cataloguing/addbiblio.tmpl", query => $input, type => "intranet", authnotrequired => 0, @@ -388,7 +418,7 @@ my ($template, $loggedinuser, $cookie) }); #Getting the list of all frameworks -my $queryfwk =$dbh->prepare("select frameworktext, frameworkcode from biblio_framework"); +my $queryfwk =$dbh->prepare("select frameworktext, frameworkcode from biblios_framework"); $queryfwk->execute; my %select_fwk; my @select_fwk; @@ -409,70 +439,81 @@ my $framework=CGI::scrolling_list( -name => 'Frameworks', -size => 1, -multiple => 0 ); $template->param( framework => $framework); - +my $xmlhash; +my $xml; +#####DO NOT RETRIVE FROM ZEBRA###### +my $record =XMLgetbiblio($dbh,$biblionumber) if ($biblionumber); +$xmlhash=XML_xml2hash_onerecord($record) if ($biblionumber); +$frameworkcode=MARCfind_frameworkcode( $dbh, $biblionumber ); +########### $tagslib = &MARCgettagslib($dbh,1,$frameworkcode); -my $record=-1; -my $encoding=""; -#$record = MARCgetbiblio($dbh,$biblionumber) if ($biblionumber); -$record=get_record($biblionumber) if ($biblionumber); -($record,$encoding) = MARCfindbreeding($dbh,$breedingid) if ($breedingid); +my $encoding=""; +($xmlhash,$encoding) = MARCfindbreeding($dbh,$breedingid,$oldbiblionumber) if ($breedingid); $is_a_modif=0; -my ($biblionumtagfield,$biblionumtagsubfield); -my ($biblioitemnumtagfield,$biblioitemnumtagsubfield,$bibitem,$biblioitemnumber); -if ($biblionumber) { +$is_a_modif=1 if $oldbiblionumber; +my ($oldbiblionumtagfield,$oldbiblionumtagsubfield); +if ($biblionumber && !$z3950) { $is_a_modif=1; - # if it's a modif, retrieve bibli and biblioitem numbers for the future modification of old-DB. - ($biblionumtagfield,$biblionumtagsubfield) = &MARCfind_marc_from_kohafield($dbh,"biblio.biblionumber",$frameworkcode); - ($biblioitemnumtagfield,$biblioitemnumtagsubfield) = &MARCfind_marc_from_kohafield($dbh,"biblioitems.biblioitemnumber",$frameworkcode); - # search biblioitems value - my $sth=$dbh->prepare("select biblioitemnumber from biblioitems where biblionumber=?"); - $sth->execute($biblionumber); - ($biblioitemnumber) = $sth->fetchrow; + # if it's a modif, retrieve old biblionumber for the future modification of old-DB. + ($oldbiblionumtagfield,$oldbiblionumtagsubfield) = &MARCfind_marc_from_kohafield($dbh,"biblionumber","biblios"); + + } #------------------------------------------------------------------------------------------------------------------------------ if ($op eq "addbiblio") { #------------------------------------------------------------------------------------------------------------------------------ # rebuild my @tags = $input->param('tag'); - my @subfields = $input->param('subfield'); - my @values = $input->param('field_value'); + my @subfields =$input->param('subfield'); + my @values=$input->param('field_value'); # build indicator hash. my @ind_tag = $input->param('ind_tag'); my @indicator = $input->param('indicator'); - my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag); - my $record=MARC::Record::new_from_xml($xml, 'UTF-8'); - # check for a duplicate - my ($duplicatebiblionumber,$duplicatebibid,$duplicatetitle) = FindDuplicate($record) if ($op eq "addbiblio") && (!$is_a_modif); + + + +## check for malformed xml -- non UTF-8 like (MARC8) will break xml without warning +### This usually happens with data coming from other Z3950 servers +## Slows the saving process so comment out at your own risk +eval{ + $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag); +}; + if ($@){ +warn $@; + $template->param(error =>1,xmlerror=>1,); +goto FINAL; + }; +my $xmlhash=XML_xml2hash_onerecord($xml); + my ($duplicatebiblionumber,$duplicatetitle) = FindDuplicate($xmlhash) if (($op eq "addbiblio") && (!$is_a_modif) && (!$duplicateok)); my $confirm_not_duplicate = $input->param('confirm_not_duplicate'); # it is not a duplicate (determined either by Koha itself or by user checking it's not a duplicate) if (!$duplicatebiblionumber or $confirm_not_duplicate) { # MARC::Record built => now, record in DB + my $oldbibnum; + my $oldbibitemnum; if ($is_a_modif) { - warn "CONFIRM ITS A MODIF : .$biblionumber"; - NEWmodbiblioframework($dbh,$biblionumber,$frameworkcode); - NEWmodbiblio($dbh,$record,$biblionumber,$frameworkcode); + NEWmodbiblio($dbh,$biblionumber,$xmlhash,$frameworkcode); + } else { - my $biblioitemnumber; - ($biblionumber,$biblioitemnumber) = NEWnewbiblio($dbh,$record,$frameworkcode); - logaction($loggedinuser,"acqui.simple","add",$biblionumber,"record : ".$record->as_formatted) if (C4::Context->preference("Activate_Log")); + + ($biblionumber) = NEWnewbiblio($dbh,$xmlhash,$frameworkcode); + } # now, redirect to additem page print $input->redirect("additem.pl?biblionumber=$biblionumber&frameworkcode=$frameworkcode"); exit; } else { +FINAL: # it may be a duplicate, warn the user and do nothing - build_tabs ($template, $record, $dbh,$encoding); + build_tabs ($template, $xmlhash, $dbh); build_hidden_data; $template->param( - oldbiblionumber => $biblionumber, - biblionumber => $biblionumber, - biblionumtagfield => $biblionumtagfield, - biblionumtagsubfield => $biblionumtagsubfield, - biblioitemnumtagfield => $biblioitemnumtagfield, - biblioitemnumtagsubfield => $biblioitemnumtagsubfield, - biblioitemnumber => $biblioitemnumber, + oldbiblionumber => $oldbiblionumber, + biblionumber => $biblionumber, + oldbiblionumtagfield => $oldbiblionumtagfield, + oldbiblionumtagsubfield => $oldbiblionumtagsubfield, duplicatebiblionumber => $duplicatebiblionumber, duplicatetitle => $duplicatetitle, ); @@ -481,65 +522,69 @@ if ($op eq "addbiblio") { } elsif ($op eq "addfield") { #------------------------------------------------------------------------------------------------------------------------------ my $addedfield = $input->param('addfield_field'); - my $tagaddfield_subfield = $input->param('addfield_subfield'); my @tags = $input->param('tag'); my @subfields = $input->param('subfield'); my @values = $input->param('field_value'); + # build indicator hash. my @ind_tag = $input->param('ind_tag'); my @indicator = $input->param('indicator'); my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag); - my $record=MARC::Record::new_from_xml($xml, 'UTF-8'); + my $xmlhash=XML_xml2hash_onerecord($xml); # adding an empty field - my $field = MARC::Field->new("$addedfield",'','','$tagaddfield_subfield' => ""); - $record->append_fields($field); - build_tabs ($template, $record, $dbh,$encoding); + build_tabs ($template, $xmlhash, $dbh,$addedfield); build_hidden_data; $template->param( - oldbiblionumber => $biblionumber, - biblionumber => $biblionumber, - biblionumtagfield => $biblionumtagfield, - biblionumtagsubfield => $biblionumtagsubfield, - biblioitemnumtagfield => $biblioitemnumtagfield, - biblioitemnumtagsubfield => $biblioitemnumtagsubfield, - biblioitemnumber => $biblioitemnumber ); + oldbiblionumber => $oldbiblionumber, + biblionumber => $biblionumber, + oldbiblionumtagfield => $oldbiblionumtagfield, + oldbiblionumtagsubfield => $oldbiblionumtagsubfield, + ); } elsif ($op eq "delete") { #------------------------------------------------------------------------------------------------------------------------------ - &NEWdelbiblio($dbh,$biblionumber); - logaction($loggedinuser,"acqui.simple","del",$biblionumber,"") if (logstatus); - - print "Content-Type: text/html\n\n"; +my $sth=$dbh->prepare("select iss.itemnumber from items i ,issues iss where iss.itemnumber=i.itemnumber and iss.returndate is null and i.biblionumber=?"); + $sth->execute($biblionumber); +my $onloan=$sth->fetchrow; + + if (!$onloan){ + NEWdelbiblio($dbh,$biblionumber); +print $input->redirect("/cgi-bin/koha/catalogue/catalogue-search.pl"); exit; + }else{ + +$template->param(error => 1, onloan=>1,); + +goto OUT; + } #------------------------------------------------------------------------------------------------------------------------------ #------------------------------------------------------------------------------------------------------------------------------ } else { #------------------------------------------------------------------------------------------------------------------------------ - # If we're in a duplication case, we have to set to "" the bibid and biblionumber + + # If we're in a duplication case, we have to set to "" the biblionumber # as we'll save the biblio as a new one. if ($op eq "duplicate") { - $biblionumber= ""; + $biblionumber = ""; + $oldbiblionumber= ""; + $template->param(duplicateok => 1); } - #FIXME: it's kind of silly to go from MARC::Record to MARC::File::XML and then back again just to fix the encoding - eval { - my $uxml = $record->as_xml; - my $urecord = MARC::Record::new_from_xml($uxml, 'UTF-8'); - $record = $urecord; - }; - build_tabs ($template, $record, $dbh,$encoding); + build_tabs ($template, $xmlhash, $dbh); build_hidden_data; $template->param( - oldbiblionumber => $biblionumber, - biblionumber => $biblionumber, - biblionumtagfield => $biblionumtagfield, - biblionumtagsubfield => $biblionumtagsubfield, - biblioitemnumtagfield => $biblioitemnumtagfield, - biblioitemnumtagsubfield => $biblioitemnumtagsubfield, - biblioitemnumber => $biblioitemnumber, + oldbiblionumber => $oldbiblionumber, + biblionumber => $biblionumber, + oldbiblionumtagfield => $oldbiblionumtagfield, + oldbiblionumtagsubfield => $oldbiblionumtagsubfield ); } $template->param( frameworkcode => $frameworkcode, itemtype => $frameworkcode, # HINT: if the library has itemtype = framework, itemtype is auto filled ! hide_marc => C4::Context->preference('hide_marc'), + intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"), + intranetstylesheet => C4::Context->preference("intranetstylesheet"), + IntranetNav => C4::Context->preference("IntranetNav"), + advancedMARCEditor => C4::Context->preference("advancedMARCEditor"), ); + output_html_with_http_headers $input, $cookie, $template->output; diff --git a/cataloguing/additem-nomarc.pl b/cataloguing/additem-nomarc.pl deleted file mode 100755 index 9bd0fdc981..0000000000 --- a/cataloguing/additem-nomarc.pl +++ /dev/null @@ -1,220 +0,0 @@ -#!/usr/bin/perl - -# $Id$ - -# 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 - -# $Log$ -# Revision 1.4 2006/07/27 13:52:49 toins -# 1 sub renamed and cleaned. -# -# Revision 1.3 2006/07/21 10:12:00 toins -# subs renamed according to coding guidelines. -# -# Revision 1.2 2006/07/12 17:17:12 toins -# getitemtypes renamed to GetItemTypes -# -# Revision 1.1 2006/01/17 16:40:54 tipaul -# moving acqui.simple directory to cataloguing, as acqui.simple contains cataloguing scripts... -# -# Revision 1.8 2005/10/26 09:11:34 tipaul -# big commit, still breaking things... -# -# * synch with rel_2_2. Probably the last non manual synch, as rel_2_2 should not be modified deeply. -# * code cleaning (cleaning warnings from perl -w) continued -# -# Revision 1.4.2.1 2005/03/25 12:52:44 tipaul -# needs "editcatalogue" flag, not "catalogue" -# -# Revision 1.4 2004/11/19 16:41:49 tipaul -# improving behaviour when MARC=OFF -# -# Revision 1.3 2004/08/13 16:37:25 tipaul -# adding frameworkcode to API in some subs -# -# Revision 1.2 2003/05/11 06:59:11 rangi -# Mostly templated. -# Still needs some work -# - -use CGI; -use strict; -use C4::Biblio; -use C4::Koha; -use C4::Output; -use HTML::Template; -use C4::Auth; -use C4::Interface::CGI::Output; - -my $input = new CGI; -my $biblionumber = $input->param('biblionumber'); -my $error = $input->param('error'); -my $maxbarcode; -my $isbn; -my $bibliocount; -my @biblios; -my $biblioitemcount; -my @biblioitems; -# my @branches; -# my %branchnames; -my $itemcount; -my @items; - -if ( !$biblionumber ) { - print $input->redirect('addbooks.pl'); -} -else { - my $input = new CGI; - my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { - template_name => "acqui.simple/additem-nomarc.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { editcatalogue => 1 }, - debug => 1, - } - ); - ( $bibliocount, @biblios ) = &getbiblio($biblionumber); - - if ( !$bibliocount ) { - print $input->redirect('addbooks.pl'); - } - else { - @biblioitems = &GetBiblioItemByBiblioNumber($biblionumber); - $biblioitemcount = scalar @biblioitems; - my $branches = GetBranches; - my @branchloop; - foreach my $thisbranch (sort keys %$branches) { - my %row =(value => $thisbranch, - branchname => $branches->{$thisbranch}->{'branchname'}, - ); - push @branchloop, \%row; - } - my $itemtypes = &GetItemTypes; - my @itemtypeloop; - foreach my $thisitemtype (sort keys %$itemtypes) { - my %row =(value => $thisitemtype, - description => $itemtypes->{$thisitemtype}->{'description'}, - ); - push @itemtypeloop, \%row; - } - if ( $error eq "nobarcode" ) { - $template->param( NOBARCODE => 1 ); - } - elsif ( $error eq "nobiblioitem" ) { - $template->param( NOBIBLIOITEM => 1 ); - } - elsif ( $error eq "barcodeinuse" ) { - $template->param( BARCODEINUSE => 1 ); - } # elsif - - for ( my $i = 0 ; $i < $biblioitemcount ; $i++ ) { - if ( $biblioitems[$i]->{'itemtype'} eq "WEB" ) { - $biblioitems[$i]->{'WEB'} = 1; - } - $biblioitems[$i]->{'dewey'} =~ /(\d*\.\d\d)/; - $biblioitems[$i]->{'dewey'} = $1; - ( $itemcount, @items ) = &getitemsbybiblioitem( $biblioitems[$i]->{'biblioitemnumber'} ); - $biblioitems[$i]->{'items'} = \@items; - } # for - $template->param( - BIBNUM => $biblionumber, - AUTHOR => $biblios[0]->{'author'}, - TITLE => $biblios[0]->{'title'}, - COPYRIGHT => $biblios[0]->{'copyrightdate'}, - SERIES => $biblios[0]->{'seriestitle'}, - NOTES => $biblios[0]->{'notes'}, - BIBITEMS => \@biblioitems, - branchloop => \@branchloop, - itemtypeloop => \@itemtypeloop, - - ( $bibliocount, @biblios ) = &getbiblio($biblionumber); - - if ( !$bibliocount ) { - print $input->redirect('addbooks.pl'); - } - else { - - @biblioitems =&GetBiblioItemByBiblioNumber($biblionumber); - $biblioitemcount = scalar @biblioitems; - @branches = &GetBranches; - ( $itemtypecount, @itemtypes ) = &GetItemTypes; - - for ( my $i = 0 ; $i < $itemtypecount ; $i++ ) { - $itemtypedescriptions{ $itemtypes[$i]->{'itemtype'} } = - $itemtypes[$i]->{'description'}; - } # for - - for ( my $i = 0 ; $i < $#branches ; $i++ ) { - $branchnames{ $branches[$i]->{'branchcode'} } = - $branches[$i]->{'branchname'}; - } # for - - # print $input->header; - # print startpage(); - # print startmenu('acquisitions'); - my $input = new CGI; - my ( $template, $loggedinuser, $cookie ) = get_template_and_user( - { - template_name => "acqui.simple/additem-nomarc.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => { editcatalogue => 1 }, - debug => 1, - } - ); - - if ( $error eq "nobarcode" ) { - $template->param( NOBARCODE => 1 ); - } - elsif ( $error eq "nobiblioitem" ) { - $template->param( NOBIBLIOITEM => 1 ); - } - elsif ( $error eq "barcodeinuse" ) { - $template->param( BARCODEINUSE => 1 ); - } # elsif - - for ( my $i = 0 ; $i < $biblioitemcount ; $i++ ) { - if ( $biblioitems[$i]->{'itemtype'} eq "WEB" ) { - $biblioitems[$i]->{'WEB'} = 1; - - } - $biblioitems[$i]->{'dewey'} =~ /(\d*\.\d\d)/; - $biblioitems[$i]->{'dewey'} = $1; - ( $itemcount, @items ) = - &getitemsbybiblioitem( $biblioitems[$i]->{'biblioitemnumber'} ); - $biblioitems[$i]->{'items'} = \@items; - } # for - $template->param( - BIBNUM => $biblionumber, - AUTHOR => $biblios[0]->{'author'}, - TITLE => $biblios[0]->{'title'}, - COPYRIGHT => $biblios[0]->{'copyrightdate'}, - SERIES => $biblios[0]->{'seriestitle'}, - NOTES => $biblios[0]->{'notes'}, - BIBITEMS => \@biblioitems, - BRANCHES => \@branches, - ITEMTYPES => \@itemtypes, - - ); - - output_html_with_http_headers $input, $cookie, $template->output; - } # if -} # if diff --git a/cataloguing/additem.pl b/cataloguing/additem.pl index 4f241b1834..22d5f940aa 100755 --- a/cataloguing/additem.pl +++ b/cataloguing/additem.pl @@ -28,175 +28,280 @@ use C4::Biblio; use C4::Context; use C4::Koha; # XXX subfield_is_koha_internal_p use C4::Search; -use HTML::Template; -use MARC::File::USMARC; -use Smart::Comments; +use C4::Circulation::Circ2; +use Encode; +use C4::Log; + +my $logstatus=C4::Context->preference('Activate_log'); sub find_value { my ($tagfield,$insubfield,$record) = @_; my $result; my $indicator; - foreach my $field ($record->field($tagfield)) { - my @subfields = $field->subfields(); - foreach my $subfield (@subfields) { - if (@$subfield[0] eq $insubfield) { - $result .= @$subfield[1]; - $indicator = $field->indicator(1).$field->indicator(2); - } +my $item=$record->{datafield}; +my $controlfield=$record->{controlfield}; +my $leader=$record->{leader}; + if ($tagfield eq '000'){ +## We are getting the leader +$result=$leader->[0]; +return($indicator,$result); +} + if ($tagfield <10){ + foreach my $control (@$controlfield) { + if ($control->{tag} eq $tagfield){ + $result.=$control->{content}; } } + }else{ + foreach my $field (@$item) { + if ($field->{tag} eq $tagfield){ + foreach my $subfield ( $field->{'subfield'}){ + foreach my $code ( @$subfield){ + if ($code->{code} eq $insubfield) { + $result .= $code->{content}; + $indicator = $field->{ind1}.$field->{ind2}; + } + }## each code + }##each subfield + }## if tag + }### $field + }## tag<10 return($indicator,$result); } my $input = new CGI; my $dbh = C4::Context->dbh; my $error = $input->param('error'); my $biblionumber = $input->param('biblionumber'); -if (!$biblionumber){ - $biblionumber=$input->param('bibid'); -} -my $biblioitemnumber = find_biblioitemnumber($dbh,$biblionumber); -my $itemnumber = $input->param('itemnumber'); -if (!$itemnumber){ - $itemnumber=$input->param('itemnum'); - } - +my $oldbiblionumber =$biblionumber; +my $frameworkcode=$input->param('frameworkcode'); my $op = $input->param('op'); - -# find itemtype -my $itemtype = &MARCfind_frameworkcode($dbh,$biblionumber); - -my $tagslib = &MARCgettagslib($dbh,1,$itemtype); -my $record = MARCgetbiblio($dbh,$biblionumber); -# warn "==>".$record->as_formatted; -my $oldrecord = MARCmarc2koha($dbh,$record); +my $itemnumber = $input->param('itemnumber'); +my $fromserials=$input->param('fromserials');## if a serial is being added do not display navigation menus +my $serialid=$input->param('serialid'); +my @itemrecords; ##Builds existing items +my $bibliorecord; #Bibliorecord relared to this item +my $newrecord; ## the new record buing built +my $itemrecexist; #item record we are editing +my $xml; ## data on html + $frameworkcode=MARCfind_frameworkcode($dbh,$biblionumber) unless $frameworkcode; +my $tagslib = &MARCitemsgettagslib($dbh,1,$frameworkcode); my $itemrecord; my $nextop="additem"; my @errors; # store errors found while checking data BEFORE saving item. + +###DO NOT CHANGE TO RETRIVE FROM ZEBRA##### +my $record =XMLgetbiblio($dbh,$biblionumber); +$bibliorecord=XML_xml2hash_onerecord($record); +my @itemxmls=XMLgetallitems($dbh,$biblionumber); + foreach my $itemrecord(@itemxmls){ + my $itemhash=XML_xml2hash($itemrecord); + push @itemrecords, $itemhash; + } +#### + +my ($template, $loggedinuser, $cookie) + = get_template_and_user({template_name => "cataloguing/additem.tmpl", + query => $input, + type => "intranet", + authnotrequired => 0, + flagsrequired => {editcatalogue => 1}, + debug => 1, + }); + #------------------------------------------------------------------------------------------------------------------------------ if ($op eq "additem") { #------------------------------------------------------------------------------------------------------------------------------ # rebuild + my @tags = $input->param('tag'); my @subfields = $input->param('subfield'); my @values = $input->param('field_value'); # build indicator hash. my @ind_tag = $input->param('ind_tag'); my @indicator = $input->param('indicator'); - my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag); - my $record=MARC::Record::new_from_xml($xml, 'UTF-8'); + my %indicators; + for (my $i=0;$i<=$#ind_tag;$i++) { + $indicators{$ind_tag[$i]} = $indicator[$i]; + } +## check for malformed xml -- non UTF-8 like (MARC8) will break xml without warning +### This usually happens with data coming from other Z3950 servers +## Slows the saving process so comment out at your own risk +eval{ + $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag); +}; + if ($@){ +push @errors,"non_utf8" ; +$nextop = "additem"; +goto FINAL; + }; + my $newrecord=XML_xml2hash_onerecord($xml); +my $newbarcode=XML_readline_onerecord($newrecord,"barcode","holdings"); + # if autoBarcode is ON, calculate barcode... - if (C4::Context->preference('autoBarcode')) { - my ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,"items.barcode"); - unless ($record->field($tagfield)->subfield($tagsubfield)) { + if (C4::Context->preference('autoBarcode')) { + unless ($newbarcode) { my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items"); $sth_barcode->execute; - my ($newbarcode) = $sth_barcode->fetchrow; + ($newbarcode) = $sth_barcode->fetchrow; $newbarcode++; # OK, we have the new barcode, now create the entry in MARC record - my $fieldItem = $record->field($tagfield); - $record->delete_field($fieldItem); - $fieldItem->add_subfields($tagsubfield => $newbarcode); - $record->insert_fields_ordered($fieldItem); + $newrecord=XML_writeline( $newrecord, "barcode", $newbarcode,"holdings" ); } } # check for item barcode # being unique - my $addedolditem = MARCmarc2koha($dbh,$record); - my $exists = get_item_from_barcode($addedolditem->{'barcode'}); - push @errors,"barcode_not_unique" if($exists); - # if barcode exists, don't create, but report The problem. - $itemnumber = NEWnewitem($dbh,$record,$biblionumber,$biblioitemnumber) unless ($exists); + my ($oldrecord)=XMLgetitem($dbh,"",$newbarcode); + + push @errors,"barcode_not_unique" if($oldrecord); +# MARC::Record builded => now, record in DB +## User may be keeping serialids in marc records -- check and add it +if ($fromserials){ +$newrecord=XML_writeline( $newrecord, "serialid", $serialid,"holdings" ); +} + # if barcode exists, don't create, but report the problem. + unless ($oldrecord){ + $itemnumber=NEWnewitem($dbh,$newrecord,$biblionumber) ; + if ($fromserials){ + my $holdingbranch=XML_readline_onerecord($newrecord,"holdingbranch","holdings"); + $template->param(exit=>1,holdingbranch=>$holdingbranch); + } $nextop = "additem"; + } + else{ + $nextop = "additem"; + $itemrecexist = $newrecord; + } #------------------------------------------------------------------------------------------------------------------------------ } elsif ($op eq "edititem") { #------------------------------------------------------------------------------------------------------------------------------ # retrieve item if exist => then, it's a modif - $itemrecord = get_record($biblionumber); + ($itemrecexist) = XMLfinditem($itemnumber,@itemrecords);## item is already in our array-getit $nextop="saveitem"; + +#logaction($loggedinuser,"acqui.simple","modify",$oldbiblionumber,"item : ".$itemnumber) if ($logstatus); + #------------------------------------------------------------------------------------------------------------------------------ } elsif ($op eq "delitem") { #------------------------------------------------------------------------------------------------------------------------------ # retrieve item if exist => then, it's a modif - &NEWdelitem($dbh,$biblionumber,$itemnumber); +my $sth=$dbh->prepare("select * from issues i where i.returndate is null and i.itemnumber=?"); + $sth->execute($itemnumber); +my $onloan=$sth->fetchrow; +push @errors,"book_on_loan" if ($onloan); + if ($onloan){ + $nextop = "additem"; +}else{ + &NEWdelitem($dbh,$itemnumber); $nextop="additem"; +} #------------------------------------------------------------------------------------------------------------------------------ } elsif ($op eq "saveitem") { #------------------------------------------------------------------------------------------------------------------------------ # rebuild +#warn "save item"; my @tags = $input->param('tag'); my @subfields = $input->param('subfield'); my @values = $input->param('field_value'); # build indicator hash. my @ind_tag = $input->param('ind_tag'); my @indicator = $input->param('indicator'); -# my $itemnumber = $input->param('itemnumber'); - my $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag); - my $itemrecord=MARC::Record::new_from_xml($xml, 'UTF-8'); -# MARC::Record builded => now, record in DB -# warn "R: ".$record->as_formatted; - my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = NEWmoditem($dbh,$itemrecord,$biblionumber,$itemnumber,0); + my $itemnumber = $input->param('itemnumber'); + my %indicators; + for (my $i=0;$i<=$#ind_tag;$i++) { + $indicators{$ind_tag[$i]} = $indicator[$i]; + } +## check for malformed xml -- non UTF-8 like (MARC8) will break xml without warning +### This usually happens with data coming from other Z3950 servers +## Slows the saving process so comment out at your own risk +eval{ + $xml = MARChtml2xml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag); +}; + if ($@){ +push @errors,"non_utf8" ; +$nextop = "edititem"; +goto FINAL; + }; + my $newrecord=XML_xml2hash_onerecord($xml); + my $newbarcode=XML_readline_onerecord($newrecord,"barcode","holdings"); + my ($oldrecord)=XMLgetitem($dbh,"",$newbarcode); + $oldrecord=XML_xml2hash_onerecord($oldrecord); + my $exist=XML_readline_onerecord($oldrecord,"itemnumber","holdings") if $oldrecord; + if ($exist && ($exist ne $itemnumber)){ + push @errors,"barcode_not_unique" ; ## Although editing user may have changed the barcode + $nextop="edititem"; + }else{ + NEWmoditem($dbh,$newrecord,$biblionumber,$itemnumber); $itemnumber=""; $nextop="additem"; + + } } # #------------------------------------------------------------------------------------------------------------------------------ # build screen with existing items. and "new" one #------------------------------------------------------------------------------------------------------------------------------ -my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "acqui.simple/additem.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => {editcatalogue => 1}, - debug => 1, - }); - +FINAL: my %indicators; $indicators{995}=' '; -# now, build existiing item list -my $temp = get_record($biblionumber); -my @fields = $temp->fields(); -#my @fields = $record->fields(); +# now, build existing item list + + + +my ($itemtagfield,$itemtagsubfield) = &MARCfind_marc_from_kohafield("itemnumber","holdings"); +my @itemnums; +my @fields; my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code my @big_array; -#---- finds where items.itemnumber is stored -my ($itemtagfield,$itemtagsubfield) = &MARCfind_marc_from_kohafield($dbh,"items.itemnumber",$itemtype); -my ($branchtagfield,$branchtagsubfield) = &MARCfind_marc_from_kohafield($dbh,"items.homebranch",$itemtype); +my @item_value_loop; +my @header_value_loop; +unless($fromserials){ ## do not display existing items if adding a serial. It could be a looong list +foreach my $itemrecord (@itemrecords){ -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 && ($field->tag() ne $itemtagfield && $subf[$i][0] ne $itemtagsubfield)); - $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib} if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} eq 10); - $this_row{$subf[$i][0]} =$subf[$i][1] if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} eq 10); - if (($field->tag eq $branchtagfield) && ($subf[$i][$0] eq $branchtagsubfield) && C4::Context->preference("IndependantBranches")) { - #verifying rights - my $userenv = C4::Context->userenv; - unless (($userenv->{'flags'} == 1) or (($userenv->{'branch'} eq $subf[$i][1]))){ - $this_row{'nomod'}=1; +my $item=$itemrecord->{datafield}; +my $controlfield=$itemrecord->{controlfield}; +my $leader=$itemrecord->{leader}; +my %this_row; + ### The leader + unless ($tagslib->{'000'}->{'@'}->{tab} ne 10 || substr($tagslib->{'000'}->{'@'}->{hidden},1,1)>0){ + my @datasub='000@'; + $witness{$datasub[0]} = $tagslib->{'000'}->{'@'}->{lib}; + $this_row{$datasub[0]} =$leader->[0]; + }## leader + foreach my $control (@$controlfield){ + push @itemnums,$control->{content} if ($control->{tag} eq $itemtagfield); + next if ($tagslib->{$control->{tag}}->{'@'}->{tab} ne 10); + next if (substr($tagslib->{$control->{tag}}->{'@'}->{hidden},1,1)>0); + + my @datasub=$control->{tag}.'@'; + $witness{$datasub[0]} = $tagslib->{$control->{tag}}->{'@'}->{lib}; + $this_row{$datasub[0]} =$control->{content}; + }## Controlfields + foreach my $data (@$item){ + foreach my $subfield ( $data->{'subfield'}){ + foreach my $code ( @$subfield){ + # loop through each subfield + push @itemnums,$code->{content} if ($data->{tag} eq $itemtagfield && $code->{code} eq $itemtagsubfield); + next if ($tagslib->{$data->{tag}}->{$code->{code}}->{tab} ne 10); + next if (substr($tagslib->{$data->{tag}}->{$code->{code}}->{hidden},1,1)>0); + $witness{$data->{tag}.$code->{code}} = $tagslib->{$data->{tag}}->{$code->{code}}->{lib}; + $this_row{$data->{tag}.$code->{code}} =$code->{content}; } - } - $this_row{itemnum} = $subf[$i][1] if ($field->tag() eq $itemtagfield && $subf[$i][0] eq $itemtagsubfield); - } + + }# subfield + + }## each data if (%this_row) { - push(@big_array, \%this_row); + push(@big_array, \%this_row); } -} +}## each record #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}); } } -my ($holdingbrtagf,$holdingbrtagsubf) = &MARCfind_marc_from_kohafield($dbh,"items.holdingbranch",$itemtype); -@big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array; - # 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 (sort keys(%witness)) { @@ -204,9 +309,7 @@ for (my $i=0;$i<=$#big_array; $i++) { } my %row_data; $row_data{item_value} = $items_data; - $row_data{itemnum} = $big_array[$i]->{itemnum}; - #reporting this_row values - $row_data{'nomod'} = $big_array[$i]{'nomod'}; + $row_data{itemnumber} = $itemnums[$i]; push(@item_value_loop,\%row_data); } foreach my $subfield_code (sort keys(%witness)) { @@ -214,40 +317,43 @@ foreach my $subfield_code (sort keys(%witness)) { $header_value{header_value} = $witness{$subfield_code}; push(@header_value_loop, \%header_value); } - +}## unless from serials # next item form my @loop_data =(); my $i=0; my $authorised_values_sth = $dbh->prepare("select authorised_value,lib from authorised_values where category=? order by lib"); foreach my $tag (sort keys %{$tagslib}) { + if ($itemtagfield <10){ +next if($tag==$itemtagfield); +} my $previous_tag = ''; # loop through each subfield foreach my $subfield (sort keys %{$tagslib->{$tag}}) { next if subfield_is_koha_internal_p($subfield); next if ($tagslib->{$tag}->{$subfield}->{'tab'} ne "10"); + next if ($tagslib->{$tag} eq $itemtagfield && $tagslib->{$tag}->{$subfield} eq $itemtagsubfield); my %subfield_data; $subfield_data{tag}=$tag; $subfield_data{subfield}=$subfield; -# $subfield_data{marc_lib}=$tagslib->{$tag}->{$subfield}->{lib}; $subfield_data{marc_lib}="".$tagslib->{$tag}->{$subfield}->{lib}.""; $subfield_data{mandatory}=$tagslib->{$tag}->{$subfield}->{mandatory}; $subfield_data{repeatable}=$tagslib->{$tag}->{$subfield}->{repeatable}; + $subfield_data{hidden}= "display:none" if (substr($tagslib->{$tag}->{$subfield}->{hidden},2,1)>0); + my ($x,$value); - ($x,$value) = find_value($tag,$subfield,$itemrecord) if ($itemrecord); - #testing branch value if IndependantBranches. - my $test = (C4::Context->preference("IndependantBranches")) && - ($tag eq $branchtagfield) && ($subfield eq $branchtagsubfield) && - (C4::Context->userenv->{flags} != 1) && ($value) && ($value ne C4::Context->userenv->{branch}) ; -# print $input->redirect(".pl?biblionumber=$biblionumber") if ($test); + ($x,$value) = find_value($tag,$subfield,$itemrecexist) if ($itemrecexist); # search for itemcallnumber if applicable - if ($tagslib->{$tag}->{$subfield}->{kohafield} eq 'items.itemcallnumber' && C4::Context->preference('itemcallnumber')) { + my ($itemcntag,$itemcntagsub)=MARCfind_marc_from_kohafield("itemcallnumber","holdings"); + if ($tag eq $itemcntag && $subfield eq $itemcntagsub && C4::Context->preference('itemcallnumber')) { my $CNtag = substr(C4::Context->preference('itemcallnumber'),0,3); my $CNsubfield = substr(C4::Context->preference('itemcallnumber'),3,1); - my $temp = $record->field($CNtag); - if ($temp) { - $value = $temp->subfield($CNsubfield); - } + my $CNsubfield2 = substr(C4::Context->preference('itemcallnumber'),4,1); + my $temp1 = XML_readline_onerecord($bibliorecord,"","",$CNtag,$CNsubfield); + my $temp2 = XML_readline_onerecord($bibliorecord,"","",$CNtag,$CNsubfield2); + $value = $temp1.' '.$temp2; + $value=~s/^\s+|\s+$//g; + } if ($tagslib->{$tag}->{$subfield}->{authorised_value}) { my @authorised_values; @@ -255,22 +361,12 @@ foreach my $tag (sort keys %{$tagslib}) { # builds list, depending on authorised value... #---- branch if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { - if ((C4::Context->preference("IndependantBranches")) && (C4::Context->userenv->{flags} != 1)){ - my $sth=$dbh->prepare("select branchcode,branchname from branches where branchcode = ? order by branchname"); - $sth->execute(C4::Context->userenv->{branch}); - push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory}); - while (my ($branchcode,$branchname) = $sth->fetchrow_array) { - push @authorised_values, $branchcode; - $authorised_lib{$branchcode}=$branchname; - } - } else { - my $sth=$dbh->prepare("select branchcode,branchname from branches order by branchname"); - $sth->execute; - push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory}); - while (my ($branchcode,$branchname) = $sth->fetchrow_array) { - push @authorised_values, $branchcode; - $authorised_lib{$branchcode}=$branchname; - } + my $sth=$dbh->prepare("select branchcode,branchname from branches order by branchname"); + $sth->execute; + push @authorised_values, "" unless ($tagslib->{$tag}->{$subfield}->{mandatory}); + while (my ($branchcode,$branchname) = $sth->fetchrow_array) { + push @authorised_values, $branchcode; + $authorised_lib{$branchcode}=$branchname; } #----- itemtypes } elsif ($tagslib->{$tag}->{$subfield}->{authorised_value} eq "itemtypes") { @@ -292,20 +388,21 @@ foreach my $tag (sort keys %{$tagslib}) { } $subfield_data{marc_value}= CGI::scrolling_list(-name=>'field_value', -values=> \@authorised_values, - -default=>"$value", - -labels => \%authorised_lib, - -size=>1, - -multiple=>0, - ); + -default=>"$value", -labels => \%authorised_lib, -size=>1, + -multiple=>0, ); } elsif ($tagslib->{$tag}->{$subfield}->{thesaurus_category}) { - $subfield_data{marc_value}=" {$tag}->{$subfield}->{thesaurus_category}&index=$i',$i)\">..."; + $subfield_data{marc_value}=" {$tag}->{$subfield}->{authtypecode}."&index=$i',$i)\">..."; #" } elsif ($tagslib->{$tag}->{$subfield}->{'value_builder'}) { - my $plugin="../value_builder/".$tagslib->{$tag}->{$subfield}->{'value_builder'}; - require $plugin; - my $extended_param = plugin_parameters($dbh,$record,$tagslib,$i,0); - my ($function_name,$javascript) = plugin_javascript($dbh,$record,$tagslib,$i,0); - $subfield_data{marc_value}=" ... $javascript"; + my $cgidir = C4::Context->intranetdir ."/cgi-bin/value_builder"; + unless (opendir(DIR, "$cgidir")) { + $cgidir = C4::Context->intranetdir."/value_builder"; + } + my $plugin=$cgidir."/".$tagslib->{$tag}->{$subfield}->{'value_builder'}; + require $plugin; + my $extended_param = plugin_parameters($dbh,$newrecord,$tagslib,$i,0); + my ($function_name,$javascript) = plugin_javascript($dbh,$newrecord,$tagslib,$i,0); + $subfield_data{marc_value}=" ... $javascript"; } else { $subfield_data{marc_value}=""; } @@ -315,21 +412,32 @@ foreach my $tag (sort keys %{$tagslib}) { } } + # what's the next op ? it's what we are not in : an add if we're editing, otherwise, and edit. $template->param(item_loop => \@item_value_loop, item_header_loop => \@header_value_loop, - biblionumber => $biblionumber, - bibid => $biblionumber, - title => $oldrecord->{title}, - author => $oldrecord->{author}, + biblionumber =>$biblionumber, + title => &XML_readline_onerecord($bibliorecord,"title","biblios"), + author => &XML_readline_onerecord($bibliorecord,"author","biblios"), item => \@loop_data, itemnumber => $itemnumber, - itemnum => $itemnumber, itemtagfield => $itemtagfield, itemtagsubfield =>$itemtagsubfield, op => $nextop, - opisadd => ($nextop eq "saveitem")?0:1); + opisadd => ($nextop eq "saveitem")?0:1, + fromserials=>$fromserials, serialid=>$serialid,); foreach my $error (@errors) { $template->param($error => 1); + } output_html_with_http_headers $input, $cookie, $template->output; + +sub XMLfinditem { +my ($itemnumber,@itemrecords)=@_; +foreach my $record (@itemrecords){ +my $inumber=XML_readline_onerecord($record,"itemnumber","holdings"); + if ($inumber ==$itemnumber){ + return $record; + } +} +} diff --git a/cataloguing/keywordsearch.pl b/cataloguing/keywordsearch.pl deleted file mode 100755 index a5b4f2524e..0000000000 --- a/cataloguing/keywordsearch.pl +++ /dev/null @@ -1,123 +0,0 @@ -#!/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 CGI; -use strict; -# use C4::Catalogue; -use C4::Biblio; -use C4::Search; -use C4::Output; - -my $input = new CGI; -my $keywords = $input->param('keyword'); -my $offset = $input->param('offset'); -my $num = $input->param('num'); -my $total; -my $count; -my @results; - -if (! $keywords) { - print $input->redirect('addbooks.pl'); -} else { - if (! $offset) { $offset = 0 }; - if (! $num) { $num = 10 }; - my %search; - $search{'keyword'}=$keywords; - ($count, @results) = KeywordSearch(undef,'intra',\%search,$num,$offset); - - if ($count < ($offset + $num)) { - $total = $count; - } else { - $total = $offset + $num; - } # else - - print $input->header; - print startpage(); - print startmenu('acquisitions'); - - print << "EOF"; -Biblio Search Results
-
-You searched on keywords $keywords, $count results found
-Results $offset to $total displayed -
-

Add New Biblio

-
-

- - - - - - -EOF - - for (my $i = 0; $i < ($total - $offset); $i++) { - if ($i % 2) { - print << "EOF"; - -EOF - } else { - print << "EOF"; - -EOF - } # else - - print << "EOF"; - - - - -EOF - } # for - - print << "EOF"; - - - - - -
TITLEAUTHOR©
$results[$i]->{'title'}$results[$i]->{'author'}$results[$i]->{'copyrightdate'}
   
-
-EOF - - for (my $i = 0; ($i * $num) < $count; $i++) { - my $newoffset = $i * $num; - my $shownumber = $i + 1; - print << "EOF"; -$shownumber -EOF - } # for - - print << "EOF"; -

-Results per page: -5 -10 -20 -50 -

-
-

 

-EOF - - print endmenu(); - print endpage(); -} # else diff --git a/cataloguing/savebiblio.pl b/cataloguing/savebiblio.pl deleted file mode 100755 index f9de3b08d5..0000000000 --- a/cataloguing/savebiblio.pl +++ /dev/null @@ -1,57 +0,0 @@ -#!/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 CGI; -use strict; -# use C4::Catalogue; -use C4::Biblio; - -my $input = new CGI; -my $biblio = { - title => $input->param('title'), - subtitle => $input->param('subtitle') ? $input->param('subtitle') : "", - author => $input->param('author') ? $input->param('author') : "", - seriestitle => $input->param('seriestitle') ? $input->param('seriestitle') - : "", - copyrightdate => $input->param('copyrightdate') - ? $input->param('copyrightdate') - : "", - abstract => $input->param('abstract') ? $input->param('abstract') : "", - notes => $input->param('notes') ? $input->param('notes') : "" -}; # my $biblio - -my $subjectheadings = $input->param('subjectheadings'); -# Different O.S.es use different codes to end lines. This ensures that all cases -# are allowed for. -my @subjects = split ( /\n|\r|\n\r|\r\n/, $subjectheadings ); -my $biblionumber; -my $aauthors = $input->param('additionalauthors'); -my @authors = split ( /\n|\r|\n\r|\r\n/, $aauthors ); -my $force = $input->param('force'); - -if ( !$biblio->{'title'} ) { - print $input->redirect('addbiblio-nomarc.pl?error=notitle'); -} -else { - $biblionumber = &newbiblio($biblio); - &newsubtitle( $biblionumber, $biblio->{'subtitle'} ); - my $error = modsubject( $biblionumber, 1, @subjects ); - modaddauthor( $biblionumber, @authors ); - print $input->redirect("additem-nomarc.pl?biblionumber=$biblionumber"); -} # else diff --git a/cataloguing/saveitem.pl b/cataloguing/saveitem.pl deleted file mode 100755 index dadf0f8c37..0000000000 --- a/cataloguing/saveitem.pl +++ /dev/null @@ -1,95 +0,0 @@ -#!/usr/bin/perl - -# $Id$ - -# 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 CGI; -use strict; -# use C4::Catalogue; -use C4::Biblio; - -my $input = new CGI; -my $barcode = $input->param('barcode'); -my $biblionumber = $input->param('biblionumber'); -my $biblioitemnumber = $input->param('biblioitemnumber'); -my $item = { - biblionumber => $biblionumber, - biblioitemnumber => $biblioitemnumber?$biblioitemnumber:"", - homebranch => $input->param('homebranch'), - holdingbranch => $input->param('homebranch'), - replacementprice => $input->param('replacementprice')?$input->param('replacementprice'):"", - itemnotes => $input->param('notes')?$input->param('notes'):"" -}; # my $item -my $biblioitem = { - biblionumber => $biblionumber, - itemtype => $input->param('itemtype'), - isbn => $input->param('isbn')?$input->param('isbn'):"", - publishercode => $input->param('publishercode')?$input->param('publishercode'):"", - publicationyear => $input->param('publicationyear')?$input->param('publicationyear'):"", - place => $input->param('place')?$input->param('place'):"", - illus => $input->param('illus')?$input->param('illus'):"", - url => $input->param('url')?$input->param('url'):"", - dewey => $input->param('dewey')?$input->param('dewey'):"", - subclass => $input->param('subclass')?$input->param('subclass'):"", - issn => $input->param('issn')?$input->param('issn'):"", - lccn => $input->param('lccn')?$input->param('lccn'):"", - volume => $input->param('volume')?$input->param('volume'):"", - number => $input->param('number')?$input->param('number'):"", - volumeddesc => $input->param('volumeddesc')?$input->param('volumeddesc'):"", - pages => $input->param('pages')?$input->param('pages'):"", - size => $input->param('size')?$input->param('size'):"", - notes => $input->param('itemnotes')?$input->param('itemnotes'):"" -}; # my biblioitem -my $newgroup = 0; -my $website = 0; -my $count; -my @results; - -if ($input->param('newgroup')) { - $newgroup = 1; - if ($biblioitem->{'itemtype'} eq "WEB") { - $website = 1; - } # if -} # if - -if (! $biblionumber) { - print $input->redirect('addbooks.pl'); -} elsif ((! $barcode) && (! $website)) { - print $input->redirect("additem-nomarc.pl?biblionumber=$biblionumber&error=nobarcode"); -} elsif ((! $newgroup) && (! $biblioitemnumber)) { - print $input->redirect("additem-nomarc.pl?biblionumber=$biblionumber&error=nobiblioitem"); -} else { - - if ($website) { - &newbiblioitem($biblioitem); - print $input->redirect("additem-nomarc.pl?biblionumber=$biblionumber"); - } elsif (&checkitems(1,$barcode)) { - print $input->redirect("additem-nomarc.pl?biblionumber=$biblionumber&error=barcodeinuse"); - } else { - - if ($newgroup) { - $biblioitemnumber = &newbiblioitem($biblioitem); - $item->{'biblioitemnumber'} = $biblioitemnumber; - } # if - - &newitems($item, ($barcode)); - - print $input->redirect("additem-nomarc.pl?biblionumber=$biblionumber"); - } # else -} # else diff --git a/cataloguing/thesaurus_popup.pl b/cataloguing/thesaurus_popup.pl deleted file mode 100755 index 62518ba37d..0000000000 --- a/cataloguing/thesaurus_popup.pl +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/perl - -# written 10/5/2002 by Paul -# build result field using bibliothesaurus table - - -# 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::Auth; -use CGI; -use C4::Context; -use HTML::Template; -use C4::Search; -use C4::Output; -use C4::Authorities; -use C4::Interface::CGI::Output; -# get all the data .... -my %env; - -my $input = new CGI; -my $result = $input->param('result'); -my $search_string= $input->param('search_string'); -$search_string = $result unless ($search_string); -my $op = $input->param('op'); -my $id = $input->param('id'); -my $category = $input->param('category'); -my $index= $input->param('index'); -my $insert = $input->param('insert'); -my $nohierarchy = $input->param('nohierarchy'); # if 1, just show the last part of entry (Marseille). If 0, show everything (Europe -- France --Marseille) -my $dbh = C4::Context->dbh; - -# make the page ... -#print $input->header; -if ($op eq "select") { - my $sti = $dbh->prepare("select father,stdlib from bibliothesaurus where id=?"); - $sti->execute($id); - my ($father,$freelib_text) = $sti->fetchrow_array; - if (length($result)>0) { - if ($nohierarchy) { - $result .= "|$freelib_text"; - } else { - $result .= "|$father $freelib_text"; - } - } else { - if ($nohierarchy) { - $result = "$freelib_text"; - } else { - $result = "$father $freelib_text"; - } - } -} -if ($op eq "add") { - newauthority($dbh,$category,$insert,$insert,'',1,''); - $search_string=$insert; -} -my ($template, $loggedinuser, $cookie) - = get_template_and_user({template_name => "thesaurus_popup.tmpl", - query => $input, - type => "intranet", - authnotrequired => 0, - flagsrequired => {parameters => 1}, - debug => 1, - }); -# /search thesaurus terms starting by search_string -my @freelib; -my %stdlib; -my $select_list; -if ($search_string) { -# my $sti=$dbh->prepare("select id,freelib from bibliothesaurus where freelib like '".$search_string."%' and category ='$category'"); - my $sti=$dbh->prepare("select id,freelib,father from bibliothesaurus where match (category,freelib) AGAINST (?) and category =?"); - $sti->execute($search_string,$category); - while (my $line=$sti->fetchrow_hashref) { - if ($nohierarchy) { - $stdlib{$line->{'id'}} = "$line->{'freelib'}"; - } else { - $stdlib{$line->{'id'}} = "$line->{'father'} $line->{'freelib'}"; - } - push(@freelib,$line->{'id'}); - } - $select_list= CGI::scrolling_list( -name=>'id', - -values=> \@freelib, - -default=> "", - -size=>1, - -multiple=>0, - -labels=> \%stdlib - ); -} -my @x = SearchDeeper('',$category,$search_string); -#my @son; -#foreach (my $value @$x) { -# warn \@$x[$value]->{'stdlib'}; -#} -my $dig_list= CGI::scrolling_list( -name=>'search_string', - -values=> \@x, - -default=> "", - -size=>1, - -multiple=>0, - ); - -$template->param(select_list => $select_list, - search_string => $search_string, - dig_list => $dig_list, - result => $result, - category => $category, - index => $index, - nohierarchy => $nohierarchy, - ); -output_html_with_http_headers $input, $cookie, $template->output; - - diff --git a/cataloguing/websitesearch.pl b/cataloguing/websitesearch.pl deleted file mode 100755 index 2faeae2717..0000000000 --- a/cataloguing/websitesearch.pl +++ /dev/null @@ -1,119 +0,0 @@ -#!/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 CGI; -use strict; -# use C4::Catalogue; -use C4::Biblio; -use C4::Output; - -my $input = new CGI; -my $keywords = $input->param('keyword'); -my $offset = $input->param('offset'); -my $num = $input->param('num'); -my $total; -my $count; -my @results; - -if (! $keywords) { - print $input->redirect('addbooks.pl'); -} else { - if (! $offset) { $offset = 0 }; - if (! $num) { $num = 10 }; - - ($count, @results) = &websitesearch($keywords); - - if ($count < ($offset + $num)) { - $total = $count; - } else { - $total = $offset + $num; - } # else - - print $input->header; - print startpage(); - print startmenu('acquisitions'); - - print << "EOF"; -Website Search Results
-
-You searched on keywords $keywords, $count results found
-Results $offset to $total displayed -
-

Add New Biblio

-
-

- - - - - - -EOF - - for (my $i = $offset; $i < $total; $i++) { - if ($i % 2) { - print << "EOF"; - -EOF - } else { - print << "EOF"; - -EOF - } # else - - print << "EOF"; - - - - -EOF - } # for - print << "EOF"; - - - - - -
TITLEAUTHOR©
$results[$i]->{'title'}$results[$i]->{'author'}$results[$i]->{'copyrightdate'}
   
-
-EOF - - for (my $i = 0; ($i * $num) < $count; $i++) { - my $newoffset = $i * $num; - print << "EOF"; -$i -EOF - } # for - - print << "EOF"; -

-Results per page: -5 -10 -20 -50 -

-
-

 

-EOF - - print endmenu(); - print endpage(); -} # else -- 2.39.2