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

(-)a/C4/Log.pm (-1 lines)
Lines 241-247 sub GetLogs { Link Here
241
    
241
    
242
    my @logs;
242
    my @logs;
243
    while( my $row = $sth->fetchrow_hashref ) {
243
    while( my $row = $sth->fetchrow_hashref ) {
244
        $row->{$row->{module}} = 1;
245
        push @logs , $row;
244
        push @logs , $row;
246
    }
245
    }
247
    return \@logs;
246
    return \@logs;
(-)a/tools/viewlog.pl (-22 / +41 lines)
Lines 18-27 Link Here
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
18
# with Koha; if not, write to the Free Software Foundation, Inc.,
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20
20
21
use strict;
21
use Modern::Perl;
22
#use warnings; FIXME - Bug 2505
22
23
use C4::Auth;
23
use C4::Auth;
24
use CGI;
24
use CGI;
25
use Text::CSV::Encoded;
25
use C4::Context;
26
use C4::Context;
26
use C4::Koha;
27
use C4::Koha;
27
use C4::Dates;
28
use C4::Dates;
Lines 131-152 if ($do_it) { Link Here
131
    @data=@$results;
132
    @data=@$results;
132
    my $total = scalar @data;
133
    my $total = scalar @data;
133
    foreach my $result (@data){
134
    foreach my $result (@data){
135
    # Init additional columns for CSV export
136
    $result->{'biblionumber'} = q{};
137
    $result->{'biblioitemnumber'} = q{};
138
    $result->{'barcode'} = q{};
139
    $result->{'userfirstname'} = q{};
140
    $result->{'usersurname'} = q{};
141
    $result->{'borrowerfirstname'} = q{};
142
    $result->{'borrowersurname'} = q{};
143
134
	if (substr($result->{'info'}, 0, 4) eq 'item' || $result->{module} eq "CIRCULATION"){
144
	if (substr($result->{'info'}, 0, 4) eq 'item' || $result->{module} eq "CIRCULATION"){
135
	    # get item information so we can create a working link
145
	    # get item information so we can create a working link
136
        my $itemnumber=$result->{'object'};
146
        my $itemnumber=$result->{'object'};
137
        $itemnumber=$result->{'info'} if ($result->{module} eq "CIRCULATION");
147
        $itemnumber=$result->{'info'} if ($result->{module} eq "CIRCULATION");
138
	    my $item=GetItem($itemnumber);
148
	    my $item=GetItem($itemnumber);
139
	    $result->{'biblionumber'}=$item->{'biblionumber'};
149
        if ($item) {
140
	    $result->{'biblioitemnumber'}=$item->{'biblionumber'};		
150
            $result->{'biblionumber'}=$item->{'biblionumber'};
141
        $result->{'barcode'}=$item->{'barcode'};
151
            $result->{'biblioitemnumber'}=$item->{'biblionumber'};
152
            $result->{'barcode'}=$item->{'barcode'};
153
        }
142
	}
154
	}
143
    #always add firstname and surname for librarian/user
155
    #always add firstname and surname for librarian/user
144
    if ($result->{'user'}){
156
    if ($result->{'user'}){
145
        my $userdetails = C4::Members::GetMemberDetails($result->{'user'});
157
        my $userdetails = C4::Members::GetMemberDetails($result->{'user'});
146
        if ($userdetails->{'firstname'}){
158
        if ($userdetails){
147
            $result->{'userfirstname'} = $userdetails->{'firstname'};
159
            $result->{'userfirstname'} = $userdetails->{'firstname'};
148
        }
149
        if ($userdetails->{'surname'}){
150
            $result->{'usersurname'} = $userdetails->{'surname'};
160
            $result->{'usersurname'} = $userdetails->{'surname'};
151
        }
161
        }
152
    }
162
    }
Lines 154-163 if ($do_it) { Link Here
154
    if ($result->{module} eq "CIRCULATION" || $result->{module} eq "MEMBERS" || $result->{module} eq "FINES"){
164
    if ($result->{module} eq "CIRCULATION" || $result->{module} eq "MEMBERS" || $result->{module} eq "FINES"){
155
        if($result->{'object'}){
165
        if($result->{'object'}){
156
            my $borrowerdetails = C4::Members::GetMemberDetails($result->{'object'});
166
            my $borrowerdetails = C4::Members::GetMemberDetails($result->{'object'});
157
            if ($borrowerdetails->{'firstname'}){
167
            if ($borrowerdetails){
158
            $result->{'borrowerfirstname'} = $borrowerdetails->{'firstname'};
168
                $result->{'borrowerfirstname'} = $borrowerdetails->{'firstname'};
159
            }
160
            if ($borrowerdetails->{'surname'}){
161
                $result->{'borrowersurname'} = $borrowerdetails->{'surname'};
169
                $result->{'borrowersurname'} = $borrowerdetails->{'surname'};
162
            }
170
            }
163
        }
171
        }
Lines 187-204 if ($do_it) { Link Here
187
        output_html_with_http_headers $input, $cookie, $template->output;
195
        output_html_with_http_headers $input, $cookie, $template->output;
188
    } else {
196
    } else {
189
        # Printing to a csv file
197
        # Printing to a csv file
198
        my $content = q{};
199
        my $delimiter = C4::Context->preference('delimiter') || ',';
200
        if (@data) {
201
            my $csv = Text::CSV::Encoded->new( { encoding_out => 'utf8', sep_char => $delimiter } );
202
            $csv or die "Text::CSV::Encoded->new FAILED: " . Text::CSV::Encoded->error_diag();
203
            # First line with heading
204
            # Exporting bd id seems useless
205
            my @headings = grep { $_ ne 'action_id' } sort keys $data[0];
206
            if ( $csv->combine( @headings ) ) {
207
                $content .= $csv->string() . "\n";
208
            }
209
            # Lines of logs
210
            foreach my $line (@data) {
211
                my @cells = map { $line->{$_} } @headings;
212
                if ( $csv->combine( @cells ) ) {
213
                    $content .= $csv->string() . "\n";
214
                }
215
            }
216
        }
190
        print $input->header(
217
        print $input->header(
191
            -type       => 'text/csv',
218
            -type       => 'text/csv',
192
            -attachment => "$basename.csv",
219
            -attachment => $basename . '.csv',
193
            -filename   => "$basename.csv"
194
        );
220
        );
195
        my $sep = C4::Context->preference("delimiter");
221
        print $content;
196
        foreach my $line (@data) {
197
            #next unless $modules[0] eq "catalogue";
198
		foreach (qw(timestamp firstname surname action info title author)) {
199
			print $line->{$_} . $sep;
200
		}	
201
	}
202
    }
222
    }
203
	exit;
223
	exit;
204
} else {
224
} else {
205
- 

Return to bug 11331