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