Using get_record() from C4::Search now (ie fetching the record from zebra)
[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 my @title;
36 $dat->{'count'}=@items;
37 my @author;
38 if ($dat->{'author'}){
39         my %authorpush; 
40         $authorpush{author}=$dat->{'author'};
41         push @author, \%authorpush
42 }
43 $dat->{'additional'}=$addauthor->[0]->{'author'};
44 if ($dat->{'additional'}){
45         my %authorpush;
46         $authorpush{author} =$addauthor->[0]->{'author'};
47         push @author, \%authorpush
48 }
49
50 foreach my $word (split(" ", $dat->{'title'})){
51         unless (length($word) == 4){
52                 $word =~s/\%//g
53         }
54         unless (C4::Context->stopwords->{uc($word)} or length($word)==1) {
55         my %titlepush;
56         $titlepush{title} =$word;
57                 push @title, \%titlepush;
58         }#it's NOT a stopword => use it. Otherwise, ignore
59 }
60
61 for (my $i = 1; $i < $authorcount; $i++) {
62         $dat->{'additional'} .= " ; " . $addauthor->[$i]->{'author'};
63     
64         my %authorpush;
65         $authorpush{author}=$addauthor->[$i]->{'author'};
66         push @author, \%authorpush
67 } # for
68
69 my $norequests = 1;
70 foreach my $itm (@items) {
71     $norequests = 0 unless (($itm->{'wthdrawn'}) || ($itm->{'itemlost'}) || ($itm->{'notforloan'}) || ($itm->{'itemnotforloan'}) || (!$itm->{'itemnumber'}));
72     $itm->{$itm->{'publictype'}} = 1;
73 }
74
75 $template->param(norequests => $norequests);
76
77   ## get notes and subjects from MARC record
78 my $marc = C4::Context->preference("marc");
79 my @results = ($dat,);
80 if (C4::Boolean::true_p($marc)) {
81         my $dbh = C4::Context->dbh;
82         my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
83         my $marcflavour = C4::Context->preference("marcflavour");
84         my $marcnotesarray = &getMARCnotes($dbh,$bibid,$marcflavour);
85         $results[0]->{MARCNOTES} = $marcnotesarray;
86         my $marcsubjctsarray = &getMARCsubjects($dbh,$bibid,$marcflavour);
87         $results[0]->{MARCSUBJCTS} = $marcsubjctsarray;
88 #       $template->param(MARCNOTES => $marcnotesarray);
89 #       $template->param(MARCSUBJCTS => $marcsubjctsarray);
90 }
91
92 # get the number of reviews
93 my $reviewcount=numberofreviews($biblionumber);
94 $dat->{'reviews'}=$reviewcount;
95
96 my @results = ($dat,);
97 my $resultsarray=\@results;
98 my $itemsarray=\@items;
99 my $webarray=\@webbiblioitems;
100 my $sitearray=\@websites;
101 my $titlewords=\@title;
102 my $authorwords=\@author;
103
104
105 #coping with subscriptions
106 my $subscriptionsnumber = getsubscriptionfrombiblionumber($biblionumber);
107 my @subscriptions = getsubscriptions($dat->{title},$dat->{issn},$biblionumber);
108 my @subs;
109 foreach my $subscription (@subscriptions){
110         warn "subsid :".$subscription->{subscriptionid};
111         my %cell;
112         $cell{subscriptionid}= $subscription->{subscriptionid};
113         $cell{subscriptionnotes}= $subscription->{notes};
114         #get the three latest serials.
115         $cell{latestserials}=getlatestserials($subscription->{subscriptionid},3);
116         push @subs, \%cell;
117 }
118
119 $template->param(BIBLIO_RESULTS => $resultsarray,
120                                 ITEM_RESULTS => $itemsarray,
121                                 WEB_RESULTS => $webarray,
122                                 SITE_RESULTS => $sitearray,
123                                 subscriptionsnumber => $subscriptionsnumber,
124                              LibraryName => C4::Context->preference("LibraryName"),
125                                 suggestion => C4::Context->preference("suggestion"),
126                                 virtualshelves => C4::Context->preference("virtualshelves"),
127         titlewords => $titlewords,
128         authorwords => $authorwords,
129 );
130   ## Amazon.com stuff
131 =head
132 my $isbn=$dat->{'isbn'};
133 my $amazon_details = &get_amazon_details($isbn);
134 foreach my $result (@{$amazon_details->{Details}}){
135         $template->param(item_description => $result->{ProductDescription});
136         $template->param(image => $result->{ImageUrlMedium});
137         $template->param(list_price => $result->{ListPrice});
138         $template->param(amazon_url => $result->{url});
139                                 }
140
141 my @products;
142 my @reviews;
143 for my $details( @{ $amazon_details->{ Details } } ) {
144         next unless $details->{ SimilarProducts };
145         for my $product ( @{ $details->{ SimilarProducts }->{ Product } } ) {
146                 push @products, +{ Product => $product };
147         }
148         next unless $details->{ Reviews };
149         for my $product ( @{ $details->{ Reviews }->{ AvgCustomerRating } } ) {
150                 $template->param(rating => $product);
151         }
152         for my $reviews ( @{ $details->{ Reviews }->{ CustomerReview } } ) {
153                 push @reviews, +{ Summary => $reviews->{ Summary }, Comment => $reviews->{ Comment }, };
154         }
155 }
156 $template->param( SIMILAR_PRODUCTS => \@products );
157 $template->param( REVIEWS => \@reviews );
158   ## End of Amazon Stuff
159 =cut
160 output_html_with_http_headers $query, $cookie, $template->output;
161