X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=C4%2FBiblio.pm;h=385f1413f7539fd509df3f24749275507d30c65e;hb=fda88bdd301dc63785ef9256ed2c11b1bb73f15c;hp=bb8699985211f5ecbd9c011b1616424602e858c1;hpb=b21a5bdadce5ac15bf2deaba47ae57e56ca3bc4f;p=koha.git diff --git a/C4/Biblio.pm b/C4/Biblio.pm index bb86999852..385f1413f7 100755 --- a/C4/Biblio.pm +++ b/C4/Biblio.pm @@ -36,7 +36,7 @@ use C4::Charset; require C4::Heading; require C4::Serials; -use vars qw($VERSION @ISA @EXPORT); +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); BEGIN { $VERSION = 1.00; @@ -46,23 +46,28 @@ BEGIN { # to add biblios # EXPORTED FUNCTIONS. + push @EXPORT_OK, qw( + &GetRecordValue + ); + push @EXPORT, qw( &AddBiblio ); # to get something push @EXPORT, qw( - &Get &GetBiblio &GetBiblioData &GetBiblioItemData &GetBiblioItemInfosOf &GetBiblioItemByBiblioNumber &GetBiblioFromItemNumber + &GetBiblioSummary - GetFieldMapping - SetFieldMapping - DeleteFieldMapping + &GetRecordValue + &GetFieldMapping + &SetFieldMapping + &DeleteFieldMapping &GetISBDView @@ -223,21 +228,13 @@ unless you can guarantee that C will be called. =cut sub AddBiblio { - my $record = shift; - my $frameworkcode = shift; - my $options = @_ ? shift : undef; - my $defer_marc_save = 0; - if (defined $options and exists $options->{'defer_marc_save'} and $options->{'defer_marc_save'}) { - $defer_marc_save = 1; - } - - my ($biblionumber,$biblioitemnumber,$error); + my ( $record, $frameworkcode, $options ) = @_; my $dbh = C4::Context->dbh; # transform the data into koha-table style data my $olddata = TransformMarcToKoha( $dbh, $record, $frameworkcode ); - ($biblionumber,$error) = _koha_add_biblio( $dbh, $olddata, $frameworkcode ); + my ($biblionumber) = _koha_add_biblio( $dbh, $olddata, $frameworkcode ); $olddata->{'biblionumber'} = $biblionumber; - ($biblioitemnumber,$error) = _koha_add_biblioitem( $dbh, $olddata ); + my ($biblioitemnumber) = _koha_add_biblioitem( $dbh, $olddata ); _koha_marc_update_bib_ids($record, $frameworkcode, $biblionumber, $biblioitemnumber); @@ -245,7 +242,7 @@ sub AddBiblio { _koha_marc_update_biblioitem_cn_sort($record, $olddata, $frameworkcode); # now add the record - ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $defer_marc_save; + ModBiblioMarc( $record, $biblionumber, $frameworkcode ) unless $$options{defer_marc_save} ||= 0; logaction("CATALOGUING", "ADD", $biblionumber, "biblio") if C4::Context->preference("CataloguingLog"); return ( $biblionumber, $biblioitemnumber ); @@ -471,11 +468,11 @@ sub LinkBibHeadingsToAuthorities { return $num_headings_changed; } -=head2 Get +=head2 GetRecordValue =over 4 -my $values = Get($field, $record, $frameworkcode); +my $values = GetRecordValue($field, $record, $frameworkcode); =back @@ -483,7 +480,7 @@ Get MARC fields from a keyword defined in fieldmapping table. =cut -sub Get { +sub GetRecordValue { my ($field, $record, $frameworkcode) = @_; my $dbh = C4::Context->dbh; @@ -505,7 +502,7 @@ sub Get { } } - return @result; + return \@result; } =head2 SetFieldMapping @@ -738,13 +735,17 @@ Return the ISBD view which can be included in opac and intranet =cut sub GetISBDView { - my $biblionumber = shift; + my ($biblionumber, $template) = @_; my $record = GetMarcBiblio($biblionumber); my $itemtype = &GetFrameworkCode($biblionumber); my ($holdingbrtagf,$holdingbrtagsubf) = &GetMarcFromKohaField("items.holdingbranch",$itemtype); my $tagslib = &GetMarcStructure( 1, $itemtype ); my $ISBD = C4::Context->preference('ISBD'); + if($template eq "opac"){ + $ISBD = C4::Context->preference('OPACISBD'); + } + my $bloc = $ISBD; my $res; my $blocres; @@ -782,7 +783,6 @@ sub GetISBDView { my $tagsubf = $tag . $subfvalue; $calculated =~ s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g; - $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g; # field builded, store the result if ( $calculated && !$hasputtextbefore ) @@ -808,22 +808,16 @@ sub GetISBDView { else { my @subf = $field->subfields; for my $i ( 0 .. $#subf ) { - my $valuecode = $subf[$i][1]; - my $subfieldcode = $subf[$i][0]; - my $subfieldvalue = - GetAuthorisedValueDesc( $tag, $subf[$i][0], - $subf[$i][1], '', $tagslib ); - my $tagsubf = $tag . $subfieldcode; - - $calculated =~ s/ # replace all {{}} codes by the value code. - \{\{$tagsubf\}\} # catch the {{actualcode}} - / - $valuecode # replace by the value code - /gx; - - $calculated =~ - s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g; - $calculated =~s#/cgi-bin/koha/[^/]+/([^.]*.pl\?.*)$#opac-$1#g; + my $valuecode = $subf[$i][1]; + my $subfieldcode = $subf[$i][0]; + my $subfieldvalue = + GetAuthorisedValueDesc( $tag, $subf[$i][0], + $subf[$i][1], '', $tagslib ); + my $tagsubf = $tag . $subfieldcode; + + $calculated =~ s/\{\{$tagsubf\}\}/$valuecode/gx; + $calculated =~ + s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g; } # field builded, store the result @@ -1195,8 +1189,8 @@ sub GetCOinSBiblio { $genre = ($mtx eq 'dc') ? "&rft.type=$genre" : "&rft.genre=$genre"; # Setting datas - $aulast = $record->subfield('700','a'); - $aufirst = $record->subfield('700','b'); + $aulast = $record->subfield('700','a') || ''; + $aufirst = $record->subfield('700','b') || ''; $oauthors = "&rft.au=$aufirst $aulast"; # others authors if($record->field('200')){ @@ -1206,10 +1200,10 @@ sub GetCOinSBiblio { } $title = ( $mtx eq 'dc' ) ? "&rft.title=".$record->subfield('200','a') : "&rft.title=".$record->subfield('200','a')."&rft.btitle=".$record->subfield('200','a'); - $pubyear = $record->subfield('210','d'); - $publisher = $record->subfield('210','c'); - $isbn = $record->subfield('010','a'); - $issn = $record->subfield('011','a'); + $pubyear = $record->subfield('210','d') || ''; + $publisher = $record->subfield('210','c') || ''; + $isbn = $record->subfield('010','a') || ''; + $issn = $record->subfield('011','a') || ''; }else{ # MARC21 need some improve my $fmts; @@ -1242,6 +1236,121 @@ sub GetCOinSBiblio { return $coins_value; } +=head2 GetBiblioSummary + +=over 4 + +$summary = GetBiblioSummary($marcrecord); + +Return the summary of a record. + +=back + +=cut + +sub GetBiblioSummary { + my $recorddata =shift @_; + + return unless $recorddata; + my $marcflavour = C4::Context->preference("marcflavour"); + my $marc=MARC::Record::new_from_xml($recorddata,"utf-8",$marcflavour); + return unless $marc; + + my $str; + + if($marcflavour eq "MARC21"){ + $str="".$marc->subfield('245',"a")."" if $marc->subfield('245','a'); + $str.= " ".$marc->subfield('245',"b")." " if $marc->subfield('245','b'); + + if ($marc->field('245')){ + $str.=" / "; + foreach ($marc->field('100')->subfield("a")) { + $str.=$_." ; "; + } + $str=~s/ ; $/. /; + } + + if ($marc->field('260')){ + $str.=" - "; + $str.=$marc->subfield('260',"a")." " if $marc->subfield('260','a'); + $str.=" : ".$marc->subfield('260',"b")." " if $marc->subfield('260','b'); + $str.=", ".$marc->subfield('260',"c")." " if $marc->subfield('260','c'); + } + if ($marc->field('300')){ + $str.=" - "; + $str.=$marc->subfield('300','a') if ($marc->subfield(300,'a')); + $str.=" ; ".$marc->subfield('300','b') if $marc->subfield('300','b'); + $str.=" ; ".$marc->subfield('300','c') if $marc->subfield('300','c'); + $str.=" ; ".$marc->subfield('300','e') if $marc->subfield('300','e'); + } + foreach ($marc->field('500')){ + $str.= " - "; + foreach ($_->subfield("a")){ + $str.=$_."; " + } + } + my $itemtypes=GetItemTypes(); + $str.=" - ".$itemtypes->{$marc->subfield('942','c')}->{'description'}." "; + $str.="
\n"; + + }else{ + $str = "".$marc->subfield('200','a')."" if $marc->subfield('200','a'); + $str.= " ".$marc->subfield('200','e')." " if $marc->subfield('200','e'); + if ($marc->field('200')){ + $str.=" / "; + foreach ($marc->field('200')->subfield("f")) { + $str.=$_." ; "; + } + $str=~s/ ; $/. /; + } + + if ($marc->subfield('200','g')){ + $str.=" ; "; + foreach ($marc->field('200')->subfield("g")){ + $str.=$_." ; "; + } + $str=~s/ ; $/. /; + } + + if ($marc->field('461')){ + $str.="- In :"; + $str.= $marc->subfield('461','t') if $marc->subfield('461','t'); + $str.=", ".$marc->subfield('461','d') if $marc->subfield('461','d'); + $str.=", ".$marc->subfield('461','v') if $marc->subfield('461','v'); + $str.=", ".$marc->subfield('461','h') if $marc->subfield('461','h'); + $str.=" ; ".$marc->subfield('461','x') if $marc->subfield('461','x'); + } + + if ($marc->field('210')){ + $str.=" - "; + $str.=$marc->subfield('210',"a")." " if $marc->subfield('210','a'); + $str.=" : ".$marc->subfield('210',"c")." " if $marc->subfield('210','c'); + $str.=", ".$marc->subfield('210',"d")." " if $marc->subfield('210','d'); + } + + if ($marc->field('215')){ + $str.=" - "; + $str.=$marc->subfield('215','a') if ($marc->subfield(215,'a')); + $str.=" ; ".$marc->subfield('215','d') if $marc->subfield('215','d'); + $str.=" ; ".$marc->subfield('215','c') if $marc->subfield('215','c'); + $str.=" ; ".$marc->subfield('215','e') if $marc->subfield('215','e'); + } + foreach ($marc->field('300')){ + $str.=" - "; + foreach ($_->subfield("a")){ + $str.=$_."; " + } + } + + my $itemtypes=GetItemTypes; + if($itemtypes->{$marc->subfield('200','b')}){ + $str.=" - ".$itemtypes->{$marc->subfield('200','b')}->{'description'}." "; + } + $str.="
\n"; + } + return $str; +} + =head2 GetAuthorisedValueDesc =over 4 @@ -1490,13 +1599,13 @@ sub GetMarcUrls { my @marcurls; for my $field ( $record->field('856') ) { - my $marcurl; my @notes; for my $note ( $field->subfield('z') ) { push @notes, { note => $note }; } my @urls = $field->subfield('u'); foreach my $url (@urls) { + my $marcurl; if ( $marcflavour eq 'MARC21' ) { my $s3 = $field->subfield('3'); my $link = $field->subfield('y'); @@ -1761,20 +1870,22 @@ sub TransformHtmlToXml { # } if ( ( @$tags[$i] ne $prevtag ) ) { $j++ unless ( @$tags[$i] eq "" ); + my $indicator1=eval{substr( @$indicator[$j], 0, 1 )}; + my $indicator2=eval{substr( @$indicator[$j], 1, 1 )}; + my $ind1 = _default_ind_to_space($indicator1); + my $ind2; + if ( @$indicator[$j] ) { + $ind2 = _default_ind_to_space($indicator2); + } + else { + warn "Indicator in @$tags[$i] is empty"; + $ind2 = " "; + } if ( !$first ) { $xml .= "\n"; if ( ( @$tags[$i] && @$tags[$i] > 10 ) && ( @$values[$i] ne "" ) ) { - my $ind1 = substr( @$indicator[$j], 0, 1 ); - my $ind2; - if ( @$indicator[$j] ) { - $ind2 = substr( @$indicator[$j], 1, 1 ); - } - else { - warn "Indicator in @$tags[$i] is empty"; - $ind2 = " "; - } $xml .= "\n"; $xml .= "@$values[$i]\n"; $first = 0; @@ -1798,10 +1909,6 @@ sub TransformHtmlToXml { $first = 1; } else { - my $ind1 = substr( @$indicator[$j], 0, 1 ); - my $ind2 = substr( @$indicator[$j], 1, 1 ); - $ind1 = " " if !defined($ind2) or $ind2 eq ""; - $ind2 = " " if !defined($ind2) or $ind2 eq ""; $xml .= "\n"; $xml .= "@$values[$i]\n"; $first = 0; @@ -1810,14 +1917,21 @@ sub TransformHtmlToXml { } } else { # @$tags[$i] eq $prevtag - if ( @$values[$i] eq "" ) { + my $indicator1=eval{substr( @$indicator[$j], 0, 1 )}; + my $indicator2=eval{substr( @$indicator[$j], 1, 1 )}; + my $ind1 = _default_ind_to_space($indicator1); + my $ind2; + if ( @$indicator[$j] ) { + $ind2 = _default_ind_to_space($indicator2); + } + else { + warn "Indicator in @$tags[$i] is empty"; + $ind2 = " "; + } + if ( @$values[$i] eq "" ) { } else { if ($first) { - my $ind1 = substr( @$indicator[$j], 0, 1 ); - my $ind2 = substr( @$indicator[$j], 1, 1 ); - $ind1 = " " if !defined($ind2) or $ind2 eq ""; - $ind2 = " " if !defined($ind2) or $ind2 eq ""; $xml .= "\n"; $first = 0; } @@ -1844,6 +1958,21 @@ sub TransformHtmlToXml { return $xml; } +=head2 _default_ind_to_space + +Passed what should be an indicator returns a space +if its undefined or zero length + +=cut + +sub _default_ind_to_space { + my $s = shift; + if (!defined $s || $s eq q{}) { + return ' '; + } + return $s; +} + =head2 TransformHtmlToMarc L<$record> = TransformHtmlToMarc(L<$params>,L<$cgi>) @@ -1916,8 +2045,8 @@ sub TransformHtmlToMarc { elsif ($param =~ /^tag_(\d*)_indicator1_/){ # new field start when having 'input name="..._indicator1_..." my $tag = $1; - my $ind1 = substr($cgi->param($param),0,1); - my $ind2 = substr($cgi->param($params->[$i+1]),0,1); + my $ind1 = _default_ind_to_space(substr($cgi->param($param), 0, 1)); + my $ind2 = _default_ind_to_space(substr($cgi->param($params->[$i+1]), 0, 1)); $newfield=0; my $j=$i+2; @@ -1946,8 +2075,8 @@ sub TransformHtmlToMarc { if ( $cgi->param($params->[$j+1]) ne '' ) { # creating only if there is a value (code => value) $newfield = MARC::Field->new( $tag, - ''.$ind1, - ''.$ind2, + $ind1, + $ind2, $cgi->param($inner_param) => $cgi->param($params->[$j+1]), ); } @@ -2253,11 +2382,15 @@ sub PrepareItemrecordDisplay { my ( $bibnum, $itemnum, $defaultvalues ) = @_; my $dbh = C4::Context->dbh; + my $today_iso = C4::Dates->today('iso'); my $frameworkcode = &GetFrameworkCode( $bibnum ); my ( $itemtagfield, $itemtagsubfield ) = &GetMarcFromKohaField( "items.itemnumber", $frameworkcode ); my $tagslib = &GetMarcStructure( 1, $frameworkcode ); my $itemrecord = C4::Items::GetMarcItem( $bibnum, $itemnum) if ($itemnum); + # FIXME : I'd rather have GetMarcBiblio called out of this. + # Since it gets the whole Biblio record for each item + my $marcrecord = GetMarcBiblio( $bibnum) if ($bibnum); my @loop_data; my $authorised_values_sth = $dbh->prepare( @@ -2290,9 +2423,15 @@ sub PrepareItemrecordDisplay { if ($itemrecord) { ( $x, $value ) = _find_value( $tag, $subfield, $itemrecord ); } - if (!defined $value) { - $value = q||; - } + unless ($value) { + $value = $tagslib->{$tag}->{$subfield}->{defaultvalue}; + $value ||= $defaultvalues->{$tagslib->{$tag}->{$subfield}->{'kohafield'}}; + # get today date & replace YYYY, MM, DD if provided in the default value + my ( $year, $month, $day ) = split ',', $today_iso; # FIXME: iso dates don't have commas! + $value =~ s/YYYY/$year/g; + $value =~ s/MM/$month/g; + $value =~ s/DD/$day/g; + } $value =~ s/"/"/g; # search for itemcallnumber if applicable @@ -2304,7 +2443,7 @@ sub PrepareItemrecordDisplay { substr( C4::Context->preference('itemcallnumber'), 0, 3 ); my $CNsubfield = substr( C4::Context->preference('itemcallnumber'), 3, 1 ); - my $temp = $itemrecord->field($CNtag) if ($itemrecord); + my $temp = $marcrecord->field($CNtag) if ($marcrecord); if ($temp) { $value = $temp->subfield($CNsubfield); } @@ -3156,78 +3295,33 @@ Internal function to add a biblioitem sub _koha_add_biblioitem { my ( $dbh, $biblioitem ) = @_; - my $error; + my @fields = qw/ biblionumber + cn_class cn_item cn_sort cn_source cn_suffix + collectionissn collectiontitle collectionvolume + editionresponsibility editionstatement + illus isbn issn itemtype lccn marc + notes number pages place + publicationyear publishercode size + totalissues url + volume volumedate volumedesc + /; + + ($$biblioitem{cn_sort}) = GetClassSort( @$biblioitem{qw/ biblioitems.cn_source cn_class cn_item /} ); + + my $query = 'INSERT INTO biblioitems SET ' + . join ( ',', map { "$_ =?" } @fields ) + . ';' + ; - my ($cn_sort) = GetClassSort($biblioitem->{'biblioitems.cn_source'}, $biblioitem->{'cn_class'}, $biblioitem->{'cn_item'} ); - my $query = - "INSERT INTO biblioitems SET - biblionumber = ?, - volume = ?, - number = ?, - itemtype = ?, - isbn = ?, - issn = ?, - publicationyear = ?, - publishercode = ?, - volumedate = ?, - volumedesc = ?, - collectiontitle = ?, - collectionissn = ?, - collectionvolume= ?, - editionstatement= ?, - editionresponsibility = ?, - illus = ?, - pages = ?, - notes = ?, - size = ?, - place = ?, - lccn = ?, - marc = ?, - url = ?, - cn_source = ?, - cn_class = ?, - cn_item = ?, - cn_suffix = ?, - cn_sort = ?, - totalissues = ? - "; my $sth = $dbh->prepare($query); - $sth->execute( - $biblioitem->{'biblionumber'}, - $biblioitem->{'volume'}, - $biblioitem->{'number'}, - $biblioitem->{'itemtype'}, - $biblioitem->{'isbn'}, - $biblioitem->{'issn'}, - $biblioitem->{'publicationyear'}, - $biblioitem->{'publishercode'}, - $biblioitem->{'volumedate'}, - $biblioitem->{'volumedesc'}, - $biblioitem->{'collectiontitle'}, - $biblioitem->{'collectionissn'}, - $biblioitem->{'collectionvolume'}, - $biblioitem->{'editionstatement'}, - $biblioitem->{'editionresponsibility'}, - $biblioitem->{'illus'}, - $biblioitem->{'pages'}, - $biblioitem->{'bnotes'}, - $biblioitem->{'size'}, - $biblioitem->{'place'}, - $biblioitem->{'lccn'}, - $biblioitem->{'marc'}, - $biblioitem->{'url'}, - $biblioitem->{'biblioitems.cn_source'}, - $biblioitem->{'cn_class'}, - $biblioitem->{'cn_item'}, - $biblioitem->{'cn_suffix'}, - $cn_sort, - $biblioitem->{'totalissues'} - ); + $sth->execute( @$biblioitem{@fields} ); my $bibitemnum = $dbh->{'mysql_insertid'}; - if ( $dbh->errstr ) { - $error.="ERROR in _koha_add_biblioitem $query".$dbh->errstr; - warn $error; - } + my $error = ''; + $dbh->errstr and warn $error .= + 'ERROR in _koha_add_biblioitem ' + . $query + . $dbh->errstr + ; $sth->finish(); return ($bibitemnum,$error); }