X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=tags%2Freview.pl;h=b7e959b69bbf05e3ee4b63ca10ccd03fa2eb3251;hb=72fea80a33bc9ea57335e6d8c00500439a38b1c4;hp=010f133e5b2e0883c6a7aec747c457c50ecf2529;hpb=366affe1200b84a936f8fee6ff5568fac28bff50;p=koha.git diff --git a/tags/review.pl b/tags/review.pl index 010f133e5b..b7e959b69b 100755 --- a/tags/review.pl +++ b/tags/review.pl @@ -6,65 +6,49 @@ # # This file is part of Koha. # -# Koha is free software; you can redistribute it and/or modify it under the -# terms of the GNU General Public License as published by the Free Software -# Foundation; either version 2 of the License, or (at your option) any later -# version. +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. # -# Koha is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. # -# You should have received a copy of the GNU General Public License along with -# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . use warnings; use strict; use Data::Dumper; use POSIX; -use CGI; +use CGI qw ( -utf8 ); 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 Koha::DateUtils; # use C4::Koha; -use C4::Output 3.02 qw(:html :ajax pagination_bar); +use C4::Output 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 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; - my %cookies = fetch CGI::Cookie; + my %cookies = CGI::Cookie->fetch; my $input = CGI->new; - my $sessid = $cookies{'CGISESSID'}->value || $input->param('CGISESSID'); + my $sessid = $cookies{'CGISESSID'}->value; my ($auth_status, $auth_sessid) = check_cookie_auth($sessid, $needed_flags); $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), @@ -78,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"; @@ -86,25 +72,32 @@ 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; } ### Below is the sad, boring, necessary non-AJAX HTML code. my $input = CGI->new; -my ($template, $borrowernumber, $cookie) = get_template_and_user({ - template_name => "tags/review.tmpl", - query => $input, - type => "intranet", - debug => 1, - authnotrequired => 0, - flagsrequired => $needed_flags, -}); +my ($template, $borrowernumber, $cookie) = get_template_and_user( + { + template_name => "tags/review.tt", + query => $input, + type => "intranet", + debug => 1, + authnotrequired => 0, + flagsrequired => $needed_flags, + } +); my ($op, @errors, @tags); -$op = $input->param('op') || 'none'; -@tags = $input->param('tags'); + +foreach (qw( approve reject test )) { + $op = $_ if ( $input->param("op-$_") ); +} +$op ||= 'none'; + +@tags = $input->multi_param('tags'); $borrowernumber == 0 and push @errors, {op_zero=>1}; if ($op eq 'approve') { @@ -118,13 +111,15 @@ $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->{$_}); } @@ -174,7 +169,8 @@ if ($filter = $input->param('tag')) { $filters{term} = $filter; } if ($filter = $input->param('from')) { - if ($date_from = format_date_in_iso($filter)) { + $date_from = eval { output_pref( { dt => dt_from_string( $filter ), dateonly => 1, dateformat => 'iso' } ); }; + if ( $date_from ) { $template->param(filter_date_approved_from=>$filter); $filters{date_approved} = ">=$date_from"; } else { @@ -182,7 +178,8 @@ if ($filter = $input->param('from')) { } } if ($filter = $input->param('to')) { - if ($date_to = format_date_in_iso($filter)) { + $date_to = eval { output_pref( { dt => dt_from_string( $filter ), dateonly => 1, dateformat => 'iso' } ); }; + if ( $date_to ) { $template->param(filter_date_approved_to=>$filter); $filters{date_approved} = "<=$date_to"; } else { @@ -190,11 +187,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}; } } @@ -215,7 +213,6 @@ $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); $template->param( - DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(), offset => $offset, # req'd for EXPR op => $op, op_count => scalar(@tags),