Added code to support search options sidebar ref to http://katipo.co.nz/gallery/koha2...
[koha.git] / opac / opac-detail.pl
1 #!/usr/bin/perl
2 use strict;
3 require Exporter;
4 use CGI;
5 use C4::Search;
6 use C4::Auth;
7 use C4::Bull; #uses getsubscriptionfrom biblionumber
8 use C4::Interface::CGI::Output;
9 use HTML::Template;
10 use C4::Biblio;
11 use C4::SearchMarc;
12 use C4::Amazon;
13 my $query=new CGI;
14 my ($template, $borrowernumber, $cookie) 
15     = get_template_and_user({template_name => "opac-detail.tmpl",
16                              query => $query,
17                              type => "opac",
18                              authnotrequired => 1,
19                              flagsrequired => {borrow => 1},
20                              });
21
22 my $biblionumber=$query->param('bib');
23 $template->param(biblionumber => $biblionumber);
24
25
26 # change back when ive fixed request.pl
27 my @items                                 = &ItemInfo(undef, $biblionumber, 'opac');
28 my $dat                                   = &bibdata($biblionumber);
29 my ($authorcount, $addauthor)             = &addauthor($biblionumber);
30 my ($webbiblioitemcount, @webbiblioitems) = &getwebbiblioitems($biblionumber);
31 my ($websitecount, @websites)             = &getwebsites($biblionumber);
32 my $subscriptionsnumber = getsubscriptionfrombiblionumber($biblionumber);
33
34 $dat->{'count'}=@items;
35 my @author;
36 $dat->{'additional'}=$addauthor->[0]->{'author'};
37 for (my $i = 1; $i < $authorcount; $i++) {
38         $dat->{'additional'} .= " ; " . $addauthor->[$i]->{'author'};
39         my %authorpush;
40         $authorpush{author} =$addauthor->[$i]->{'author'};
41         push @author, \%authorpush
42 } # for
43
44 my $norequests = 1;
45 foreach my $itm (@items) {
46     $norequests = 0 unless $itm->{'notforloan'};
47     $itm->{$itm->{'publictype'}} = 1;
48 }
49
50 $template->param(norequests => $norequests);
51
52   ## get notes and subjects from MARC record
53 my $marc = C4::Context->preference("marc");
54 if ($marc eq "yes") {
55         my $dbh = C4::Context->dbh;
56         my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
57         my $marcflavour = C4::Context->preference("marcflavour");
58         my $marcnotesarray = &getMARCnotes($dbh,$bibid,$marcflavour);
59         my $marcsubjctsarray = &getMARCsubjects($dbh,$bibid,$marcflavour);
60
61         $template->param(MARCNOTES => $marcnotesarray);
62         $template->param(MARCSUBJCTS => $marcsubjctsarray);
63 }
64
65 my @results = ($dat,);
66 my @title;
67
68
69 foreach my $word (split(" ", $dat->{'title'})){
70         unless (length($word) == 4){
71                 $word =~s/\%//g
72         }
73         unless (C4::Context->stopwords->{uc($word)} or length($word)==1) {
74         my %titlepush;
75         $titlepush{title} =$word;
76                 push @title, \%titlepush;
77         }#it's NOT a stopword => use it. Otherwise, ignore
78 }
79 foreach my $word (split(" ", $dat->{'author'})){
80         unless (length($word) == 4){
81                 $word =~s/\%//g
82         }
83         unless (C4::Context->stopwords->{uc($word)} or length($word)==1) {
84         my %authorpush;
85         $authorpush{author}=$word;
86                 push @author, \%authorpush;
87         }#it's NOT a stopword => use it. Otherwise, ignore
88 }
89
90 my $resultsarray=\@results;
91 my $itemsarray=\@items;
92 my $webarray=\@webbiblioitems;
93 my $sitearray=\@websites;
94 my $titlewords=\@title;
95 my $authorwords=\@author;
96
97
98 #coping with subscriptions
99 my $subscriptionsnumber = getsubscriptionfrombiblionumber($biblionumber);
100 my @subscriptions = getsubscriptions($dat->{title},$dat->{issn},$biblionumber);
101 my @subs;
102 foreach my $subscription (@subscriptions){
103         warn "subsid :".$subscription->{subscriptionid};
104         my %cell;
105         $cell{subscriptionid}= $subscription->{subscriptionid};
106         $cell{subscriptionnotes}= $subscription->{notes};
107         #get the three latest serials.
108         $cell{latestserials}=getlatestserials($subscription->{subscriptionid},3);
109         push @subs, \%cell;
110 }
111
112 $template->param(BIBLIO_RESULTS => $resultsarray,
113                                 ITEM_RESULTS => $itemsarray,
114                                 WEB_RESULTS => $webarray,
115                                 SITE_RESULTS => $sitearray,
116                                 subscriptionsnumber => $subscriptionsnumber,
117                              LibraryName => C4::Context->preference("LibraryName"),
118                                 suggestion => C4::Context->preference("suggestion"),
119                                 virtualshelves => C4::Context->preference("virtualshelves"),
120         titlewords => $titlewords,
121         authorwords => $authorwords,
122 );
123   ## Amazon.com stuff
124 =head
125 my $isbn=$dat->{'isbn'};
126 my $amazon_details = &get_amazon_details($isbn);
127 foreach my $result (@{$amazon_details->{Details}}){
128         $template->param(item_description => $result->{ProductDescription});
129         $template->param(image => $result->{ImageUrlMedium});
130         $template->param(list_price => $result->{ListPrice});
131         $template->param(amazon_url => $result->{url});
132                                 }
133
134 my @products;
135 my @reviews;
136 for my $details( @{ $amazon_details->{ Details } } ) {
137         next unless $details->{ SimilarProducts };
138         for my $product ( @{ $details->{ SimilarProducts }->{ Product } } ) {
139                 push @products, +{ Product => $product };
140         }
141         next unless $details->{ Reviews };
142         for my $product ( @{ $details->{ Reviews }->{ AvgCustomerRating } } ) {
143                 $template->param(rating => $product);
144         }
145         for my $reviews ( @{ $details->{ Reviews }->{ CustomerReview } } ) {
146                 push @reviews, +{ Summary => $reviews->{ Summary }, Comment => $reviews->{ Comment }, };
147         }
148 }
149 $template->param( SIMILAR_PRODUCTS => \@products );
150 $template->param( REVIEWS => \@reviews );
151   ## End of Amazon Stuff
152 =cut
153 output_html_with_http_headers $query, $cookie, $template->output;