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