From 66f7cec728b266130d5da30b04ea85afc5645a68 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 14 Jul 2014 09:50:32 -0400 Subject: [PATCH] Bug 12571 - Add ability to customize SIP2 screen messages We should add the ability to apply a regular expression to screen messages for the SIP2 server. This would allow libraries to not only customize the screen messages the patron sees, but can also allow screen messages to be translated. Test Plan: 1) Apply this patch 2) Inspect etc/SIPconfig.xml, note the new screen_msg_regex tags that can be nested inside a given login tag. 3) Add one or more screen_msg_regex tags to your own SIP config Recommendation: s/Greetings from Koha./Welcome to your library!/g 4) Restart your SIP2 server 5) Test with a SIP2 machine, or use /misc/sip_cli_emulator.pl 6) Note your new AF fields! Signed-off-by: Jason Burds --- C4/SIP/Sip.pm | 15 +++++++++++++-- C4/SIP/Sip/MsgType.pm | 32 ++++++++++++++++---------------- etc/SIPconfig.xml | 5 ++++- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/C4/SIP/Sip.pm b/C4/SIP/Sip.pm index b6f1916..d59b1c1 100644 --- a/C4/SIP/Sip.pm +++ b/C4/SIP/Sip.pm @@ -13,7 +13,7 @@ use POSIX qw(strftime); use Socket qw(:crlf); use IO::Handle; -use Sip::Constants qw(SIP_DATETIME); +use Sip::Constants qw(SIP_DATETIME FID_SCREEN_MSG); use Sip::Checksum qw(checksum); use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS); @@ -91,7 +91,18 @@ sub add_field { # NOTE: if zero is a valid value for your field, don't use maybe_add! # sub maybe_add { - my ($fid, $value) = @_; + my ($fid, $value, $server) = @_; + + if ( $fid eq FID_SCREEN_MSG && $server->{account}->{screen_msg_regex} ) { + foreach my $regex ( + ref $server->{account}->{screen_msg_regex} eq "ARRAY" + ? @{ $server->{account}->{screen_msg_regex} } + : $server->{account}->{screen_msg_regex} ) + { + $value =~ s/$regex->{find}/$regex->{replace}/g; + } + } + return (defined($value) && $value) ? add_field($fid, $value) : ''; } diff --git a/C4/SIP/Sip/MsgType.pm b/C4/SIP/Sip/MsgType.pm index 4bad2ea..2aca72f 100644 --- a/C4/SIP/Sip/MsgType.pm +++ b/C4/SIP/Sip/MsgType.pm @@ -452,8 +452,8 @@ sub build_patron_status { $resp .= maybe_add(FID_FEE_AMT, $patron->fee_amount); } - $resp .= maybe_add( FID_SCREEN_MSG, $patron->screen_msg ); - $resp .= maybe_add( FID_SCREEN_MSG, $patron->{branchcode} ) + $resp .= maybe_add( FID_SCREEN_MSG, $patron->screen_msg, $server ); + $resp .= maybe_add( FID_SCREEN_MSG, $patron->{branchcode}, $server ) if ( $server->{account}->{send_patron_home_library_in_af} ); $resp .= maybe_add(FID_PRINT_LINE, $patron->print_line); @@ -556,7 +556,7 @@ sub handle_checkout { $resp .= add_field(FID_DUE_DATE, q{}); } - $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg); + $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg, $server); $resp .= maybe_add(FID_PRINT_LINE, $status->print_line); if ($protocol_version >= 2) { @@ -593,7 +593,7 @@ sub handle_checkout { # it's not due, so leave the date blank $resp .= add_field(FID_DUE_DATE, ''); - $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg); + $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg, $server); $resp .= maybe_add(FID_PRINT_LINE, $status->print_line); if ($protocol_version >= 2) { @@ -693,7 +693,7 @@ sub handle_checkin { } $resp .= maybe_add(FID_ALERT_TYPE, $status->alert_type) if $status->alert; - $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg); + $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg, $server); $resp .= maybe_add(FID_PRINT_LINE, $status->print_line); $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); @@ -997,8 +997,8 @@ sub handle_patron_info { # Custom protocol extension to report patron internet privileges $resp .= maybe_add(FID_INET_PROFILE, $patron->inet_privileges); - $resp .= maybe_add( FID_SCREEN_MSG, $patron->screen_msg ); - $resp .= maybe_add( FID_SCREEN_MSG, $patron->{branchcode} ) + $resp .= maybe_add( FID_SCREEN_MSG, $patron->screen_msg, $server ); + $resp .= maybe_add( FID_SCREEN_MSG, $patron->{branchcode}, $server ) if ( $server->{account}->{send_patron_home_library_in_af} ); $resp .= maybe_add(FID_PRINT_LINE, $patron->print_line); @@ -1043,7 +1043,7 @@ sub handle_end_patron_session { $resp .= add_field(FID_INST_ID, $server->{ils}->institution); $resp .= add_field(FID_PATRON_ID, $fields->{(FID_PATRON_ID)}); - $resp .= maybe_add(FID_SCREEN_MSG, $screen_msg); + $resp .= maybe_add(FID_SCREEN_MSG, $screen_msg, $server); $resp .= maybe_add(FID_PRINT_LINE, $print_line); $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); @@ -1077,7 +1077,7 @@ sub handle_fee_paid { $resp .= add_field(FID_INST_ID, $inst_id); $resp .= add_field(FID_PATRON_ID, $patron_id); $resp .= maybe_add(FID_TRANSACTION_ID, $status->transaction_id); - $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg); + $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg, $server); $resp .= maybe_add(FID_PRINT_LINE, $status->print_line); $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); @@ -1143,7 +1143,7 @@ sub handle_item_information { $resp .= add_field(FID_HOLD_PICKUP_DATE, Sip::timestamp($i)); } - $resp .= maybe_add(FID_SCREEN_MSG, $item->screen_msg); + $resp .= maybe_add(FID_SCREEN_MSG, $item->screen_msg, $server); $resp .= maybe_add(FID_PRINT_LINE, $item->print_line); } @@ -1193,7 +1193,7 @@ sub handle_item_status_update { $resp .= maybe_add(FID_ITEM_PROPS, $item->sip_item_properties); } - $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg); + $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg, $server); $resp .= maybe_add(FID_PRINT_LINE, $status->print_line); $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); @@ -1241,7 +1241,7 @@ sub handle_patron_enable { sipbool($patron->check_password($patron_pwd))); } $resp .= add_field(FID_VALID_PATRON, 'Y'); - $resp .= maybe_add(FID_SCREEN_MSG, $patron->screen_msg); + $resp .= maybe_add(FID_SCREEN_MSG, $patron->screen_msg, $server); $resp .= maybe_add(FID_PRINT_LINE, $patron->print_line); } @@ -1310,7 +1310,7 @@ sub handle_hold { } $resp .= add_field(FID_INST_ID, $ils->institution); - $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg); + $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg, $server); $resp .= maybe_add(FID_PRINT_LINE, $status->print_line); $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); @@ -1399,7 +1399,7 @@ sub handle_renew { } $resp .= add_field(FID_INST_ID, $ils->institution); - $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg); + $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg, $server); $resp .= maybe_add(FID_PRINT_LINE, $status->print_line); $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); @@ -1449,7 +1449,7 @@ sub handle_renew_all { $resp .= join('', map(add_field(FID_RENEWED_ITEMS , $_), @renewed )); $resp .= join('', map(add_field(FID_UNRENEWED_ITEMS, $_), @unrenewed)); - $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg); + $resp .= maybe_add(FID_SCREEN_MSG, $status->screen_msg, $server); $resp .= maybe_add(FID_PRINT_LINE, $status->print_line); $self->write_msg($resp,undef,$server->{account}->{terminator},$server->{account}->{encoding}); @@ -1549,7 +1549,7 @@ sub send_acs_status { $msg .= add_field(FID_SUPPORTED_MSGS, $supported_msgs); } - $msg .= maybe_add(FID_SCREEN_MSG, $screen_msg); + $msg .= maybe_add(FID_SCREEN_MSG, $screen_msg, $server); if (defined($account->{print_width}) && defined($print_line) && $account->{print_width} < length($print_line)) { diff --git a/etc/SIPconfig.xml b/etc/SIPconfig.xml index bd8d49e..8d2d77b 100644 --- a/etc/SIPconfig.xml +++ b/etc/SIPconfig.xml @@ -42,7 +42,10 @@ + send_patron_home_library_in_af="1" > + + +