Bug 32482: (follow-up) Add markup comments
[koha.git] / catalogue / imageviewer.pl
1 #!/usr/bin/perl
2
3 # Copyright 2011 C & P Bibliography Services
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20 use Modern::Perl;
21
22 use CGI qw ( -utf8 );
23 use C4::Auth qw( get_template_and_user );
24 use C4::Output qw( output_html_with_http_headers );
25 use C4::Search qw( enabled_staff_search_views );
26
27 use Koha::Biblios;
28 use Koha::Items;
29 use Koha::Patrons;
30
31 my $query = CGI->new;
32 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
33     {
34         template_name   => "catalogue/imageviewer.tt",
35         query           => $query,
36         type            => "intranet",
37         flagsrequired   => { catalogue => 1 },
38     }
39 );
40
41 my $itemnumber  = $query->param('itemnumber');
42 my $biblionumber = $query->param('biblionumber') || $query->param('bib') || Koha::Items->find($itemnumber)->biblionumber;
43 my $imagenumber = $query->param('imagenumber');
44 my $biblio = Koha::Biblios->find( $biblionumber );
45 my $itemcount = $biblio ? $biblio->items->count : 0;
46
47 if ( $query->cookie("holdfor") ) {
48     my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
49     $template->param(
50         holdfor        => $query->cookie("holdfor"),
51         holdfor_patron => $holdfor_patron,
52     );
53 }
54
55 if( $query->cookie("searchToOrder") ){
56     my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
57     $template->param(
58         searchtoorder_basketno => $basketno,
59         searchtoorder_vendorid => $vendorid
60     );
61 }
62
63 if ( C4::Context->preference("LocalCoverImages") ) {
64     my $images;
65     if ( $itemnumber ) {
66         my $item = Koha::Items->find($itemnumber);
67         $images = $item->cover_images->as_list;
68     } else {
69         $images = $biblio->cover_images->as_list;
70     }
71
72     $template->param(
73         LocalCoverImages => 1,
74         images           => $images,
75         imagenumber      => ( $imagenumber || ( @$images ? $images->[0]->imagenumber : undef ) ),
76     );
77 }
78 $template->{VARS}->{'count'}        = $itemcount;
79 $template->param(C4::Search::enabled_staff_search_views);
80 $template->{VARS}->{'biblio'} = $biblio;
81
82 $template->param(
83     biblionumber => $biblionumber,
84     itemnumber => $itemnumber,
85 );
86
87 my $hold_count = $biblio ? $biblio->holds->count : 0;
88 $template->param( holdcount => $hold_count );
89
90 output_html_with_http_headers $query, $cookie, $template->output;