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