Revert "reverting defaut-search-on-kw-wrdl and doing it elsewhere"
[koha.git] / catalogue / detail.pl
1 #!/usr/bin/perl
2
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17
18
19 use strict;
20 require Exporter;
21 use CGI;
22 use C4::Auth;
23 use C4::Serials;    #uses getsubscriptionfrom biblionumber
24 use C4::Output;
25 use C4::Biblio;
26 use C4::Serials;
27
28 my $query = new CGI;
29 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
30     {
31         template_name   => "catalogue/detail.tmpl",
32         query           => $query,
33         type            => "intranet",
34         authnotrequired => 0,
35         flagsrequired   => { catalogue => 1 },
36     }
37 );
38
39 my $biblionumber = $query->param('biblionumber');
40
41 # change back when ive fixed request.pl
42 my @items = &GetItemsInfo( $biblionumber, 'intra' );
43 my $dat = &GetBiblioData($biblionumber);
44
45 if (!$dat) { 
46         print $query->redirect("/cgi-bin/koha/koha-tmpl/errors/404.pl");
47 }
48
49 #coping with subscriptions
50 my $subscriptionsnumber = CountSubscriptionFromBiblionumber($biblionumber);
51 my @subscriptions       = GetSubscriptions( $dat->{title}, $dat->{issn}, $biblionumber );
52
53 my @subs;
54 foreach my $subscription (@subscriptions) {
55     my %cell;
56     $cell{subscriptionid}    = $subscription->{subscriptionid};
57     $cell{subscriptionnotes} = $subscription->{notes};
58
59     #get the three latest serials.
60     $cell{latestserials} =
61       GetLatestSerials( $subscription->{subscriptionid}, 3 );
62     push @subs, \%cell;
63 }
64
65 $dat->{'count'} = @items;
66
67 my $norequests = 1;
68 foreach my $itm (@items) {
69     $norequests = 0
70       unless ( ( $itm->{'notforloan'} > 0 )
71         || ( $itm->{'itemnotforloan'} > 0 ) );
72     $itm->{ $itm->{'publictype'} } = 1;
73 }
74
75 $template->param( norequests => $norequests );
76
77 ## get notes and subjects from MARC record
78     my $dbh              = C4::Context->dbh;
79     my $marcflavour      = C4::Context->preference("marcflavour");
80     my $record           = GetMarcBiblio($biblionumber);
81     my $marcnotesarray   = GetMarcNotes( $record, $marcflavour );
82     my $marcauthorsarray = GetMarcAuthors( $record, $marcflavour );
83     my $marcsubjctsarray = GetMarcSubjects( $record, $marcflavour );
84
85     $template->param(
86         MARCNOTES   => $marcnotesarray,
87         MARCSUBJCTS => $marcsubjctsarray,
88         MARCAUTHORS => $marcauthorsarray
89     );
90
91 my @results = ( $dat, );
92 foreach ( keys %{$dat} ) {
93     $template->param( "$_" => $dat->{$_} . "" );
94 }
95
96 $template->param(
97     ITEM_RESULTS        => \@items,
98     biblionumber        => $biblionumber,
99     subscriptions       => \@subs,
100     subscriptionsnumber => $subscriptionsnumber,
101     subscriptiontitle   => $dat->{title},
102 );
103
104 output_html_with_http_headers $query, $cookie, $template->output;