Bug 16534: Block AddIssue from issuing if the return is not possible
[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
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.
11 #
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.
16 #
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>.
19
20 use strict;
21 use warnings;
22 use CGI qw ( -utf8 );
23 use C4::Auth;
24 use C4::Koha;
25 use C4::Output;
26 use C4::Review;
27 use C4::Biblio;
28 use C4::Scrubber;
29 use C4::Debug;
30
31 my $query        = new CGI;
32 my $biblionumber = $query->param('biblionumber');
33 my $review       = $query->param('review');
34 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
35     {
36         template_name   => "opac-review.tt",
37         query           => $query,
38         type            => "opac",
39         authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
40     }
41 );
42
43 # FIXME: need to allow user to delete their own comment(s)
44
45 my $biblio = GetBiblioData($biblionumber);
46 my $savedreview = getreview($biblionumber,$borrowernumber);
47 my ($clean, @errors);
48 if (defined $review) {
49         if ($review !~ /\S/) {
50                 push @errors, {empty=>1};
51         } else {
52                 $clean = C4::Scrubber->new('comment')->scrub($review);
53                 if ($clean !~ /\S/) {
54                         push @errors, {scrubbed_all=>1};
55                 } else {
56                         if ($clean ne $review) {
57                                 push @errors, {scrubbed=>$clean};
58                         }
59                         my $js_ok_review = $clean;
60                         $js_ok_review =~ s/"/&quot;/g;  # probably redundant w/ TMPL ESCAPE=JS
61                         $template->param(clean_review=>$js_ok_review);
62                         if ($savedreview) {
63                         updatereview($biblionumber, $borrowernumber, $clean);
64                         } else {
65                         savereview($biblionumber, $borrowernumber, $clean);
66                         }
67                         unless (@errors){ $template->param(WINDOW_CLOSE=>1); }
68                 }
69         }
70 }
71 (@errors   ) and $template->param(   ERRORS=>\@errors);
72 ($cgi_debug) and $template->param(cgi_debug=>1       );
73 $template->param(
74     'biblionumber'   => $biblionumber,
75     'borrowernumber' => $borrowernumber,
76     'review'         => $clean || $savedreview->{'review'},
77         'reviewid'       => scalar $query->param('reviewid') || 0,
78     'title'          => $biblio->{'title'},
79 );
80
81 output_html_with_http_headers $query, $cookie, $template->output;
82