Fixing error trap routine in picture-upload.pl
[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 = GetPatronImage($data->{'cardnumber'});
77     $template->param(   menu => 1,
78                         title => $data->{'title'},
79                         initials => $data->{'initials'},
80                         surname => $data->{'surname'},
81                         borrowernumber => $borrowernumber,
82                         firstname => $data->{'firstname'},
83                         cardnumber => $data->{'cardnumber'},
84                         categorycode => $data->{'categorycode'},
85                         address => $data->{'address'},
86                         address2 => $data->{'address2'},
87                         city => $data->{'city'},
88                         phone => $data->{'phone'},
89                         phonepro => $data->{'phonepro'},
90                         email => $data->{'email'},
91                         branchcode => $data->{'branchcode'},
92                         picture => $picture,
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             total    => $total,
119             $module  => 1,
120             looprow  => $results,
121             do_it    => 1,
122             datefrom => $datefrom,
123             dateto   => $dateto,
124             user     => $user,
125             module   => $module,
126             object   => $object,
127             action   => $action,
128             info     => $info,
129         );
130         output_html_with_http_headers $input, $cookie, $template->output;
131     } else {
132         # Printing to a csv file
133         print $input->header(
134             -type       => 'application/vnd.sun.xml.calc',
135             -attachment => "$basename.csv",
136             -filename   => "$basename.csv"
137         );
138         my $sep = C4::Context->preference("delimiter");
139         foreach my $line (@$results) {
140             ($module eq "catalogue") or next;
141                         foreach (qw(timestamp firstname surname action info title author)) {
142                                 print $line->{$_} . $sep;
143                         }       
144                 }
145     }
146         exit;
147 } else {
148     my @values;
149     my %labels;
150     my %select;
151     my @mime = ( C4::Context->preference("MIME") );
152     my $CGIextChoice = CGI::scrolling_list(
153         -name     => 'MIME',
154         -id       => 'MIME',
155         -values   => \@mime,
156         -size     => 1,
157         -multiple => 0
158     );
159     my @dels         = ( C4::Context->preference("delimiter") );
160     my $CGIsepChoice = CGI::scrolling_list(
161         -name     => 'sep',
162         -id       => 'sep',
163         -values   => \@dels,
164         -size     => 1,
165         -multiple => 0
166     );
167     $template->param(
168         total        => 0,
169         CGIextChoice => $CGIextChoice,
170         CGIsepChoice => $CGIsepChoice,
171     );
172     output_html_with_http_headers $input, $cookie, $template->output;
173 }