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