1 package C4::Log; #assumes C4/Log
3 #package to deal with Logging Actions in DB
6 # Copyright 2000-2002 Katipo Communications
8 # This file is part of Koha.
10 # Koha is free software; you can redistribute it and/or modify it under the
11 # terms of the GNU General Public License as published by the Free Software
12 # Foundation; either version 2 of the License, or (at your option) any later
15 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
16 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License along with
20 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
21 # Suite 330, Boston, MA 02111-1307 USA
29 use vars qw($VERSION @ISA @EXPORT);
31 # set the version for version checking
36 C4::Log - Koha Log Facility functions
44 The functions in this module perform various functions in order to log all the operations done on the Database, including deleting and undeleting books, adding/editing members, etc.
53 @EXPORT = qw(&logaction &GetLogStatus &displaylog &GetLogs);
57 &logaction($usernumber, $modulename, $actionname, $infos);
59 Adds a record into action_logs table to report the different changes upon the database
65 my ($usernumber,$modulename, $actionname, $objectnumber, $infos)=@_;
66 $usernumber='' unless $usernumber;
67 my $dbh = C4::Context->dbh;
68 my $sth=$dbh->prepare("Insert into action_logs (timestamp,user,module,action,object,info) values (now(),?,?,?,?,?)");
69 $sth->execute($usernumber,$modulename,$actionname,$objectnumber,$infos);
75 $status = GetLogStatus;
77 C<$status> is a hasref like this example:
90 $hash{BorrowersLog} = C4::Context->preference("BorrowersLog");
91 $hash{CataloguingLog} = C4::Context->preference("CataloguingLog");
92 $hash{IssueLog} = C4::Context->preference("IssueLog");
93 $hash{ReturnLog} = C4::Context->preference("CataloguingLog");
94 $hash{SubscriptionLog} = C4::Context->preference("CataloguingLog");
95 $hash{LetterLog} = C4::Context->preference("LetterLog");
96 $hash{FinesLog} = C4::Context->preference("FinesLog");
103 &displaylog($modulename, @filters);
104 $modulename is the name of the module on which the user wants to display logs
105 @filters is an optional table of hash containing :
106 - name : the name of the variable to filter
107 - value : the value of the filter.... May be with * joker
109 returns a table of hash containing who did what on which object at what time
115 my ($modulename, @filters) = @_;
116 my $dbh = C4::Context->dbh;
118 if ($modulename eq "catalogue"){
119 $strsth="select action_logs.timestamp, action_logs.action, action_logs.info, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,";
120 $strsth .= "biblio.biblionumber, biblio.title, biblio.author" ;#if ($modulename eq "acqui.simple");
121 $strsth .= " FROM action_logs LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user";
122 $strsth .= " LEFT JOIN biblio ON action_logs.object=biblio.biblionumber " ;#if ($modulename eq "acqui.simple");
124 $strsth .=" WHERE action_logs.module = 'cataloguing' ";# if ($modulename eq "acqui.simple");
126 foreach my $filter (@filters) {
127 if ($filter->{name} =~ /user/) {
128 $filter->{value}=~s/\*/%/g;
129 $strsth .= " AND borrowers.surname like ".$filter->{value};
130 } elsif ($filter->{name} =~ /title/) {
131 $filter->{value}=~s/\*/%/g;
132 $strsth .= " AND biblio.title like ".$filter->{value};
133 } elsif ($filter->{name} =~ /author/) {
134 $filter->{value}=~s/\*/%/g;
135 $strsth .= " AND biblio.author like ".$filter->{value};
139 } elsif ($modulename eq "acqui") {
140 $strsth=qq|select action_logs.timestamp, action_logs.action, action_logs.info, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,
141 biblio.biblionumber, biblio.title, biblio.author
142 FROM action_logs LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user
143 LEFT JOIN biblio ON action_logs.object=biblio.biblionumber
144 WHERE action_logs.module = 'cataloguing' |;# if ($modulename eq "acqui.simple");
146 foreach my $filter (@filters){
147 if ($filter->{name} =~ /user/){
148 $filter->{value}=~s/\*/%/g;
149 $strsth .= " AND borrowers.surname like ".$filter->{value};
150 }elsif ($filter->{name} =~ /title/){
151 $filter->{value}=~s/\*/%/g;
152 $strsth .= " AND biblio.title like ".$filter->{value};
153 }elsif ($filter->{name} =~ /author/){
154 $filter->{value}=~s/\*/%/g;
155 $strsth .= " AND biblio.author like ".$filter->{value};
159 } elsif ($modulename eq "members"){
160 $strsth=qq|SELECT action_logs.timestamp, action_logs.action, action_logs.info,
161 borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,
162 bor2.cardnumber, bor2.surname, bor2.firstname, bor2.userid
163 FROM action_logs LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user LEFT JOIN borrowers as bor2 ON action_logs.object=bor2.borrowernumber
164 WHERE action_logs.module = 'members' |;# if ($modulename eq "acqui.simple");
166 foreach my $filter (@filters){
167 if ($filter->{name} =~ /user/){
168 $filter->{value}=~s/\*/%/g;
169 $strsth .= " AND borrowers.surname like ".$filter->{value};
170 }elsif ($filter->{name} =~ /surname/){
171 $filter->{value}=~s/\*/%/g;
172 $strsth .= " AND bor2.surname like ".$filter->{value};
173 }elsif ($filter->{name} =~ /firstname/){
174 $filter->{value}=~s/\*/%/g;
175 $strsth .= " AND bor2.firsntame like ".$filter->{value};
176 }elsif ($filter->{name} =~ /cardnumber/){
177 $filter->{value}=~s/\*/%/g;
178 $strsth .= " AND bor2.cardnumber like ".$filter->{value};
185 my $sth=$dbh->prepare($strsth);
190 while (my $data = $sth->fetchrow_hashref){
191 $data->{hilighted} = ($hilighted>0);
192 $data->{info} =~ s/\n/<br\/>/g;
193 $data->{day} = format_date($data->{timestamp});
194 push @results, $data;
196 $hilighted = -$hilighted;
198 return ($count, \@results);
204 $logs = GetLogs($datefrom,$dateto,$user,$module,$action,$object,$info);
207 C<$logs> is a ref to a hash which containts all columns from action_logs
212 my $datefrom = shift;
220 my $dbh = C4::Context->dbh;
226 $query .= " AND DATE_FORMAT(timestamp, '%Y-%m-%d') >= \"".$datefrom."\" " if $datefrom;
227 $query .= " AND DATE_FORMAT(timestamp, '%Y-%m-%d') <= \"".$dateto."\" " if $dateto;
228 $query .= " AND user LIKE \"%".$user."%\" " if $user;
229 $query .= " AND module LIKE \"%".$module."%\" " if $module;
230 $query .= " AND action LIKE \"%".$action."%\" " if $action;
231 $query .= " AND object LIKE \"%".$object."%\" " if $object;
232 $query .= " AND info LIKE \"%".$info."%\" " if $info;
234 my $sth = $dbh->prepare($query);
238 while( my $row = $sth->fetchrow_hashref ) {
239 $row->{$row->{module}} = 1;
245 END { } # module clean-up code here (global destructor)
254 Koha Developement team <info@koha.org>