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