koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] koha/C4 Log.pm [rel_3_0]


From: Antoine Farnault
Subject: [Koha-cvs] koha/C4 Log.pm [rel_3_0]
Date: Thu, 11 Jan 2007 14:25:01 +0000

CVSROOT:        /sources/koha
Module name:    koha
Branch:         rel_3_0
Changes by:     Antoine Farnault <toins>        07/01/11 14:25:01

Modified files:
        C4             : Log.pm 

Log message:
        new function : GetLogs, this function enable to read action_logs table.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Log.pm?cvsroot=koha&only_with_tag=rel_3_0&r1=1.5.2.2&r2=1.5.2.3

Patches:
Index: Log.pm
===================================================================
RCS file: /sources/koha/koha/C4/Log.pm,v
retrieving revision 1.5.2.2
retrieving revision 1.5.2.3
diff -u -b -r1.5.2.2 -r1.5.2.3
--- Log.pm      10 Jan 2007 16:31:15 -0000      1.5.2.2
+++ Log.pm      11 Jan 2007 14:25:01 -0000      1.5.2.3
@@ -29,7 +29,7 @@
 use vars qw($VERSION @ISA @EXPORT);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.5.2.2 $' =~ /\d+/g; shift(@v) . "." . 
join( "_", map { sprintf "%03d", $_ } @v ); };
+$VERSION = do { my @v = '$Revision: 1.5.2.3 $' =~ /\d+/g; shift(@v) . "." . 
join( "_", map { sprintf "%03d", $_ } @v ); };
 
 =head1 NAME
 
@@ -50,7 +50,7 @@
 =cut
 
 @ISA = qw(Exporter);
address@hidden = qw(&logaction &logstatus &displaylog);
address@hidden = qw(&logaction &logstatus &displaylog &GetLogs);
 
 =item logaction
 
@@ -80,7 +80,7 @@
 =cut
 
 #'
-sub logstatus{
+sub logstatus {
     return C4::Context->preference("Activate_Log");
 }
 
@@ -97,8 +97,8 @@
 =cut
 
 #'
-sub displaylog{
-  my ($modulename, @filters)address@hidden;
+sub displaylog {
+  my ($modulename, @filters) = @_;
     my $dbh = C4::Context->dbh;
     my $strsth;
     if ($modulename eq "catalogue"){
@@ -109,15 +109,15 @@
     
         $strsth .=" WHERE borrowers.borrowernumber=action_logs.user";
         $strsth .=" AND action_logs.module = 'cataloguing' AND 
action_logs.object=biblio.biblionumber ";# if ($modulename eq "acqui.simple");
-        if (@filters){
-            foreach my $filter (@filters){
-                if ($filter->{name} =~ /user/){
+        if (@filters) {
+            foreach my $filter (@filters) {
+                if ($filter->{name} =~ /user/) {
                     $filter->{value}=~s/\*/%/g;
                     $strsth .= " AND borrowers.surname like ".$filter->{value};
-                }elsif ($filter->{name} =~ /title/){
+                } elsif ($filter->{name} =~ /title/) {
                     $filter->{value}=~s/\*/%/g;
                     $strsth .= " AND biblio.title like ".$filter->{value};
-                }elsif ($filter->{name} =~ /author/){
+                } elsif ($filter->{name} =~ /author/) {
                     $filter->{value}=~s/\*/%/g;
                     $strsth .= " AND biblio.author like ".$filter->{value};
                 }
@@ -170,7 +170,7 @@
             }
         }
     }
-#     warn "displaylog :".$strsth;
+    
     if ($strsth){
         my $sth=$dbh->prepare($strsth);
         $sth->execute;
@@ -188,6 +188,50 @@
         return ($count, address@hidden);
     } else {return 0;}
 }
+
+=head2 GetLogs
+
+$logs = GetLogs($datefrom,$dateto,$user,$module,$action,$object,$info);
+
+Return: 
+C<$logs> is a ref to a hash which containts all columns from action_logs
+
+=cut
+
+sub GetLogs {
+    my $datefrom = shift;
+    my $dateto   = shift;
+    my $user     = shift;
+    my $module   = shift;
+    my $action   = shift;
+    my $object   = shift;
+    my $info     = shift;
+    
+    my $dbh = C4::Context->dbh;
+    my $query = "
+        SELECT *
+        FROM   action_logs
+        WHERE 1
+    ";
+    $query .= " AND DATE_FORMAT(timestamp, '%Y-%m-%d') >= \"".$datefrom."\" " 
if $datefrom;
+    $query .= " AND DATE_FORMAT(timestamp, '%Y-%m-%d') <= \"".$dateto."\" " if 
$dateto;
+    $query .= " AND user LIKE \"%".$user."%\" "     if $user;
+    $query .= " AND module LIKE \"%".$module."%\" " if $module;
+    $query .= " AND action LIKE \"%".$action."%\" " if $action;
+    $query .= " AND object LIKE \"%".$object."%\" " if $object;
+    $query .= " AND info LIKE \"%".$info."%\" "     if $info;
+    
+    my $sth = $dbh->prepare($query);
+    $sth->execute;
+    
+    my @logs;
+    while( my $row = $sth->fetchrow_hashref ) {
+        $row->{$row->{module}} = 1;
+        push @logs , $row;
+    }
+    return address@hidden;
+}
+
 END { }       # module clean-up code here (global destructor)
 
 1;




reply via email to

[Prev in Thread] Current Thread [Next in Thread]