Correct URL for Baker & Taylor ContentCafe
[koha.git] / tools / viewlog.pl
blob48804517fe054374404a99e20a23060f74e743b1
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 $mime = $input->param("MIME");
57 #my $del = $input->param("sep");
58 my $output = $input->param("output") || "screen";
59 my $src = $input->param("src"); # this param allows us to be told where we were called from -fbcit
61 my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
63 template_name => "tools/viewlog.tmpl",
64 query => $input,
65 type => "intranet",
66 authnotrequired => 0,
67 flagsrequired => { tools => 'view_system_logs' },
68 debug => 1,
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 categoryname => $data->{'description'},
87 address => $data->{'address'},
88 address2 => $data->{'address2'},
89 city => $data->{'city'},
90 zipcode => $data->{'zipcode'},
91 phone => $data->{'phone'},
92 phonepro => $data->{'phonepro'},
93 email => $data->{'email'},
94 branchcode => $data->{'branchcode'},
95 branchname => GetBranchName($data->{'branchcode'}),
99 $template->param(
100 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
101 dateformat => C4::Dates->new()->format(),
102 debug => $debug,
103 C4::Search::enabled_staff_search_views,
106 #### This code was never really used - maybe some day some will fix it ###
107 #my @mime = ( C4::Context->preference("MIME") );
108 #my $CGIextChoice = CGI::scrolling_list(
109 # -name => 'MIME',
110 # -id => 'MIME',
111 # -values => \@mime,
112 # -size => 1,
113 # -multiple => 0
115 #my @dels = ( C4::Context->preference("delimiter") );
116 #my $CGIsepChoice = CGI::scrolling_list(
117 # -name => 'sep',
118 # -id => 'sep',
119 # -values => \@dels,
120 # -size => 1,
121 # -multiple => 0
123 #$template->param(
124 # CGIextChoice => $CGIextChoice,
125 # CGIsepChoice => $CGIsepChoice,
128 if ($do_it) {
130 my $results = GetLogs($datefrom,$dateto,$user,\@modules,$action,$object,$info);
131 my $total = scalar @$results;
132 foreach my $result (@$results){
133 if ($result->{'info'} eq 'item'){
134 # get item information so we can create a working link
135 my $item=GetItem($result->{'object'});
136 $result->{'biblionumber'}=$item->{'biblionumber'};
137 $result->{'biblioitemnumber'}=$item->{'biblionumber'};
141 if ( $output eq "screen" ) {
142 # Printing results to screen
143 $template->param (
144 logview => 1,
145 total => $total,
146 looprow => $results,
147 do_it => 1,
148 datefrom => $datefrom,
149 dateto => $dateto,
150 user => $user,
151 object => $object,
152 action => $action,
153 info => $info,
154 src => $src,
156 #module => 'fix this', #this seems unused in actual code
157 foreach my $module (@modules) {
158 $template->param($module => 1);
161 output_html_with_http_headers $input, $cookie, $template->output;
162 } else {
163 # Printing to a csv file
164 print $input->header(
165 -type => 'text/csv',
166 -attachment => "$basename.csv",
167 -filename => "$basename.csv"
169 my $sep = C4::Context->preference("delimiter");
170 foreach my $line (@$results) {
171 #next unless $modules[0] eq "catalogue";
172 foreach (qw(timestamp firstname surname action info title author)) {
173 print $line->{$_} . $sep;
177 exit;
178 } else {
179 #my @values;
180 #my %labels;
181 #my %select;
182 #initialize some paramaters that might not be used in the template - it seems to evaluate EXPR even if a false TMPL_IF
183 $template->param(
184 total => 0,
185 module => "",
186 info => ""
188 output_html_with_http_headers $input, $cookie, $template->output;