View | Details | Raw Unified | Return to bug 13342
Collapse All | Expand All

(-)a/opac/opac-review.pl (-32 / +31 lines)
Lines 36-97 my $op = $query->param('op') // q{}; Link Here
36
36
37
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
37
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
38
    {
38
    {
39
        template_name   => "opac-review.tt",
39
        template_name => "opac-review.tt",
40
        query           => $query,
40
        query         => $query,
41
        type            => "opac",
41
        type          => "opac",
42
        authnotrequired => ( C4::Context->preference("OpacPublic") ? 1 : 0 ),
43
    }
42
    }
44
);
43
);
45
44
46
# FIXME: need to allow user to delete their own comment(s)
45
# FIXME: need to allow user to delete their own comment(s)
47
46
48
my ( $clean, @errors, $savedreview );
47
my ( $clean, @errors, $savedreview );
49
my $biblio = Koha::Biblios->find( $biblionumber );
48
my $biblio = Koha::Biblios->find($biblionumber);
50
49
51
if( !$biblio ) {
50
if ( !$biblio ) {
52
    push @errors, { nobiblio => 1 };
51
    push @errors, { nobiblio => 1 };
53
} elsif( $reviewid ) { # edit existing one, check on creator
52
} elsif ($reviewid) {    # edit existing one, check on creator
54
    $savedreview = Koha::Reviews->search({ reviewid => $reviewid, borrowernumber => $borrowernumber })->next;
53
    $savedreview = Koha::Reviews->search( { reviewid => $reviewid, borrowernumber => $borrowernumber } )->next;
55
    push @errors, { unauthorized => 1 } if !$savedreview;
54
    push @errors, { unauthorized => 1 } if !$savedreview;
56
} else { # this check prevents adding multiple comments
55
} else {    # this check prevents adding multiple comments
57
    # FIXME biblionumber, borrowernumber should be a unique key of reviews
56
            # FIXME biblionumber, borrowernumber should be a unique key of reviews
58
    $savedreview = Koha::Reviews->search({ biblionumber => $biblionumber, borrowernumber => $borrowernumber })->next;
57
    $savedreview = Koha::Reviews->search( { biblionumber => $biblionumber, borrowernumber => $borrowernumber } )->next;
59
    $review = $savedreview? $savedreview->review: $review;
58
    $review      = $savedreview ? $savedreview->review : $review;
60
}
59
}
61
60
62
if( $op =~ /^cud-/ && !@errors && defined $review ) {
61
if ( $op =~ /^cud-/ && !@errors && defined $review ) {
63
	if ($review !~ /\S/) {
62
    if ( $review !~ /\S/ ) {
64
		push @errors, {empty=>1};
63
        push @errors, { empty => 1 };
65
	} else {
64
    } else {
66
		$clean = C4::Scrubber->new('comment')->scrub($review);
65
        $clean = C4::Scrubber->new('comment')->scrub($review);
67
		if ($clean !~ /\S/) {
66
        if ( $clean !~ /\S/ ) {
68
			push @errors, {scrubbed_all=>1};
67
            push @errors, { scrubbed_all => 1 };
69
		} else {
68
        } else {
70
			if ($clean ne $review) {
69
            if ( $clean ne $review ) {
71
				push @errors, {scrubbed=>$clean};
70
                push @errors, { scrubbed => $clean };
72
			}
71
            }
73
            if ($savedreview) {
72
            if ($savedreview) {
74
                $savedreview->set(
73
                $savedreview->set(
75
                    {
74
                    {
76
                        review        => $clean,
75
                        review       => $clean,
77
                        approved      => 0,
76
                        approved     => 0,
78
                        datereviewed  => dt_from_string
77
                        datereviewed => dt_from_string
79
                    }
78
                    }
80
                )->store;
79
                )->store;
81
            } else {
80
            } else {
82
                $reviewid = Koha::Review->new(
81
                $reviewid = Koha::Review->new(
83
                    {   biblionumber   => $biblionumber,
82
                    {
83
                        biblionumber   => $biblionumber,
84
                        borrowernumber => $borrowernumber,
84
                        borrowernumber => $borrowernumber,
85
                        review         => $clean,
85
                        review         => $clean,
86
                        datereviewed   => dt_from_string
86
                        datereviewed   => dt_from_string
87
                    }
87
                    }
88
                )->store->reviewid;
88
                )->store->reviewid;
89
            }
89
            }
90
			unless (@errors){ $template->param(WINDOW_CLOSE=>1); }
90
            unless (@errors) { $template->param( WINDOW_CLOSE => 1 ); }
91
		}
91
        }
92
	}
92
    }
93
}
93
}
94
(@errors   ) and $template->param(   ERRORS=>\@errors);
94
(@errors) and $template->param( ERRORS => \@errors );
95
$review = $clean;
95
$review = $clean;
96
$review ||= $savedreview->review if $savedreview;
96
$review ||= $savedreview->review if $savedreview;
97
$template->param(
97
$template->param(
98
- 

Return to bug 13342