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
22 MARCdetail.pl : script to show a biblio in MARC format
29 This script needs a biblionumber in bib parameter (bibnumber
30 from koha style DB. Automaticaly maps to marc biblionumber).
32 It shows the biblio in a (nice) MARC format depending on MARC
35 The template is in <templates_dir>/catalogue/MARCdetail.tmpl.
36 this template must be divided into 11 "tabs".
38 The first 10 tabs present the biblio, the 11th one presents
39 the items attached to the biblio
52 use C4::Interface::CGI::Output;
57 use C4::Serials; #uses getsubscriptionsfrombiblionumber
62 my $dbh=C4::Context->dbh;
63 my $retrieve_from=C4::Context->preference('retrieve_from');
64 my $biblionumber=$query->param('biblionumber');
65 my $frameworkcode = $query->param('frameworkcode');
66 my $popup = $query->param('popup'); # if set to 1, then don't insert links, it's just to show the biblio
70 $frameworkcode=MARCfind_frameworkcode($dbh,$biblionumber);
71 my $tagslib = &MARCgettagslib($dbh,1,$frameworkcode);
72 my $itemstagslib = &MARCitemsgettagslib($dbh,1,$frameworkcode);
74 if ($retrieve_from eq "zebra"){
75 ($xmlhash,@itemrecords)=ZEBRAgetrecord($biblionumber);
78 $record =XMLgetbiblio($dbh,$biblionumber);
79 $xmlhash=XML_xml2hash_onerecord($record);
80 my @itemxmls=XMLgetallitems($dbh,$biblionumber);
81 foreach my $itemrecord(@itemxmls){
82 my $itemhash=XML_xml2hash($itemrecord);
83 push @itemrecords, $itemhash;
87 my ($template, $loggedinuser, $cookie)
88 = get_template_and_user({template_name => "catalogue/MARCdetail.tmpl",
92 flagsrequired => {catalogue => 1},
96 #Getting the list of all frameworks
97 my $queryfwk =$dbh->prepare("select frameworktext, frameworkcode from biblios_framework");
102 push @select_fwk,"Default";
103 $select_fwk{"Default"} = "Default";
104 while (my ($description, $fwk) =$queryfwk->fetchrow) {
105 push @select_fwk, $fwk;
106 $select_fwk{$fwk} = $description;
108 $curfwk=$frameworkcode;
109 my $framework=CGI::scrolling_list( -name => 'Frameworks',
112 -OnChange => 'Changefwk(this);',
113 -values => \@select_fwk,
114 -labels => \%select_fwk,
118 $template->param( framework => $framework);
122 # loop through each tab 0 through 9
123 ##Only attempt to fill the template if we actually received a MARC record
125 my ($isbntag,$isbnsub)=MARCfind_marc_from_kohafield("isbn","biblios");
126 my $biblio=$xmlhash->{'datafield'};
127 my $controlfields=$xmlhash->{'controlfield'};
128 my $leader=$xmlhash->{'leader'};
129 for (my $tabloop = 0; $tabloop<10;$tabloop++) {
130 # loop through each tag
135 unless (($tagslib->{'000'}->{'@'}->{tab} ne $tabloop) || (substr($tagslib->{'000'}->{'@'}->{hidden},1,1)>0)) {
138 $subfield_data{marc_value}=$leader->[0] ;
139 push(@subfields_data, \%subfield_data);
141 $tag_data{tag}='000 -'. $tagslib->{'000'}->{lib};
142 my @tmp = @subfields_data;
143 $tag_data{subfield} = \@tmp;
144 push (@loop_data, \%tag_data);
145 undef @subfields_data;
149 foreach my $control (@$controlfields){
152 next if ($tagslib->{$control->{'tag'}}->{'@'}->{tab} ne $tabloop);
153 next if (substr($tagslib->{$control->{'tag'}}->{'@'}->{hidden},1,1)>0);
154 $subfield_data{marc_value}=$control->{'content'} ;
155 push(@subfields_data, \%subfield_data);
156 if (C4::Context->preference('hide_marc')) {
157 $tag_data{tag}=$tagslib->{$control->{'tag'}}->{lib};
159 $tag_data{tag}=$control->{'tag'}.' -'. $tagslib->{$control->{'tag'}}->{lib};
161 my @tmp = @subfields_data;
162 $tag_data{subfield} = \@tmp;
163 push (@loop_data, \%tag_data);
164 undef @subfields_data;
169 foreach my $data (@$biblio){
170 $datatags{$i++}=$data->{'tag'};
171 foreach my $subfield ( $data->{'subfield'}){
172 foreach my $code ( @$subfield){
173 next if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{tab} ne $tabloop);
174 next if (substr($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{hidden},1,1)>0);
176 my $value=$code->{'content'};
177 $subfield_data{marc_lib}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{lib};
178 $subfield_data{link}=$tagslib->{$data->{'tag'}}->{$code->{'code'}}->{link};
179 if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{isurl}) {
180 $subfield_data{marc_value}="<a href=\"$value]\">$value</a>";
181 } elsif ($data->{'tag'} eq $isbntag && $code->{'code'} eq $isbnsub) {
182 $subfield_data{marc_value}=DisplayISBN($value);
184 if ($tagslib->{$data->{'tag'}}->{$code->{'code'}}->{authtypecode}) {
185 my ($authtag,$authtagsub)=MARCfind_marc_from_kohafield("auth_authid","biblios");
186 $subfield_data{authority}=XML_readline_onerecord($xmlhash,"","",$data->{'tag'},$authtagsub);
188 $subfield_data{marc_value}=get_authorised_value_desc($data->{'tag'}, $code->{'code'}, $value, '', $dbh);
190 $subfield_data{marc_subfield}=$code->{'code'};
191 $subfield_data{marc_tag}=$data->{'tag'};
192 push(@subfields_data, \%subfield_data);
196 if ($#subfields_data==0) {
197 # $subfields_data[0]->{marc_lib}='';
198 # $subfields_data[0]->{marc_subfield}='';
200 if ($#subfields_data>=0) {
202 if (($datatags{$i} eq $datatags{$i-1}) && (C4::Context->preference('LabelMARCView') eq 'economical')) {
205 if (C4::Context->preference('hide_marc')) {
206 $tag_data{tag}=$tagslib->{$data->{'tag'}}->{lib};
208 $tag_data{tag}=$data->{'tag'}.' -'. $tagslib->{$data->{'tag'}}->{lib};
211 my @tmp = @subfields_data;
212 $tag_data{subfield} = \@tmp;
213 push (@loop_data, \%tag_data);
214 undef @subfields_data;
219 $template->param($tabloop."XX" =>\@loop_data);
221 # now, build item tab !
222 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
223 # loop through each tag
224 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
225 # then construct template.
227 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
229 foreach my $itemrecord (@itemrecords){
230 my $item=$itemrecord->{'datafield'};
231 my $controlfields=$itemrecord->{'controlfield'};
232 my $leader=$itemrecord->{'leader'};
235 unless (substr($itemstagslib->{'000'}->{'@'}->{hidden},1,1)>0){
237 $witness{$datasub[0]} = $itemstagslib->{'000'}->{'@'}->{lib};
238 $this_row{$datasub[0]} =$leader->[0];
240 foreach my $control (@$controlfields){
241 next if ($itemstagslib->{$control->{'tag'}}->{'@'}->{tab} ne 10);
242 next if (substr($itemstagslib->{$control->{'tag'}}->{'@'}->{hidden},1,1)>0);
243 my @datasub=$control->{'tag'}.'@';
244 $witness{$datasub[0]} = $itemstagslib->{$control->{'tag'}}->{'@'}->{lib};
245 $this_row{$datasub[0]} =$control->{'content'};
248 foreach my $data (@$item){
249 foreach my $subfield ( $data->{'subfield'}){
250 foreach my $code ( @$subfield){
251 next if ($itemstagslib->{$data->{'tag'}}->{$code->{'code'}}->{tab} ne 10);
252 next if (substr($itemstagslib->{$data->{'tag'}}->{$code->{'code'}}->{hidden},1,1)>0);
253 $witness{$data->{'tag'}.$code->{'code'}} = $itemstagslib->{$data->{'tag'}}->{$code->{'code'}}->{lib};
254 $this_row{$data->{'tag'}.$code->{'code'}} =$code->{'content'};
259 push(@big_array, \%this_row);
262 my ($holdingbrtagf,$holdingbrtagsubf) = &MARCfind_marc_from_kohafield("holdingbranch","holdings");
263 @big_array = sort {$a->{$holdingbrtagsubf} cmp $b->{$holdingbrtagsubf}} @big_array;
265 #fill big_row with missing datas
266 foreach my $subfield_code (keys(%witness)) {
267 for (my $i=0;$i<=$#big_array;$i++) {
268 $big_array[$i]{$subfield_code}=" " unless ($big_array[$i]{$subfield_code});
271 # now, construct template !
273 my @header_value_loop;
274 for (my $i=0;$i<=$#big_array; $i++) {
276 foreach my $subfield_code (keys(%witness)) {
277 $items_data .="<td>".$big_array[$i]{$subfield_code}."</td>";
280 $row_data{item_value} = $items_data;
281 push(@item_value_loop,\%row_data);
283 foreach my $subfield_code (keys(%witness)) {
285 $header_value{header_value} = $witness{$subfield_code};
286 push(@header_value_loop, \%header_value);
289 my $subscriptionsnumber = GetSubscriptionsFromBiblionumber($biblionumber);
290 $template->param(item_loop => \@item_value_loop,
291 item_header_loop => \@header_value_loop,
292 biblionumber => $biblionumber,
293 subscriptionsnumber => $subscriptionsnumber,
295 hide_marc => C4::Context->preference('hide_marc'),
296 intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
297 intranetstylesheet => C4::Context->preference("intranetstylesheet"),
298 IntranetNav => C4::Context->preference("IntranetNav"),
301 output_html_with_http_headers $query, $cookie, $template->output;
303 sub get_authorised_value_desc ($$$$$) {
304 my($tag, $subfield, $value, $framework, $dbh) = @_;
307 if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "branches" ) {
308 return getbranchname($value);
312 if ($tagslib->{$tag}->{$subfield}->{'authorised_value'} eq "itemtypes" ) {
313 return ItemType($value);
316 #---- "true" authorized value
317 my $category = $tagslib->{$tag}->{$subfield}->{'authorised_value'};
319 if ($category ne "") {
320 my $sth = $dbh->prepare("select lib from authorised_values where category = ? and authorised_value = ?");
321 $sth->execute($category, $value);
322 my $data = $sth->fetchrow_hashref;
323 return $data->{'lib'};
325 return $value; # if nothing is found return the original value