3 # Copyright 2006 Katipo Communications
5 # This file is part of Koha.
7 # Koha is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
12 # Koha is distributed in the hope that it will be useful, but
13 # WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with Koha; if not, see <http://www.gnu.org/licenses>.
32 my $biblionumber = $query->param('biblionumber');
33 my $review = $query->param('review');
34 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
36 template_name => "opac-review.tt",
39 authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
43 # FIXME: need to allow user to delete their own comment(s)
45 my $biblio = GetBiblioData($biblionumber);
46 # FIXME biblionumber, borrowernumber should be a unique key of reviews
47 my $savedreview = Koha::Reviews->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber })->next;
49 if (defined $review) {
50 if ($review !~ /\S/) {
51 push @errors, {empty=>1};
53 $clean = C4::Scrubber->new('comment')->scrub($review);
55 push @errors, {scrubbed_all=>1};
57 if ($clean ne $review) {
58 push @errors, {scrubbed=>$clean};
60 my $js_ok_review = $clean;
61 $js_ok_review =~ s/"/"/g; # probably redundant w/ TMPL ESCAPE=JS
62 $template->param(clean_review=>$js_ok_review);
64 updatereview($biblionumber, $borrowernumber, $clean);
66 savereview($biblionumber, $borrowernumber, $clean);
68 unless (@errors){ $template->param(WINDOW_CLOSE=>1); }
72 (@errors ) and $template->param( ERRORS=>\@errors);
73 ($cgi_debug) and $template->param(cgi_debug=>1 );
75 $review ||= $savedreview->review if $savedreview;
77 'biblionumber' => $biblionumber,
78 'borrowernumber' => $borrowernumber,
80 'reviewid' => scalar $query->param('reviewid') || 0,
81 'title' => $biblio->{'title'},
84 output_html_with_http_headers $query, $cookie, $template->output;