Bug 32842: Fix cataloguing/value_builder/unimarc_field_123j.pl
[koha-ffzg.git] / tags / review.pl
index 3acf28a..c2c97c8 100755 (executable)
 # along with Koha; if not, see <http://www.gnu.org/licenses>.
 
 use Modern::Perl;
-use Data::Dumper;
-use POSIX;
+use POSIX qw( ceil );
 use CGI qw ( -utf8 );
 use CGI::Cookie;     # need to check cookies before having CGI parse the POST request
-use URI::Escape;
-use C4::Auth qw(:DEFAULT check_cookie_auth);
+use URI::Escape qw( uri_escape_utf8 );
+use C4::Auth qw( check_cookie_auth get_template_and_user );
 use C4::Context;
-use Koha::DateUtils;
-# use C4::Koha;
-use C4::Output qw(:html :ajax pagination_bar);
-use C4::Debug;
-use C4::Tags qw(get_tags get_approval_rows approval_counts whitelist blacklist is_approved);
+use C4::Output qw( output_with_http_headers is_ajax pagination_bar output_html_with_http_headers );
+use C4::Tags qw(
+    approval_counts
+    blacklist
+    get_approval_rows
+    is_approved
+    whitelist
+);
 
 my $script_name = "/cgi-bin/koha/tags/review.pl";
 my $needed_flags = { tools => 'moderate_tags' };    # FIXME: replace when more specific permission is created.
@@ -41,24 +43,19 @@ sub ajax_auth_cgi { # returns CGI object
     my %cookies = CGI::Cookie->fetch;
     my $input = CGI->new;
     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";
+    my ($auth_status) = check_cookie_auth($sessid, $needed_flags);
     if ($auth_status ne "ok") {
         output_with_http_headers $input, undef,
             "window.alert('Your CGI session cookie ($sessid) is not current.  " .
             "Please refresh the page and try again.');\n", 'js';
         exit 0;
     }
-    $debug and print STDERR "AJAX request: " . Dumper($input),
-        "\n(\$auth_status,\$auth_sessid) = ($auth_status,$auth_sessid)\n";
     return $input;
 }
 
 if (is_ajax()) {
     my $input = &ajax_auth_cgi($needed_flags);
     my $operator = C4::Context->userenv->{'number'};  # must occur AFTER auth
-    $debug and print STDERR "op: " . Dumper($operator) . "\n";
     my ($tag, $js_reply);
     if ($tag = $input->param('test')) {
         my $check = is_approved($tag);
@@ -82,7 +79,6 @@ my ($template, $borrowernumber, $cookie) = get_template_and_user(
         template_name   => "tags/review.tt",
         query           => $input,
         type            => "intranet",
-        debug           => 1,
         flagsrequired   => $needed_flags,
     }
 );
@@ -165,23 +161,15 @@ if ($filter = $input->param('tag')) {
     $template->param(filter_tag=>$filter);
     $filters{term} = $filter;
 }
-if ($filter = $input->param('from')) {
-        $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 {
-        push @errors, {date_from=>$filter};
-    }
+if ( $filter = $input->param('from') ) {
+    $date_from = $filter;
+    $template->param( filter_date_approved_from => $filter );
+    $filters{date_approved} = ">=$date_from";
 }
-if ($filter = $input->param('to')) {
-        $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 {
-        push @errors, {date_to=>$filter};
-    }
+if ( $filter = $input->param('to') ) {
+    $date_to = $filter;
+    $template->param( filter_date_approved_to => $filter );
+    $filters{date_approved} = "<=$date_to";
 }
 if ($filter = $input->param('approver')) {      # name (or borrowernumber) from input box
     if ($filter =~ /^\d+$/ and $filter > 0) {
@@ -201,13 +189,11 @@ if ($filter = $input->param('approved_by')) {   # borrowernumber from link
         push @errors, {approved_by=>$filter};
     }
 }
-$debug and print STDERR "filters: " . Dumper(\%filters);
 my $tagloop = get_approval_rows(\%filters);
 my $qstring = $input->query_string;
 $qstring =~ s/([&;])*\blimit=\d+//;         # remove pagination var
 $qstring =~ s/^;+//;                        # remove leading delims
 $qstring = "limit=$pagesize" . ($qstring ? '&amp;' . $qstring : '');
-$debug and print STDERR "number of approval_rows: " . scalar(@$tagloop) . "rows\n";
 (scalar @errors) and $template->param(message_loop=>\@errors);
 $template->param(
     offset => $offset,  # req'd for EXPR