-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);