From 538ac9c2d78f4e4dd97e33db49ce0a079612ee36 Mon Sep 17 00:00:00 2001 From: tgarip1957 Date: Fri, 1 Sep 2006 15:36:42 +0000 Subject: [PATCH] Read XML. Sytem preference retrive_from to wheter read from SQL DB or ZEBRA DB --- catalogue/MARCdetail.pl | 215 +++++++++++++++++++++++----------------- catalogue/detail.pl | 79 ++++++++------- 2 files changed, 167 insertions(+), 127 deletions(-) diff --git a/catalogue/MARCdetail.pl b/catalogue/MARCdetail.pl index ae9e00af38..a6397b8c44 100755 --- a/catalogue/MARCdetail.pl +++ b/catalogue/MARCdetail.pl @@ -46,43 +46,44 @@ the items attached to the biblio use strict; -require Exporter; use C4::Auth; use C4::Context; use C4::Output; use C4::Interface::CGI::Output; use CGI; -use C4::Koha; -use MARC::Record; +use C4::Search; use C4::Biblio; use C4::Acquisition; use C4::Serials; #uses getsubscriptionsfrombiblionumber -use HTML::Template; -use C4::Search; +use C4::Koha; my $query=new CGI; my $dbh=C4::Context->dbh; - +my $retrieve_from=C4::Context->preference('retrieve_from'); my $biblionumber=$query->param('biblionumber'); -if (!$biblionumber){ - $biblionumber = $query->param('bib'); -} -# my $bibid = $query->param('bibid'); -my $itemtype = $query->param('frameworkcode'); +my $frameworkcode = $query->param('frameworkcode'); my $popup = $query->param('popup'); # if set to 1, then don't insert links, it's just to show the biblio +my $record; +my @itemrecords; +my $xmlhash; +$frameworkcode=MARCfind_frameworkcode($dbh,$biblionumber); +my $tagslib = &MARCgettagslib($dbh,1,$frameworkcode); +my $itemstagslib = &MARCitemsgettagslib($dbh,1,$frameworkcode); -# $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber) unless $bibid; -# $biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid) unless $biblionumber; -# $itemtype = &MARCfind_frameworkcode($dbh,$biblionumber) if not ($itemtype); -# $itemtype = '' if ($itemtype eq 'Default'); -# warn "itemtype :".$itemtype; +if ($retrieve_from eq "zebra"){ +($xmlhash,@itemrecords)=ZEBRAgetrecord($biblionumber); -my $tagslib = &MARCgettagslib($dbh,1,$itemtype); -#my $record = C4::Search::get_record($biblionumber); +}else{ + $record =XMLgetbiblio($dbh,$biblionumber); +$xmlhash=XML_xml2hash_onerecord($record); +my @itemxmls=XMLgetallitems($dbh,$biblionumber); + foreach my $itemrecord(@itemxmls){ + my $itemhash=XML_xml2hash($itemrecord); + push @itemrecords, $itemhash; + } +} -my $record =MARCgetbiblio($dbh,$biblionumber); -# open template my ($template, $loggedinuser, $cookie) = get_template_and_user({template_name => "catalogue/MARCdetail.tmpl", query => $query, @@ -93,7 +94,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; @@ -104,7 +105,7 @@ while (my ($description, $fwk) =$queryfwk->fetchrow) { push @select_fwk, $fwk; $select_fwk{$fwk} = $description; } -$curfwk=$itemtype; +$curfwk=$frameworkcode; my $framework=CGI::scrolling_list( -name => 'Frameworks', -id => 'Frameworks', -default => $curfwk, @@ -119,78 +120,92 @@ $template->param( framework => $framework); my @loop_data =(); my $tag; # loop through each tab 0 through 9 -for (my $tabloop = 0; $tabloop<=10;$tabloop++) { +##Only attempt to fill the template if we actually received a MARC record +if ($xmlhash){ +my ($isbntag,$isbnsub)=MARCfind_marc_from_kohafield("isbn","biblios"); +my $biblio=$xmlhash->{'datafield'}; +my $controlfields=$xmlhash->{'controlfield'}; +my $leader=$xmlhash->{'leader'}; +for (my $tabloop = 0; $tabloop<10;$tabloop++) { # loop through each tag - my @fields = $record->fields(); my @loop_data =(); my @subfields_data; - # deal with leader - unless ($tagslib->{'000'}->{'@'}->{tab} ne $tabloop) { # or ($tagslib->{'000'}->{'@'}->{hidden}==(-7|-4|-3|-2|2|3|5|8))) { + + # deal with leader + unless (($tagslib->{'000'}->{'@'}->{tab} ne $tabloop) || (substr($tagslib->{'000'}->{'@'}->{hidden},1,1)>0)) { + my %subfield_data; - $subfield_data{marc_lib}=$tagslib->{'000'}->{'@'}->{lib}; - $subfield_data{marc_value}=$record->leader(); - $subfield_data{marc_subfield}='@'; - $subfield_data{marc_tag}='000'; + $subfield_data{marc_value}=$leader->[0] ; push(@subfields_data, \%subfield_data); my %tag_data; - $tag_data{tag}='000 -'. $tagslib->{'000'}->{lib}; + $tag_data{tag}='000 -'. $tagslib->{'000'}->{lib}; my @tmp = @subfields_data; $tag_data{subfield} = \@tmp; push (@loop_data, \%tag_data); undef @subfields_data; } - my @fields = $record->fields(); - for (my $x_i=0;$x_i<=$#fields;$x_i++) { - # if tag <10, there's no subfield, use the "@" trick - if ($fields[$x_i]->tag()<10) { - next if ($tagslib->{$fields[$x_i]->tag()}->{'@'}->{tab} ne $tabloop); - next if ($tagslib->{$fields[$x_i]->tag()}->{'@'}->{hidden}); + ##Controlfields + + foreach my $control (@$controlfields){ my %subfield_data; - $subfield_data{marc_lib}=$tagslib->{$fields[$x_i]->tag()}->{'@'}->{lib}; - $subfield_data{marc_value}=$fields[$x_i]->data(); - $subfield_data{marc_subfield}='@'; - $subfield_data{marc_tag}=$fields[$x_i]->tag(); + my %tag_data; + next if ($tagslib->{$control->{'tag'}}->{'@'}->{tab} ne $tabloop); + next if (substr($tagslib->{$control->{'tag'}}->{'@'}->{hidden},1,1)>0); + $subfield_data{marc_value}=$control->{'content'} ; push(@subfields_data, \%subfield_data); - } else { - my @subf=$fields[$x_i]->subfields; - # loop through each subfield - for my $i (0..$#subf) { - $subf[$i][0] = "@" unless $subf[$i][0]; - next if ($tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}->{tab} ne $tabloop); - next if ($tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}->{hidden}); - my %subfield_data; - $subfield_data{marc_lib}=$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}->{lib}; - $subfield_data{link}=$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}->{link}; -# warn "tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}."lien koha? : "$subfield_data{link}; - if ($tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}->{isurl}) { - $subfield_data{marc_value}="$subf[$i][1]"; - } elsif ($tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}->{kohafield} eq "biblioitems.isbn") { -# warn " tag : ".$tagslib->{$fields[$x_i]->tag()}." subfield :".$tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}. "ISBN : ".$subf[$i][1]."PosttraitementISBN :".DisplayISBN($subf[$i][1]); - $subfield_data{marc_value}=DisplayISBN($subf[$i][1]); + if (C4::Context->preference('hide_marc')) { + $tag_data{tag}=$tagslib->{$control->{'tag'}}->{lib}; } else { - if ($tagslib->{$fields[$x_i]->tag()}->{$subf[$i][0]}->{authtypecode}) { - $subfield_data{authority}=$fields[$x_i]->subfield(9); - } - $subfield_data{marc_value}=get_authorised_value_desc($fields[$x_i]->tag(), $subf[$i][0], $subf[$i][1], '', $dbh); - } - $subfield_data{marc_subfield}=$subf[$i][0]; - $subfield_data{marc_tag}=$fields[$x_i]->tag(); - push(@subfields_data, \%subfield_data); - } + $tag_data{tag}=$control->{'tag'}.' -'. $tagslib->{$control->{'tag'}}->{lib}; + } + my @tmp = @subfields_data; + $tag_data{subfield} = \@tmp; + push (@loop_data, \%tag_data); + undef @subfields_data; } + my $previoustag; + my %datatags; + my $i=0; + foreach my $data (@$biblio){ + $datatags{$i++}=$data->{'tag'}; + foreach my $subfield ( $data->{'subfield'}){ + foreach my $code ( @$subfield){ + next if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{tab} ne $tabloop); + next if (substr($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{hidden},1,1)>0); + my %subfield_data; + my $value=$code->{'content'}; + $subfield_data{marc_lib}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{lib}; + $subfield_data{link}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{link}; + if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{isurl}) { + $subfield_data{marc_value}="$value"; + } elsif ($data->{'tag'} eq $isbntag && $code->{'code'} eq $isbnsub) { + $subfield_data{marc_value}=DisplayISBN($value); + } else { + if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{authtypecode}) { + my ($authtag,$authtagsub)=MARCfind_marc_from_kohafield("auth_authid","biblios"); + $subfield_data{authority}=XML_readline_onerecord($xmlhash,"","",$data->{'tag'},$authtagsub); + } + $subfield_data{marc_value}=get_authorised_value_desc($data->{'tag'}, $code->{'code'}, $value, '', $dbh); + } + $subfield_data{marc_subfield}=$code->{'code'}; + $subfield_data{marc_tag}=$data->{'tag'}; + push(@subfields_data, \%subfield_data); + }### $code + + if ($#subfields_data==0) { - $subfields_data[0]->{marc_lib}=''; - $subfields_data[0]->{marc_subfield}=''; + # $subfields_data[0]->{marc_lib}=''; + # $subfields_data[0]->{marc_subfield}=''; } if ($#subfields_data>=0) { my %tag_data; - if ($fields[$x_i]->tag() eq $fields[$x_i-1]->tag()) { + if (($datatags{$i} eq $datatags{$i-1}) && (C4::Context->preference('LabelMARCView') eq 'economical')) { $tag_data{tag}=""; } else { if (C4::Context->preference('hide_marc')) { - $tag_data{tag}=$tagslib->{$fields[$x_i]->tag()}->{lib}; + $tag_data{tag}=$tagslib->{$data->{'tag'}}->{lib}; } else { - $tag_data{tag}=$fields[$x_i]->tag().' -'. $tagslib->{$fields[$x_i]->tag()}->{lib}; + $tag_data{tag}=$data->{'tag'}.' -'. $tagslib->{$data->{'tag'}}->{lib}; } } my @tmp = @subfields_data; @@ -198,7 +213,9 @@ for (my $tabloop = 0; $tabloop<=10;$tabloop++) { push (@loop_data, \%tag_data); undef @subfields_data; } + }### each $subfield } + $template->param($tabloop."XX" =>\@loop_data); } # now, build item tab ! @@ -206,25 +223,43 @@ for (my $tabloop = 0; $tabloop<=10;$tabloop++) { # loop through each tag # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary # then construct template. -my @fields = $record->fields(); +my @fields; my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code my @big_array; -foreach my $field (@fields) { - next if ($field->tag()<10); - my @subf=$field->subfields; - my %this_row; -# loop through each subfield - for my $i (0..$#subf) { - next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab} ne 10); - next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{hidden}); - $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib}; - $this_row{$subf[$i][0]} =$subf[$i][1]; - } +foreach my $itemrecord (@itemrecords){ +my $item=$itemrecord->{'datafield'}; +my $controlfields=$itemrecord->{'controlfield'}; +my $leader=$itemrecord->{'leader'}; +my %this_row; + ### The leader + unless (substr($itemstagslib->{'000'}->{'@'}->{hidden},1,1)>0){ + my @datasub='000@'; + $witness{$datasub[0]} = $itemstagslib->{'000'}->{'@'}->{lib}; + $this_row{$datasub[0]} =$leader->[0]; + } + foreach my $control (@$controlfields){ + next if ($itemstagslib->{$control->{'tag'}}->{'@'}->{tab} ne 10); + next if (substr($itemstagslib->{$control->{'tag'}}->{'@'}->{hidden},1,1)>0); + my @datasub=$control->{'tag'}.'@'; + $witness{$datasub[0]} = $itemstagslib->{$control->{'tag'}}->{'@'}->{lib}; + $this_row{$datasub[0]} =$control->{'content'}; + } + + foreach my $data (@$item){ + foreach my $subfield ( $data->{'subfield'}){ + foreach my $code ( @$subfield){ + next if ($itemstagslib->{$data->{'tag'}}->{$code->{'code'}}->{tab} ne 10); + next if (substr($itemstagslib->{$data->{'tag'}}->{$code->{'code'}}->{hidden},1,1)>0); + $witness{$data->{'tag'}.$code->{'code'}} = $itemstagslib->{$data->{'tag'}}->{$code->{'code'}}->{lib}; + $this_row{$data->{'tag'}.$code->{'code'}} =$code->{'content'}; + } + }# subfield + }## each field if (%this_row) { - push(@big_array, \%this_row); + push(@big_array, \%this_row); } -} -my ($holdingbrtagf,$holdingbrtagsubf) = &MARCfind_marc_from_kohafield($dbh,"items.holdingbranch",$itemtype); +}## each record +my ($holdingbrtagf,$holdingbrtagsubf) = &MARCfind_marc_from_kohafield("holdingbranch","holdings"); @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array; #fill big_row with missing datas @@ -251,7 +286,7 @@ foreach my $subfield_code (keys(%witness)) { push(@header_value_loop, \%header_value); } -my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber); +my $subscriptionsnumber = GetSubscriptionsFromBiblionumber($biblionumber); $template->param(item_loop => \@item_value_loop, item_header_loop => \@header_value_loop, biblionumber => $biblionumber, @@ -262,6 +297,7 @@ $template->param(item_loop => \@item_value_loop, intranetstylesheet => C4::Context->preference("intranetstylesheet"), IntranetNav => C4::Context->preference("IntranetNav"), ); +} output_html_with_http_headers $query, $cookie, $template->output; sub get_authorised_value_desc ($$$$$) { @@ -269,13 +305,12 @@ sub get_authorised_value_desc ($$$$$) { #---- branch if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) { -# return getbranchdetail($value)->{branchname}; + return getbranchname($value); } #---- itemtypes if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) { - # my $itemtypedef = getitemtypeinfo($itemtype); - # return $itemtypedef->{description}; + return ItemType($value); } #---- "true" authorized value diff --git a/catalogue/detail.pl b/catalogue/detail.pl index 00b7711d83..78b724dbc7 100755 --- a/catalogue/detail.pl +++ b/catalogue/detail.pl @@ -1,14 +1,17 @@ #!/usr/bin/perl use strict; require Exporter; -use CGI; +use C4::Search; use C4::Auth; use C4::Serials; #uses getsubscriptionfrom biblionumber use C4::Interface::CGI::Output; -use HTML::Template; +use CGI; use C4::Biblio; -use C4::Search; +use C4::Context; + +use Encode; +my $dbh=C4::Context->dbh; my $query=new CGI; my ($template, $borrowernumber, $cookie) = get_template_and_user({template_name => "catalogue/detail.tmpl", @@ -19,58 +22,60 @@ my ($template, $borrowernumber, $cookie) }); my $biblionumber=$query->param('biblionumber'); -if (!$biblionumber){ - $biblionumber=$query->param('bib'); - } $template->param(biblionumber => $biblionumber); +my $retrieve_from=C4::Context->preference('retrieve_from'); +my ($record,$frameworkcode); +my @itemrecords; +my @items; +if ($retrieve_from eq "zebra"){ +($record,@itemrecords)=ZEBRAgetrecord($biblionumber); +}else{ + $record =XMLgetbiblio($dbh,$biblionumber); +$record=XML_xml2hash_onerecord($record); +my @itemxmls=XMLgetallitems($dbh,$biblionumber); + foreach my $itemrecord(@itemxmls){ + my $itemhash=XML_xml2hash_onerecord($itemrecord); + push @itemrecords, $itemhash; + } +} - -# change back when ive fixed request.pl -my @items = &ItemInfo(undef, $biblionumber, 'intra'); -my $dat = &bibdata($biblionumber); -my ($authorcount, $addauthor) = &addauthor($biblionumber); -my ($webbiblioitemcount, @webbiblioitems) = &getwebbiblioitems($biblionumber); -my ($websitecount, @websites) = &getwebsites($biblionumber); -my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber); - -$dat->{'count'}=@items; - -$dat->{'additional'}=$addauthor->[0]->{'author'}; -for (my $i = 1; $i < $authorcount; $i++) { - $dat->{'additional'} .= " ; " . $addauthor->[$i]->{'author'}; -} # for - +my $dat = XMLmarc2koha_onerecord($dbh,$record,"biblios"); my $norequests = 1; -foreach my $itm (@items) { - $norequests = 0 unless $itm->{'notforloan'}; - $itm->{$itm->{'publictype'}} = 1; +foreach my $itemrecord (@itemrecords){ + +my $item= XMLmarc2koha_onerecord($dbh,$itemrecord,"holdings"); +$item=ItemInfo($dbh,$item); +$item->{itemtype}=$dat->{itemtype}; + $norequests = 0 unless $item->{'notforloan'}; + $item->{$item->{'publictype'}} = 1; ## NOT sure what this is kept from old db probably useless now +push @items,$item; } +my $subscriptionsnumber = GetSubscriptionsFromBiblionumber($biblionumber); + +$dat->{'count'}=@items; +$template->param(count =>$dat->{'count'}); $template->param(norequests => $norequests); - ## get notes and subjects from MARC record -my $marc = C4::Context->preference("marc"); -if ($marc eq "yes") { - my $dbh = C4::Context->dbh; + ## get notes subjects and URLS from MARC record + my $marcflavour = C4::Context->preference("marcflavour"); - my $marcnotesarray = &getMARCnotes($dbh,$biblionumber,$marcflavour); - my $marcsubjctsarray = &getMARCsubjects($dbh,$biblionumber,$marcflavour); - + my $marcnotesarray = &getMARCnotes($dbh,$record,$marcflavour); + my $marcsubjctsarray = &getMARCsubjects($dbh,$record,$marcflavour); + my $marcurlssarray = &getMARCurls($dbh,$record,$marcflavour); + $template->param(MARCURLS => $marcurlssarray); $template->param(MARCNOTES => $marcnotesarray); $template->param(MARCSUBJCTS => $marcsubjctsarray); -} + my @results = ($dat,); my $resultsarray=\@results; my $itemsarray=\@items; -my $webarray=\@webbiblioitems; -my $sitearray=\@websites; + $template->param(BIBLIO_RESULTS => $resultsarray, ITEM_RESULTS => $itemsarray, - WEB_RESULTS => $webarray, - SITE_RESULTS => $sitearray, subscriptionsnumber => $subscriptionsnumber, ); -- 2.39.5