-sub displaylog {
- my ($modulename, @filters) = @_;
- my $dbh = C4::Context->dbh;
- my $strsth=qq|
- SELECT action_logs.timestamp, action_logs.action, action_logs.info,
- borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,
- biblio.biblionumber, biblio.title, biblio.author
- FROM action_logs
- LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user
- LEFT JOIN biblio ON action_logs.object=biblio.biblionumber
- WHERE action_logs.module = 'cataloguing'
- |;
- my %filtermap = ();
- if ($modulename eq "catalogue" or $modulename eq "acqui") {
- %filtermap = (
- user => 'borrowers.surname',
- title => 'biblio.title',
- author => 'biblio.author',
- );
- } elsif ($modulename eq "members") {
- $strsth=qq|
- SELECT action_logs.timestamp, action_logs.action, action_logs.info,
- borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,
- bor2.cardnumber, bor2.surname, bor2.firstname, bor2.userid
- FROM action_logs
- LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user
- LEFT JOIN borrowers as bor2 ON action_logs.object=bor2.borrowernumber
- WHERE action_logs.module = 'members'
- |;
- %filtermap = (
- user => 'borrowers.surname',
- surname => 'bor2.surname',
- firstname => 'bor2.firstname',
- cardnumber => 'bor2.cardnumber',
- );
- } else {
- return 0;
- }
-
- if (@filters) {
- foreach my $filter (@filters) {
- my $tempname = $filter->{name} or next;
- (grep {/^$tempname$/} keys %filtermap) or next;
- $filter->{value} =~ s/\*/%/g;
- $strsth .= " AND " . $filtermap{$tempname} . " LIKE " . $filter->{value};
- }
- }
- 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);
-}
-
-=item GetLogs
-
-$logs = GetLogs($datefrom,$dateto,$user,\@modules,$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 $modules = shift;
- my $action = shift;
- my $object = shift;
- my $info = shift;
-
- my $iso_datefrom = C4::Dates->new($datefrom,C4::Context->preference("dateformat"))->output('iso');
- my $iso_dateto = C4::Dates->new($dateto,C4::Context->preference("dateformat"))->output('iso');
-
- my $dbh = C4::Context->dbh;
- my $query = "
- SELECT *
- FROM action_logs
- WHERE 1
- ";
-
- my @parameters;
- $query .= " AND DATE_FORMAT(timestamp, '%Y-%m-%d') >= \"".$iso_datefrom."\" " if $iso_datefrom; #fix me - mysql specific
- $query .= " AND DATE_FORMAT(timestamp, '%Y-%m-%d') <= \"".$iso_dateto."\" " if $iso_dateto;
- if($user) {
- $query .= " AND user LIKE ? ";
- push(@parameters,"%".$user."%");
- }
- if(scalar @$modules > 1 or @$modules[0] ne "") {
- $query .= " AND (1 = 2"; #always false but used to build the query
- foreach my $module (@$modules) {
- next if $module eq "";
- $query .= " or module = ?";
- push(@parameters,$module);
- }
- $query .= ")";
- }
- if($action) {
- $query .= " AND action LIKE ? ";
- push(@parameters,"%".$action."%");
- }
- if($object) {
- $query .= " AND object LIKE ? ";
- push(@parameters,"%".$object."%");
- }
- if($info) {
- $query .= " AND info LIKE ? ";
- push(@parameters,"%".$info."%");
- }
-
- my $sth = $dbh->prepare($query);
- $sth->execute(@parameters);
-
- my @logs;
- while( my $row = $sth->fetchrow_hashref ) {
- $row->{$row->{module}} = 1;
- push @logs , $row;
- }
- return \@logs;