Bug 29270: Expiration date must be in future
[koha-ffzg.git] / tools / viewlog.pl
index eb1a690..5909cb3 100755 (executable)
 
 use Modern::Perl;
 
-use C4::Auth;
+use C4::Auth qw( get_template_and_user );
 use CGI qw ( -utf8 );
 use Text::CSV::Encoded;
 use C4::Context;
-use C4::Koha;
-use C4::Output;
-use C4::Items;
-use C4::Serials;
-use C4::Debug;
-use C4::Search;    # enabled_staff_search_views
+use C4::Output qw( output_html_with_http_headers );
+use C4::Serials qw( CountSubscriptionFromBiblionumber );
+use C4::Search qw( enabled_staff_search_views );
 
 use Koha::ActionLogs;
 use Koha::Database;
-use Koha::DateUtils;
+use Koha::DateUtils qw( dt_from_string );
 use Koha::Items;
 use Koha::Patrons;
 
-use vars qw($debug $cgi_debug);
 
 =head1 viewlog.pl
 
@@ -45,9 +41,8 @@ plugin that shows stats
 
 =cut
 
-my $input = new CGI;
+my $input = CGI->new;
 
-$debug or $debug = $cgi_debug;
 my $do_it    = $input->param('do_it');
 my @modules  = $input->multi_param("modules");
 my $user     = $input->param("user") // '';
@@ -67,9 +62,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
         template_name   => "tools/viewlog.tt",
         query           => $input,
         type            => "intranet",
-        authnotrequired => 0,
         flagsrequired   => { tools => 'view_system_logs' },
-        debug           => 1,
     }
 );
 
@@ -89,9 +82,8 @@ if ( $src eq 'circ' ) {
 }
 
 $template->param(
-    debug => $debug,
     C4::Search::enabled_staff_search_views,
-    subscriptionsnumber => CountSubscriptionFromBiblionumber(scalar $input->param('object')),
+    subscriptionsnumber => ( $object ? CountSubscriptionFromBiblionumber($object) : 0 ),
     object => $object,
 );
 
@@ -187,6 +179,16 @@ if ($do_it) {
                 }
             }
         }
+
+        if ( $log->module eq 'NOTICES' ) {
+            if ( $log->object ) {
+                my $notice = Koha::Notice::Templates->find( { id => $log->object } );
+                if ($notice && $output eq 'screen') {
+                    $result->{notice} = $notice->unblessed;
+                }
+            }
+        }
+
         push @data, $result;
     }
     if ( $output eq "screen" ) {
@@ -217,7 +219,7 @@ if ($do_it) {
 
         # Printing to a csv file
         my $content = q{};
-        my $delimiter = C4::Context->preference('delimiter') || ',';
+        my $delimiter = C4::Context->preference('CSVDelimiter') || ',';
         if (@data) {
             my $csv = Text::CSV::Encoded->new( { encoding_out => 'utf8', sep_char => $delimiter } );
             $csv or die "Text::CSV::Encoded->new FAILED: " . Text::CSV::Encoded->error_diag();