Bug 3449: Fixes the perpetual error message that pops up when filtering by tag reviewer.
[koha.git] / tags / review.pl
index f6e9501..d4db972 100755 (executable)
@@ -35,7 +35,7 @@ use C4::Debug;
 use C4::Tags 0.03 qw(get_tags get_approval_rows approval_counts whitelist blacklist is_approved);
 
 my $script_name = "/cgi-bin/koha/tags/review.pl";
-my $needed_flags = { tools => 'moderate_comments' };   # FIXME: replace when more specific permission is created.
+my $needed_flags = { tools => 'moderate_tags' };       # FIXME: replace when more specific permission is created.
 
 sub ajax_auth_cgi ($) {                # returns CGI object
        my $needed_flags = shift;
@@ -46,9 +46,9 @@ sub ajax_auth_cgi ($) {               # returns CGI object
        $debug and
        print STDERR "($auth_status, $auth_sessid) = check_cookie_auth($sessid," . Dumper($needed_flags) . ")\n";
        if ($auth_status ne "ok") {
-               output_ajax_with_http_headers $input,
+               output_with_http_headers $input, undef,
                        "window.alert('Your CGI session cookie ($sessid) is not current.  " . 
-                       "Please refresh the page and try again.');\n";
+                       "Please refresh the page and try again.');\n", 'js';
                exit 0;
        }
        $debug and print STDERR "AJAX request: " . Dumper($input),
@@ -62,7 +62,9 @@ if (is_ajax()) {
        $debug and print STDERR "op: " . Dumper($operator) . "\n";
        my ($tag, $js_reply);
        if ($tag = $input->param('test')) {
-               $js_reply = ( is_approved(          $tag) ? 'success' : 'failure') . "_test('$tag');\n";
+               my $check = is_approved($tag);
+               $js_reply = ( $check >=  1 ? 'success' :
+                                         $check <= -1 ? 'failure' : 'indeterminate' ) . "_test('$tag');\n";
        }
        if ($tag = $input->param('ok')) {
                $js_reply = (   whitelist($operator,$tag) ? 'success' : 'failure') . "_approve('$tag');\n";
@@ -70,7 +72,7 @@ if (is_ajax()) {
        if ($tag = $input->param('rej')) {
                $js_reply = (   blacklist($operator,$tag) ? 'success' : 'failure')  . "_reject('$tag');\n";
        }
-       output_ajax_with_http_headers $input, $js_reply;
+       output_with_http_headers $input, undef, $js_reply, 'js';
        exit;
 }
 
@@ -87,7 +89,7 @@ my ($template, $borrowernumber, $cookie) = get_template_and_user({
 });
 
 my ($op, @errors, @tags);
-$op   = $input->param('op') || 'none';
+$op   = lc($input->param('op')) || 'none';
 @tags = $input->param('tags');
 
 $borrowernumber == 0 and push @errors, {op_zero=>1};
@@ -102,9 +104,11 @@ $borrowernumber == 0 and push @errors, {op_zero=>1};
 } elsif ($op eq 'test'   ) {
        my $tag = $input->param('test');
        push @tags, $tag;
+       my $check = is_approved($tag);
        $template->param(
                test_term => $tag,
-               (is_approved($tag) ? 'verdict_ok' : 'verdict_rej') => 1,
+               ( $check >=  1 ? 'verdict_ok' :
+                 $check <= -1 ? 'verdict_rej' : 'verdict_indeterminate' ) => 1,
        );
 }
 
@@ -174,11 +178,12 @@ if ($filter = $input->param('to')) {
        }
 }
 if ($filter = $input->param('approver')) {             # name (or borrowernumber) from input box
-       if (($filter =~ /^\d+$/ and $filter > 0) or
-               (1) ){  # $filter=get borrowernumber from name
+       if ($filter =~ /^\d+$/ and $filter > 0) {
+               # $filter=get borrowernumber from name
+               # FIXME: get borrowernumber from name not implemented.
                $template->param(filter_approver=>$filter);
                $filters{approved_by} = $filter;
-       } else {
+       } else {
                push @errors, {approver=>$filter};
        }
 }