Merge remote-tracking branch 'origin/new/bug_7805'
[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 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.
12 #
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.
16 #
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.
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.tmpl.
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 strict;
43 use warnings;
44
45 use C4::Auth;
46 use C4::Context;
47 use C4::Output;
48 use CGI;
49 use MARC::Record;
50 use C4::Biblio;
51 use C4::Items;
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.tmpl",
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
71 # get biblionumbers stored in the cart
72 my @cart_list;
73
74 if($query->cookie("bib_list")){
75     my $cart_list = $query->cookie("bib_list");
76     @cart_list = split(/\//, $cart_list);
77     if ( grep {$_ eq $biblionumber} @cart_list) {
78         $template->param( incart => 1 );
79     }
80 }
81
82 $template->param( 'AllowOnShelfHolds' => C4::Context->preference('AllowOnShelfHolds') );
83 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
84
85 my $marcflavour      = C4::Context->preference("marcflavour");
86 my $record = GetMarcBiblio($biblionumber);
87 if ( ! $record ) {
88     print $query->redirect("/cgi-bin/koha/errors/404.pl");
89     exit;
90 }
91 # some useful variables for enhanced content;
92 # in each case, we're grabbing the first value we find in
93 # the record and normalizing it
94 my $upc = GetNormalizedUPC($record,$marcflavour);
95 my $ean = GetNormalizedEAN($record,$marcflavour);
96 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
97 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
98 my $content_identifier_exists;
99 if ( $isbn or $ean or $oclc or $upc ) {
100     $content_identifier_exists = 1;
101 }
102 $template->param(
103     normalized_upc => $upc,
104     normalized_ean => $ean,
105     normalized_oclc => $oclc,
106     normalized_isbn => $isbn,
107         content_identifier_exists => $content_identifier_exists,
108 );
109
110 #coping with subscriptions
111 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
112 my $dbh = C4::Context->dbh;
113 my $dat                 = TransformMarcToKoha( $dbh, $record );
114
115 my @subscriptions       = GetSubscriptions( $dat->{title}, $dat->{issn}, undef, $biblionumber );
116 my @subs;
117 foreach my $subscription (@subscriptions) {
118     my %cell;
119         my $serials_to_display;
120     $cell{subscriptionid}    = $subscription->{subscriptionid};
121     $cell{subscriptionnotes} = $subscription->{notes};
122     $cell{branchcode}        = $subscription->{branchcode};
123
124     #get the three latest serials.
125         $serials_to_display = $subscription->{opacdisplaycount};
126         $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
127         $cell{opacdisplaycount} = $serials_to_display;
128     $cell{latestserials} =
129       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
130     push @subs, \%cell;
131 }
132
133 $template->param(
134     subscriptions       => \@subs,
135     subscriptionsnumber => $subscriptionsnumber,
136 );
137
138 my $norequests = 1;
139 my $res = GetISBDView($biblionumber, "opac");
140 my @items = GetItemsInfo( $biblionumber );
141
142 my $itemtypes = GetItemTypes();
143 for my $itm (@items) {
144     $norequests = 0
145        if ( (not $itm->{'wthdrawn'} )
146          && (not $itm->{'itemlost'} )
147          && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'} )
148                  && (not $itemtypes->{$itm->{'itype'}}->{notforloan} )
149          && ($itm->{'itemnumber'} ) );
150 }
151
152 my $reviews = getreviews( $biblionumber, 1 );
153 foreach ( @$reviews ) {
154     my $borrower_number_review = $_->{borrowernumber};
155     my $borrowerData           = GetMember('borrowernumber' =>$borrower_number_review);
156     # setting some borrower info into this hash
157     $_->{title}     = $borrowerData->{'title'};
158     $_->{surname}   = $borrowerData->{'surname'};
159     $_->{firstname} = $borrowerData->{'firstname'};
160 }
161
162
163 $template->param(
164     RequestOnOpac       => C4::Context->preference("RequestOnOpac"),
165     AllowOnShelfHolds   => C4::Context->preference('AllowOnShelfHolds'),
166     norequests   => $norequests,
167     ISBD         => $res,
168     biblionumber => $biblionumber,
169     reviews             => $reviews,
170 );
171
172 #Export options
173 my $OpacExportOptions=C4::Context->preference("OpacExportOptions");
174 my @export_options = split(/\|/,$OpacExportOptions);
175 $template->{VARS}->{'export_options'} = \@export_options;
176
177 #Search for title in links
178 my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
179 my $marcissns = GetMarcISSN ( $record, $marcflavour );
180 my $issn = $marcissns->[0] || '';
181
182 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
183     $dat->{author} ? $search_for_title =~ s/{AUTHOR}/$dat->{author}/g : $search_for_title =~ s/{AUTHOR}//g;
184     $dat->{title} =~ s/\/+$//; # remove trailing slash
185     $dat->{title} =~ s/\s+$//; # remove trailing space
186     $dat->{title} ? $search_for_title =~ s/{TITLE}/$dat->{title}/g : $search_for_title =~ s/{TITLE}//g;
187     $isbn ? $search_for_title =~ s/{ISBN}/$isbn/g : $search_for_title =~ s/{ISBN}//g;
188     $issn ? $search_for_title =~ s/{ISSN}/$issn/g : $search_for_title =~ s/{ISSN}//g;
189     $marccontrolnumber ? $search_for_title =~ s/{CONTROLNUMBER}/$marccontrolnumber/g : $search_for_title =~ s/{CONTROLNUMBER}//g;
190     $search_for_title =~ s/{BIBLIONUMBER}/$biblionumber/g;
191  $template->param('OPACSearchForTitleIn' => $search_for_title);
192 }
193
194 output_html_with_http_headers $query, $cookie, $template->output;