Bug 7276 : Follow up, adding a sub to clear the cache
[koha.git] / catalogue / labeledMARCdetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2008-2009 LibLime
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
17 # with Koha; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20 use strict;
21 use warnings;
22 use CGI; 
23 use MARC::Record;
24 use C4::Auth;
25 use C4::Context;
26 use C4::Output;
27 use C4::Biblio;
28 use C4::Items;
29 use C4::Members; # to use GetMember
30 use C4::Search;         # enabled_staff_search_views
31
32 my $query        = new CGI;
33 my $dbh          = C4::Context->dbh;
34 my $biblionumber = $query->param('biblionumber');
35 my $frameworkcode = $query->param('frameworkcode');
36 $frameworkcode = GetFrameworkCode( $biblionumber ) unless ($frameworkcode);
37 my $popup        =
38   $query->param('popup')
39   ;    # if set to 1, then don't insert links, it's just to show the biblio
40
41 # open template
42 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
43     {
44         template_name   => "catalogue/labeledMARCdetail.tmpl",
45         query           => $query,
46         type            => "intranet",
47         authnotrequired => 0,
48         flagsrequired   => { catalogue => 1 },
49         debug           => 1,
50     }
51 );
52
53 my $record = GetMarcBiblio($biblionumber);
54 if ( not defined $record ) {
55     # biblionumber invalid -> report and exit
56     $template->param( unknownbiblionumber => 1,
57                 biblionumber => $biblionumber
58     );
59     output_html_with_http_headers $query, $cookie, $template->output;
60     exit;
61 }
62
63 my $tagslib = GetMarcStructure(1,$frameworkcode);
64 my $biblio = GetBiblioData($biblionumber);
65
66 if($query->cookie("holdfor")){ 
67     my $holdfor_patron = GetMember('borrowernumber' => $query->cookie("holdfor"));
68     $template->param(
69         holdfor => $query->cookie("holdfor"),
70         holdfor_surname => $holdfor_patron->{'surname'},
71         holdfor_firstname => $holdfor_patron->{'firstname'},
72         holdfor_cardnumber => $holdfor_patron->{'cardnumber'},
73     );
74 }
75
76 #count of item linked
77 my $itemcount = GetItemsCount($biblionumber);
78 $template->param( count => $itemcount,
79                                         bibliotitle => $biblio->{title}, );
80
81 #Getting the list of all frameworks
82 my $queryfwk =
83   $dbh->prepare("select frameworktext, frameworkcode from biblio_framework");
84 $queryfwk->execute;
85 my %select_fwk;
86 my @select_fwk;
87 my $curfwk;
88 push @select_fwk, "Default";
89 $select_fwk{"Default"} = "Default";
90
91 while ( my ( $description, $fwk ) = $queryfwk->fetchrow ) {
92     push @select_fwk, $fwk;
93     $select_fwk{$fwk} = $description;
94 }
95 $curfwk=$frameworkcode;
96 my $framework=CGI::scrolling_list( -name     => 'Frameworks',
97             -id => 'Frameworks',
98             -default => $curfwk,
99             -OnChange => 'Changefwk(this);',
100             -values   => \@select_fwk,
101             -labels   => \%select_fwk,
102             -size     => 1,
103             -multiple => 0 );
104 $template->param(framework => $framework);
105
106 my @marc_data;
107 my $prevlabel = '';
108 for my $field ($record->fields)
109 {
110         my $tag = $field->tag;
111         next if ! exists $tagslib->{$tag}->{lib};
112         my $label = $tagslib->{$tag}->{lib};
113         if ($label eq $prevlabel)
114         {
115                 $label = '';
116         }
117         else
118         {
119                 $prevlabel = $label;
120         }
121         my $value = $tag < 10
122                 ? $field->data
123                 : join ' ', map { $_->[1] } $field->subfields;
124         push @marc_data, {
125                 label => $label,
126                 value => $value,
127         };
128 }
129
130 $template->param (
131         marc_data                               => \@marc_data,
132     biblionumber            => $biblionumber,
133     popup                   => $popup,
134         labeledmarcview => 1,
135         z3950_search_params             => C4::Search::z3950_search_args($biblio),
136         C4::Search::enabled_staff_search_views,
137 );
138
139 output_html_with_http_headers $query, $cookie, $template->output;