road to 1.3.1 : viewing biblio MARC detail
[koha.git] / MARCdetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
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
10 # version.
11 #
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.
15 #
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
19
20 use strict;
21 require Exporter;
22 use C4::Context;
23 use C4::Output;
24 use CGI;
25 use C4::Search;
26 use MARC::Record;
27 use C4::Biblio;
28 use C4::Catalogue;
29 use HTML::Template;
30
31 my $query=new CGI;
32
33 my $dbh=C4::Context->dbh;
34
35 my $biblionumber=$query->param('biblionumber');
36 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
37
38 my $tagslib = &MARCgettagslib($dbh,1);
39
40 my $record =MARCgetbiblio($dbh,$bibid);
41 # open template
42 my $template = gettemplate("catalogue/MARCdetail.tmpl",0);
43 # fill arrays
44 my @loop_data =();
45 my $tag;
46 for ($tag=0 ; $tag<=9 ; $tag++) {
47 # marc array (tags and subfields)
48 # loop each field having tag = $tag."XX"
49         my @fields = $record->field($tag."XX");
50                 my @loop_data =();
51         foreach my $field (@fields) {
52                 my @subf=$field->subfields;
53                 my $previous_tag = '';
54                 my @subfields_data;
55 # loop through each subfield
56                 for my $i (0..$#subf) {
57 # if we not exactly the same tag (XX can varry !), loop for "tag tittle".
58                         if ($previous_tag ne $field->tag()) {
59                                 my %tag_data;
60                                 $tag_data{tag}=$field->tag().' '. $tagslib->{$field->tag()}->{lib};
61                                 $tag_data{subfield} = \@subfields_data;
62                                 push (@loop_data, \%tag_data);
63                                 $previous_tag = $field->tag();
64                         }
65                         $previous_tag = $field->tag();
66                         my %subfield_data;
67                         $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
68                         $subfield_data{marc_value}=$subf[$i][1];
69                         $subfield_data{marc_tag}=$field->tag().$subf[$i][0];
70                         push(@subfields_data, \%subfield_data);
71                 }
72         }
73         $template->param($tag."XX" =>\@loop_data);
74 }
75
76 # fill template with arrays
77 $template->param(biblionumber => $biblionumber);
78 #$template->param(marc =>\@loop_data);
79 $template->param(bibid => $bibid);
80 print "Content-Type: text/html\n\n", $template->output;
81