Patch from Joe Atzberger to remove $Id$ and $Log$ from scripts
[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::Output;
27 use C4::Log;
28 use Date::Manip;
29
30 =head1 viewlog.pl
31
32 plugin that shows a stats on borrowers
33
34 =cut
35
36 my $input    = new CGI;
37 my $do_it    = $input->param('do_it');
38 my $module   = $input->param("module");
39 my $user     = $input->param("user");
40 my $action   = $input->param("action");
41 my $object   = $input->param("object");
42 my $info     = $input->param("info");
43 my $datefrom = $input->param("from");
44 my $dateto   = $input->param("to");
45 my $basename = $input->param("basename");
46 my $mime     = $input->param("MIME");
47 my $del      = $input->param("sep");
48 my $output   = $input->param("output") || "screen";
49
50 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
51     {
52         template_name   => "tools/viewlog.tmpl",
53         query           => $input,
54         type            => "intranet",
55         authnotrequired => 0,
56         flagsrequired   => { tools => 1 },
57         debug           => 1,
58     }
59 );
60
61 if ($do_it) {
62
63     my $results = GetLogs($datefrom,$dateto,$user,$module,$action,$object,$info);
64     my $total = scalar @$results;
65     
66     if ( $output eq "screen" ) {
67
68         # Printing results to screen
69         $template->param (
70             total    => $total,
71             $module  => 1,
72             looprow  => $results,
73             do_it    => 1,
74             datefrom => $datefrom,
75             dateto   => $dateto,
76             user     => $user,
77             module   => $module,
78             object   => $object,
79             action   => $action,
80             info     => $info,
81         );
82         output_html_with_http_headers $input, $cookie, $template->output;
83         exit;
84     }
85     else {
86
87         # Printing to a csv file
88         print $input->header(
89             -type       => 'application/vnd.sun.xml.calc',
90             -attachment => "$basename.csv",
91             -filename   => "$basename.csv"
92         );
93         my $sep;
94         $sep = C4::Context->preference("delimiter");
95
96         foreach my $line (@$results) {
97             if ( $module eq "catalogue" ) {
98                 print $line->{timestamp} . $sep;
99                 print $line->{firstname} . $sep;
100                 print $line->{surname} . $sep;
101                 print $line->{action} . $sep;
102                 print $line->{info} . $sep;
103                 print $line->{title} . $sep;
104                 print $line->{author} . $sep;
105             }
106         }
107
108         exit;
109     }
110 }
111 else {
112     my $dbh = C4::Context->dbh;
113     my @values;
114     my %labels;
115     my %select;
116     my $req;
117
118     my @mime = ( C4::Context->preference("MIME") );
119
120     my $CGIextChoice = CGI::scrolling_list(
121         -name     => 'MIME',
122         -id       => 'MIME',
123         -values   => \@mime,
124         -size     => 1,
125         -multiple => 0
126     );
127
128     my @dels         = ( C4::Context->preference("delimiter") );
129     my $CGIsepChoice = CGI::scrolling_list(
130         -name     => 'sep',
131         -id       => 'sep',
132         -values   => \@dels,
133         -size     => 1,
134         -multiple => 0
135     );
136
137     $template->param(
138         total        => 0,
139         CGIextChoice => $CGIextChoice,
140         CGIsepChoice => $CGIsepChoice,
141         DHTMLcalendar_dateformat => get_date_format_string_for_DHTMLcalendar(),
142     );
143     output_html_with_http_headers $input, $cookie, $template->output;
144 }