View | Details | Raw Unified | Return to bug 22363
Collapse All | Expand All

(-)a/tools/viewlog.pl (-20 / +53 lines)
Lines 26-36 use Text::CSV::Encoded; Link Here
26
use C4::Context;
26
use C4::Context;
27
use C4::Koha;
27
use C4::Koha;
28
use C4::Output;
28
use C4::Output;
29
use C4::Log;
30
use C4::Items;
29
use C4::Items;
31
use C4::Serials;
30
use C4::Serials;
32
use C4::Debug;
31
use C4::Debug;
33
use C4::Search;    # enabled_staff_search_views
32
use C4::Search;    # enabled_staff_search_views
33
use Koha::ActionLogs;
34
use Koha::Database;
35
use Koha::DateUtils;
34
use Koha::Patrons;
36
use Koha::Patrons;
35
37
36
use vars qw($debug $cgi_debug);
38
use vars qw($debug $cgi_debug);
Lines 100-125 $template->param( Link Here
100
);
102
);
101
103
102
if ($do_it) {
104
if ($do_it) {
105
    my $dtf = Koha::Database->new->schema->storage->datetime_parser;
106
    my %search_params;
107
108
    if ($datefrom and $dateto ) {
109
        my $dateto_endday = dt_from_string($dateto);
110
        $dateto_endday->set( # We set last second of day to see all log from that day
111
            hour => 23,
112
            minute => 59,
113
            second => 59
114
        );
115
        $search_params{'timestamp'} = {
116
            -between => [
117
                $dtf->format_datetime( dt_from_string($datefrom) ),
118
                $dtf->format_datetime( $dateto_endday ),
119
            ]
120
        };
121
    } elsif ($datefrom) {
122
        $search_params{'timestamp'} = {
123
            '>=' => $dtf->format_datetime( dt_from_string($datefrom) )
124
        };
125
    } elsif ($dateto) {
126
        my $dateto_endday = dt_from_string($dateto);
127
        $dateto_endday->set( # We set last second of day to see all log from that day
128
            hour => 23,
129
            minute => 59,
130
            second => 59
131
        );
132
        $search_params{'timestamp'} = {
133
            '<=' => $dtf->format_datetime( $dateto_endday )
134
        };
135
    }
136
    $search_params{user} = $user if $user;
137
    $search_params{module} = { -in => [ @modules ] } if ( defined $modules[0] and $modules[0] ne '' ) ;
138
    $search_params{action} = { -in => [ @actions ] } if ( defined $actions[0] && $actions[0] ne '' );
139
    $search_params{object} = $object if $object;
140
    $search_params{info} = $info if $info;
141
    $search_params{interface} = { -in => [ @interfaces ] } if ( defined $interfaces[0] && $interfaces[0] ne '' );
103
142
104
    my @data;
143
    my @logs = Koha::ActionLogs->search(\%search_params);
105
    my ( $results, $modules, $actions, $interfaces );
106
    if ( defined $actions[0] && $actions[0] ne '' ) { $actions  = \@actions; }     # match All means no limit
107
    if ( $modules[0] ne '' ) { $modules = \@modules; }    # match All means no limit
108
    if ( defined $interfaces[0] && $interfaces[0] ne '' ) { $interfaces = \@interfaces; }    # match All means no limit
109
    $results = GetLogs( $datefrom, $dateto, $user, $modules, $actions, $object, $info, $interfaces );
110
    @data = @$results;
111
    foreach my $result (@data) {
112
144
145
    my @data;
146
    foreach my $log (@logs) {
147
        my $result = $log->unblessed;
113
        # Init additional columns for CSV export
148
        # Init additional columns for CSV export
114
        $result->{'biblionumber'}      = q{};
149
        $result->{'biblionumber'}      = q{};
115
        $result->{'biblioitemnumber'}  = q{};
150
        $result->{'biblioitemnumber'}  = q{};
116
        $result->{'barcode'}           = q{};
151
        $result->{'barcode'}           = q{};
117
152
118
        if ( substr( $result->{'info'}, 0, 4 ) eq 'item' || $result->{module} eq "CIRCULATION" ) {
153
        if ( substr( $log->info, 0, 4 ) eq 'item' || $log->module eq "CIRCULATION" ) {
119
154
120
            # get item information so we can create a working link
155
            # get item information so we can create a working link
121
            my $itemnumber = $result->{'object'};
156
            my $itemnumber = $log->object;
122
            $itemnumber = $result->{'info'} if ( $result->{module} eq "CIRCULATION" );
157
            $itemnumber = $log->info if ( $log->module eq "CIRCULATION" );
123
            my $item = GetItem($itemnumber);
158
            my $item = GetItem($itemnumber);
124
            if ($item) {
159
            if ($item) {
125
                $result->{'biblionumber'}     = $item->{'biblionumber'};
160
                $result->{'biblionumber'}     = $item->{'biblionumber'};
Lines 129-152 if ($do_it) { Link Here
129
        }
164
        }
130
165
131
        #always add firstname and surname for librarian/user
166
        #always add firstname and surname for librarian/user
132
        if ( $result->{'user'} ) {
167
        if ( $log->user ) {
133
            my $patron = Koha::Patrons->find( $result->{'user'} );
168
            my $patron = Koha::Patrons->find( $log->user );
134
            if ($patron) {
169
            if ($patron) {
135
                $result->{librarian} = $patron;
170
                $result->{librarian} = $patron;
136
            }
171
            }
137
        }
172
        }
138
173
139
        #add firstname and surname for borrower, when using the CIRCULATION, MEMBERS, FINES
174
        #add firstname and surname for borrower, when using the CIRCULATION, MEMBERS, FINES
140
        if ( $result->{module} eq "CIRCULATION" || $result->{module} eq "MEMBERS" || $result->{module} eq "FINES" ) {
175
        if ( $log->module eq "CIRCULATION" || $log->module eq "MEMBERS" || $log->module eq "FINES" ) {
141
            if ( $result->{'object'} ) {
176
            if ( $log->object ) {
142
                my $patron = Koha::Patrons->find( $result->{'object'} );
177
                my $patron = Koha::Patrons->find( $log->object );
143
                if ($patron) {
178
                if ($patron) {
144
                    $result->{patron} = $patron;
179
                    $result->{patron} = $patron;
145
                }
180
                }
146
            }
181
            }
147
        }
182
        }
183
        push @data, $result;
148
    }
184
    }
149
150
    if ( $output eq "screen" ) {
185
    if ( $output eq "screen" ) {
151
186
152
        # Printing results to screen
187
        # Printing results to screen
Lines 169-175 if ($do_it) { Link Here
169
        foreach my $module (@modules) {
204
        foreach my $module (@modules) {
170
            $template->param( $module => 1 );
205
            $template->param( $module => 1 );
171
        }
206
        }
172
173
        output_html_with_http_headers $input, $cookie, $template->output;
207
        output_html_with_http_headers $input, $cookie, $template->output;
174
    }
208
    }
175
    else {
209
    else {
176
- 

Return to bug 22363