adding authentification with Auth.pm
[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 =head1 NAME
21
22 MARCdetail.pl : script to show a biblio in MARC format
23
24 =head1 SYNOPSIS
25
26
27 =head1 DESCRIPTION
28
29 This script needs a biblionumber in bib parameter (bibnumber from koha style DB. Automaticaly maps to marc biblionumber).
30 It shows the biblio in a (nice) MARC format depending on MARC parameters tables.
31 The template is in <templates_dir>/catalogue/MARCdetail.tmpl. this template must be divided in 11 "tabs".
32 The 10 firsts presents the biblio, the 11th one presents the items attached to the biblio
33
34 =head1 FUNCTIONS
35
36 =over 2
37
38 =cut
39
40
41 use strict;
42 require Exporter;
43 use C4::Context;
44 use C4::Output;
45 use CGI;
46 use C4::Search;
47 use MARC::Record;
48 use C4::Biblio;
49 use C4::Catalogue;
50 use HTML::Template;
51
52 my $query=new CGI;
53
54 my $dbh=C4::Context->dbh;
55
56 my $biblionumber=$query->param('bib');
57 my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
58
59 my $tagslib = &MARCgettagslib($dbh,1);
60
61 my $record =MARCgetbiblio($dbh,$bibid);
62 #warn $record->as_formatted();
63 # open template
64 my $template = gettemplate("catalogue/MARCdetail.tmpl",0);
65 # fill arrays
66 my @loop_data =();
67 my $tag;
68 # loop through each tab 0 through 9
69 for (my $tabloop = 0; $tabloop<=10;$tabloop++) {
70 # loop through each tag
71         my @fields = $record->fields();
72         my @loop_data =();
73         foreach my $field (@fields) {
74                 my @subf=$field->subfields;
75                 my $previous_tag = '';
76                 my @subfields_data;
77 # loop through each subfield
78                 for my $i (0..$#subf) {
79                         $previous_tag = $field->tag();
80                         next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  ne $tabloop);
81                         my %subfield_data;
82                         $subfield_data{marc_lib}=$tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
83                         $subfield_data{marc_value}=$subf[$i][1];
84                         $subfield_data{marc_tag}=$subf[$i][0];
85                         push(@subfields_data, \%subfield_data);
86                 }
87                 if ($#subfields_data>=0) {
88                         my %tag_data;
89                         $tag_data{tag}=$field->tag().' -'. $tagslib->{$field->tag()}->{lib};
90                         $tag_data{subfield} = \@subfields_data;
91                         push (@loop_data, \%tag_data);
92                 }
93         }
94         $template->param($tabloop."XX" =>\@loop_data);
95 }
96 # now, build item tab !
97 # the main difference is that datas are in lines and not in columns : thus, we build the <th> first, then the values...
98 # loop through each tag
99 # warning : we may have differents number of columns in each row. Thus, we first build a hash, complete it if necessary
100 # then construct template.
101 my @fields = $record->fields();
102 my %witness; #---- stores the list of subfields used at least once, with the "meaning" of the code
103 my @big_array;
104 foreach my $field (@fields) {
105         my @subf=$field->subfields;
106         my %this_row;
107 # loop through each subfield
108         for my $i (0..$#subf) {
109                 next if ($tagslib->{$field->tag()}->{$subf[$i][0]}->{tab}  ne 10);
110                 $witness{$subf[$i][0]} = $tagslib->{$field->tag()}->{$subf[$i][0]}->{lib};
111                 $this_row{$subf[$i][0]} =$subf[$i][1];
112         }
113         if (%this_row) {
114                 push(@big_array, \%this_row);
115         }
116 }
117 #fill big_row with missing datas
118 foreach my $subfield_code  (keys(%witness)) {
119         for (my $i=0;$i<=$#big_array;$i++) {
120                 $big_array[$i]{$subfield_code}="&nbsp;" unless ($big_array[$i]{$subfield_code});
121 #               warn "filled : ".$big_array[$i]{$subfield_code};
122         }
123 }
124 # now, construct template !
125 my @item_value_loop;
126 my @header_value_loop;
127 for (my $i=0;$i<=$#big_array; $i++) {
128         my $items_data;
129         foreach my $subfield_code (keys(%witness)) {
130                 $items_data .="<td>".$big_array[$i]{$subfield_code}."</td>";
131         }
132 #       warn $items_data;
133         my %row_data;
134         $row_data{item_value} = $items_data;
135         push(@item_value_loop,\%row_data);
136 }
137 foreach my $subfield_code (keys(%witness)) {
138         my %header_value;
139         $header_value{header_value} = $witness{$subfield_code};
140         push(@header_value_loop, \%header_value);
141 }
142
143 $template->param(item_loop => \@item_value_loop,
144                                                 item_header_loop => \@header_value_loop,
145                                                 biblionumber => $biblionumber,
146                                                 bibid => $bibid);
147 print "Content-Type: text/html\n\n", $template->output;
148