Modified viewlog.pl to discern where it was called from and display the appropriate...
[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
30 use vars qw($debug);
31
32 BEGIN {
33         $debug = $ENV{DEBUG} || 0;
34 }
35
36 =head1 viewlog.pl
37
38 plugin that shows a stats on borrowers
39
40 =cut
41
42 my $input    = new CGI;
43 $debug or $debug = $input->param('debug') || 0;
44 my $do_it    = $input->param('do_it');
45 my $module   = $input->param("module");
46 my $user     = $input->param("user");
47 my $action   = $input->param("action");
48 my $object   = $input->param("object");
49 my $info     = $input->param("info");
50 my $datefrom = $input->param("from");
51 my $dateto   = $input->param("to");
52 my $basename = $input->param("basename");
53 my $mime     = $input->param("MIME");
54 my $del      = $input->param("sep");
55 my $output   = $input->param("output") || "screen";
56 my $src      = $input->param("src");    # this param allows us to be told where we were called from -fbcit
57
58 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
59     {
60         template_name   => "tools/viewlog.tmpl",
61         query           => $input,
62         type            => "intranet",
63         authnotrequired => 0,
64         flagsrequired   => { tools => 1 },
65         debug           => 1,
66     }
67 );
68
69 warn "Source of call was $src";
70
71 if ($src eq 'circ') {   # if we were called from circulation, use the circulation menu and get data to populate it -fbcit
72     use C4::Members;
73     my $borrowernumber = $object;
74     my $data = GetMember($borrowernumber,'borrowernumber');
75     my $picture = GetPatronImage($data->{'cardnumber'});
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                         address => $data->{'address'},
85                         address2 => $data->{'address2'},
86                         city => $data->{'city'},
87                         phone => $data->{'phone'},
88                         phonepro => $data->{'phonepro'},
89                         email => $data->{'email'},
90                         branchcode => $data->{'branchcode'},
91                         picture => $picture,
92     );
93 }
94
95 $template->param(
96         DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
97                       dateformat => C4::Dates->new()->format(),
98                                        debug => $debug,
99 );
100
101 if ($do_it) {
102
103     my $results = GetLogs($datefrom,$dateto,$user,$module,$action,$object,$info);
104     my $total = scalar @$results;
105     
106     if ( $output eq "screen" ) {
107         # Printing results to screen
108         $template->param (
109             total    => $total,
110             $module  => 1,
111             looprow  => $results,
112             do_it    => 1,
113             datefrom => $datefrom,
114             dateto   => $dateto,
115             user     => $user,
116             module   => $module,
117             object   => $object,
118             action   => $action,
119             info     => $info,
120         );
121         output_html_with_http_headers $input, $cookie, $template->output;
122     } else {
123         # Printing to a csv file
124         print $input->header(
125             -type       => 'application/vnd.sun.xml.calc',
126             -attachment => "$basename.csv",
127             -filename   => "$basename.csv"
128         );
129         my $sep = C4::Context->preference("delimiter");
130         foreach my $line (@$results) {
131             ($module eq "catalogue") or next;
132                         foreach (qw(timestamp firstname surname action info title author)) {
133                                 print $line->{$_} . $sep;
134                         }       
135                 }
136     }
137         exit;
138 } else {
139     my @values;
140     my %labels;
141     my %select;
142     my @mime = ( C4::Context->preference("MIME") );
143     my $CGIextChoice = CGI::scrolling_list(
144         -name     => 'MIME',
145         -id       => 'MIME',
146         -values   => \@mime,
147         -size     => 1,
148         -multiple => 0
149     );
150     my @dels         = ( C4::Context->preference("delimiter") );
151     my $CGIsepChoice = CGI::scrolling_list(
152         -name     => 'sep',
153         -id       => 'sep',
154         -values   => \@dels,
155         -size     => 1,
156         -multiple => 0
157     );
158     $template->param(
159         total        => 0,
160         CGIextChoice => $CGIextChoice,
161         CGIsepChoice => $CGIsepChoice,
162     );
163     output_html_with_http_headers $input, $cookie, $template->output;
164 }