Tidying up, and getting it working again
[koha.git] / opac / opac-review.pl
1 #!/usr/bin/perl
2
3 # Copyright 2006 Katipo Communications
4 #
5 # This file is part of Koha.
6 #
7 # Koha is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
10 # version.
11 #
12 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License along with
17 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
18 # Suite 330, Boston, MA  02111-1307 USA
19
20 use strict;
21 require Exporter;
22 use CGI;
23
24 use C4::Auth;
25 use C4::Koha;
26 use HTML::Template;
27 use C4::Interface::CGI::Output;
28 use C4::Circulation::Circ2;
29 use C4::Review;
30 use C4::Biblio;
31
32 my $query        = new CGI;
33 my $biblionumber = $query->param('biblionumber');
34 my $type         = $query->param('type');
35 my $review       = $query->param('review');
36 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37     {
38         template_name   => "opac-review.tmpl",
39         query           => $query,
40         type            => "opac",
41         authnotrequired => 0,
42         flagsrequired   => { borrow => 1 },
43         debug           => 1,
44     }
45 );
46
47 # get borrower information ....
48 # my ($borr, $flags) = getpatroninformation(undef, $borrowernumber);
49 # $template->param($borr);
50
51 my $biblio = bibdata( $biblionumber, 'opac' );
52
53 my $savedreview = getreview( $biblionumber, $borrowernumber );
54 if ( $type eq 'save' ) {
55     savereview( $biblionumber, $borrowernumber, $review );
56 }
57 if ( $type eq 'update' ) {
58     updatereview( $biblionumber, $borrowernumber, $review );
59 }
60 if ($savedreview) {
61     $type = "update";
62 }
63 else {
64     $type = "save";
65 }
66 my $reviewdata = $savedreview->{'review'};
67 $template->param(
68     'biblionumber'   => $biblionumber,
69     'borrowernumber' => $borrowernumber,
70     'type'           => $type,
71     'review'         => $reviewdata,
72     'title'          => $biblio->{'title'}
73 );
74
75 # get the record
76 my $order  = $query->param('order');
77 my $order2 = $order;
78 if ( $order2 eq '' ) {
79     $order2 = "date_due desc";
80 }
81 my $limit = $query->param('limit');
82 if ( $limit eq 'full' ) {
83     $limit = 0;
84 }
85 else {
86     $limit = 50;
87 }
88
89 output_html_with_http_headers $query, $cookie, $template->output;
90