defaulting usernumber to '' (root login)
[koha-ffzg.git] / C4 / Log.pm
index 825aa14..a64720a 100644 (file)
--- a/C4/Log.pm
+++ b/C4/Log.pm
@@ -22,6 +22,7 @@ package C4::Log; #assumes C4/Log
 
 use strict;
 use C4::Context;
+use C4::Date;
 
 require Exporter;
 
@@ -49,7 +50,7 @@ The functions in this module perform various functions in order to log all the o
 =cut
 
 @ISA = qw(Exporter);
-@EXPORT = qw(&logaction &logstatus);
+@EXPORT = qw(&logaction &logstatus &displaylog);
 
 =item logaction
 
@@ -61,6 +62,7 @@ Adds a record into action_logs table to report the different changes upon the da
 #'
 sub logaction{
   my ($usernumber,$modulename, $actionname, $objectnumber, $infos)=@_;
+       $usernumber='' unless $usernumber;
        my $dbh = C4::Context->dbh;
        my $sth=$dbh->prepare("Insert into action_logs (timestamp,user,module,action,object,info) values (now(),?,?,?,?,?)");
        $sth->execute($usernumber,$modulename,$actionname,$objectnumber,$infos);
@@ -95,13 +97,35 @@ sub displaylog{
   my ($modulename, @filters)=@_;
        my $dbh = C4::Context->dbh;
        my $strsth;
-       if ($modulename eq "acqui.simple"){
-               $strsth="select action_logs.timestamp, action_logs.action, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,";
+       if ($modulename eq "catalogue"){
+               $strsth="select action_logs.timestamp, action_logs.action, action_logs.info, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,";
+               $strsth .= "biblio.biblionumber, biblio.title, biblio.author" ;#if ($modulename eq "acqui.simple");
+               $strsth .= " FROM borrowers,action_logs ";
+               $strsth .= ",biblio " ;#if ($modulename eq "acqui.simple");
+       
+               $strsth .=" WHERE borrowers.borrowernumber=action_logs.user";
+               $strsth .=" AND action_logs.module = 'acqui.simple' AND action_logs.object=biblio.biblionumber ";# if ($modulename eq "acqui.simple");
+               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/){
+                                       $filter->{value}=~s/\*/%/g;
+                                       $strsth .= " AND biblio.title like ".$filter->{value};
+                               }elsif ($filter->{name} =~ /author/){
+                                       $filter->{value}=~s/\*/%/g;
+                                       $strsth .= " AND biblio.author like ".$filter->{value};
+                               }
+                       }
+               }
+       } elsif ($modulename eq "acqui")  {
+               $strsth="select action_logs.timestamp, action_logs.action, action_logs.info, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,";
                $strsth .= "biblio.biblionumber, biblio.title, biblio.author" ;#if ($modulename eq "acqui.simple");
                $strsth .= "FROM borrowers,action_logs ";
-               $strsth .= ",biblio" ;#if ($modulename eq "acqui.simple");
+               $strsth .= ",biblio " ;#if ($modulename eq "acqui.simple");
        
-               $strsth .="WHERE borrowers.borrowernumber=action_logs.user";
+               $strsth .=" WHERE borrowers.borrowernumber=action_logs.user";
                $strsth .= "AND action_logs.module = 'acqui.simple' AND action_logs.object=biblio.biblionumber ";# if ($modulename eq "acqui.simple");
                if (@filters){
                        foreach my $filter (@filters){
@@ -117,20 +141,48 @@ sub displaylog{
                                }
                        }
                }
-       } elsif ($modulename eq "acqui")  {
-       } elsif ($modulename eq "circ")   {
        } elsif ($modulename eq "members"){
+               $strsth="select action_logs.timestamp, action_logs.action, action_logs.info, borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,";
+               $strsth .= "bor2.cardnumber, bor2.surname, bor2.firstname, bor2.userid,";
+               $strsth .= "FROM borrowers,action_logs,borrowers as bor2 ";
+       
+               $strsth .=" WHERE borrowers.borrowernumber=action_logs.user";
+               $strsth .= "AND action_logs.module = 'members' AND action_logs.object=bor2.borrowernumber ";# if ($modulename eq "acqui.simple");
+               if (@filters){
+                       foreach my $filter (@filters){
+                               if ($filter->{name} =~ /user/){
+                                       $filter->{value}=~s/\*/%/g;
+                                       $strsth .= " AND borrowers.surname like ".$filter->{value};
+                               }elsif ($filter->{name} =~ /surname/){
+                                       $filter->{value}=~s/\*/%/g;
+                                       $strsth .= " AND bor2.surname like ".$filter->{value};
+                               }elsif ($filter->{name} =~ /firstname/){
+                                       $filter->{value}=~s/\*/%/g;
+                                       $strsth .= " AND bor2.firsntame like ".$filter->{value};
+                               }elsif ($filter->{name} =~ /cardnumber/){
+                                       $filter->{value}=~s/\*/%/g;
+                                       $strsth .= " AND bor2.cardnumber like ".$filter->{value};
+                               }
+                       }
+               }
        }
-       warn "displaylog :".$strsth;
-       my $sth=$dbh->prepare($strsth);
-       $sth->execute;
-       my @results;
-       my $count;
-       while (my $data = $sth->fetchrow_hashref){
-               push @results, $data;
-               $count++;
-       }
-       return ($count, \@results);
+#      warn "displaylog :".$strsth;
+       if ($strsth){
+               my $sth=$dbh->prepare($strsth);
+               $sth->execute;
+               my @results;
+               my $count;
+               my $hilighted=1;
+               while (my $data = $sth->fetchrow_hashref){
+                       $data->{hilighted} = ($hilighted>0);
+                       $data->{info} =~ s/\n/<br\/>/g;
+                       $data->{day} = format_date($data->{timestamp});
+                       push @results, $data;
+                       $count++;
+                       $hilighted = -$hilighted;
+               }
+               return ($count, \@results);
+       } else {return 0;}
 }
 END { }       # module clean-up code here (global destructor)