Added POD.
[koha.git] / marc / 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 HTML::Template;
21 use strict;
22 require Exporter;
23 use C4::Database;
24 use C4::Output;  # contains picktemplate
25 use CGI;
26 use C4::Search;
27 use MARC::Record;
28 use C4::Biblio;
29 use C4::Catalogue;
30  
31 my $query=new CGI;
32
33
34 my $language='french';
35
36
37 my %configfile;
38 open (KC, "/etc/koha.conf");
39 while (<KC>) {
40     chomp;
41     (next) if (/^\s*#/
42             );
43     if (/(.*)\s*=\s*(.*)/) {
44         my $variable=$1;
45         my $value=$2;
46         # Clean up white space at beginning and end
47         $variable=~s/^\s*//g;
48         $variable=~s/\s*$//g;
49         $value=~s/^\s*//g;
50         $value=~s/\s*$//g;
51         $configfile{$variable}=$value;
52     }
53 }
54
55     
56 my $biblionumber=$query->param('bib');
57 my $tag=$query->param('tag');
58 if (! defined $tag) { $tag='2XX';}
59 #print STDERR "BIB : $biblionumber // TAG : $tag\n";
60 if (! defined $biblionumber) {
61     my $includes=$configfile{'includes'};
62     ($includes) || ($includes="/usr/local/www/hdl/htdocs/includes");
63     my $templatebase="MARCdetailbiblioselect.tmpl";
64     my $theme=picktemplate($includes, $templatebase);
65     my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]);
66     print "Content-Type: text/html\n\n", $template->output;
67
68 } else {
69     &showmarcrecord($biblionumber,$tag);
70 }
71
72 sub showmarcrecord {
73     my ($biblionumber,$tag) = @_;
74     my $dbh=&C4Connect;
75     my $sth=$dbh->prepare("select liblibrarian from marc_subfield_structure where tagfield=? and tagsubfield=?");
76     my $record =MARCgetbiblio($dbh,$biblionumber);
77 # open template
78     my $templatebase="catalogue/MARCdetail.tmpl";
79     my $includes=$configfile{'includes'};
80     ($includes) || ($includes="/usr/local/www/hdl/htdocs/includes");
81     my $theme=picktemplate($includes, $templatebase);
82     my $template = HTML::Template->new(filename => "$includes/templates/$theme/$templatebase", die_on_bad_params => 0, path => [$includes]);
83 # fill arrays
84     my @loop_data =();
85     my @fields = $record->field($tag);
86     foreach my $field (@fields) {
87         my @subf=$field->subfields;
88         for my $i (0..$#subf) {
89             $sth->execute($field->tag(), $subf[$i][0]);
90             my $row=$sth->fetchrow_hashref;
91             my %row_data;
92             $row_data{marc_lib}=$row->{'liblibrarian'};
93             $row_data{marc_value}=$subf[$i][1];
94             $row_data{marc_tag}=$field->tag().$subf[$i][0];
95             push(@loop_data, \%row_data);
96 #           print $field->tag(), " ", $field->indicator(1),$field->indicator(2), "subf: ", $subf[$i][0]," =",$subf[$i][1]," <-- \n";
97         }
98     }
99     
100 # fill template with arrays
101     $template->param(biblionumber => $biblionumber);
102     $template->param(marc =>\@loop_data);
103     print "Content-Type: text/html\n\n", $template->output;
104     
105 }