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