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