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 &logstatus &displaylog);
57 &logaction($usernumber, $modulename, $actionname, $infos);
59 Adds a record into action_logs table to report the different changes upon the database
64 my ($usernumber,$modulename, $actionname, $objectnumber, $infos)=@_;
65 my $dbh = C4::Context->dbh;
66 my $sth=$dbh->prepare("Insert into action_logs (timestamp,user,module,action,object,info) values (now(),?,?,?,?,?)");
67 $sth->execute($usernumber,$modulename,$actionname,$objectnumber,$infos);
75 returns True If Activate_Log variable is equal to On
76 Activate_Log is a system preference Variable
80 return C4::Context->preference("Activate_Log");
85 &displaylog($modulename, @filters);
86 $modulename is the name of the module on which the user wants to display logs
87 @filters is an optional table of hash containing :
88 - name : the name of the variable to filter
89 - value : the value of the filter.... May be with * joker
91 returns a table of hash containing who did what on which object at what time
96 my ($modulename, @filters)=@_;
97 my $dbh = C4::Context->dbh;
99 if ($modulename eq "catalogue"){
100 $strsth="select action_logs.timestamp, action_logs.action, action_logs.info, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,";
101 $strsth .= "biblio.biblionumber, biblio.title, biblio.author" ;#if ($modulename eq "acqui.simple");
102 $strsth .= " FROM borrowers,action_logs ";
103 $strsth .= ",biblio " ;#if ($modulename eq "acqui.simple");
105 $strsth .=" WHERE borrowers.borrowernumber=action_logs.user";
106 $strsth .=" AND action_logs.module = 'acqui.simple' AND action_logs.object=biblio.biblionumber ";# if ($modulename eq "acqui.simple");
108 foreach my $filter (@filters){
109 if ($filter->{name} =~ /user/){
110 $filter->{value}=~s/\*/%/g;
111 $strsth .= " AND borrowers.surname like ".$filter->{value};
112 }elsif ($filter->{name} =~ /title/){
113 $filter->{value}=~s/\*/%/g;
114 $strsth .= " AND biblio.title like ".$filter->{value};
115 }elsif ($filter->{name} =~ /author/){
116 $filter->{value}=~s/\*/%/g;
117 $strsth .= " AND biblio.author like ".$filter->{value};
121 } elsif ($modulename eq "acqui") {
122 $strsth="select action_logs.timestamp, action_logs.action, action_logs.info, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,";
123 $strsth .= "biblio.biblionumber, biblio.title, biblio.author" ;#if ($modulename eq "acqui.simple");
124 $strsth .= "FROM borrowers,action_logs ";
125 $strsth .= ",biblio " ;#if ($modulename eq "acqui.simple");
127 $strsth .=" WHERE borrowers.borrowernumber=action_logs.user";
128 $strsth .= "AND action_logs.module = 'acqui.simple' AND action_logs.object=biblio.biblionumber ";# if ($modulename eq "acqui.simple");
130 foreach my $filter (@filters){
131 if ($filter->{name} =~ /user/){
132 $filter->{value}=~s/\*/%/g;
133 $strsth .= " AND borrowers.surname like ".$filter->{value};
134 }elsif ($filter->{name} =~ /title/){
135 $filter->{value}=~s/\*/%/g;
136 $strsth .= " AND biblio.title like ".$filter->{value};
137 }elsif ($filter->{name} =~ /author/){
138 $filter->{value}=~s/\*/%/g;
139 $strsth .= " AND biblio.author like ".$filter->{value};
143 } elsif ($modulename eq "members"){
144 $strsth="select action_logs.timestamp, action_logs.action, action_logs.info, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,";
145 $strsth .= "bor2.cardnumber, bor2.surname, bor2.firstname, bor2.userid,";
146 $strsth .= "FROM borrowers,action_logs,borrowers as bor2 ";
148 $strsth .=" WHERE borrowers.borrowernumber=action_logs.user";
149 $strsth .= "AND action_logs.module = 'members' AND action_logs.object=bor2.borrowernumber ";# if ($modulename eq "acqui.simple");
151 foreach my $filter (@filters){
152 if ($filter->{name} =~ /user/){
153 $filter->{value}=~s/\*/%/g;
154 $strsth .= " AND borrowers.surname like ".$filter->{value};
155 }elsif ($filter->{name} =~ /surname/){
156 $filter->{value}=~s/\*/%/g;
157 $strsth .= " AND bor2.surname like ".$filter->{value};
158 }elsif ($filter->{name} =~ /firstname/){
159 $filter->{value}=~s/\*/%/g;
160 $strsth .= " AND bor2.firsntame like ".$filter->{value};
161 }elsif ($filter->{name} =~ /cardnumber/){
162 $filter->{value}=~s/\*/%/g;
163 $strsth .= " AND bor2.cardnumber like ".$filter->{value};
168 # warn "displaylog :".$strsth;
170 my $sth=$dbh->prepare($strsth);
175 while (my $data = $sth->fetchrow_hashref){
176 $data->{hilighted} = ($hilighted>0);
177 $data->{info} =~ s/\n/<br\/>/g;
178 $data->{day} = format_date($data->{timestamp});
179 push @results, $data;
181 $hilighted = -$hilighted;
183 return ($count, \@results);
186 END { } # module clean-up code here (global destructor)
195 Koha Developement team <info@koha.org>