Fix bug on opac-detail.pl with switch statement
[koha.git] / tools / viewlog.pl
blob84c247468b5e780948d81e99c4a4cd489089a2ef
1 #!/usr/bin/perl
4 # Copyright 2000-2002 Katipo Communications
6 # This file is part of Koha.
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.
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.
17 # You should have received a copy of the GNU General Public License along
18 # with Koha; if not, write to the Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 use strict;
22 #use warnings; FIXME - Bug 2505
23 use C4::Auth;
24 use CGI;
25 use C4::Context;
26 use C4::Koha;
27 use C4::Dates;
28 use C4::Output;
29 use C4::Log;
30 use C4::Items;
31 use C4::Branch;
32 use C4::Debug;
33 # use Data::Dumper;
34 use C4::Search; # enabled_staff_search_views
36 use vars qw($debug $cgi_debug);
38 =head1 viewlog.pl
40 plugin that shows stats
42 =cut
44 my $input = new CGI;
46 $debug or $debug = $cgi_debug;
47 my $do_it = $input->param('do_it');
48 my @modules = $input->param("modules");
49 my $user = $input->param("user");
50 my $action = $input->param("action");
51 my $object = $input->param("object");
52 my $info = $input->param("info");
53 my $datefrom = $input->param("from");
54 my $dateto = $input->param("to");
55 my $basename = $input->param("basename");
56 #my $del = $input->param("sep");
57 my $output = $input->param("output") || "screen";
58 my $src = $input->param("src"); # this param allows us to be told where we were called from -fbcit
60 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
62 template_name => "tools/viewlog.tmpl",
63 query => $input,
64 type => "intranet",
65 authnotrequired => 0,
66 flagsrequired => { tools => 'view_system_logs' },
67 debug => 1,
71 if ($src eq 'circ') { # if we were called from circulation, use the circulation menu and get data to populate it -fbcit
72 use C4::Members;
73 my $borrowernumber = $object;
74 my $data = GetMember('borrowernumber'=>$borrowernumber);
75 my ($picture, $dberror) = GetPatronImage($data->{'cardnumber'});
76 $template->param( picture => 1 ) if $picture;
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 categoryname => $data->{'description'},
86 address => $data->{'address'},
87 address2 => $data->{'address2'},
88 city => $data->{'city'},
89 zipcode => $data->{'zipcode'},
90 phone => $data->{'phone'},
91 phonepro => $data->{'phonepro'},
92 email => $data->{'email'},
93 branchcode => $data->{'branchcode'},
94 branchname => GetBranchName($data->{'branchcode'}),
98 $template->param(
99 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
100 dateformat => C4::Dates->new()->format(),
101 debug => $debug,
102 C4::Search::enabled_staff_search_views,
105 if ($do_it) {
107 my $results = GetLogs($datefrom,$dateto,$user,\@modules,$action,$object,$info);
108 my $total = scalar @$results;
109 foreach my $result (@$results){
110 if ($result->{'info'} eq 'item'){
111 # get item information so we can create a working link
112 my $item=GetItem($result->{'object'});
113 $result->{'biblionumber'}=$item->{'biblionumber'};
114 $result->{'biblioitemnumber'}=$item->{'biblionumber'};
118 if ( $output eq "screen" ) {
119 # Printing results to screen
120 $template->param (
121 logview => 1,
122 total => $total,
123 looprow => $results,
124 do_it => 1,
125 datefrom => $datefrom,
126 dateto => $dateto,
127 user => $user,
128 object => $object,
129 action => $action,
130 info => $info,
131 src => $src,
133 #module => 'fix this', #this seems unused in actual code
134 foreach my $module (@modules) {
135 $template->param($module => 1);
138 output_html_with_http_headers $input, $cookie, $template->output;
139 } else {
140 # Printing to a csv file
141 print $input->header(
142 -type => 'text/csv',
143 -attachment => "$basename.csv",
144 -filename => "$basename.csv"
146 my $sep = C4::Context->preference("delimiter");
147 foreach my $line (@$results) {
148 #next unless $modules[0] eq "catalogue";
149 foreach (qw(timestamp firstname surname action info title author)) {
150 print $line->{$_} . $sep;
154 exit;
155 } else {
156 #my @values;
157 #my %labels;
158 #my %select;
159 #initialize some paramaters that might not be used in the template - it seems to evaluate EXPR even if a false TMPL_IF
160 $template->param(
161 total => 0,
162 module => "",
163 info => ""
165 output_html_with_http_headers $input, $cookie, $template->output;