Bug 17089: Koha::Ratings - Remove AddRating
[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 use Koha::RecordProcessor;
58
59 my $query = CGI->new();
60 my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
61     {
62         template_name   => "opac-ISBDdetail.tt",
63         query           => $query,
64         type            => "opac",
65         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
66         debug           => 1,
67     }
68 );
69
70 my $biblionumber = $query->param('biblionumber');
71 $biblionumber = int($biblionumber);
72
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 );
78     }
79 }
80
81 $template->param( 'ItemsIssued' => CountItemsIssued( $biblionumber ) );
82
83 my $marcflavour      = C4::Context->preference("marcflavour");
84
85 my @items = GetItemsInfo($biblionumber);
86 if (scalar @items >= 1) {
87     my @hiddenitems = GetHiddenItemnumbers(@items);
88
89     if (scalar @hiddenitems == scalar @items ) {
90         print $query->redirect("/cgi-bin/koha/errors/404.pl"); # escape early
91         exit;
92     }
93 }
94
95 my $record = GetMarcBiblio($biblionumber,1);
96 if ( ! $record ) {
97     print $query->redirect("/cgi-bin/koha/errors/404.pl");
98     exit;
99 }
100 my $framework = GetFrameworkCode( $biblionumber );
101 my $record_processor = Koha::RecordProcessor->new({
102     filters => 'ViewPolicy',
103     options => {
104         interface => 'opac',
105         frameworkcode => $framework
106     }
107 });
108 $record_processor->process($record);
109
110 # some useful variables for enhanced content;
111 # in each case, we're grabbing the first value we find in
112 # the record and normalizing it
113 my $upc = GetNormalizedUPC($record,$marcflavour);
114 my $ean = GetNormalizedEAN($record,$marcflavour);
115 my $oclc = GetNormalizedOCLCNumber($record,$marcflavour);
116 my $isbn = GetNormalizedISBN(undef,$record,$marcflavour);
117 my $content_identifier_exists;
118 if ( $isbn or $ean or $oclc or $upc ) {
119     $content_identifier_exists = 1;
120 }
121 $template->param(
122     normalized_upc => $upc,
123     normalized_ean => $ean,
124     normalized_oclc => $oclc,
125     normalized_isbn => $isbn,
126     content_identifier_exists => $content_identifier_exists,
127 );
128
129 #coping with subscriptions
130 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
131 my $dbh = C4::Context->dbh;
132 my $dat                 = TransformMarcToKoha( $record );
133
134 my @subscriptions       = SearchSubscriptions({ biblionumber => $biblionumber, orderby => 'title' });
135 my @subs;
136 foreach my $subscription (@subscriptions) {
137     my %cell;
138         my $serials_to_display;
139     $cell{subscriptionid}    = $subscription->{subscriptionid};
140     $cell{subscriptionnotes} = $subscription->{notes};
141     $cell{branchcode}        = $subscription->{branchcode};
142
143     #get the three latest serials.
144         $serials_to_display = $subscription->{opacdisplaycount};
145         $serials_to_display = C4::Context->preference('OPACSerialIssueDisplayCount') unless $serials_to_display;
146         $cell{opacdisplaycount} = $serials_to_display;
147     $cell{latestserials} =
148       GetLatestSerials( $subscription->{subscriptionid}, $serials_to_display );
149     push @subs, \%cell;
150 }
151
152 $template->param(
153     subscriptions       => \@subs,
154     subscriptionsnumber => $subscriptionsnumber,
155 );
156
157 my $norequests = 1;
158 my $allow_onshelf_holds;
159 my $res = GetISBDView({
160     'record'    => $record,
161     'template'  => 'opac',
162     'framework' => $framework
163 });
164
165 my $itemtypes = GetItemTypes();
166 my $borrower = GetMember( 'borrowernumber' => $loggedinuser );
167 for my $itm (@items) {
168     $norequests = 0
169       if $norequests
170         && !$itm->{'withdrawn'}
171         && !$itm->{'itemlost'}
172         && ($itm->{'itemnotforloan'}<0 || not $itm->{'itemnotforloan'})
173         && !$itemtypes->{$itm->{'itype'}}->{notforloan}
174         && $itm->{'itemnumber'};
175
176     $allow_onshelf_holds = C4::Reserves::OnShelfHoldsAllowed($itm, $borrower)
177       unless $allow_onshelf_holds;
178 }
179
180 my $reviews = getreviews( $biblionumber, 1 );
181 foreach ( @$reviews ) {
182     my $borrower_number_review = $_->{borrowernumber};
183     my $borrowerData           = GetMember('borrowernumber' =>$borrower_number_review);
184     # setting some borrower info into this hash
185     $_->{title}     = $borrowerData->{'title'};
186     $_->{surname}   = $borrowerData->{'surname'};
187     $_->{firstname} = $borrowerData->{'firstname'};
188 }
189
190
191 $template->param(
192     RequestOnOpac       => C4::Context->preference("RequestOnOpac"),
193     AllowOnShelfHolds   => $allow_onshelf_holds,
194     norequests   => $norequests,
195     ISBD         => $res,
196     biblionumber => $biblionumber,
197     reviews             => $reviews,
198 );
199
200 #Search for title in links
201 my $marccontrolnumber   = GetMarcControlnumber ($record, $marcflavour);
202 my $marcissns = GetMarcISSN ( $record, $marcflavour );
203 my $issn = $marcissns->[0] || '';
204
205 if (my $search_for_title = C4::Context->preference('OPACSearchForTitleIn')){
206     $dat->{title} =~ s/\/+$//; # remove trailing slash
207     $dat->{title} =~ s/\s+$//; # remove trailing space
208     $search_for_title = parametrized_url(
209         $search_for_title,
210         {
211             TITLE         => $dat->{title},
212             AUTHOR        => $dat->{author},
213             ISBN          => $isbn,
214             ISSN          => $issn,
215             CONTROLNUMBER => $marccontrolnumber,
216             BIBLIONUMBER  => $biblionumber,
217         }
218     );
219     $template->param('OPACSearchForTitleIn' => $search_for_title);
220 }
221
222 output_html_with_http_headers $query, $cookie, $template->output;