Lines 29-44
use Koha::DateUtils;
Link Here
|
29 |
use Koha::Review; |
29 |
use Koha::Review; |
30 |
use Koha::Reviews; |
30 |
use Koha::Reviews; |
31 |
|
31 |
|
32 |
my $query = new CGI; |
32 |
my $query = CGI->new; |
33 |
my $biblionumber = $query->param('biblionumber'); |
33 |
my $biblionumber = $query->param('biblionumber'); |
34 |
my $review = $query->param('review'); # if defined submit |
34 |
my $review = $query->param('review'); # if defined submit |
35 |
my $reviewid = $query->param('reviewid'); # if defined edit |
35 |
my $reviewid = $query->param('reviewid'); # if defined edit |
36 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
36 |
my ( $template, $borrowernumber, $cookie ) = get_template_and_user( |
37 |
{ |
37 |
{ |
38 |
template_name => "opac-review.tt", |
38 |
template_name => 'opac-review.tt', |
39 |
query => $query, |
39 |
query => $query, |
40 |
type => "opac", |
40 |
type => 'opac', |
41 |
authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ), |
41 |
authnotrequired => ( C4::Context->preference('OpacPublic') ? 1 : 0 ), |
42 |
} |
42 |
} |
43 |
); |
43 |
); |
44 |
|
44 |
|
Lines 55-61
if( !$biblio ) {
Link Here
|
55 |
push @errors, { nobiblio => 1 }; |
55 |
push @errors, { nobiblio => 1 }; |
56 |
} elsif( $reviewid ) { # edit existing one, check on creator |
56 |
} elsif( $reviewid ) { # edit existing one, check on creator |
57 |
$savedreview = Koha::Reviews->search({ reviewid => $reviewid, borrowernumber => $borrowernumber })->next; |
57 |
$savedreview = Koha::Reviews->search({ reviewid => $reviewid, borrowernumber => $borrowernumber })->next; |
58 |
push @errors, { unauthorized => 1 } if !$savedreview; |
58 |
if (!$savedreview) { push @errors, { unauthorized => 1 } }; |
59 |
} else { # this check prevents adding multiple comments |
59 |
} else { # this check prevents adding multiple comments |
60 |
# FIXME biblionumber, borrowernumber should be a unique key of reviews |
60 |
# FIXME biblionumber, borrowernumber should be a unique key of reviews |
61 |
$savedreview = Koha::Reviews->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber })->next; |
61 |
$savedreview = Koha::Reviews->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber })->next; |
Lines 63-80
if( !$biblio ) {
Link Here
|
63 |
} |
63 |
} |
64 |
|
64 |
|
65 |
if( !@errors && $submitting ) { |
65 |
if( !@errors && $submitting ) { |
66 |
if ($review !~ /\S/) { |
66 |
if ($review !~ /\S/xsm) { |
67 |
push @errors, {empty=>1}; |
67 |
push @errors, {empty=>1}; |
68 |
} else { |
68 |
} else { |
69 |
$clean = C4::Scrubber->new('comment')->scrub($review); |
69 |
$clean = C4::Scrubber->new('comment')->scrub($review); |
70 |
if ($clean !~ /\S/) { |
70 |
if ($clean !~ /\S/xsm) { |
71 |
push @errors, {scrubbed_all=>1}; |
71 |
push @errors, {scrubbed_all=>1}; |
72 |
} else { |
72 |
} else { |
73 |
if ($clean ne $review) { |
73 |
if ($clean ne $review) { |
74 |
push @errors, {scrubbed=>$clean}; |
74 |
push @errors, {scrubbed=>$clean}; |
75 |
} |
75 |
} |
76 |
my $js_ok_review = $clean; |
76 |
my $js_ok_review = $clean; |
77 |
$js_ok_review =~ s/"/"/g; # probably redundant w/ TMPL ESCAPE=JS |
77 |
$js_ok_review =~ s/"/"/gx; # probably redundant w/ TMPL ESCAPE=JS |
78 |
$template->param(clean_review=>$js_ok_review); |
78 |
$template->param(clean_review=>$js_ok_review); |
79 |
if ($editing) { |
79 |
if ($editing) { |
80 |
my $updatedreview = $savedreview->set( |
80 |
my $updatedreview = $savedreview->set( |
Lines 103-116
if( !@errors && $submitting ) {
Link Here
|
103 |
}); |
103 |
}); |
104 |
} |
104 |
} |
105 |
|
105 |
|
106 |
unless (@errors){ $template->param(WINDOW_CLOSE=>1); } |
106 |
if (@errors = 0){ $template->param(WINDOW_CLOSE=>1); } |
107 |
} |
107 |
} |
108 |
} |
108 |
} |
109 |
} |
109 |
} |
110 |
(@errors ) and $template->param( ERRORS=>\@errors); |
110 |
(@errors ) and $template->param( ERRORS=>\@errors); |
111 |
($cgi_debug) and $template->param(cgi_debug=>1 ); |
111 |
($cgi_debug) and $template->param(cgi_debug=>1 ); |
112 |
$review = $clean; |
112 |
$review = $clean; |
113 |
$review ||= $savedreview->review if $savedreview; |
113 |
if ($savedreview) { $review ||= $savedreview->review; } |
114 |
$template->param( |
114 |
$template->param( |
115 |
'biblionumber' => $biblionumber, |
115 |
'biblionumber' => $biblionumber, |
116 |
'borrowernumber' => $borrowernumber, |
116 |
'borrowernumber' => $borrowernumber, |
117 |
- |
|
|