Modified log reporting to allow multiple modules to be selected.
[koha.git] / tools / viewlog.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it under the
9 # terms of the GNU General Public License as published by the Free Software
10 # Foundation; either version 2 of the License, or (at your option) any later
11 # version.
12 #
13 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
14 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
15 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License along with
18 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
19 # Suite 330, Boston, MA  02111-1307 USA
20
21 use strict;
22 use C4::Auth;
23 use CGI;
24 use C4::Context;
25 use C4::Koha;
26 use C4::Dates;
27 use C4::Output;
28 use C4::Log;
29 use C4::Items;
30 use C4::Branch;
31 use C4::Debug;
32 # use Data::Dumper;
33
34 use vars qw($debug $cgi_debug);
35
36 =head1 viewlog.pl
37
38 plugin that shows stats
39
40 =cut
41
42 my $input    = new CGI;
43
44 $debug or $debug = $cgi_debug;
45 my $do_it    = $input->param('do_it');
46 my @modules   = $input->param("modules");
47 my $user     = $input->param("user");
48 my $action   = $input->param("action");
49 my $object   = $input->param("object");
50 my $info     = $input->param("info");
51 my $datefrom = $input->param("from");
52 my $dateto   = $input->param("to");
53 my $basename = $input->param("basename");
54 my $mime     = $input->param("MIME");
55 #my $del      = $input->param("sep");
56 my $output   = $input->param("output") || "screen";
57 my $src      = $input->param("src");    # this param allows us to be told where we were called from -fbcit
58
59 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
60     {
61         template_name   => "tools/viewlog.tmpl",
62         query           => $input,
63         type            => "intranet",
64         authnotrequired => 0,
65         flagsrequired   => { tools => 'view_system_logs' },
66         debug           => 1,
67     }
68 );
69
70 if ($src eq 'circ') {   # if we were called from circulation, use the circulation menu and get data to populate it -fbcit
71     use C4::Members;
72     my $borrowernumber = $object;
73     my $data = GetMember($borrowernumber,'borrowernumber');
74     my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
75     $template->param( picture => 1 ) if $picture;
76     $template->param(   menu            => 1,
77                         title           => $data->{'title'},
78                         initials        => $data->{'initials'},
79                         surname         => $data->{'surname'},
80                         borrowernumber  => $borrowernumber,
81                         firstname       => $data->{'firstname'},
82                         cardnumber      => $data->{'cardnumber'},
83                         categorycode    => $data->{'categorycode'},
84                         categoryname    => $data->{'description'},
85                         address         => $data->{'address'},
86                         address2        => $data->{'address2'},
87                         city            => $data->{'city'},
88                         zipcode         => $data->{'zipcode'},
89                         phone           => $data->{'phone'},
90                         phonepro        => $data->{'phonepro'},
91                         email           => $data->{'email'},
92                         branchcode      => $data->{'branchcode'},
93                         branchname              => GetBranchName($data->{'branchcode'}),
94     );
95 }
96
97 $template->param(
98         DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
99                       dateformat => C4::Dates->new()->format(),
100                                        debug => $debug,
101 );
102 #
103 #### This code was never really used - maybe some day some will fix it ###
104 #my @mime = ( C4::Context->preference("MIME") );
105 #my $CGIextChoice = CGI::scrolling_list(
106 #        -name     => 'MIME',
107 #        -id       => 'MIME',
108 #        -values   => \@mime,
109 #        -size     => 1,
110 #        -multiple => 0
111 #);
112 #my @dels         = ( C4::Context->preference("delimiter") );
113 #my $CGIsepChoice = CGI::scrolling_list(
114 #        -name     => 'sep',
115 #        -id       => 'sep',
116 #        -values   => \@dels,
117 #        -size     => 1,
118 #        -multiple => 0
119 #);
120 #$template->param(
121 #        CGIextChoice => $CGIextChoice,
122 #        CGIsepChoice => $CGIsepChoice,
123 #);
124 #
125 if ($do_it) {
126
127     my $results = GetLogs($datefrom,$dateto,$user,\@modules,$action,$object,$info);
128     my $total = scalar @$results;
129     foreach my $result (@$results){
130         if ($result->{'info'} eq 'item'){
131             # get item information so we can create a working link
132             my $item=GetItem($result->{'object'});
133             $result->{'biblionumber'}=$item->{'biblionumber'};
134             $result->{'biblioitemnumber'}=$item->{'biblionumber'};              
135         }
136     }
137     
138     if ( $output eq "screen" ) {
139         # Printing results to screen
140         $template->param (
141                         logview => 1,
142             total    => $total,
143             looprow  => $results,
144             do_it    => 1,
145             datefrom => $datefrom,
146             dateto   => $dateto,
147             user     => $user,
148             object   => $object,
149             action   => $action,
150             info     => $info,
151             src      => $src,
152         );
153             #module   => 'fix this', #this seems unused in actual code
154         foreach my $module (@modules) {
155                 $template->param($module  => 1);
156         }
157
158         output_html_with_http_headers $input, $cookie, $template->output;
159     } else {
160         # Printing to a csv file
161         print $input->header(
162             -type       => 'text/csv',
163             -attachment => "$basename.csv",
164             -filename   => "$basename.csv"
165         );
166         my $sep = C4::Context->preference("delimiter");
167         foreach my $line (@$results) {
168             #next unless $modules[0] eq "catalogue";
169                 foreach (qw(timestamp firstname surname action info title author)) {
170                         print $line->{$_} . $sep;
171                 }       
172         }
173     }
174         exit;
175 } else {
176     #my @values;
177     #my %labels;
178     #my %select;
179         #initialize some paramaters that might not be used in the template - it seems to evaluate EXPR even if a false TMPL_IF
180         $template->param(
181                 total => 0,
182                 module => "",
183                 info => ""
184         );
185         output_html_with_http_headers $input, $cookie, $template->output;
186 }