Script to add or edit a review
[wip/koha-chris_n.git] / opac / opac-review.pl
1 #!/usr/bin/perl
2 use strict;
3 require Exporter;
4 use CGI;
5
6 use C4::Auth;
7 use C4::Koha;
8 use HTML::Template;
9 use C4::Interface::CGI::Output;
10 use C4::Search;
11 use C4::Circulation::Circ2;
12 use C4::Review;
13
14 my $query = new CGI;
15 my $biblionumber = $query->param('biblionumber');
16 my $type = $query->param('type');
17 my $review = $query->param('review');
18 my ($template, $borrowernumber, $cookie) 
19     = get_template_and_user({template_name => "opac-review.tmpl",
20                              query => $query,
21                              type => "opac",
22                              authnotrequired => 0,
23                              flagsrequired => {borrow => 1},
24                              debug => 1,
25                              });
26
27 # get borrower information ....
28 # my ($borr, $flags) = getpatroninformation(undef, $borrowernumber);
29 # $template->param($borr);
30
31 my $biblio=bibdata($biblionumber,'opac');
32
33 my $savedreview=getreview($biblionumber,$borrowernumber);
34 if ($type eq 'save'){
35    savereview($biblionumber,$borrowernumber,$review);    
36 }
37 if ($type eq 'update'){
38     updatereview($biblionumber,$borrowernumber,$review);
39 }
40 if ($savedreview){
41         $type="update";
42     }
43 else {
44     $type="save";
45 }
46 my $reviewdata=$savedreview->{'review'};
47 $template->param('biblionumber' => $biblionumber,
48     'borrowernumber' => $borrowernumber,
49     'type'=>$type,
50     'review'=>$reviewdata,
51     'title'=>$biblio->{'title'});
52
53 # get the record
54 my $order=$query->param('order');
55 my $order2=$order;
56 if ($order2 eq ''){
57   $order2="date_due desc";
58 }
59 my $limit=$query->param('limit');
60 if ($limit eq 'full'){
61   $limit=0;
62 } else {
63   $limit=50;
64 }
65
66 output_html_with_http_headers $query, $cookie, $template->output;
67