bug 2569: added the zipcode to display along with the patron address
[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                         zipcode         => $data->{'zipcode'},
92                         phone           => $data->{'phone'},
93                         phonepro        => $data->{'phonepro'},
94                         email           => $data->{'email'},
95                         branchcode      => $data->{'branchcode'},
96                         branchname              => GetBranchName($data->{'branchcode'}),
97     );
98 }
99
100 $template->param(
101         DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
102                       dateformat => C4::Dates->new()->format(),
103                                        debug => $debug,
104 );
105
106 if ($do_it) {
107
108     my $results = GetLogs($datefrom,$dateto,$user,$module,$action,$object,$info);
109     my $total = scalar @$results;
110     warn "Total records retrieved = $total";
111     foreach my $result (@$results){
112         if ($result->{'info'} eq 'item'){
113             # get item information so we can create a working link
114             my $item=GetItem($result->{'object'});
115             $result->{'biblionumber'}=$item->{'biblionumber'};
116             $result->{'biblioitemnumber'}=$item->{'biblionumber'};              
117         }
118     }
119     
120     if ( $output eq "screen" ) {
121         # Printing results to screen
122         $template->param (
123                         logview => 1,
124             total    => $total,
125             $module  => 1,
126             looprow  => $results,
127             do_it    => 1,
128             datefrom => $datefrom,
129             dateto   => $dateto,
130             user     => $user,
131             module   => $module,
132             object   => $object,
133             action   => $action,
134             info     => $info,
135             src      => $src,
136         );
137         output_html_with_http_headers $input, $cookie, $template->output;
138     } else {
139         # Printing to a csv file
140         print $input->header(
141             -type       => 'application/vnd.sun.xml.calc',
142             -attachment => "$basename.csv",
143             -filename   => "$basename.csv"
144         );
145         my $sep = C4::Context->preference("delimiter");
146         foreach my $line (@$results) {
147             ($module eq "catalogue") or next;
148                         foreach (qw(timestamp firstname surname action info title author)) {
149                                 print $line->{$_} . $sep;
150                         }       
151                 }
152     }
153         exit;
154 } else {
155     my @values;
156     my %labels;
157     my %select;
158     my @mime = ( C4::Context->preference("MIME") );
159     my $CGIextChoice = CGI::scrolling_list(
160         -name     => 'MIME',
161         -id       => 'MIME',
162         -values   => \@mime,
163         -size     => 1,
164         -multiple => 0
165     );
166     my @dels         = ( C4::Context->preference("delimiter") );
167     my $CGIsepChoice = CGI::scrolling_list(
168         -name     => 'sep',
169         -id       => 'sep',
170         -values   => \@dels,
171         -size     => 1,
172         -multiple => 0
173     );
174     $template->param(
175         total        => 0,
176         CGIextChoice => $CGIextChoice,
177         CGIsepChoice => $CGIsepChoice,
178     );
179     output_html_with_http_headers $input, $cookie, $template->output;
180 }