From 5c67993c8f80b73c2bbea280fc32d1c4f1bb6161 Mon Sep 17 00:00:00 2001 From: tipaul Date: Tue, 19 Nov 2002 12:31:34 +0000 Subject: [PATCH] road to 1.3.2 various bugfixes, improvments, and migration from acquisition.pm to biblio.pm --- C4/Biblio.pm | 119 ++++++++++++++++++++++++++++---------------------- C4/Output.pm | 3 ++ C4/Search.pm | 18 ++++---- MARCdetail.pl | 2 +- detail.pl | 4 +- request.pl | 4 +- search.pl | 2 - 7 files changed, 82 insertions(+), 70 deletions(-) diff --git a/C4/Biblio.pm b/C4/Biblio.pm index 23543038c8..576ac597c6 100644 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -1,6 +1,10 @@ package C4::Biblio; # $Id$ # $Log$ +# Revision 1.27 2002/11/19 12:36:16 tipaul +# road to 1.3.2 +# various bugfixes, improvments, and migration from acquisition.pm to biblio.pm +# # Revision 1.26 2002/11/12 15:58:43 tipaul # road to 1.3.2 : # * many bugfixes @@ -175,14 +179,16 @@ $VERSION = 0.01; &MARCfind_oldbiblionumber_from_MARCbibid &MARCfind_MARCbibid_from_oldbiblionumber + &MARCfind_marc_from_kohafield + &MARCfindsubfield + &MARCgettagslib - &NEWnewbiblio &NEWnewitem + &NEWnewbiblio &NEWnewitem + &NEWmodbiblio &NEWmoditem - &MARCgettagslib &MARCaddbiblio &MARCadditem &MARCmodsubfield &MARCaddsubfield &MARCmodbiblio &MARCmoditem - &MARCfindsubfield &MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem &MARChtml2marc &MARCgetbiblio &MARCgetitem @@ -256,8 +262,7 @@ the db header $dbh is always passed as parameter to avoid over-DB connexion last param is 1 for liblibrarian and 0 for libopac returns a hash with tag/subfield meaning - -=item ($tagfield,$tagsubfield) = &MARCfindmarc_from_kohafield($dbh,$kohafield); +=item ($tagfield,$tagsubfield) = &MARCfind_marc_from_kohafield($dbh,$kohafield); finds MARC tag and subfield for a given kohafield kohafield is "table.field" where table= biblio|biblioitems|items, and field a field of the previous table @@ -348,9 +353,9 @@ sub MARCgettagslib { my ($dbh,$forlibrarian)= @_; my $sth; if ($forlibrarian eq 1) { - $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure"); + $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure order by tagfield"); } else { - $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure"); + $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure order by tagfield"); } $sth->execute; my ($lib,$tag,$res,$tab,$mandatory,$repeatable); @@ -360,9 +365,9 @@ sub MARCgettagslib { } if ($forlibrarian eq 1) { - $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder from marc_subfield_structure"); + $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder from marc_subfield_structure order by tagfield,tagsubfield"); } else { - $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder from marc_subfield_structure"); + $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib,tab, mandatory, repeatable,authorised_value,thesaurus_category,value_builder from marc_subfield_structure order by tagfield,tagsubfield"); } $sth->execute; @@ -538,13 +543,13 @@ sub MARCgetbiblio { $record->add_fields($field); $prevtagorder=$row->{tagorder}; $prevtag = $row->{tag}; - $previndicator=$row->{tag}; + $previndicator=$row->{tag_indicator}; %subfieldlist={}; %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'}; } else { %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'}; $prevtag= $row->{tag}; - $previndicator=$row->{indicator}; + $previndicator=$row->{tag_indicator}; } } # the last has not been included inside the loop... do it now ! @@ -604,6 +609,7 @@ sub MARCmodbiblio { my $oldrecord=&MARCgetbiblio($dbh,$bibid); # if nothing to change, don't waste time... if ($oldrecord eq $record) { + warn "NOTHING TO CHANGE"; return; } # otherwise, skip through each subfield... @@ -632,38 +638,44 @@ sub MARCmodbiblio { } } sub MARCmoditem { - my ($dbh,$record,$bibid,$itemnumber,$delete)=@_; - my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber); -# if nothing to change, don't waste time... - if ($oldrecord eq $record) { - return; - } -# otherwise, skip through each subfield... - my @fields = $record->fields(); -# search old MARC item - my $sth2 = $dbh->prepare("select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?"); - $sth2->execute($bibid,$itemnumber); - my ($tagorder) = $sth2->fetchrow_array(); - foreach my $field (@fields) { - my $oldfield = $oldrecord->field($field->tag()); - my @subfields=$field->subfields(); - my $subfieldorder=0; - foreach my $subfield (@subfields) { - $subfieldorder++; - if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) { -# just adding datas... - &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2), - $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]); - } else { -# modify he subfield if it's a different string - if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) { - my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder); - &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]); + my ($dbh,$record,$bibid,$itemnumber,$delete)=@_; + my $oldrecord=&MARCgetitem($dbh,$bibid,$itemnumber); + # if nothing to change, don't waste time... + if ($oldrecord eq $record) { + warn "nothing to change"; + return; + } + warn "MARCmoditem : ".$record->as_formatted; + # otherwise, skip through each subfield... + my @fields = $record->fields(); + # search old MARC item + my $sth2 = $dbh->prepare("select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?"); + $sth2->execute($bibid,$itemnumber); + my ($tagorder) = $sth2->fetchrow_array(); + foreach my $field (@fields) { + my $oldfield = $oldrecord->field($field->tag()); + my @subfields=$field->subfields(); + my $subfieldorder=0; + foreach my $subfield (@subfields) { + $subfieldorder++; + if ($oldfield eq 0 or (! $oldfield->subfield(@$subfield[0])) ) { + # just adding datas... + warn "addfield : / $subfieldorder / @$subfield[0] - @$subfield[1]"; + &MARCaddsubfield($dbh,$bibid,$field->tag(),$field->indicator(1).$field->indicator(2), + $tagorder,@$subfield[0],$subfieldorder,@$subfield[1]); } else { + warn "modfield : / $subfieldorder / @$subfield[0] - @$subfield[1]"; + # modify he subfield if it's a different string + if ($oldfield->subfield(@$subfield[0]) ne @$subfield[1] ) { + my $subfieldid=&MARCfindsubfieldid($dbh,$bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder); + warn "HERE : $subfieldid, $bibid,$field->tag(),$tagorder,@$subfield[0],$subfieldorder"; + &MARCmodsubfield($dbh,$subfieldid,@$subfield[1]); + } else { + warn "ICI"; + } + } } - } } - } } @@ -1012,9 +1024,9 @@ sub NEWnewbiblio { (my $tagfield1, my $tagsubfield1) = $sth->fetchrow; $sth->execute("biblioitems.biblioitemnumber"); (my $tagfield2, my $tagsubfield2) = $sth->fetchrow; - if ($tagsubfield1 != $tagsubfield2) { - print STDERR "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same subfield number"; - print "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same subfield number"; + if ($tagfield1 != $tagfield2) { + print STDERR "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number"; + print "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number"; die; } my $newfield = MARC::Field->new( $tagfield1,'','', @@ -1028,9 +1040,15 @@ sub NEWnewbiblio { return ($bibid,$oldbibnum,$oldbibitemnum ); } +sub NEWmodbiblio { +my ($dbh,$record,$bibid) =@_; +&MARCmodbiblio($dbh,$record,$bibid); +return 1; +} + + sub NEWnewitem { my ($dbh, $record,$bibid) = @_; - warn "add item : ".$record->as_formatted(); # add item in old-DB my $item = &MARCmarc2koha($dbh,$record); # needs old biblionumber and biblioitemnumber @@ -1046,6 +1064,10 @@ sub NEWnewitem { my $bib = &MARCadditem($dbh,$record,$item->{'biblionumber'}); } +sub NEWmoditem { + my ($dbh,$record,$bibid,$itemnumber,$delete) = @_; + &MARCmoditem($dbh,$record,$bibid,$itemnumber,$delete); +} # # @@ -1422,15 +1444,6 @@ sub OLDnewitems { $itemnumber = $data->{'max(itemnumber)'} + 1; $sth->finish; - $item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'}); - $item->{'homebranch'} = $dbh->quote($item->{'homebranch'}); - $item->{'price'} = $dbh->quote($item->{'price'}); - $item->{'replacementprice'} = $dbh->quote($item->{'replacementprice'}); - $item->{'itemnotes'} = $dbh->quote($item->{'itemnotes'}); - - # foreach my $barcode (@barcodes) { - # $barcode = uc($barcode); - $barcode = $dbh->quote($barcode); $sth=$dbh->prepare("Insert into items set itemnumber = ?, biblionumber = ?, biblioitemnumber = ?, barcode = ?, diff --git a/C4/Output.pm b/C4/Output.pm index 3f5755721c..7c09591932 100644 --- a/C4/Output.pm +++ b/C4/Output.pm @@ -105,6 +105,7 @@ sub themelanguage { my $dbh = C4::Context->dbh; my @languages = split " ", C4::Context->preference("opaclanguages"); + warn "==>".C4::Context->preference("opaclanguages"); # language preference my @themes = split " ", C4::Context->preference("opacthemes"); # theme preferences @@ -124,8 +125,10 @@ sub themelanguage { } } if ($theme and $lang) { + warn "IN"; return ($theme, $lang); } else { + warn "OUT"; return ('default', 'en'); } } diff --git a/C4/Search.pm b/C4/Search.pm index 5644aa7a46..7a535aab55 100755 --- a/C4/Search.pm +++ b/C4/Search.pm @@ -1690,16 +1690,14 @@ and issues.borrowernumber = borrowers.borrowernumber"; # Find the last 3 people who borrowed this item. $query2 = "select * from issues, borrowers -where itemnumber = '$data->{'itemnumber'}' -and issues.borrowernumber = borrowers.borrowernumber -and returndate is not NULL -order by returndate desc,timestamp desc"; - $sth2 = $dbh->prepare($query2) - || die $dbh->errstr; - $sth2->execute - || die $sth2->errstr; - - for (my $i2 = 0; $i2 < 2; $i2++) { + where itemnumber = ? + and issues.borrowernumber = borrowers.borrowernumber + and returndate is not NULL + order by returndate desc,timestamp desc"; +warn "$query2"; + $sth2 = $dbh->prepare($query2) || die $dbh->errstr; + $sth2->execute($data->{'itemnumber'}) || die $sth2->errstr; + for (my $i2 = 0; $i2 < 2; $i2++) { # FIXME : error if there is less than 3 pple borrowing this item if (my $data2 = $sth2->fetchrow_hashref) { $data->{"timestamp$i2"} = $data2->{'timestamp'}; $data->{"card$i2"} = $data2->{'cardnumber'}; diff --git a/MARCdetail.pl b/MARCdetail.pl index 14ddd6ac55..b82d6facdd 100755 --- a/MARCdetail.pl +++ b/MARCdetail.pl @@ -59,7 +59,7 @@ my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber); my $tagslib = &MARCgettagslib($dbh,1); my $record =MARCgetbiblio($dbh,$bibid); -warn $record->as_formatted(); +#warn $record->as_formatted(); # open template my $template = gettemplate("catalogue/MARCdetail.tmpl",0); # fill arrays diff --git a/detail.pl b/detail.pl index b4d48f44c3..d39c1828a1 100755 --- a/detail.pl +++ b/detail.pl @@ -28,12 +28,12 @@ use C4::Auth; my $query=new CGI; my $type=$query->param('type'); -(-e "opac") && ($type='opac'); +#(-e "opac") && ($type='opac'); ($type) || ($type='intra'); my ($loggedinuser, $cookie, $sessionID) = checkauth($query, ($type eq 'opac') ? (1) : (0)); my $biblionumber=$query->param('bib'); -my $type='intra'; # FIXME - There's already a $type in this scope +#my $type='intra'; # FIXME - There's already a $type in this scope # change back when ive fixed request.pl diff --git a/request.pl b/request.pl index 2f75994b26..fd2d644c44 100755 --- a/request.pl +++ b/request.pl @@ -28,7 +28,7 @@ use strict; use C4::Search; use C4::Output; use C4::Reserves2; -use C4::Acquisitions; +use C4::Biblio; use C4::Koha; use C4::Circulation::Circ2; @@ -154,7 +154,7 @@ $rank $notes $date -$pickup +OO $pickup $type EOF diff --git a/search.pl b/search.pl index 3a41869862..81677bc025 100755 --- a/search.pl +++ b/search.pl @@ -28,12 +28,10 @@ use C4::Output; my $query=new CGI; my $type=$query->param('type'); -warn $type; # FIXME - What's this for? #(-e "opac") && ($type='opac'); my ($loggedinuser, $cookie, $sessionID) = checkauth($query, ($type eq 'opac') ? (1) : (0)); -warn $type; # FIXME - What's this for? my $startfrom=$query->param('startfrom'); ($startfrom) || ($startfrom=0); -- 2.39.5