address => '2 Meadowvale Dr. St Thomas, ON',
home_phone => '(519) 555 1234',
email_addr => 'djfiander@hotmail.com',
- charge_ok => 'Y',
- renew_ok => 'Y',
- recall_ok => 'N',
- hold_ok => 'Y',
- card_lost => 'N',
+ charge_ok => 1,
+ renew_ok => 1,
+ recall_ok => 0,
+ hold_ok => 1,
+ card_lost => 0,
items_charged => 5,
claims_returned => 0,
fines => 100,
my $self;
if (!exists($patron_db{$patron_id})) {
+ syslog("DEBUG", "new ILS::Patron(%s): no such patron", $patron_id);
return undef;
}
+
$self = $patron_db{$patron_id};
+ syslog("DEBUG", "new ILS::Patron(%s): found patron '%s'", $patron_id,
+ $self->{id});
+
bless $self, $type;
return $self;
}
my ($self, $card_retained, $blocked_card_msg) = @_;
foreach my $field ('charge_ok', 'renew_ok', 'recall_ok', 'hold_ok') {
- $self->{$field} = 'N';
+ $self->{$field} = 0;
}
$self->{screen_msg} = $blocked_card_msg || "Card Blocked. Please contact library staff";
my $self = shift;
foreach my $field ('charge_ok', 'renew_ok', 'recall_ok', 'hold_ok') {
- $self->{$field} = 'Y';
+ $self->{$field} = 1;
}
syslog("DEBUG", "Patron(%s)->enable: charge: %s, renew:%s, recall:%s",
sub denied {
my $bool = shift;
- if (!$bool || ($bool eq 'N') || $bool eq 'False') {
- return 'Y';
- } else {
- return ' ';
- }
+ return boolspace(!$bool);
}
sub sipbool {
my $bool = shift;
- if (!$bool || ($bool =~/^false|n|no$/i)) {
- return('N');
- } else {
- return('Y');
- }
+ return $bool ? 'Y' : 'N';
}
#
sub boolspace {
my $bool = shift;
- if (!$bool || ($bool eq 'N' || $bool eq 'False')) {
- return ' ';
- } else {
- return 'Y';
- }
+ return $bool ? 'Y' : ' ';
}
#
-# write_msg($msg, $server)
+# write_msg($msg, $file)
#
# Send $msg to the SC. If error detection is active, then
# add the sequence number (if $seqno is non-zero) and checksum
# to the message, and save the whole thing as $last_response
+#
+# If $file is set, then it's a file handle: write to it, otherwise
+# just write to the default destination.
#
sub write_msg {
- my ($self, $msg, $server) = @_;
+ my ($self, $msg, $file) = @_;
my $cksum;
if ($error_detection) {
syslog("LOG_DEBUG", "OUTPUT MSG: '$msg'");
- print "$msg\r";
+ if ($file) {
+ print $file "$msg\r";
+ } else {
+ print "$msg\r";
+ }
+
$last_response = $msg;
}
$resp = build_patron_status($patron, $lang, $fields);
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return (PATRON_STATUS_REQ);
}
}
}
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return(CHECKOUT);
}
$resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return(CHECKIN);
}
$fields->{(FID_PATRON_PWD)} = $patron->password;
$resp = build_patron_status($patron, '000', $fields);
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return(BLOCK_PATRON);
}
if (!$last_response) {
# We haven't sent anything yet, so respond with a
# REQUEST_SC_RESEND msg (p. 16)
- $self->write_msg(REQUEST_SC_RESEND, $server);
+ $self->write_msg(REQUEST_SC_RESEND);
} elsif ((length($last_response) < 9)
|| substr($last_response, -9, 2) ne 'AY') {
# When resending a message, we aren't supposed to include
# Cut out the sequence number and checksum, since the old
# checksum is wrong for the resent message.
$rebuilt = substr($last_response, 0, -9);
- $self->write_msg($rebuilt, $server);
+ $self->write_msg($rebuilt);
}
return REQUEST_ACS_RESEND;
$server->{account}->{id}, $server->{account}->{institution});
}
- $self->write_msg(LOGIN_RESP . $status, $server);
+ $self->write_msg(LOGIN_RESP . $status);
return $status ? LOGIN : '';
}
$resp .= add_field(FID_INST_ID, $server->{ils}->institution);
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return(PATRON_INFO);
}
$resp .= maybe_add(FID_SCREEN_MSG, $screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $print_line);
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return(END_PATRON_SESSION);
}
$resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return(FEE_PAID);
}
$resp .= maybe_add(FID_PRINT_LINE, $item->print_line);
}
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return(ITEM_INFORMATION);
}
$resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return(ITEM_STATUS_UPDATE);
}
$resp .= add_field(FID_INST_ID, $ils->institution);
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return(PATRON_ENABLE);
}
$resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return(HOLD);
}
$resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return(RENEW);
}
$resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg);
$resp .= maybe_add(FID_PRINT_LINE, $status->print_line);
- $self->write_msg($resp, $server);
+ $self->write_msg($resp);
return(RENEW_ALL);
}
# Do we want to tell the terminal its location?
- $self->write_msg($msg, $server);
+ $self->write_msg($msg);
return 1;
}
my $patron = shift;
my $patron_status;
+ syslog("DEBUG", "patron_status_string: %s charge_ok: %s", $patron->id,
+ $patron->charge_ok);
$patron_status = sprintf('%s%s%s%s%s%s%s%s%s%s%s%s%s%s',
denied($patron->charge_ok),
denied($patron->renew_ok),