From e4a19baab617d312b8af3733dba15fcb353a3ecd Mon Sep 17 00:00:00 2001 From: hdl Date: Tue, 19 Jul 2005 16:48:15 +0000 Subject: [PATCH] Adding an object field to action_logs. + Minor Correction to updatedatabase Changing Activate_Log from choice to YesNo Variable. --- C4/Log.pm | 65 +++++++++++++++++++++++++++++++++------ acqui.simple/addbiblio.pl | 6 ++-- updater/updatedatabase | 11 +++++-- 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/C4/Log.pm b/C4/Log.pm index 7727528ad7..825aa14c95 100644 --- a/C4/Log.pm +++ b/C4/Log.pm @@ -60,10 +60,10 @@ Adds a record into action_logs table to report the different changes upon the da =cut #' sub logaction{ - my ($usernumber,$modulename, $actionname, $infos)=@_; + my ($usernumber,$modulename, $actionname, $objectnumber, $infos)=@_; my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("Insert into action_logs (timestamp,user,module,action,info) values (now(),?,?,?,?)"); - $sth->execute($usernumber,$modulename,$actionname,$infos); + my $sth=$dbh->prepare("Insert into action_logs (timestamp,user,module,action,object,info) values (now(),?,?,?,?,?)"); + $sth->execute($usernumber,$modulename,$actionname,$objectnumber,$infos); $sth->finish; } @@ -76,15 +76,62 @@ Activate_Log is a system preference Variable =cut #' sub logstatus{ - my ($usernumber,$modulename, $actionname, $infos)=@_; + return C4::Context->preference("Activate_Log"); +} + +=item displaylog + + &displaylog($modulename, @filters); + $modulename is the name of the module on which the user wants to display logs + @filters is an optional table of hash containing : + - name : the name of the variable to filter + - value : the value of the filter.... May be with * joker + +returns a table of hash containing who did what on which object at what time + +=cut +#' +sub displaylog{ + my ($modulename, @filters)=@_; my $dbh = C4::Context->dbh; - my $sth=$dbh->prepare("select value from systempreferences where variable='Activate_Log'"); + my $strsth; + if ($modulename eq "acqui.simple"){ + $strsth="select action_logs.timestamp, action_logs.action, 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") { + } elsif ($modulename eq "circ") { + } elsif ($modulename eq "members"){ + } + warn "displaylog :".$strsth; + my $sth=$dbh->prepare($strsth); $sth->execute; - my ($var)=$sth->fetchrow; - $sth->finish; - return ($var eq "On"?"True":"") + my @results; + my $count; + while (my $data = $sth->fetchrow_hashref){ + push @results, $data; + $count++; + } + return ($count, \@results); } - END { } # module clean-up code here (global destructor) 1; diff --git a/acqui.simple/addbiblio.pl b/acqui.simple/addbiblio.pl index 7a1f6e8067..e072a78220 100755 --- a/acqui.simple/addbiblio.pl +++ b/acqui.simple/addbiblio.pl @@ -429,10 +429,10 @@ if ($op eq "addbiblio") { if ($is_a_modif) { NEWmodbiblioframework($dbh,$bibid,$frameworkcode); NEWmodbiblio($dbh,$record,$bibid,$frameworkcode); - logaction($loggedinuser,"acqui.simple","modify","biblionumber :$oldbiblionumber\nrecord : ".$record->as_formatted) if (logstatus); + logaction($loggedinuser,"acqui.simple","modify",$oldbiblionumber,"record : ".$record->as_formatted) if (C4::Context->preference("Activate_Log")); } else { ($bibid,$oldbibnum,$oldbibitemnum) = NEWnewbiblio($dbh,$record,$frameworkcode); - logaction($loggedinuser,"acqui.simple","add","biblionumber :$oldbibnum\nrecord : ".$record->as_formatted) if (logstatus); + logaction($loggedinuser,"acqui.simple","add",$oldbibnum,"record : ".$record->as_formatted) if (C4::Context->preference("Activate_Log")); } # now, redirect to additem page print $input->redirect("additem.pl?bibid=$bibid&frameworkcode=$frameworkcode"); @@ -485,7 +485,7 @@ if ($op eq "addbiblio") { } elsif ($op eq "delete") { #------------------------------------------------------------------------------------------------------------------------------ &NEWdelbiblio($dbh,$bibid); - logaction($loggedinuser,"acqui.simple","del","biblionumber :$bibid") if (logstatus); + logaction($loggedinuser,"acqui.simple","del",$bibid,"") if (logstatus); print "Content-Type: text/html\n\n"; exit; diff --git a/updater/updatedatabase b/updater/updatedatabase index 96e0825ae4..9f2a4ba150 100755 --- a/updater/updatedatabase +++ b/updater/updatedatabase @@ -388,6 +388,7 @@ my %requiretables = ( `user` INT( 11 ) NOT NULL , `module` TEXT default '', `action` TEXT default '' , + `object` INT(11) default '' , `info` TEXT default '' , PRIMARY KEY ( `timestamp` , `user` ) )", @@ -911,13 +912,12 @@ my %tabledata = ( }, { uniquefieldrequired => 'variable', - variable => 'Acitvate_Log', + variable => 'Activate_Log', value => 'On', forceupdate => { 'explanation' => 1, 'type' => 1}, explanation => 'Turn Log Actions on DB On an Off', - type => 'Choice', - options => 'On|Off' + type => 'YesNo', }, ], @@ -1520,6 +1520,11 @@ $sth->finish; exit; # $Log$ +# Revision 1.109 2005/07/19 16:48:16 hdl +# Adding an object field to action_logs. +# + Minor Correction to updatedatabase +# Changing Activate_Log from choice to YesNo Variable. +# # Revision 1.108 2005/07/15 16:10:35 hdl # Adding Log Facility. # Needs Two Update in database... -- 2.20.1