3 # Copyright 2000-2002 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA 02111-1307 USA
24 MARCdetail.pl : script to show a biblio in MARC format
31 This script needs a biblionumber in bib parameter (bibnumber
32 from koha style DB. Automaticaly maps to marc biblionumber).
34 It shows the biblio in a (nice) MARC format depending on MARC
37 The template is in <templates_dir>/catalogue/MARCdetail.tmpl.
38 this template must be divided into 11 "tabs".
40 The first 10 tabs present the biblio, the 11th one presents
41 the items attached to the biblio
55 use C4::Interface::CGI::Output;
61 use C4::Serials; #uses getsubscriptionfrom biblionumber
66 my $dbh=C4::Context->dbh;
68 my $biblionumber=$query->param('bib');
69 my $bibid = $query->param('bibid');
70 #$bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber) unless $bibid;
71 #$biblionumber = &MARCfind_oldbiblionumber_from_MARCbibid($dbh,$bibid) unless $biblionumber;
72 #my $itemtype = &MARCfind_frameworkcode($dbh,$bibid);
74 my $tagslib = &MARCgettagslib($dbh,1,$itemtype);
76 my $record =MARCgetbiblio($dbh,$bibid);
78 #coping with subscriptions
79 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
80 my $dat = MARCmarc2koha($dbh,$record);
81 my @subscriptions = GetSubscriptions($dat->{title},$dat->{issn},$biblionumber);
83 foreach my $subscription (@subscriptions){
85 $cell{subscriptionid}= $subscription->{subscriptionid};
86 $cell{subscriptionnotes}= $subscription->{notes};
87 #get the three latest serials.
88 $cell{latestserials}=GetLatestSerials($subscription->{subscriptionid},3);
93 my ($template, $loggedinuser, $cookie)
94 = get_template_and_user({template_name => "opac-ISBDdetail.tmpl",
101 subscriptions => \@subs,
102 subscriptionsnumber => $subscriptionsnumber,
105 my $ISBD = C4::Context->preference('ISBD');
106 # my @blocs = split /\@/,$ISBD;
107 # my @fields = $record->fields();
109 # foreach my $bloc (@blocs) {
113 foreach my $isbdfield (split /#/,$bloc) {
114 # $isbdfield= /(.?.?.?)/;
115 $isbdfield =~ /(\d\d\d)\|(.*)\|(.*)\|(.*)/;
118 my $analysestring=$3;
120 # warn "==> $1 / $2 / $3 / $4";
121 # my $fieldvalue=substr($isbdfield,0,3);
123 # warn "ERROR IN ISBD DEFINITION at : $isbdfield" unless $fieldvalue;
124 # warn "FV : $fieldvalue";
125 my $hasputtextbefore=0;
126 foreach my $field ($record->field($fieldvalue)) {
127 my $calculated = $analysestring;
128 my $tag = $field->tag();
131 my @subf = $field->subfields;
132 for my $i (0..$#subf) {
133 my $subfieldcode = $subf[$i][0];
134 my $subfieldvalue = get_authorised_value_desc($tag, $subf[$i][0], $subf[$i][1], '', $dbh);
135 my $tagsubf = $tag.$subfieldcode;
136 $calculated =~ s/\{(.?.?.?.?)$tagsubf(.*?)\}/$1$subfieldvalue$2\{$1$tagsubf$2\}/g;
138 # field builded, store the result
139 if ($calculated && !$hasputtextbefore) { # put textbefore if not done
140 $blocres .=$textbefore;
143 # remove punctuation at start
144 $calculated =~ s/^( |;|:|\.|-)*//g;
145 $blocres.=$calculated;
148 $blocres .=$textafter if $hasputtextbefore;
150 $blocres.=$isbdfield;
155 $res =~ s/\{(.*?)\}//g;
157 $res =~ s/\n/<br\/>/g;
160 $template->param(ISBD => $res,
161 biblionumber => $biblionumber);
163 output_html_with_http_headers $query, $cookie, $template->output;
165 sub get_authorised_value_desc ($$$$$) {
166 my($tag, $subfield, $value, $framework, $dbh) = @_;
169 if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
170 return getbranchname($value);
174 if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
175 return ItemType($value);
178 #---- "true" authorized value
179 my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
181 if ($category ne "") {
182 my $sth = $dbh->prepare("select lib from authorised_values where category = ? and authorised_value = ?");
183 $sth->execute($category, $value);
184 my $data = $sth->fetchrow_hashref;
185 return $data->{'lib'};
187 return $value; # if nothing is found return the original value