Removing $dbh from GetMarcFromKohaField (dbh is not used in this function.)
[koha.git] / tools / viewlog.pl
1 #!/usr/bin/perl
2
3 # $Id$
4
5 # Copyright 2000-2002 Katipo Communications
6 #
7 # This file is part of Koha.
8 #
9 # Koha is free software; you can redistribute it and/or modify it under the
10 # terms of the GNU General Public License as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option) any later
12 # version.
13 #
14 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License along with
19 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
20 # Suite 330, Boston, MA  02111-1307 USA
21
22 use strict;
23 use C4::Auth;
24 use CGI;
25 use C4::Context;
26 use C4::Koha;
27 use C4::Output;
28 use C4::Log;
29 use Date::Manip;
30
31 =head1 viewlog.pl
32
33 plugin that shows a stats on borrowers
34
35 =cut
36
37 my $input    = new CGI;
38 my $do_it    = $input->param('do_it');
39 my $module   = $input->param("module");
40 my $user     = $input->param("user");
41 my $action   = $input->param("action");
42 my $object   = $input->param("object");
43 my $info     = $input->param("info");
44 my $datefrom = $input->param("from");
45 my $dateto   = $input->param("to");
46 my $basename = $input->param("basename");
47 my $mime     = $input->param("MIME");
48 my $del      = $input->param("sep");
49 my $output   = $input->param("output") || "screen";
50
51 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
52     {
53         template_name   => "tools/viewlog.tmpl",
54         query           => $input,
55         type            => "intranet",
56         authnotrequired => 0,
57         flagsrequired   => { tools => 1 },
58         debug           => 1,
59     }
60 );
61
62 if ($do_it) {
63
64     my $results = GetLogs($datefrom,$dateto,$user,$module,$action,$object,$info);
65     my $total = scalar @$results;
66     
67     if ( $output eq "screen" ) {
68
69         # Printing results to screen
70         $template->param (
71             total    => $total,
72             $module  => 1,
73             looprow  => $results,
74             do_it    => 1,
75             datefrom => $datefrom,
76             dateto   => $dateto,
77             user     => $user,
78             module   => $module,
79             object   => $object,
80             action   => $action,
81             info     => $info,
82         );
83         output_html_with_http_headers $input, $cookie, $template->output;
84         exit;
85     }
86     else {
87
88         # Printing to a csv file
89         print $input->header(
90             -type       => 'application/vnd.sun.xml.calc',
91             -attachment => "$basename.csv",
92             -filename   => "$basename.csv"
93         );
94         my $sep;
95         $sep = C4::Context->preference("delimiter");
96
97         foreach my $line (@$results) {
98             if ( $module eq "catalogue" ) {
99                 print $line->{timestamp} . $sep;
100                 print $line->{firstname} . $sep;
101                 print $line->{surname} . $sep;
102                 print $line->{action} . $sep;
103                 print $line->{info} . $sep;
104                 print $line->{title} . $sep;
105                 print $line->{author} . $sep;
106             }
107         }
108
109         exit;
110     }
111 }
112 else {
113     my $dbh = C4::Context->dbh;
114     my @values;
115     my %labels;
116     my %select;
117     my $req;
118
119     my @mime = ( C4::Context->preference("MIME") );
120
121     my $CGIextChoice = CGI::scrolling_list(
122         -name     => 'MIME',
123         -id       => 'MIME',
124         -values   => \@mime,
125         -size     => 1,
126         -multiple => 0
127     );
128
129     my @dels         = ( C4::Context->preference("delimiter") );
130     my $CGIsepChoice = CGI::scrolling_list(
131         -name     => 'sep',
132         -id       => 'sep',
133         -values   => \@dels,
134         -size     => 1,
135         -multiple => 0
136     );
137
138     $template->param(
139         total        => 0,
140         CGIextChoice => $CGIextChoice,
141         CGIsepChoice => $CGIsepChoice
142     );
143     output_html_with_http_headers $input, $cookie, $template->output;
144 }