Bug 11592: Updated License Text and use Modern::Perl
[koha.git] / opac / opac-ISBDdetail.pl
1 #!/usr/bin/perl
2
3 # Copyright 2000-2002 Katipo Communications
4 # parts copyright 2010 BibLibre
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21
22 =head1 NAME
23
24 opac-ISBDdetail.pl - script to show a biblio in ISBD format
25
26 =head1 DESCRIPTION
27
28 This script needs a biblionumber as parameter 
29
30 It shows the biblio
31
32 The template is in <templates_dir>/catalogue/ISBDdetail.tt.
33 this template must be divided into 11 "tabs".
34
35 The first 10 tabs present the biblio, the 11th one presents
36 the items attached to the biblio
37
38 =head1 FUNCTIONS
39
40 =cut
41
42 use Modern::Perl;
43
44 use C4::Auth;
45 use C4::Context;
46 use C4::Output;
47 use CGI qw ( -utf8 );
48 use MARC::Record;
49 use C4::Biblio;
50 use C4::Items;
51 use C4::Reserves;
52 use C4::Acquisition;
53 use C4::Review;
54 use C4::Serials;    # uses getsubscriptionfrom biblionumber
55 use C4::Koha;
56 use C4::Members;    # GetMember
57
58 my $query = CGI->new();
59 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
60     {
61         template_name   => "opac-ISBDdetail.tt",
62         query           => $query,
63         type            => "opac",
64         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
65         debug           => 1,
66     }
67 );
68
69 my $biblionumber = $query->param('biblionumber');
70 $biblionumber = int($biblionumber);
71
72 # get biblionumbers stored in the cart
73 if(my $cart_list = $query->cookie("bib_list")){
74     my @cart_list = split(/\//, $cart_list);
75     if ( grep {$_ eq $biblionumber} @cart_list) {
76         $template->param( incart => 1 );
77     }
78 }
79
80 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
81
82 my $marcflavour      = C4::Context->preference("marcflavour");
83
84 my @items = GetItemsInfo($biblionumber);
85 if (scalar @items >= 1) {
86     my @hiddenitems = GetHiddenItemnumbers(@items);
87
88     if (scalar @hiddenitems == scalar @items ) {
89         print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
90         exit;
91     }
92 }
93
94 my $record = GetMarcBiblio($biblionumber);
95 if ( ! $record ) {
96     print $query->redirect("/cgi-bin/koha/errors/404.pl");
97     exit;
98 }
99 # some useful variables for enhanced content;
100 # in each case, we're grabbing the first value we find in
101 # the record and normalizing it
102 my $upc = GetNormalizedUPC($record,$marcflavour);
103 my $ean = GetNormalizedEAN($record,$marcflavour);
104 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
105 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
106 my $content_identifier_exists;
107 if ( $isbn or $ean or $oclc or $upc ) {
108     $content_identifier_exists = 1;
109 }
110 $template->param(
111     normalized_upc => $upc,
112     normalized_ean => $ean,
113     normalized_oclc => $oclc,
114     normalized_isbn => $isbn,
115         content_identifier_exists => $content_identifier_exists,
116 );
117
118 #coping with subscriptions
119 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
120 my $dbh = C4::Context->dbh;
121 my $dat                 = TransformMarcToKoha( $record );
122
123 my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
124 my @subs;
125 foreach my $subscription (@subscriptions) {
126     my %cell;
127         my $serials_to_display;
128     $cell{subscriptionid}    = $subscription->{subscriptionid};
129     $cell{subscriptionnotes} = $subscription->{notes};
130     $cell{branchcode}        = $subscription->{branchcode};
131
132     #get the three latest serials.
133         $serials_to_display = $subscription->{opacdisplaycount};
134         $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
135         $cell{opacdisplaycount} = $serials_to_display;
136     $cell{latestserials} =
137       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
138     push @subs, \%cell;
139 }
140
141 $template->param(
142     subscriptions       => \@subs,
143     subscriptionsnumber => $subscriptionsnumber,
144 );
145
146 my $norequests = 1;
147 my $allow_onshelf_holds;
148 my $res = GetISBDView($biblionumber, "opac");
149
150 my $itemtypes = GetItemTypes();
151 my $borrower = GetMember( 'borrowernumber' => $loggedinuser );
152 for my $itm (@items) {
153     $norequests = 0
154       if $norequests
155         && !$itm->{'withdrawn'}
156         && !$itm->{'itemlost'}
157         && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
158         && !$itemtypes->{$itm->{'itype'}}->{notforloan}
159         && $itm->{'itemnumber'};
160
161     $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed($itm, $borrower)
162       unless $allow_onshelf_holds;
163 }
164
165 my $reviews = getreviews( $biblionumber, 1 );
166 foreach ( @$reviews ) {
167     my $borrower_number_review = $_->{borrowernumber};
168     my $borrowerData           = GetMember('borrowernumber' =>$borrower_number_review);
169     # setting some borrower info into this hash
170     $_->{title}     = $borrowerData->{'title'};
171     $_->{surname}   = $borrowerData->{'surname'};
172     $_->{firstname} = $borrowerData->{'firstname'};
173 }
174
175
176 $template->param(
177     RequestOnOpac       => C4::Context->preference("RequestOnOpac"),
178     AllowOnShelfHolds   => $allow_onshelf_holds,
179     norequests   => $norequests,
180     ISBD         => $res,
181     biblionumber => $biblionumber,
182     reviews             => $reviews,
183 );
184
185 #Search for title in links
186 my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
187 my $marcissns = GetMarcISSN ( $record, $marcflavour );
188 my $issn = $marcissns->[0] || '';
189
190 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
191     $dat->{title} =~ s/\/+$//; # remove trailing slash
192     $dat->{title} =~ s/\s+$//; # remove trailing space
193     $search_for_title = parametrized_url(
194         $search_for_title,
195         {
196             TITLE         => $dat->{title},
197             AUTHOR        => $dat->{author},
198             ISBN          => $isbn,
199             ISSN          => $issn,
200             CONTROLNUMBER => $marccontrolnumber,
201             BIBLIONUMBER  => $biblionumber,
202         }
203     );
204     $template->param('OPACSearchForTitleIn' => $search_for_title);
205 }
206
207 output_html_with_http_headers $query, $cookie, $template->output;