Lines 25-48
use Digest::MD5 qw(md5_base64);
Link Here
|
25 |
|
25 |
|
26 |
our $VERSION = 3.07.00.049; |
26 |
our $VERSION = 3.07.00.049; |
27 |
|
27 |
|
28 |
our $kp; # koha patron |
28 |
our $kp; # koha patron |
29 |
|
29 |
|
30 |
sub new { |
30 |
sub new { |
31 |
my ($class, $patron_id) = @_; |
31 |
my ($class, $patron_id) = @_; |
32 |
my $type = ref($class) || $class; |
32 |
my $type = ref($class) || $class; |
33 |
my $self; |
33 |
my $self; |
34 |
$kp = GetMember(cardnumber=>$patron_id) || GetMember(userid=>$patron_id); |
34 |
$kp = GetMember(cardnumber=>$patron_id) || GetMember(userid=>$patron_id); |
35 |
$debug and warn "new Patron (GetMember): " . Dumper($kp); |
35 |
$debug and warn "new Patron (GetMember): " . Dumper($kp); |
36 |
unless (defined $kp) { |
36 |
unless (defined $kp) { |
37 |
syslog("LOG_DEBUG", "new ILS::Patron(%s): no such patron", $patron_id); |
37 |
syslog("LOG_DEBUG", "new ILS::Patron(%s): no such patron", $patron_id); |
38 |
return; |
38 |
return; |
39 |
} |
39 |
} |
40 |
$kp = GetMemberDetails($kp->{borrowernumber}); |
40 |
$kp = GetMemberDetails($kp->{borrowernumber}); |
41 |
$debug and warn "new Patron (GetMemberDetails): " . Dumper($kp); |
41 |
$debug and warn "new Patron (GetMemberDetails): " . Dumper($kp); |
42 |
my $pw = $kp->{password}; ### FIXME - md5hash -- deal with . |
42 |
my $pw = $kp->{password}; ### FIXME - md5hash -- deal with . |
43 |
my $flags = $kp->{flags}; # or warn "Warning: No flags from patron object for '$patron_id'"; |
43 |
my $flags = $kp->{flags}; # or warn "Warning: No flags from patron object for '$patron_id'"; |
44 |
my $debarred = $kp->{debarred}; # 1 if ($kp->{flags}->{DBARRED}->{noissues}); |
44 |
my $debarred = $kp->{debarred}; # 1 if ($kp->{flags}->{DBARRED}->{noissues}); |
45 |
$debug and warn sprintf("Debarred = %s : ", ($debarred||'undef')) . Dumper(%{$kp->{flags}}); |
45 |
$debug and warn sprintf("Debarred = %s : ", ($debarred||'undef')) . Dumper(%{$kp->{flags}}); |
46 |
my ($day, $month, $year) = (localtime)[3,4,5]; |
46 |
my ($day, $month, $year) = (localtime)[3,4,5]; |
47 |
my $today = sprintf '%04d-%02d-%02d', $year+1900, $month+1, $day; |
47 |
my $today = sprintf '%04d-%02d-%02d', $year+1900, $month+1, $day; |
48 |
my $expired = ($today gt $kp->{dateexpiry}) ? 1 : 0; |
48 |
my $expired = ($today gt $kp->{dateexpiry}) ? 1 : 0; |
Lines 52-69
sub new {
Link Here
|
52 |
} |
52 |
} |
53 |
$kp->{opacnote} .= 'PATRON EXPIRED'; |
53 |
$kp->{opacnote} .= 'PATRON EXPIRED'; |
54 |
} |
54 |
} |
55 |
my %ilspatron; |
55 |
my %ilspatron; |
56 |
my $adr = $kp->{streetnumber} || ''; |
56 |
my $adr = $kp->{streetnumber} || ''; |
57 |
my $address = $kp->{address} || ''; |
57 |
my $address = $kp->{address} || ''; |
58 |
my $dob = $kp->{dateofbirth}; |
58 |
my $dob = $kp->{dateofbirth}; |
59 |
$dob and $dob =~ s/-//g; # YYYYMMDD |
59 |
$dob and $dob =~ s/-//g; # YYYYMMDD |
60 |
my $dexpiry = $kp->{dateexpiry}; |
60 |
my $dexpiry = $kp->{dateexpiry}; |
61 |
$dexpiry and $dexpiry =~ s/-//g; # YYYYMMDD |
61 |
$dexpiry and $dexpiry =~ s/-//g; # YYYYMMDD |
62 |
$adr .= ($adr && $address) ? " $address" : $address; |
62 |
$adr .= ($adr && $address) ? " $address" : $address; |
63 |
my $fines_amount = $flags->{CHARGES}->{amount}; |
63 |
my $fines_amount = $flags->{CHARGES}->{amount}; |
64 |
$fines_amount = ($fines_amount and $fines_amount > 0) ? $fines_amount : 0; |
64 |
$fines_amount = ($fines_amount and $fines_amount > 0) ? $fines_amount : 0; |
65 |
{ |
65 |
{ |
66 |
no warnings; # any of these $kp->{fields} being concat'd could be undef |
66 |
no warnings; # any of these $kp->{fields} being concat'd could be undef |
67 |
%ilspatron = ( |
67 |
%ilspatron = ( |
68 |
getmemberdetails_object => $kp, |
68 |
getmemberdetails_object => $kp, |
69 |
name => $kp->{firstname} . " " . $kp->{surname}, |
69 |
name => $kp->{firstname} . " " . $kp->{surname}, |
Lines 103-126
sub new {
Link Here
|
103 |
); |
103 |
); |
104 |
} |
104 |
} |
105 |
$debug and warn "patron fines: $ilspatron{fines} ... amountoutstanding: $kp->{amountoutstanding} ... CHARGES->amount: $flags->{CHARGES}->{amount}"; |
105 |
$debug and warn "patron fines: $ilspatron{fines} ... amountoutstanding: $kp->{amountoutstanding} ... CHARGES->amount: $flags->{CHARGES}->{amount}"; |
106 |
for (qw(EXPIRED CHARGES CREDITS GNA LOST DBARRED NOTES)) { |
106 |
for (qw(EXPIRED CHARGES CREDITS GNA LOST DBARRED NOTES)) { |
107 |
($flags->{$_}) or next; |
107 |
($flags->{$_}) or next; |
108 |
if ($_ ne 'NOTES' and $flags->{$_}->{message}) { |
108 |
if ($_ ne 'NOTES' and $flags->{$_}->{message}) { |
109 |
$ilspatron{screen_msg} .= " -- " . $flags->{$_}->{message}; # show all but internal NOTES |
109 |
$ilspatron{screen_msg} .= " -- " . $flags->{$_}->{message}; # show all but internal NOTES |
110 |
} |
110 |
} |
111 |
if ($flags->{$_}->{noissues}) { |
111 |
if ($flags->{$_}->{noissues}) { |
112 |
foreach my $toggle (qw(charge_ok renew_ok recall_ok hold_ok inet)) { |
112 |
foreach my $toggle (qw(charge_ok renew_ok recall_ok hold_ok inet)) { |
113 |
$ilspatron{$toggle} = 0; # if we get noissues, disable everything |
113 |
$ilspatron{$toggle} = 0; # if we get noissues, disable everything |
114 |
} |
114 |
} |
115 |
} |
115 |
} |
116 |
} |
116 |
} |
117 |
|
117 |
|
118 |
# FIXME: populate fine_items recall_items |
118 |
# FIXME: populate fine_items recall_items |
119 |
# $ilspatron{hold_items} = (GetReservesFromBorrowernumber($kp->{borrowernumber},'F')); |
119 |
# $ilspatron{hold_items} = (GetReservesFromBorrowernumber($kp->{borrowernumber},'F')); |
120 |
$ilspatron{unavail_holds} = [(GetReservesFromBorrowernumber($kp->{borrowernumber}))]; |
120 |
$ilspatron{unavail_holds} = [(GetReservesFromBorrowernumber($kp->{borrowernumber}))]; |
121 |
$ilspatron{items} = GetPendingIssues($kp->{borrowernumber}); |
121 |
$ilspatron{items} = GetPendingIssues($kp->{borrowernumber}); |
122 |
$self = \%ilspatron; |
122 |
$self = \%ilspatron; |
123 |
$debug and warn Dumper($self); |
123 |
$debug and warn Dumper($self); |
124 |
syslog("LOG_DEBUG", "new ILS::Patron(%s): found patron '%s'", $patron_id,$self->{id}); |
124 |
syslog("LOG_DEBUG", "new ILS::Patron(%s): found patron '%s'", $patron_id,$self->{id}); |
125 |
bless $self, $type; |
125 |
bless $self, $type; |
126 |
return $self; |
126 |
return $self; |
Lines 178-201
sub AUTOLOAD {
Link Here
|
178 |
$name =~ s/.*://; |
178 |
$name =~ s/.*://; |
179 |
|
179 |
|
180 |
unless (exists $fields{$name}) { |
180 |
unless (exists $fields{$name}) { |
181 |
croak "Cannot access '$name' field of class '$class'"; |
181 |
croak "Cannot access '$name' field of class '$class'"; |
182 |
} |
182 |
} |
183 |
|
183 |
|
184 |
if (@_) { |
184 |
if (@_) { |
185 |
$fields{$name} or croak "Field '$name' of class '$class' is READ ONLY."; |
185 |
$fields{$name} or croak "Field '$name' of class '$class' is READ ONLY."; |
186 |
return $self->{$name} = shift; |
186 |
return $self->{$name} = shift; |
187 |
} else { |
187 |
} else { |
188 |
return $self->{$name}; |
188 |
return $self->{$name}; |
189 |
} |
189 |
} |
190 |
} |
190 |
} |
191 |
|
191 |
|
192 |
sub check_password { |
192 |
sub check_password { |
193 |
my ($self, $pwd) = @_; |
193 |
my ($self, $pwd) = @_; |
194 |
my $md5pwd = $self->{password}; |
194 |
my $md5pwd = $self->{password}; |
195 |
# warn sprintf "check_password for %s: '%s' vs. '%s'",($self->{name}||''),($self->{password}||''),($pwd||''); |
195 |
# warn sprintf "check_password for %s: '%s' vs. '%s'",($self->{name}||''),($self->{password}||''),($pwd||''); |
196 |
(defined $pwd ) or return 0; # you gotta give me something (at least ''), or no deal |
196 |
(defined $pwd ) or return 0; # you gotta give me something (at least ''), or no deal |
197 |
(defined $md5pwd) or return($pwd eq ''); # if the record has a NULL password, accept '' as match |
197 |
(defined $md5pwd) or return($pwd eq ''); # if the record has a NULL password, accept '' as match |
198 |
return (md5_base64($pwd) eq $md5pwd); |
198 |
return (md5_base64($pwd) eq $md5pwd); |
199 |
} |
199 |
} |
200 |
|
200 |
|
201 |
# A few special cases, not in AUTOLOADed %fields |
201 |
# A few special cases, not in AUTOLOADed %fields |
Lines 229-245
sub expired {
Link Here
|
229 |
sub drop_hold { |
229 |
sub drop_hold { |
230 |
my ($self, $item_id) = @_; |
230 |
my ($self, $item_id) = @_; |
231 |
return if !$item_id; |
231 |
return if !$item_id; |
232 |
my $result = 0; |
232 |
my $result = 0; |
233 |
foreach (qw(hold_items unavail_holds)) { |
233 |
foreach (qw(hold_items unavail_holds)) { |
234 |
$self->{$_} or next; |
234 |
$self->{$_} or next; |
235 |
for (my $i = 0; $i < scalar @{$self->{$_}}; $i++) { |
235 |
for (my $i = 0; $i < scalar @{$self->{$_}}; $i++) { |
236 |
my $held_item = $self->{$_}[$i]->{item_id} or next; |
236 |
my $held_item = $self->{$_}[$i]->{item_id} or next; |
237 |
if ($held_item eq $item_id) { |
237 |
if ($held_item eq $item_id) { |
238 |
splice @{$self->{$_}}, $i, 1; |
238 |
splice @{$self->{$_}}, $i, 1; |
239 |
$result++; |
239 |
$result++; |
240 |
} |
240 |
} |
241 |
} |
241 |
} |
242 |
} |
242 |
} |
243 |
return $result; |
243 |
return $result; |
244 |
} |
244 |
} |
245 |
|
245 |
|
Lines 250-256
sub x_items {
Link Here
|
250 |
my $self = shift; |
250 |
my $self = shift; |
251 |
my $array_var = shift or return; |
251 |
my $array_var = shift or return; |
252 |
my ($start, $end) = @_; |
252 |
my ($start, $end) = @_; |
253 |
$self->{$array_var} or return []; |
253 |
$self->{$array_var} or return []; |
254 |
$start = 1 unless defined($start); |
254 |
$start = 1 unless defined($start); |
255 |
$end = scalar @{$self->{$array_var}} unless defined($end); |
255 |
$end = scalar @{$self->{$array_var}} unless defined($end); |
256 |
# syslog("LOG_DEBUG", "$array_var: start = %d, end = %d; items(%s)", $start, $end, join(', ', @{$self->{items}})); |
256 |
# syslog("LOG_DEBUG", "$array_var: start = %d, end = %d; items(%s)", $start, $end, join(', ', @{$self->{items}})); |
Lines 290-296
sub unavail_holds {
Link Here
|
290 |
sub block { |
290 |
sub block { |
291 |
my ($self, $card_retained, $blocked_card_msg) = @_; |
291 |
my ($self, $card_retained, $blocked_card_msg) = @_; |
292 |
foreach my $field ('charge_ok', 'renew_ok', 'recall_ok', 'hold_ok', 'inet') { |
292 |
foreach my $field ('charge_ok', 'renew_ok', 'recall_ok', 'hold_ok', 'inet') { |
293 |
$self->{$field} = 0; |
293 |
$self->{$field} = 0; |
294 |
} |
294 |
} |
295 |
$self->{screen_msg} = "Block feature not implemented"; # $blocked_card_msg || "Card Blocked. Please contact library staff"; |
295 |
$self->{screen_msg} = "Block feature not implemented"; # $blocked_card_msg || "Card Blocked. Please contact library staff"; |
296 |
# TODO: not really affecting patron record |
296 |
# TODO: not really affecting patron record |
Lines 300-310
sub block {
Link Here
|
300 |
sub enable { |
300 |
sub enable { |
301 |
my $self = shift; |
301 |
my $self = shift; |
302 |
foreach my $field ('charge_ok', 'renew_ok', 'recall_ok', 'hold_ok', 'inet') { |
302 |
foreach my $field ('charge_ok', 'renew_ok', 'recall_ok', 'hold_ok', 'inet') { |
303 |
$self->{$field} = 1; |
303 |
$self->{$field} = 1; |
304 |
} |
304 |
} |
305 |
syslog("LOG_DEBUG", "Patron(%s)->enable: charge: %s, renew:%s, recall:%s, hold:%s", |
305 |
syslog("LOG_DEBUG", "Patron(%s)->enable: charge: %s, renew:%s, recall:%s, hold:%s", |
306 |
$self->{id}, $self->{charge_ok}, $self->{renew_ok}, |
306 |
$self->{id}, $self->{charge_ok}, $self->{renew_ok}, |
307 |
$self->{recall_ok}, $self->{hold_ok}); |
307 |
$self->{recall_ok}, $self->{hold_ok}); |
308 |
$self->{screen_msg} = "Enable feature not implemented."; # "All privileges restored."; # TODO: not really affecting patron record |
308 |
$self->{screen_msg} = "Enable feature not implemented."; # "All privileges restored."; # TODO: not really affecting patron record |
309 |
return $self; |
309 |
return $self; |
310 |
} |
310 |
} |
Lines 355-389
__END__
Link Here
|
355 |
=head1 EXAMPLES |
355 |
=head1 EXAMPLES |
356 |
|
356 |
|
357 |
our %patron_example = ( |
357 |
our %patron_example = ( |
358 |
djfiander => { |
358 |
djfiander => { |
359 |
name => "David J. Fiander", |
359 |
name => "David J. Fiander", |
360 |
id => 'djfiander', |
360 |
id => 'djfiander', |
361 |
password => '6789', |
361 |
password => '6789', |
362 |
ptype => 'A', # 'A'dult. Whatever. |
362 |
ptype => 'A', # 'A'dult. Whatever. |
363 |
birthdate => '19640925', |
363 |
birthdate => '19640925', |
364 |
address => '2 Meadowvale Dr. St Thomas, ON', |
364 |
address => '2 Meadowvale Dr. St Thomas, ON', |
365 |
home_phone => '(519) 555 1234', |
365 |
home_phone => '(519) 555 1234', |
366 |
email_addr => 'djfiander@hotmail.com', |
366 |
email_addr => 'djfiander@hotmail.com', |
367 |
charge_ok => 1, |
367 |
charge_ok => 1, |
368 |
renew_ok => 1, |
368 |
renew_ok => 1, |
369 |
recall_ok => 0, |
369 |
recall_ok => 0, |
370 |
hold_ok => 1, |
370 |
hold_ok => 1, |
371 |
card_lost => 0, |
371 |
card_lost => 0, |
372 |
claims_returned => 0, |
372 |
claims_returned => 0, |
373 |
fines => 100, |
373 |
fines => 100, |
374 |
fees => 0, |
374 |
fees => 0, |
375 |
recall_overdue => 0, |
375 |
recall_overdue => 0, |
376 |
items_billed => 0, |
376 |
items_billed => 0, |
377 |
screen_msg => '', |
377 |
screen_msg => '', |
378 |
print_line => '', |
378 |
print_line => '', |
379 |
items => [], |
379 |
items => [], |
380 |
hold_items => [], |
380 |
hold_items => [], |
381 |
overdue_items => [], |
381 |
overdue_items => [], |
382 |
fine_items => ['Computer Time'], |
382 |
fine_items => ['Computer Time'], |
383 |
recall_items => [], |
383 |
recall_items => [], |
384 |
unavail_holds => [], |
384 |
unavail_holds => [], |
385 |
inet => 1, |
385 |
inet => 1, |
386 |
}, |
386 |
}, |
387 |
); |
387 |
); |
388 |
|
388 |
|
389 |
From borrowers table: |
389 |
From borrowers table: |
Lines 463-488
__END__
Link Here
|
463 |
|
463 |
|
464 |
$flags->{KEY} |
464 |
$flags->{KEY} |
465 |
{CHARGES} |
465 |
{CHARGES} |
466 |
{message} Message showing patron's credit or debt |
466 |
{message} Message showing patron's credit or debt |
467 |
{noissues} Set if patron owes >$5.00 |
467 |
{noissues} Set if patron owes >$5.00 |
468 |
{GNA} Set if patron gone w/o address |
468 |
{GNA} Set if patron gone w/o address |
469 |
{message} "Borrower has no valid address" |
469 |
{message} "Borrower has no valid address" |
470 |
{noissues} Set. |
470 |
{noissues} Set. |
471 |
{LOST} Set if patron's card reported lost |
471 |
{LOST} Set if patron's card reported lost |
472 |
{message} Message to this effect |
472 |
{message} Message to this effect |
473 |
{noissues} Set. |
473 |
{noissues} Set. |
474 |
{DBARRED} Set if patron is debarred |
474 |
{DBARRED} Set if patron is debarred |
475 |
{message} Message to this effect |
475 |
{message} Message to this effect |
476 |
{noissues} Set. |
476 |
{noissues} Set. |
477 |
{NOTES} Set if patron has notes |
477 |
{NOTES} Set if patron has notes |
478 |
{message} Notes about patron |
478 |
{message} Notes about patron |
479 |
{ODUES} Set if patron has overdue books |
479 |
{ODUES} Set if patron has overdue books |
480 |
{message} "Yes" |
480 |
{message} "Yes" |
481 |
{itemlist} ref-to-array: list of overdue books |
481 |
{itemlist} ref-to-array: list of overdue books |
482 |
{itemlisttext} Text list of overdue items |
482 |
{itemlisttext} Text list of overdue items |
483 |
{WAITING} Set if there are items available that the patron reserved |
483 |
{WAITING} Set if there are items available that the patron reserved |
484 |
{message} Message to this effect |
484 |
{message} Message to this effect |
485 |
{itemlist} ref-to-array: list of available items |
485 |
{itemlist} ref-to-array: list of available items |
486 |
|
486 |
|
487 |
=cut |
487 |
=cut |
488 |
|
488 |
|
489 |
- |
|
|