use CGI;
use CGI::Cookie; # need to check cookies before having CGI parse the POST request
-use C4::Auth qw(:DEFAULT check_cookie_auth);;
+use C4::Auth qw(:DEFAULT check_cookie_auth);
use C4::Context;
use C4::Dates qw(format_date format_date_in_iso);
# use C4::Koha;
use C4::Output 3.02 qw(:html :ajax pagination_bar);
use C4::Debug;
-use C4::Tags 0.02 qw(get_tags get_approval_rows whitelist blacklist is_approved);
-
-sub counts () {
- my $query = "SELECT " .
- # (SELECT count(*) FROM tags_all ) as tags_all,
- # (SELECT count(*) FROM tags_index ) as tags_index,
- " (SELECT count(*) FROM tags_approval WHERE approved= 1) as approved_count,
- (SELECT count(*) FROM tags_approval WHERE approved=-1) as rejected_count,
- (SELECT count(*) FROM tags_approval WHERE approved= 0) as unapproved_count
- ";
- my $sth = C4::Context->dbh->prepare($query);
- $sth->execute;
- my $result = $sth->fetchrow_hashref();
- $result->{approved_total} = $result->{approved_count} + $result->{rejected_count} + $result->{unapproved_count};
- $debug and warn "counts returned: " . Dumper $result;
- return $result;
-}
+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.
$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),
$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";
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;
}
});
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};
} 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,
);
}
-my $counts = &counts;
+my $counts = &approval_counts;
foreach (keys %$counts) {
$template->param($_ => $counts->{$_});
}
$debug and print STDERR "filters: " . Dumper(\%filters);
my $tagloop = get_approval_rows(\%filters);
my $qstring = $input->query_string;
-$qstring =~ s/([&;])*\blimit=\d+//; # remove pagination vars
-# $qstring =~ s/([&;])*\bpage=\d+//; # remove pagination vars
-# $qstring =~ s/\&[\&]+/&/g; # compress duplicates
-# $qstring =~ s/;;+/;/g; # compress duplicates
-# $qstring =~ s/\&;//g; # remove empties
-# $qstring =~ s/;+$//; # remove trailing delim
-$qstring =~ s/^;+//; # remove leading delim
+$qstring =~ s/([&;])*\blimit=\d+//; # remove pagination var
+$qstring =~ s/^;+//; # remove leading delims
$qstring = "limit=$pagesize" . ($qstring ? '&' . $qstring : '');
$debug and print STDERR "number of approval_rows: " . scalar(@$tagloop) . "rows\n";
(scalar @errors) and $template->param(message_loop=>\@errors);
output_html_with_http_headers $input, $cookie, $template->output;
__END__
+=head1 AUTHOR
+
+Joe Atzberger
+atz AT liblime.com
+
+=cut