Bug 26145: Add the ability to upload a cover image per item
[koha.git] / catalogue / ISBDdetail.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
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 =head1 NAME
21
22 ISBDdetail.pl : script to show a biblio in ISBD format
23
24 =head1 SYNOPSIS
25
26 =cut
27
28 =head1 DESCRIPTION
29
30 This script needs a biblionumber as parameter 
31
32 =head1 FUNCTIONS
33
34 =cut
35
36 use Modern::Perl;
37
38 use HTML::Entities;
39 use C4::Auth;
40 use C4::Context;
41 use C4::Output;
42 use CGI qw ( -utf8 );
43 use C4::Koha;
44 use C4::Biblio;
45 use C4::Items;
46 use C4::Serials;    # CountSubscriptionFromBiblionumber
47 use C4::Search;         # enabled_staff_search_views
48
49 use Koha::Biblios;
50 use Koha::Patrons;
51 use Koha::RecordProcessor;
52
53
54 my $query = new CGI;
55 my $dbh = C4::Context->dbh;
56
57 my $biblionumber = $query->param('biblionumber');
58 $biblionumber = HTML::Entities::encode($biblionumber);
59
60 # open template
61 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
62     {
63         template_name => "catalogue/ISBDdetail.tt",
64         query         => $query,
65         type          => "intranet",
66         flagsrequired   => { catalogue => 1 },
67     }
68 );
69
70 if ( not defined $biblionumber ) {
71        # biblionumber invalid -> report and exit
72        $template->param( unknownbiblionumber => 1,
73                                 biblionumber => $biblionumber
74        );
75        output_html_with_http_headers $query, $cookie, $template->output;
76        exit;
77 }
78
79 my $record = GetMarcBiblio({
80     biblionumber => $biblionumber,
81     embed_items  => 1 });
82
83 if ( not defined $record ) {
84        # biblionumber invalid -> report and exit
85        $template->param( unknownbiblionumber => 1,
86                                 biblionumber => $biblionumber
87        );
88        output_html_with_http_headers $query, $cookie, $template->output;
89        exit;
90 }
91
92 my $biblio = Koha::Biblios->find( $biblionumber );
93 my $framework = GetFrameworkCode( $biblionumber );
94 my $record_processor = Koha::RecordProcessor->new({
95     filters => 'ViewPolicy',
96     options => {
97         interface => 'intranet',
98         frameworkcode => $framework
99     },
100 });
101 $record_processor->process($record);
102
103 my $res = GetISBDView({
104     'record'    => $record,
105     'template'  => 'intranet',
106     'framework' => $framework,
107 });
108
109 if($query->cookie("holdfor")){ 
110     my $holdfor_patron = Koha::Patrons->find( $query->cookie("holdfor") );
111     $template->param(
112         holdfor => $query->cookie("holdfor"),
113         holdfor_surname => $holdfor_patron->surname,
114         holdfor_firstname => $holdfor_patron->firstname,
115         holdfor_cardnumber => $holdfor_patron->cardnumber,
116     );
117 }
118
119 if( $query->cookie("searchToOrder") ){
120     my ( $basketno, $vendorid ) = split( /\//, $query->cookie("searchToOrder") );
121     $template->param(
122         searchtoorder_basketno => $basketno,
123         searchtoorder_vendorid => $vendorid
124     );
125 }
126
127 # count of item linked with biblio
128 my $itemcount = $biblio->items->count;
129 $template->param( count => $itemcount);
130 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
131  
132 if ($subscriptionsnumber) {
133     my $subscriptions     = GetSubscriptionsFromBiblionumber($biblionumber);
134     my $subscriptiontitle = $subscriptions->[0]{'bibliotitle'};
135     $template->param(
136         subscriptionsnumber => $subscriptionsnumber,
137         subscriptiontitle   => $subscriptiontitle,
138     );
139 }
140
141 $template->param (
142     ISBD                => $res,
143     biblionumber        => $biblionumber,
144     isbdview            => 1,
145     z3950_search_params => C4::Search::z3950_search_args(GetBiblioData($biblionumber)),
146     ocoins => $biblio->get_coins,
147     C4::Search::enabled_staff_search_views,
148     searchid            => scalar $query->param('searchid'),
149     biblio              => $biblio,
150 );
151
152 my $holds = $biblio->holds;
153 $template->param( holdcount => $holds->count );
154
155 output_html_with_http_headers $query, $cookie, $template->output;
156