synch'ing 2.2 and head
[koha_fer] / 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
36 $dat->{'additional'}=$addauthor->[0]->{'author'};
37 for (my $i = 1; $i < $authorcount; $i++) {
38         $dat->{'additional'} .= " ; " . $addauthor->[$i]->{'author'};
39 } # for
40
41 my $norequests = 1;
42 foreach my $itm (@items) {
43     $norequests = 0 unless $itm->{'notforloan'};
44     $itm->{$itm->{'publictype'}} = 1;
45 }
46
47 $template->param(norequests => $norequests);
48
49   ## get notes and subjects from MARC record
50 my $marc = C4::Context->preference("marc");
51 if ($marc eq "yes") {
52         my $dbh = C4::Context->dbh;
53         my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
54         my $marcflavour = C4::Context->preference("marcflavour");
55         my $marcnotesarray = &getMARCnotes($dbh,$bibid,$marcflavour);
56         my $marcsubjctsarray = &getMARCsubjects($dbh,$bibid,$marcflavour);
57
58         $template->param(MARCNOTES => $marcnotesarray);
59         $template->param(MARCSUBJCTS => $marcsubjctsarray);
60 }
61
62 my @results = ($dat,);
63
64 my $resultsarray=\@results;
65 my $itemsarray=\@items;
66 my $webarray=\@webbiblioitems;
67 my $sitearray=\@websites;
68
69 #coping with subscriptions
70 my $subscriptionsnumber = getsubscriptionfrombiblionumber($biblionumber);
71 my @subscriptions = getsubscriptions($dat->{title},$dat->{issn},$biblionumber);
72 my @subs;
73 foreach my $subscription (@subscriptions){
74         warn "subsid :".$subscription->{subscriptionid};
75         my %cell;
76         $cell{subscriptionid}= $subscription->{subscriptionid};
77         $cell{subscriptionnotes}= $subscription->{notes};
78         #get the three latest serials.
79         $cell{latestserials}=getlatestserials($subscription->{subscriptionid},3);
80         push @subs, \%cell;
81 }
82
83 $template->param(BIBLIO_RESULTS => $resultsarray,
84                                 ITEM_RESULTS => $itemsarray,
85                                 WEB_RESULTS => $webarray,
86                                 SITE_RESULTS => $sitearray,
87                                 subscriptionsnumber => $subscriptionsnumber,
88                              LibraryName => C4::Context->preference("LibraryName"),
89                                 suggestion => C4::Context->preference("suggestion"),
90                                 virtualshelves => C4::Context->preference("virtualshelves"),
91 );
92   ## Amazon.com stuff
93 =head
94 my $isbn=$dat->{'isbn'};
95 my $amazon_details = &get_amazon_details($isbn);
96 foreach my $result (@{$amazon_details->{Details}}){
97         $template->param(item_description => $result->{ProductDescription});
98         $template->param(image => $result->{ImageUrlMedium});
99         $template->param(list_price => $result->{ListPrice});
100         $template->param(amazon_url => $result->{url});
101                                 }
102
103 my @products;
104 my @reviews;
105 for my $details( @{ $amazon_details->{ Details } } ) {
106         next unless $details->{ SimilarProducts };
107         for my $product ( @{ $details->{ SimilarProducts }->{ Product } } ) {
108                 push @products, +{ Product => $product };
109         }
110         next unless $details->{ Reviews };
111         for my $product ( @{ $details->{ Reviews }->{ AvgCustomerRating } } ) {
112                 $template->param(rating => $product);
113         }
114         for my $reviews ( @{ $details->{ Reviews }->{ CustomerReview } } ) {
115                 push @reviews, +{ Summary => $reviews->{ Summary }, Comment => $reviews->{ Comment }, };
116         }
117 }
118 $template->param( SIMILAR_PRODUCTS => \@products );
119 $template->param( REVIEWS => \@reviews );
120   ## End of Amazon Stuff
121 =cut
122 output_html_with_http_headers $query, $cookie, $template->output;
123
124 #output_html_with_http_headers $query, $cookie, $template->output;
125
126 output_html_with_http_headers $query, $cookie, $template->output;
127