3 # A Class for hiding the ILS's concept of the patron from the OpenSIP
7 package OpenILS::SIP::Patron;
13 use Sys::Syslog qw(syslog);
15 use Digest::MD5 qw(md5_hex);
18 use OpenILS::Application::AppUtils;
19 use OpenILS::Application::Actor;
20 use OpenILS::Const qw/:const/;
21 use OpenILS::Utils::DateTime qw/:datetime/;
22 use DateTime::Format::ISO8601;
23 use OpenILS::Utils::Fieldmapper;
24 my $U = 'OpenILS::Application::AppUtils';
26 our (@ISA, @EXPORT_OK);
30 @EXPORT_OK = qw(invalid_patron);
37 my $patron_id = shift;
40 if ($key ne 'usr' and $key ne 'barcode' and $key ne 'usrname') {
41 syslog("LOG_ERROR", "Patron (card) lookup requested by illegeal key '$key'");
45 unless(defined $patron_id) {
46 syslog("LOG_WARNING", "No patron ID provided to ILS::Patron->new");
50 my $type = ref($class) || $class;
51 my $self = bless({}, $type);
53 syslog("LOG_DEBUG", "OILS: new OpenILS Patron(%s => %s): searching...", $key, $patron_id);
55 my $idl = OpenSRF::Utils::SettingsClient->new->config_value("IDL");
56 Fieldmapper->import(IDL => $idl);
58 my $e = OpenILS::SIP->editor();
59 # Pass the authtoken, if any, to the editor so that we can use it
60 # to fake a context org_unit for the csp.ignore_proximity in
61 # flesh_user_penalties, below.
62 unless ($e->authtoken()) {
63 $e->authtoken($args{authtoken}) if ($args{authtoken});
83 # in some cases, we don't need all of this data. Only fetch the user + barcode
84 $usr_flesh = {flesh => 1, flesh_fields => {au => ['card']}} if $args{slim_user};
87 if($key eq 'barcode') { # retrieve user by barcode
89 $$usr_flesh{flesh} += 1;
90 $$usr_flesh{flesh_fields}{ac} = ['usr'];
92 my $card = $e->search_actor_card([{barcode => $patron_id}, $usr_flesh])->[0];
94 if(!$card or !$U->is_true($card->active)) {
95 syslog("LOG_WARNING", "No such patron barcode: $patron_id");
101 } elsif ($key eq 'usrname') {
102 $user = $e->search_actor_user([{usrname => $patron_id}, $usr_flesh])->[0];
104 $user = $e->retrieve_actor_user([$patron_id, $usr_flesh]);
107 if(!$user or $U->is_true($user->deleted)) {
108 syslog("LOG_WARNING", "OILS: Unable to find patron %s => %s", $key, $patron_id);
112 if(!$U->is_true($user->active)) {
113 syslog("LOG_WARNING", "OILS: Patron is inactive %s => %s", $key, $patron_id);
117 # now grab the user's penalties
119 $self->flesh_user_penalties($user, $e) unless $args{slim_user};
121 $self->{authtoken} = $args{authtoken} if $args{authtoken};
122 $self->{editor} = $e;
123 $self->{user} = $user;
124 $self->{id} = ($key eq 'barcode') ? $patron_id : $user->card->barcode; # The barcode IS the ID to SIP.
125 # We give back the passed barcode if the key was indeed a barcode, just to be safe. Otherwise pull it from the card.
127 syslog("LOG_DEBUG", "OILS: new OpenILS Patron(%s => %s): found patron : barred=%s, card:active=%s",
128 $key, $patron_id, $user->barred, $user->card->active );
130 $U->log_user_activity($user->id, $self->get_act_who, 'verify');
137 my $config = OpenILS::SIP->config();
138 my $login = OpenILS::SIP->login_account();
140 my $act_who = $config->{implementation_config}->{default_activity_who};
141 my $force_who = $config->{implementation_config}->{force_activity_who};
143 # 1. future: test sip extension for caller-provided ewho and !$force_who
145 # 2. See if the login is tagged with an ewho
146 return $login->{activity_who} if $login->{activity_who};
148 # 3. if all else fails, see if there is an institution-wide ewho
149 return $config->{activity_who} if $config->{activity_who};
154 # grab patron penalties. Only grab non-archived penalties that are for fines,
155 # excessive overdues, or otherwise block circluation activity
156 sub flesh_user_penalties {
157 my ($self, $user, $e) = @_;
159 # Use the ws_ou or home_ou of the authsession user, if any, as a
160 # context org_unit for the penalties and the csp.ignore_proximity.
162 if ($e->authtoken()) {
163 my $auth_usr = $e->checkauth();
165 $here = $auth_usr->ws_ou() || $auth_usr->home_ou();
169 # Get the "raw" list of user's penalties and flesh the
170 # standing_penalty field, so we can filter them based on
171 # csp.ignore_proximity.
173 $e->search_actor_user_standing_penalty([
178 # ignore "archived" penalties
179 {stop_date => undef},
180 {stop_date => {'>' => 'now'}}
188 transform => 'actor.org_unit_ancestors',
194 # Use "here" or user's home_ou.
195 where => {id => ($here) ? $here : $user->home_ou},
200 # in addition to fines and excessive overdue penalties,
201 # we only care about penalties that result in blocks
202 standing_penalty => {
204 select => {csp => ['id']},
208 {id => [1,2]}, # fines / overdues
209 {block_list => {'!=' => undef}}
217 flesh_fields => {ausp => ['standing_penalty']}
220 # We filter the raw penalties that apply into this array.
221 my $applied_penalties = [];
222 if (ref($raw_penalties) eq 'ARRAY' && @$raw_penalties) {
223 my $here_prox = ($here) ? $U->get_org_unit_proximity($e, $here, $user->home_ou())
225 # Filter out those that do not apply
226 $applied_penalties = [map
227 { $_->standing_penalty }
229 !defined($_->standing_penalty->ignore_proximity())
230 || ((defined($here_prox))
231 ? $_->standing_penalty->ignore_proximity() < $here_prox
232 : $_->standing_penalty->ignore_proximity() <
233 $U->get_org_unit_proximity($e, $_->org_unit(), $user->home_ou()))
236 $user->standing_penalties($applied_penalties);
246 return format_name($self->{user});
251 return sprintf('%s %s %s',
252 ($u->pref_first_given_name || $u->first_given_name || ''),
253 ($u->pref_second_given_name || $u->second_given_name || ''),
254 ($u->pref_family_name || $u->family_name || ''));
259 my $lib = OpenILS::SIP::shortname_from_id($self->{user}->home_ou);
260 syslog('LOG_DEBUG', "OILS: Patron->home_library() = $lib");
266 return "" unless $addr;
267 my $return = join( ' ', map {$_ || ''}
278 $return =~ s/\s+/ /sg; # Compress any run of of whitespace to one space
284 return $self->{user}->id;
289 my $u = $self->{user};
290 my $str = __addr_string($u->billing_address || $u->mailing_address);
291 syslog('LOG_DEBUG', "OILS: Patron address: $str");
297 return $self->{user}->email;
302 return $self->{user}->day_phone;
307 my $dob = OpenILS::SIP->format_date($self->{user}->dob, 'dob');
308 syslog('LOG_DEBUG', "OILS: Patron DOB = $dob");
314 my $expire = OpenILS::SIP->format_date($self->{user}->expire_date);
315 syslog('LOG_DEBUG', "OILS: Patron Expire = $expire");
322 my $use_code = OpenILS::SIP->get_option_value('patron_type_uses_code') || '';
324 # should we use the no_i18n version of patron profile name (as a 'code')?
325 return $self->{editor}->retrieve_permission_grp_tree(
326 [$self->{user}->profile->id, {no_i18n => 1}])->name
327 if $use_code =~ /true/io;
329 return $self->{user}->profile->name;
334 return '000'; # Unspecified
337 # method to check to see if charge_ok, renew_ok, and
338 # lost_card should be coerced to return a status indicating
339 # that the patron should be allowed to circulate; this
340 # implements a workaround further described in
341 # https://bugs.launchpad.net/evergreen/+bug/1853363
342 sub patron_status_always_permit_loans_set {
345 my $login = OpenILS::SIP->login_account();
348 OpenILS::SIP::to_bool($login->{patron_status_always_permit_loans}) //
349 OpenILS::SIP::to_bool(OpenILS::SIP->get_option_value('patron_status_always_permit_loans'))
354 # How much more detail do we need to check here?
355 # sec: adding logic to return false if user is barred, has a circulation block
359 my $u = $self->{user};
360 my $circ_is_blocked = 0;
362 return 1 if $self->patron_status_always_permit_loans_set();
364 # compute expiration date for borrowing privileges
365 my $expire = DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($u->expire_date));
368 (($u->barred eq 't') or
369 (@{$u->standing_penalties} and grep { ( $_->block_list // '') =~ /CIRC/ } @{$u->standing_penalties}) or
370 (CORE::time > $expire->epoch));
375 $u->card->active eq 't';
380 my $u = $self->{user};
381 my $renew_is_blocked = 0;
383 return 1 if $self->patron_status_always_permit_loans_set();
385 # compute expiration date for borrowing privileges
386 my $expire = DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($u->expire_date));
389 (($u->barred eq 't') or
390 (@{$u->standing_penalties} and grep { ( $_->block_list // '') =~ /RENEW/ } @{$u->standing_penalties}) or
391 (CORE::time > $expire->epoch));
394 !$renew_is_blocked &&
396 $u->card->active eq 't';
401 return $self->charge_ok if
402 OpenILS::SIP->get_option_value('patron_calculate_recal_ok');
408 my $u = $self->{user};
409 my $hold_is_blocked = 0;
411 # compute expiration date for borrowing privileges
412 my $expire = DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($u->expire_date));
415 (($u->barred eq 't') or
416 (@{$u->standing_penalties} and grep { ( $_->block_list // '') =~ /HOLD/ } @{$u->standing_penalties}) or
417 (CORE::time > $expire->epoch));
422 $u->card->active eq 't';
425 # return true if the card provided is marked as lost
429 return 0 if $self->patron_status_always_permit_loans_set();
431 return $self->{user}->card->active eq 'f';
434 sub recall_overdue { # not implemented
440 my ($self, $pwd) = @_;
441 syslog('LOG_DEBUG', 'OILS: Patron->check_password()');
442 return 0 unless (defined $pwd and $self->{user});
443 return $U->verify_migrated_user_password(
444 $self->{editor},$self->{user}->id, $pwd);
449 syslog('LOG_DEBUG', 'OILS: Patron->currency()');
450 return OpenILS::SIP->config()->{implementation_config}->{currency} || 'USD';
455 syslog('LOG_DEBUG', 'OILS: Patron->fee_amount()');
456 my $user_id = $self->{user}->id;
458 my $e = $self->{editor};
460 my $summary = $e->retrieve_money_open_user_summary($user_id);
461 $e->rollback; # xact_rollback + disconnect
463 my $total = ($summary) ? $summary->balance_owed : 0;
464 syslog('LOG_INFO', "User ".$self->{id} .":$user_id has a fee amount of \$$total");
470 my $u = $self->{user};
472 return 'barred' if $u->barred eq 't';
476 return $b if $u->active eq 'f';
477 return $b if $u->card->active eq 'f';
479 # if we have any penalties at this point, they are blocking penalties
480 return $b if $u->standing_penalties and @{$u->standing_penalties};
482 # has the patron account expired?
483 my $expire = DateTime::Format::ISO8601->new->parse_datetime(clean_ISO8601($u->expire_date));
484 return $b if CORE::time > $expire->epoch;
489 sub print_line { # not implemented
494 sub too_many_charged { # not implemented
499 sub too_many_overdue {
501 return scalar( # PATRON_EXCEEDS_OVERDUE_COUNT
502 grep { $_->id == OILS_PENALTY_PATRON_EXCEEDS_OVERDUE_COUNT } @{$self->{user}->standing_penalties}
506 # not completely sure what this means
507 sub too_many_renewal {
512 # not relevant, handled by fines/fees
513 sub too_many_claim_return {
518 # not relevant, handled by fines/fees
524 sub excessive_fines {
526 return scalar( # PATRON_EXCEEDS_FINES
527 grep { $_->id == OILS_PENALTY_PATRON_EXCEEDS_FINES } @{$self->{user}->standing_penalties}
531 # Until someone suggests otherwise, fees and fines are the same
535 return $self->excessive_fines;
538 # not relevant, handled by fines/fees
539 sub too_many_billed {
547 # List of outstanding holds placed
550 my ($self, $start, $end, $ids_only) = @_;
551 syslog('LOG_DEBUG', 'OILS: Patron->hold_items()');
553 # all of my open holds
555 usr => $self->{user}->id,
556 fulfillment_time => undef,
559 if (OpenILS::SIP->get_option_value('msg64_hold_items_available')) {
560 # Limit to available holds.
561 $holds_query->{current_shelf_lib} = {'=' => {'+ahr' => 'pickup_lib'}};
563 my $holds = $self->{editor}->search_action_hold_request($holds_query);
565 return $holds if $ids_only;
566 return $self->__format_holds($holds, $start, $end);
570 my ($self, $start, $end, $ids_only) = @_;
571 syslog('LOG_DEBUG', 'OILS: Patron->unavail_holds()');
573 my $holds = $self->{editor}->search_action_hold_request({
574 usr => $self->{user}->id,
575 fulfillment_time => undef,
576 cancel_time => undef,
578 {current_shelf_lib => undef},
579 {current_shelf_lib => {'!=' => {'+ahr' => 'pickup_lib'}}}
583 return $holds if $ids_only;
584 return $self->__format_holds($holds, $start, $end);
590 my ($self, $holds, $start, $end) = @_;
592 return [] unless @$holds;
594 my $return_datatype =
595 OpenILS::SIP->get_option_value('msg64_hold_datatype') || '';
599 for my $hold (@$holds) {
601 if ($return_datatype eq 'barcode') {
603 if (my $copy = $self->find_copy_for_hold($hold)) {
604 push(@response, $copy->barcode);
607 syslog('LOG_WARNING',
608 'OILS: No representative copy found for hold ' . $hold->id);
613 $self->__hold_to_title($hold));
617 return (defined $start and defined $end) ?
618 [ @response[($start-1)..($end-1)] ] :
622 # Finds a representative copy for the given hold.
623 # If no copy exists at all, undef is returned.
624 # The only limit placed on what constitutes a
625 # "representative" copy is that it cannot be deleted.
626 # Otherwise, any copy that allows us to find the hold
627 # later is good enough.
628 sub find_copy_for_hold {
629 my ($self, $hold) = @_;
630 my $e = $self->{editor};
632 return $e->retrieve_asset_copy($hold->current_copy)
633 if $hold->current_copy;
635 return $e->retrieve_asset_copy($hold->target)
636 if $hold->hold_type =~ /C|R|F/;
638 return $e->search_asset_copy([
639 {call_number => $hold->target, deleted => 'f'},
640 {limit => 1}])->[0] if $hold->hold_type eq 'V';
642 return $e->json_query(
644 select => { acp => ['id'] },
648 field => 'target_copy',
650 filter => { part => $hold->target }
654 where => { '+acp' => { deleted => 'f' } },
656 })->[0]->{id} if $hold->hold_type eq 'P';
659 return $e->json_query(
661 select => { acp => ['id'] },
667 filter => { issuance => $hold->target }
671 where => { '+acp' => { deleted => 'f' } },
673 })->[0]->{id} if $hold->hold_type eq 'I';
676 my $bre_ids = [$hold->target];
678 if ($hold->hold_type eq 'M') {
679 # find all of the bibs that link to the target metarecord
680 my $maps = $e->search_metabib_metarecord_source_map(
681 {metarecord => $hold->target});
682 $bre_ids = [map {$_->record} @$maps];
685 my $vol_ids = $e->search_asset_call_number(
686 {record => $bre_ids, deleted => 'f'},
690 return $e->search_asset_copy([
691 {call_number => $vol_ids, deleted => 'f'},
696 # Given a "representative" copy, finds a matching hold
697 sub find_hold_from_copy {
698 my ($self, $barcode) = @_;
699 my $e = $self->{editor};
702 my $copy = $e->search_asset_copy([
703 {barcode => $barcode, deleted => 'f'},
704 {flesh => 1, flesh_fields => {acp => ['call_number']}}
707 return undef unless $copy;
709 my $run_hold_query = sub {
711 return $e->search_action_hold_request([
712 { usr => $self->{user}->id,
713 cancel_time => undef,
714 fulfillment_time => undef,
718 order_by => {ahr => 'request_time DESC'}
723 # first see if there is a match on current_copy
724 return $hold if $hold =
725 $run_hold_query->(current_copy => $copy->id);
727 # next, assume bib-level holds are the most common
728 return $hold if $hold = $run_hold_query->(
729 target => $copy->call_number->record, hold_type => 'T');
731 # next try metarecord holds
732 my $map = $e->search_metabib_metarecord_source_map(
733 {source => $copy->call_number->record})->[0];
735 return $hold if $hold = $run_hold_query->(
736 target => $map->metarecord, hold_type => 'M');
740 my $part = $e->search_asset_copy_part_map(
741 { target_copy => $copy->id })->[0];
744 return $hold if $hold = $run_hold_query->(
745 target => $part->id, hold_type => 'P');
749 my $iss = $e->search_serial_item(
750 { unit => $copy->id })->[0];
753 return $hold if $hold = $run_hold_query->(
754 target => $iss->id, hold_type => 'I');
758 return $hold if $hold = $run_hold_query->(
759 target => $copy->call_number->id, hold_type => 'V');
762 return $run_hold_query->(
763 target => $copy->id, hold_type => ['C', 'F', 'R']);
766 sub __hold_to_title {
769 my $e = $self->{editor};
771 my( $id, $mods, $title, $volume, $copy );
773 return __copy_to_title($e,
774 $e->retrieve_asset_copy($hold->target))
775 if $hold->hold_type eq 'C' or $hold->hold_type eq 'F' or $hold->hold_type eq 'R';
777 return __part_to_title($e,
778 $e->retrieve_biblio_monograph_part($hold->target))
779 if $hold->hold_type eq 'P';
781 return __volume_to_title($e,
782 $e->retrieve_asset_call_number($hold->target))
783 if $hold->hold_type eq 'V';
785 return __issuance_to_title(
786 $e, $hold->target) # starts with the issuance id because there's more involved for I holds.
787 if $hold->hold_type eq 'I';
789 return __record_to_title(
790 $e, $hold->target) if $hold->hold_type eq 'T';
792 return __metarecord_to_title(
793 $e, $hold->target) if $hold->hold_type eq 'M';
796 sub __copy_to_title {
797 my( $e, $copy ) = @_;
798 #syslog('LOG_DEBUG', "OILS: copy_to_title(%s)", $copy->id);
799 return $copy->dummy_title if $copy->call_number == -1;
801 my $vol = (ref $copy->call_number) ?
803 $e->retrieve_asset_call_number($copy->call_number);
805 return __volume_to_title($e, $vol);
808 sub __part_to_title {
809 my( $e, $part ) = @_;
810 #syslog('LOG_DEBUG', "OILS: part_to_title(%s)", $part->id);
812 return __record_to_title($e, $part->record);
815 sub __volume_to_title {
816 my( $e, $volume ) = @_;
817 #syslog('LOG_DEBUG', "OILS: volume_to_title(%s)", $volume->id);
818 return __record_to_title($e, $volume->record);
821 sub __issuance_to_title {
822 my( $e, $issuance_id ) = @_;
823 my $bre_id = $e->json_query(
825 select => { ssub => ['record_entry'] },
829 field => 'subscription',
831 filter => { id => $issuance_id }
835 })->[0]->{record_entry};
837 return __record_to_title($e, $bre_id);
841 sub __record_to_title {
842 my( $e, $title_id ) = @_;
843 #syslog('LOG_DEBUG', "OILS: record_to_title($title_id)");
844 my $mods = $U->simplereq(
846 'open-ils.search.biblio.record.mods_slim.retrieve', $title_id );
847 return ($mods) ? $mods->title : "";
850 sub __metarecord_to_title {
851 my( $e, $m_id ) = @_;
852 #syslog('LOG_DEBUG', "OILS: metarecord_to_title($m_id)");
853 my $mods = $U->simplereq(
855 'open-ils.search.biblio.metarecord.mods_slim.retrieve', $m_id);
856 return ($U->event_code($mods)) ? "<unknown>" : $mods->title;
861 # remove the hold on item item_id from my hold queue.
862 # return true if I was holding the item, false otherwise.
865 my ($self, $item_id) = @_;
869 sub __patron_items_info {
871 return if $self->{item_info};
873 OpenILS::Application::Actor::_checked_out(
874 0, $self->{editor}, $self->{user}->id);;
880 my ($self, $start, $end, $ids_only) = @_;
882 $self->__patron_items_info();
883 my @overdues = @{$self->{item_info}->{overdue}};
884 #$overdues[$_] = __circ_to_title($self->{editor}, $overdues[$_]) for @overdues;
886 return \@overdues if $ids_only;
889 syslog('LOG_DEBUG', "OILS: overdue_items() fleshing circs @overdues");
891 my $return_datatype = OpenILS::SIP->get_option_value('msg64_summary_datatype') || '';
893 for my $circid (@overdues) {
895 if($return_datatype eq 'barcode') {
896 push( @o, __circ_to_barcode($self->{editor}, $circid));
898 push( @o, __circ_to_title($self->{editor}, $circid));
903 return (defined $start and defined $end) ?
904 [ @overdues[($start-1)..($end-1)] ] : \@overdues;
907 sub __circ_to_barcode {
910 $circ = $e->retrieve_action_circulation($circ);
911 my $copy = $e->retrieve_asset_copy($circ->target_copy);
912 return $copy->barcode;
915 sub __circ_to_title {
916 my( $e, $circ ) = @_;
918 $circ = $e->retrieve_action_circulation($circ);
919 return __copy_to_title( $e,
920 $e->retrieve_asset_copy($circ->target_copy) );
924 my ($self, $start, $end, $ids_only) = shift;
925 return $self->charged_items_impl($start, $end, undef, $ids_only);
928 # implementation method
929 # force_bc -- return barcode data regardless of msg64_summary_datatype;
930 # this is used by the renew-all code
931 sub charged_items_impl {
932 my ($self, $start, $end, $force_bc, $ids_only) = shift;
934 $self->__patron_items_info();
937 @{$self->{item_info}->{out}},
938 @{$self->{item_info}->{overdue}}
941 #$charges[$_] = __circ_to_title($self->{editor}, $charges[$_]) for @charges;
943 return \@charges if $ids_only;
946 syslog('LOG_DEBUG', "OILS: charged_items() fleshing circs @charges");
948 my $return_datatype = OpenILS::SIP->get_option_value('msg64_summary_datatype') || '';
950 for my $circid (@charges) {
952 if($return_datatype eq 'barcode' or $force_bc) {
953 push( @c, __circ_to_barcode($self->{editor}, $circid));
955 push( @c, __circ_to_title($self->{editor}, $circid));
961 return (defined $start and defined $end) ?
962 [ @charges[($start-1)..($end-1)] ] :
967 my ($self, $start, $end, $ids_only) = @_;
970 my $login = OpenILS::SIP->login_account();
971 my $AV_format = lc($login->{av_format}) || 'eg_legacy';
973 # Do a prescan for validity and default to eg_legacy
974 if ($AV_format ne "swyer_a" &&
975 $AV_format ne "swyer_b" &&
976 $AV_format ne "eg_legacy" &&
977 $AV_format ne "3m") {
979 syslog('LOG_WARNING',
980 "OILS: Unknown value for AV_format: ". $login->{av_format});
981 $AV_format = "eg_legacy";
984 my $xacts = $U->simplereq('open-ils.actor',
985 'open-ils.actor.user.transactions.history.have_balance',
986 $self->{authtoken}, $self->{user}->id);
989 foreach my $xact (@{$xacts}) {
992 push @fines, $xact->id;
996 # fine item details requested
1004 if ($xact->last_billing_type =~ /^Lost/) {
1006 } elsif ($xact->last_billing_type =~ /^Overdue/) {
1012 if ($xact->xact_type eq 'circulation') {
1013 my $e = OpenILS::SIP->editor();
1014 my $circ = $e->retrieve_action_circulation([
1018 circ => ['target_copy'],
1019 acp => ['call_number']
1024 my $displays = $e->search_metabib_flat_display_entry({
1025 source => $circ->target_copy->call_number->record,
1026 name => ['title', 'author']
1029 ($title) = map {$_->value} grep {$_->name eq 'title'} @$displays;
1030 ($author) = map {$_->value} grep {$_->name eq 'author'} @$displays;
1032 # Scrub "/" chars since they are used in some cases
1033 # to delineate title/author.
1047 if ($AV_format eq "eg_legacy") {
1049 $line = $xact->balance_owed . " " . $xact->last_billing_type . " ";
1051 if ($xact->xact_type eq 'circulation') {
1052 $line .= "$title / $author";
1054 $line .= $xact->last_billing_note;
1057 } elsif ($AV_format eq "3m" or $AV_format eq "swyer_a") {
1059 $line = $xact->id . ' $' . $xact->balance_owed . " \"$fee_type\" ";
1061 if ($xact->xact_type eq 'circulation') {
1064 $line .= $xact->last_billing_note;
1067 } elsif ($AV_format eq "swyer_b") {
1069 $line = "Charge-Number: " . $xact->id;
1070 $line .= ", Amount-Due: " . $xact->balance_owed;
1071 $line .= ", Fine-Type: $fee_type";
1073 if ($xact->xact_type eq 'circulation') {
1074 $line .= ", Title: $title";
1076 $line .= ", Title: " . $xact->last_billing_note;
1083 my $log_status = $@ ? 'ERROR: ' . $@ : 'OK';
1084 syslog('LOG_DEBUG', 'OILS: Patron->fine_items() ' . $log_status);
1085 return (defined $start and defined $end) ?
1086 [ @fines[($start-1)..($end-1)] ] : \@fines;
1089 # not currently supported
1091 my ($self, $start, $end, $ids_only) = @_;
1096 my ($self, $card_retained, $blocked_card_msg) = @_;
1097 $blocked_card_msg ||= '';
1099 my $e = $self->{editor};
1100 my $u = $self->{user};
1102 syslog('LOG_INFO', "OILS: Blocking user %s", $u->card->barcode );
1104 return $self if $u->card->active eq 'f'; # TODO: don't think this will ever be true
1106 $e->xact_begin; # connect and start a new transaction
1108 $u->card->active('f');
1109 if( ! $e->update_actor_card($u->card) ) {
1110 syslog('LOG_ERR', "OILS: Block card update failed: %s", $e->event->{textcode});
1111 $e->rollback; # rollback + disconnect
1115 # Use the ws_ou or home_ou of the authsession user, if any, as a
1116 # context org_unit for the created penalty
1118 if ($e->authtoken()) {
1119 my $auth_usr = $e->checkauth();
1121 $here = $auth_usr->ws_ou() || $auth_usr->home_ou();
1125 my $penalty = Fieldmapper::actor::user_standing_penalty->new;
1126 $penalty->usr( $u->id );
1127 $penalty->org_unit( $here );
1128 $penalty->set_date('now');
1129 $penalty->staff( $e->checkauth()->id() );
1130 $penalty->standing_penalty(20); # ALERT_NOTE
1132 my $note = "<sip> CARD BLOCKED BY SELF-CHECK MACHINE. $blocked_card_msg</sip>\n"; # XXX Config option
1137 my $penalty_result = $U->simplereq(
1139 'open-ils.actor.user.penalty.apply', $e->authtoken, $penalty, $msg);
1140 if( my $result_code = $U->event_code($penalty_result) ) {
1141 my $textcode = $penalty_result->{textcode};
1142 syslog('LOG_ERR', "OILS: Block: patron penalty failed: %s", $textcode);
1143 $e->rollback; # rollback + disconnect
1151 # Testing purposes only
1153 # TODO: we never actually enter this sub if the patron's card is not active
1154 # For now, to test the removal of the SIP penalties, manually activate the card first
1155 my ($self, $card_retained) = @_;
1156 $self->{screen_msg} = "All privileges restored.";
1158 # Un-mark card as inactive, grep out the patron alert
1159 my $e = $self->{editor};
1160 my $u = $self->{user};
1162 syslog('LOG_INFO', "OILS: Unblocking user %s", $u->card->barcode );
1164 $e->xact_begin; # connect and start a new transaction
1166 if ($u->card->active eq 'f') {
1167 $u->card->active('t');
1168 if( ! $e->update_actor_card($u->card) ) {
1169 syslog('LOG_ERR', "OILS: Unblock card update failed: %s", $e->event->{textcode});
1170 $e->rollback; # rollback + disconnect
1175 # look for sip related penalties
1176 my $sip_penalties = $e->search_actor_usr_message_penalty({ usr => $u->id, title => 'SIP', stop_date => undef });
1178 if (scalar(@{ $sip_penalties }) == 0) {
1179 syslog('LOG_INFO', 'OILS: Unblock: no SIP penalties to archive');
1182 foreach my $aump (@{ $sip_penalties }) {
1183 my $penalty = $e->retrieve_actor_user_standing_penalty( $aump->ausp_id() );
1184 $penalty->stop_date('now');
1185 if ( ! $e->update_actor_user_standing_penalty($penalty) ) {
1186 syslog('LOG_ERR', "OILS: Unblock: patron alert update failed: %s", $e->event->{textcode});
1187 $e->rollback; # rollback + disconnect
1192 $e->commit; # commits and disconnects
1200 sub invalid_patron {
1201 return "Please contact library staff";
1205 return "Please contact library staff";
1208 sub inet_privileges {
1210 my $e = OpenILS::SIP->editor();
1211 $INET_PRIVS = $e->retrieve_all_config_net_access_level() unless $INET_PRIVS;
1212 my ($level) = grep { $_->id eq $self->{user}->net_access_level } @$INET_PRIVS;
1213 my $name = $level->name;
1214 syslog('LOG_DEBUG', "OILS: Patron inet_privs = $name");
1220 my $extra_fields = {};
1221 my $u = $self->{user};
1222 foreach my $stat_cat_entry (@{$u->stat_cat_entries}) {
1223 my $stat_cat = $stat_cat_entry->stat_cat;
1224 next unless ($stat_cat->sip_field);
1225 my $value = $stat_cat_entry->stat_cat_entry;
1226 if(defined $stat_cat->sip_format && length($stat_cat->sip_format) > 0) { # Has a format string?
1227 if($stat_cat->sip_format =~ /^\|(.*)\|$/) { # Regex match?
1228 if($value =~ /($1)/) { # If we have a match
1229 if(defined $2) { # Check to see if they embedded a capture group
1230 $value = $2; # If so, use it
1232 else { # No embedded capture group?
1233 $value = $1; # Use our outer one
1237 $value = ''; # Empty string. Will be checked for below.
1240 else { # Not a regex match - Try sprintf match (looking for a %s, if any)
1241 $value = sprintf($stat_cat->sip_format, $value);
1244 next unless length($value) > 0; # No value = no export
1245 $value =~ s/\|//g; # Remove all lingering pipe chars for sane output purposes
1246 $extra_fields->{ $stat_cat->sip_field } = [] unless (defined $extra_fields->{$stat_cat->sip_field});
1247 push(@{$extra_fields->{ $stat_cat->sip_field}}, $value);
1249 return $extra_fields;