From cca508bbed276edc36f8faf78c627180359a6a0e Mon Sep 17 00:00:00 2001 From: Ryan Higgins Date: Mon, 5 Nov 2007 17:13:57 -0600 Subject: [PATCH] updating ILS::Patron for Koha. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- C4/SIP/ILS.pm | 6 ++- C4/SIP/ILS/Patron.pm | 87 ++++++++++++++++++++++++++----------------- C4/SIP/SIPServer.pm | 7 +--- C4/SIP/SIPconfig.xml | 10 +++-- C4/SIP/Sip/MsgType.pm | 9 ++++- C4/SIP/test.txt | 16 ++++++-- 6 files changed, 85 insertions(+), 50 deletions(-) diff --git a/C4/SIP/ILS.pm b/C4/SIP/ILS.pm index 20e940ff3b..69d6d10b01 100644 --- a/C4/SIP/ILS.pm +++ b/C4/SIP/ILS.pm @@ -1,5 +1,5 @@ # -# ILS.pm: Test ILS interface module +# ILS.pm: Koha ILS interface module # package ILS; @@ -43,7 +43,9 @@ sub new { my ($class, $institution) = @_; my $type = ref($class) || $class; my $self = {}; - +use Data::Dumper; +warn " INSTITUTION:"; +warn Dumper($institution); syslog("LOG_DEBUG", "new ILS '%s'", $institution->{id}); $self->{institution} = $institution; diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index ce7921050f..19b93024fb 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -14,6 +14,11 @@ use Exporter; use Sys::Syslog qw(syslog); use Data::Dumper; +use C4::Context; +use C4::Koha; +use C4::Members; +use Digest::MD5 qw(md5_base64); + our (@ISA, @EXPORT_OK); @ISA = qw(Exporter); @@ -50,51 +55,64 @@ our %patron_db = ( unavail_holds => [], inet => 1, }, - miker => { - name => "Mike Rylander", - id => 'miker', - password => '6789', - ptype => 'A', # 'A'dult. Whatever. - birthdate => '19640925', - address => 'Somewhere in Atlanta', - home_phone => '(404) 555 1235', - email_addr => 'mrylander@gmail.com', - charge_ok => 1, - renew_ok => 1, - recall_ok => 0, - hold_ok => 1, - card_lost => 0, + ); + +sub new { + my ($class, $patron_id) = @_; + my $type = ref($class) || $class; + my $self; +my %ilspatron; + my $kp = GetMember($patron_id,'cardnumber'); +warn "THIS IS what we et from getmember..."; +use Data::Dumper; +warn Dumper($kp); + if ($kp) { + my $pw = $kp->{password}; ## FIXME - md5hash -- deal with . + my $dob= $kp->{dateofbirth}; + $dob =~ s/\-//g; + + my $debarred = $kp->{debarred}; ### 1 if ($kp->{flags}->{DBARRED}->{noissues}); +warn "i am debarred: $debarred"; +#warn Dumper(%{$kp->{flags}}); + my $adr = $kp->{streetnumber} . " ". $kp->{address}; + %ilspatron = ( + name => $kp->{firstname} . " " . $kp->{surname}, + id => $kp->{cardnumber}, + password => $pw, + ptype => $kp->{categorycode}, # 'A'dult. Whatever. + birthdate => $dob, + address => $adr, + home_phone => $kp->{phone}, + email_addr => $kp->{email}, + charge_ok => (!$debarred) , ## (C4::Context->preference('FinesMode') eq 'charge') || 0, + renew_ok => 0, + recall_ok => 0, + hold_ok => 0, + card_lost => 0,#$kp->{flags}->{LOST}, claims_returned => 0, - fines => 0, + fines => 0,#$kp->{flags}->{CHARGES}, fees => 0, recall_overdue => 0, items_billed => 0, screen_msg => '', print_line => '', - items => [], - hold_items => [], - overdue_items => [], + items => [] , + hold_items => [],#$kp->{flags}->{WAITING}{itemlist}->{biblionumber}, + overdue_items =>[], # [$kp->{flags}->{ODUES}{itemlisttext}], ### FIXME -> this should be array, not texts string. fine_items => [], recall_items => [], unavail_holds => [], inet => 0, - }, - ); - -sub new { - my ($class, $patron_id) = @_; - my $type = ref($class) || $class; - my $self; - - if (!exists($patron_db{$patron_id})) { - syslog("LOG_DEBUG", "new ILS::Patron(%s): no such patron", $patron_id); - return undef; + ); + } else { + syslog("LOG_DEBUG", "new ILS::Patron(%s): no such patron", $patron_id); + return undef; } - $self = $patron_db{$patron_id}; + $self = \%ilspatron; + warn Dumper($self); - syslog("LOG_DEBUG", "new ILS::Patron(%s): found patron '%s'", $patron_id, - $self->{id}); + syslog("LOG_DEBUG", "new ILS::Patron(%s): found patron '%s'", $patron_id,$self->{id}); bless $self, $type; return $self; @@ -186,10 +204,9 @@ sub recall_overdue { sub check_password { my ($self, $pwd) = @_; + my $md5pwd=$self->{password}; ### FIXME - we're allowing access if user has no password. - # If the patron doesn't have a password, - # then we don't need to check - return (!$self->{password} || ($pwd && ($self->{password} eq $pwd))); +return (!$self->{password} || md5_base64($pwd) eq $md5pwd ); } sub currency { diff --git a/C4/SIP/SIPServer.pm b/C4/SIP/SIPServer.pm index 85d5b46e2c..987daa7378 100644 --- a/C4/SIP/SIPServer.pm +++ b/C4/SIP/SIPServer.pm @@ -125,8 +125,7 @@ sub raw_transport { alarm $service->{timeout}; $input = Sip::read_SIP_packet(*STDIN); alarm 0; - - if (!$input) { + if (!$input) { # EOF on the socket syslog("LOG_INFO", "raw_transport: shutting down: EOF during login"); return; @@ -169,7 +168,6 @@ sub telnet_transport { local $SIG{ALRM} = sub { die "alarm\n"; }; local $|; my $timeout = 0; - $| = 1; # Unbuffered output $timeout = $config->{timeout} if (exists($config->{timeout})); @@ -229,7 +227,6 @@ sub sip_protocol_loop { my $service = $self->{service}; my $config = $self->{config}; my $input; - # Now that the terminal has logged in, the first message # we recieve must be an SC_STATUS message. But it might be # an SC_REQUEST_RESEND. So, as long as we keep receiving @@ -253,7 +250,7 @@ sub sip_protocol_loop { $status = Sip::MsgType::handle($input, $self, $expect); next if $status eq REQUEST_ACS_RESEND; - +#### stopped here rch if (!$status) { syslog("LOG_ERR", "raw_transport: failed to handle %s", substr($input, 0, 2)); diff --git a/C4/SIP/SIPconfig.xml b/C4/SIP/SIPconfig.xml index 079c88d6a4..c7f972021e 100644 --- a/C4/SIP/SIPconfig.xml +++ b/C4/SIP/SIPconfig.xml @@ -28,9 +28,8 @@ - - - + + @@ -45,6 +44,11 @@ + + + diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index ce05b93ce8..5f625039c6 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -285,6 +285,7 @@ sub new { # so we'll just do it. $protocol_version = 2; } +warn "PROTOCOL: $protocol_version"; if (!exists($handlers{$msgtag})) { syslog("LOG_WARNING", "new Sip::MsgType: Skipping message of unknown type '%s' in '%s'", @@ -471,9 +472,11 @@ sub build_patron_status { return $resp; } +use Data::Dumper; sub handle_patron_status { my ($self, $server) = @_; - my $ils = $server->{ils}; +#warn Dumper($server); + my $ils = $server->{ils}; my ($lang, $date); my $fields; my $patron; @@ -482,7 +485,9 @@ sub handle_patron_status { ($lang, $date) = @{$self->{fixed_fields}}; $fields = $self->{fields}; - +warn Dumper($fields); +warn FID_INST_ID; +warn $fields->{(FID_INST_ID)}; $ils->check_inst_id($fields->{(FID_INST_ID)}, "handle_patron_status"); $patron = $ils->find_patron($fields->{(FID_PATRON_ID)}); diff --git a/C4/SIP/test.txt b/C4/SIP/test.txt index 775b14793e..c70e7dd88e 100644 --- a/C4/SIP/test.txt +++ b/C4/SIP/test.txt @@ -1,17 +1,27 @@ 97AZFEF5 -2300120060101 084235AOUWOLS|AAdjfiander|ACterminal password|ADuser password| +2300120071003 084235AOkohalibrary|AArch|ACkoha|ADkoha| + 2300120060101 084236AOUWOLS|AAmjandkilde|ACterminal password|ADuser password| 2300120060101 084237AOUWOLS|AAdjfiander|ACterminal password|ADuser password| 9300CNLoginUserID|COLoginPassword|CPLocationCode| 11YN20060329 203000 AOUWOLS|AAdjfiander|AB1565921879|AC| 09Y20060102 08423620060113 084235APUnder the bed|AOUWOLS|AB1565921879|ACterminal password| 01N20060102 084238AOUWOLS|ALHe's a jerk|AAdjfiander|ACterminal password| + 2520060102 084238AOUWOLS|AAdjfiander|ACterminal password|AD6789| 9910302.00 -3520060110 084237AOUWOLS|AAdjfiander|AD6789| + +3520060110 084237AOkohalibrary|AArch|ADkoha| 1720060110 215612AOUWOLS|AB1565921879| -6300020060329 201700Y AOUWOLS|AAdjfiander| + +patron information: +6300020060329 201700Y AOkohalibrary|AArch|ACkoha|ADkoha| + 15+20060415 110158BW20060815 110158|BSTaylor|BY2|AOUWOLS|AAdjfiander|AB1565921879| 15-20060415 110158AOUWOLS|AAdjfiander|AB1565921879| 29NN20060415 110158 AOUWOLS|AAdjfiander|AD6789|AB1565921879| 6520060415 110158AOUWOLS|AAdjfiander|AD6789| + +working: + +9300CNkoha|COkoha|CPkohalibrary| -- 2.20.1