View | Details | Raw Unified | Return to bug 22003
Collapse All | Expand All

(-)a/C4/Log.pm (-106 / +1 lines)
Lines 35-41 use vars qw(@ISA @EXPORT); Link Here
35
BEGIN {
35
BEGIN {
36
        require Exporter;
36
        require Exporter;
37
        @ISA = qw(Exporter);
37
        @ISA = qw(Exporter);
38
        @EXPORT = qw(&logaction &cronlogaction &GetLogStatus &displaylog &GetLogs);
38
        @EXPORT = qw(&logaction &cronlogaction &GetLogs);
39
}
39
}
40
40
41
=head1 NAME
41
=head1 NAME
Lines 120-230 sub cronlogaction { Link Here
120
    logaction( 'CRONJOBS', 'Run', undef, $loginfo ) if C4::Context->preference('CronjobLog');
120
    logaction( 'CRONJOBS', 'Run', undef, $loginfo ) if C4::Context->preference('CronjobLog');
121
}
121
}
122
122
123
124
=item GetLogStatus
125
126
  $status = GetLogStatus;
127
128
C<$status> is a hasref like this example:
129
    $hash = {
130
        BorrowersLog   => 1,
131
        CataloguingLog => 0,
132
        IssueLog       => 0,
133
        ...
134
    }
135
136
=cut
137
138
#'
139
sub GetLogStatus {
140
    my %hash;
141
    $hash{BorrowersLog}    = C4::Context->preference("BorrowersLog");
142
    $hash{CataloguingLog}  = C4::Context->preference("CataloguingLog");
143
    $hash{HoldsLog}        = C4::Context->preference("HoldsLog");
144
    $hash{IssueLog}        = C4::Context->preference("IssueLog");
145
    $hash{ReturnLog}       = C4::Context->preference("ReturnLog");
146
    $hash{SubscriptionLog} = C4::Context->preference("SubscriptionLog");
147
    $hash{LetterLog}       = C4::Context->preference("LetterLog");
148
    $hash{FinesLog}        = C4::Context->preference("FinesLog");
149
    return \%hash;
150
}
151
152
=item displaylog
153
154
  &displaylog($modulename, @filters);
155
  $modulename is the name of the module on which the user wants to display logs
156
  @filters is an optional table of hash containing :
157
      - name : the name of the variable to filter
158
    - value : the value of the filter.... May be with * joker
159
160
returns a table of hash containing who did what on which object at what time
161
162
=cut
163
164
#'
165
sub displaylog {
166
  my ($modulename, @filters) = @_;
167
    my $dbh = C4::Context->dbh;
168
    my $strsth=qq|
169
		SELECT action_logs.timestamp, action_logs.action, action_logs.info,
170
				borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,
171
        		biblio.biblionumber, biblio.title, biblio.author
172
        FROM action_logs
173
		LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user
174
        LEFT JOIN  biblio   ON action_logs.object=biblio.biblionumber
175
        WHERE action_logs.module = 'cataloguing'
176
	|;
177
	my %filtermap = ();
178
    if ($modulename eq "catalogue" or $modulename eq "acqui") {
179
		%filtermap = (
180
			  user => 'borrowers.surname',
181
			 title => 'biblio.title',
182
			author => 'biblio.author',
183
		);
184
    } elsif ($modulename eq "members") {
185
        $strsth=qq|
186
		SELECT action_logs.timestamp, action_logs.action, action_logs.info,
187
        		borrowers.cardnumber, borrowers.surname, borrowers.firstname, borrowers.userid,
188
        		bor2.cardnumber, bor2.surname, bor2.firstname, bor2.userid
189
        FROM action_logs
190
		LEFT JOIN borrowers ON borrowers.borrowernumber=action_logs.user
191
		LEFT JOIN borrowers as bor2 ON action_logs.object=bor2.borrowernumber
192
        WHERE action_logs.module = 'members'
193
		|;
194
		%filtermap = (
195
		       user => 'borrowers.surname',
196
		    surname => 'bor2.surname',
197
		  firstname => 'bor2.firstname',
198
		 cardnumber => 'bor2.cardnumber',
199
		);
200
    } else {
201
		return 0;
202
	}
203
204
    if (@filters) {
205
		foreach my $filter (@filters) {
206
			my $tempname = $filter->{name}         or next;
207
			(grep {/^$tempname$/} keys %filtermap) or next;
208
			$filter->{value} =~ s/\*/%/g;
209
			$strsth .= " AND " . $filtermap{$tempname} . " LIKE " . $filter->{value};
210
		}
211
	}
212
    my $sth=$dbh->prepare($strsth);
213
    $sth->execute;
214
    my @results;
215
    my $count;
216
    my $hilighted=1;
217
    while (my $data = $sth->fetchrow_hashref){
218
    	$data->{hilighted} = ($hilighted>0);
219
        $data->{info} =~ s/\n/<br\/>/g;
220
        $data->{day} = output_pref({ str => $data->{timestamp} });
221
        push @results, $data;
222
        $count++;
223
        $hilighted = -$hilighted;
224
    }
225
    return ($count, \@results);
226
}
227
228
=item GetLogs
123
=item GetLogs
229
124
230
$logs = GetLogs($datefrom,$dateto,$user,\@modules,$action,$object,$info);
125
$logs = GetLogs($datefrom,$dateto,$user,\@modules,$action,$object,$info);
(-)a/t/Log.t (-17 / +3 lines)
Lines 3-26 Link Here
3
# This Koha test module is a stub!  
3
# This Koha test module is a stub!  
4
# Add more tests here!!!
4
# Add more tests here!!!
5
5
6
use strict;
6
use Modern::Perl;
7
use warnings;
8
7
9
use Test::More tests => 3;
8
use Test::More tests => 1;
10
use t::lib::Mocks;
11
9
12
BEGIN {
10
BEGIN {
13
        use_ok('C4::Log');
11
    use_ok('C4::Log');
14
}
12
}
15
13
16
t::lib::Mocks::mock_preference('BorrowersLog', 1);
17
t::lib::Mocks::mock_preference('CataloguingLog', 1);
18
t::lib::Mocks::mock_preference('IssueLog', 1);
19
t::lib::Mocks::mock_preference('ReturnLog', 1);
20
t::lib::Mocks::mock_preference('SubscriptionLog', 1);
21
t::lib::Mocks::mock_preference('LetterLog', 1);
22
t::lib::Mocks::mock_preference('FinesLog', 1);
23
24
ok( my $hash=GetLogStatus(),"Testing GetLogStatus");
25
26
ok( $hash->{BorrowersLog}, 'Testing hash is non empty');
27
- 

Return to bug 22003