1 package OpenILS::WWW::EGCatLoader;
2 use strict; use warnings;
3 use Apache2::Const -compile => qw(OK DECLINED FORBIDDEN HTTP_INTERNAL_SERVER_ERROR REDIRECT HTTP_BAD_REQUEST);
4 use OpenSRF::Utils::Logger qw/$logger/;
5 use OpenILS::Utils::CStoreEditor qw/:funcs/;
6 use OpenILS::Utils::Fieldmapper;
7 use OpenILS::Application::AppUtils;
9 use OpenSRF::Utils::JSON;
11 $Data::Dumper::Indent = 0;
13 my $U = 'OpenILS::Application::AppUtils';
15 sub prepare_extended_user_info {
18 my $e = $self->editor;
20 # are we already in a transaction?
21 my $local_xact = !$e->{xact_id};
22 $e->xact_begin if $local_xact;
24 $self->ctx->{user} = $self->editor->retrieve_actor_user([
25 $self->ctx->{user}->id,
29 au => [qw/card home_ou addresses ident_type billing_address/, @extra_flesh]
35 $e->rollback if $local_xact;
37 return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR
38 unless $self->ctx->{user};
43 # Given an event returned by a failed attempt to create a hold, do we have
44 # permission to override? XXX Should the permission check be scoped to a
45 # given org_unit context?
46 sub test_could_override {
47 my ($self, $event) = @_;
49 return 0 unless $event;
50 return 1 if $self->editor->allowed($event->{textcode} . ".override");
51 return 1 if $event->{"fail_part"} and
52 $self->editor->allowed($event->{"fail_part"} . ".override");
56 # Find out whether we care that local copies are available
57 sub local_avail_concern {
58 my ($self, $hold_target, $hold_type, $pickup_lib) = @_;
60 my $would_block = $self->ctx->{get_org_setting}->
61 ($pickup_lib, "circ.holds.hold_has_copy_at.block");
63 $self->ctx->{get_org_setting}->
64 ($pickup_lib, "circ.holds.hold_has_copy_at.alert") and
65 not $self->cgi->param("override")
66 ) unless $would_block;
68 if ($would_block or $would_alert) {
70 "hold_target" => $hold_target,
71 "hold_type" => $hold_type,
72 "org_unit" => $pickup_lib
74 my $local_avail = $U->simplereq(
76 "open-ils.circ.hold.has_copy_at", $self->editor->authtoken, $args
79 "copy availability information for " . Dumper($args) .
80 " is " . Dumper($local_avail)
82 if (%$local_avail) { # if hash not empty
83 $self->ctx->{hold_copy_available} = $local_avail;
84 return ($would_block, $would_alert);
92 # user : au object, fleshed
93 sub load_myopac_prefs {
96 my $e = $self->editor;
97 my $pending_addr = $cgi->param('pending_addr');
98 my $replace_addr = $cgi->param('replace_addr');
99 my $delete_pending = $cgi->param('delete_pending');
101 $self->prepare_extended_user_info;
102 my $user = $self->ctx->{user};
104 my $lock_usernames = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.lock_usernames');
105 if($lock_usernames == 1) {
106 # Policy says no username changes
107 $self->ctx->{username_change_disallowed} = 1;
109 my $username_unlimit = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.unlimit_usernames');
110 if($username_unlimit != 1) {
111 my $regex_check = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.barcode_regex');
113 # Default is "starts with a number"
114 $regex_check = '^\d+';
116 # You already have a username?
117 if($regex_check and $self->ctx->{user}->usrname !~ /$regex_check/) {
118 $self->ctx->{username_change_disallowed} = 1;
123 return Apache2::Const::OK unless
124 $pending_addr or $replace_addr or $delete_pending;
126 my @form_fields = qw/address_type street1 street2 city county state country post_code/;
129 if( $pending_addr ) { # update an existing pending address
131 ($paddr) = grep { $_->id == $pending_addr } @{$user->addresses};
132 return Apache2::Const::HTTP_BAD_REQUEST unless $paddr;
133 $paddr->$_( $cgi->param($_) ) for @form_fields;
135 } elsif( $replace_addr ) { # create a new pending address for 'replace_addr'
137 $paddr = Fieldmapper::actor::user_address->new;
139 $paddr->usr($user->id);
140 $paddr->pending('t');
141 $paddr->replaces($replace_addr);
142 $paddr->$_( $cgi->param($_) ) for @form_fields;
144 } elsif( $delete_pending ) {
145 $paddr = $e->retrieve_actor_user_address($delete_pending);
146 return Apache2::Const::HTTP_BAD_REQUEST unless
147 $paddr and $paddr->usr == $user->id and $U->is_true($paddr->pending);
148 $paddr->isdeleted(1);
151 my $resp = $U->simplereq(
153 'open-ils.actor.user.address.pending.cud',
154 $e->authtoken, $paddr);
156 if( $U->event_code($resp) ) {
157 $logger->error("Error updating pending address: $resp");
158 return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
161 # in light of these changes, re-fetch latest data
163 $self->prepare_extended_user_info;
166 return Apache2::Const::OK;
169 sub load_myopac_prefs_notify {
171 my $e = $self->editor;
173 my $user_prefs = $self->fetch_optin_prefs;
174 $user_prefs = $self->update_optin_prefs($user_prefs)
175 if $self->cgi->request_method eq 'POST';
177 $self->ctx->{opt_in_settings} = $user_prefs;
179 return Apache2::Const::OK;
182 sub fetch_optin_prefs {
184 my $e = $self->editor;
186 # fetch all of the opt-in settings the user has access to
187 # XXX: user's should in theory have options to opt-in to notices
188 # for remote locations, but that opens the door for a large
189 # set of generally un-used opt-ins.. needs discussion
190 my $opt_ins = $U->simplereq(
192 'open-ils.actor.event_def.opt_in.settings.atomic',
193 $e->authtoken, $e->requestor->home_ou);
195 # some opt-ins are staff-only
196 $opt_ins = [ grep { $U->is_true($_->opac_visible) } @$opt_ins ];
198 # fetch user setting values for each of the opt-in settings
199 my $user_set = $U->simplereq(
201 'open-ils.actor.patron.settings.retrieve',
204 [map {$_->name} @$opt_ins]
207 return [map { {cust => $_, value => $user_set->{$_->name} } } @$opt_ins];
210 sub update_optin_prefs {
212 my $user_prefs = shift;
213 my $e = $self->editor;
214 my @settings = $self->cgi->param('setting');
217 # apply now-true settings
218 for my $applied (@settings) {
219 # see if setting is already applied to this user
220 next if grep { $_->{cust}->name eq $applied and $_->{value} } @$user_prefs;
221 $newsets{$applied} = OpenSRF::Utils::JSON->true;
224 # remove now-false settings
225 for my $pref (grep { $_->{value} } @$user_prefs) {
226 $newsets{$pref->{cust}->name} = undef
227 unless grep { $_ eq $pref->{cust}->name } @settings;
232 'open-ils.actor.patron.settings.update',
233 $e->authtoken, $e->requestor->id, \%newsets);
235 # update the local prefs to match reality
236 for my $pref (@$user_prefs) {
237 $pref->{value} = $newsets{$pref->{cust}->name}
238 if exists $newsets{$pref->{cust}->name};
244 sub _load_user_with_prefs {
246 my $stat = $self->prepare_extended_user_info('settings');
247 return $stat if $stat; # not-OK
249 $self->ctx->{user_setting_map} = {
250 map { $_->name => OpenSRF::Utils::JSON->JSON2perl($_->value) }
251 @{$self->ctx->{user}->settings}
257 sub _get_bookbag_sort_params {
258 my ($self, $param_name) = @_;
260 # The interface that feeds this cgi parameter will provide a single
261 # argument for a QP sort filter, and potentially a modifier after a period.
262 # In practice this means the "sort" parameter will be something like
263 # "titlesort" or "authorsort.descending".
264 my $sorter = $self->cgi->param($param_name) || "";
267 $sorter =~ s/^(.*?)\.(.*)/$1/;
268 $modifier = $2 || undef;
271 return ($sorter, $modifier);
274 sub _prepare_bookbag_container_query {
275 my ($self, $container_id, $sorter, $modifier) = @_;
278 "container(bre,bookbag,%d,%s)%s%s",
279 $container_id, $self->editor->authtoken,
280 ($sorter ? " sort($sorter)" : ""),
281 ($modifier ? "#$modifier" : "")
285 sub _prepare_anonlist_sorting_query {
286 my ($self, $list, $sorter, $modifier) = @_;
289 "record_list(%s)%s%s",
291 ($sorter ? " sort($sorter)" : ""),
292 ($modifier ? "#$modifier" : "")
297 sub load_myopac_prefs_settings {
300 my $stat = $self->_load_user_with_prefs;
301 return $stat if $stat;
303 return Apache2::Const::OK
304 unless $self->cgi->request_method eq 'POST';
306 # some setting values from the form don't match the
307 # required value/format for the db, so they have to be
308 # individually translated.
311 my $set_map = $self->ctx->{user_setting_map};
313 my $key = 'opac.hits_per_page';
314 my $val = $self->cgi->param($key);
315 $settings{$key}= $val unless $$set_map{$key} eq $val;
317 my $now = DateTime->now->strftime('%F');
318 for $key (qw/history.circ.retention_start history.hold.retention_start/) {
319 $val = $self->cgi->param($key);
320 if($val and $val eq 'on') {
321 # Set the start time to 'now' unless a start time already exists for the user
322 $settings{$key} = $now unless $$set_map{$key};
324 # clear the start time if one previously existed for the user
325 $settings{$key} = undef if $$set_map{$key};
329 # Send the modified settings off to be saved
332 'open-ils.actor.patron.settings.update',
333 $self->editor->authtoken, undef, \%settings);
335 # re-fetch user prefs
336 $self->ctx->{updated_user_settings} = \%settings;
337 return $self->_load_user_with_prefs || Apache2::Const::OK;
340 sub fetch_user_holds {
342 my $hold_ids = shift;
343 my $ids_only = shift;
345 my $available = shift;
349 my $e = $self->editor;
352 my $circ = OpenSRF::AppSession->create('open-ils.circ');
354 $hold_ids = $circ->request(
355 'open-ils.circ.holds.id_list.retrieve.authoritative',
361 $hold_ids = [ grep { defined $_ } @$hold_ids[$offset..($offset + $limit - 1)] ] if $limit or $offset;
365 return $hold_ids if $ids_only or @$hold_ids == 0;
368 suppress_notices => 1,
369 suppress_transits => 1,
371 suppress_patron_details => 1,
372 include_bre => $flesh ? 1 : 0
375 # ----------------------------------------------------------------
376 # Collect holds in batches of $batch_size for faster retrieval
380 my $mk_req_batch = sub {
382 my $top_idx = $batch_idx + $batch_size;
383 while($batch_idx < $top_idx) {
384 my $hold_id = $hold_ids->[$batch_idx++];
385 last unless $hold_id;
386 my $ses = OpenSRF::AppSession->create('open-ils.circ');
387 my $req = $ses->request(
388 'open-ils.circ.hold.details.retrieve',
389 $e->authtoken, $hold_id, $args);
390 push(@ses, {ses => $ses, req => $req});
396 my(@collected, @holds, @ses);
399 @ses = $mk_req_batch->() if $first;
400 last if $first and not @ses;
403 # If desired by the caller, filter any holds that are not available.
405 @collected = grep { $_->{hold}->{status} == 4 } @collected;
407 while(my $blob = pop(@collected)) {
408 $blob->{marc_xml} = XML::LibXML->new->parse_string($blob->{hold}->{bre}->marc) if $flesh;
413 for my $req_data (@ses) {
414 push(@collected, {hold => $req_data->{req}->gather(1)});
415 $req_data->{ses}->kill_me;
418 @ses = $mk_req_batch->();
419 last unless @collected or @ses;
423 # put the holds back into the original server sort order
425 for my $id (@$hold_ids) {
426 push @sorted, grep { $_->{hold}->{hold}->id == $id } @holds;
432 sub handle_hold_update {
435 my $hold_ids = shift;
436 my $e = $self->editor;
439 my @hold_ids = ($hold_ids) ? @$hold_ids : $self->cgi->param('hold_id'); # for non-_all actions
440 @hold_ids = @{$self->fetch_user_holds(undef, 1)} if $action =~ /_all/;
442 my $circ = OpenSRF::AppSession->create('open-ils.circ');
444 if($action =~ /cancel/) {
446 for my $hold_id (@hold_ids) {
447 my $resp = $circ->request(
448 'open-ils.circ.hold.cancel', $e->authtoken, $hold_id, 6 )->gather(1); # 6 == patron-cancelled-via-opac
451 } elsif ($action =~ /activate|suspend/) {
454 for my $hold_id (@hold_ids) {
455 my $vals = {id => $hold_id};
457 if($action =~ /activate/) {
458 $vals->{frozen} = 'f';
459 $vals->{thaw_date} = undef;
461 } elsif($action =~ /suspend/) {
462 $vals->{frozen} = 't';
463 # $vals->{thaw_date} = TODO;
465 push(@$vlist, $vals);
468 $circ->request('open-ils.circ.hold.update.batch.atomic', $e->authtoken, undef, $vlist)->gather(1);
469 } elsif ($action eq 'edit') {
472 my $val = {"id" => $_};
473 $val->{"frozen"} = $self->cgi->param("frozen");
474 $val->{"pickup_lib"} = $self->cgi->param("pickup_lib");
476 for my $field (qw/expire_time thaw_date/) {
477 # XXX TODO make this support other date formats, not just
479 next unless $self->cgi->param($field) =~
480 m:^(\d{2})/(\d{2})/(\d{4})$:;
481 $val->{$field} = "$3-$1-$2";
487 'open-ils.circ.hold.update.batch.atomic',
488 $e->authtoken, undef, \@vals
489 )->gather(1); # LFW XXX test for failure
490 $url = 'https://' . $self->apache->hostname . $self->ctx->{opac_root} . '/myopac/holds';
494 return defined($url) ? $self->generic_redirect($url) : undef;
497 sub load_myopac_holds {
499 my $e = $self->editor;
500 my $ctx = $self->ctx;
502 my $limit = $self->cgi->param('limit') || 0;
503 my $offset = $self->cgi->param('offset') || 0;
504 my $action = $self->cgi->param('action') || '';
505 my $hold_id = $self->cgi->param('id');
506 my $available = int($self->cgi->param('available') || 0);
508 my $hold_handle_result;
509 $hold_handle_result = $self->handle_hold_update($action) if $action;
511 $ctx->{holds} = $self->fetch_user_holds($hold_id ? [$hold_id] : undef, 0, 1, $available, $limit, $offset);
513 return defined($hold_handle_result) ? $hold_handle_result : Apache2::Const::OK;
516 sub load_place_hold {
518 my $ctx = $self->ctx;
519 my $gos = $ctx->{get_org_setting};
520 my $e = $self->editor;
521 my $cgi = $self->cgi;
523 $self->ctx->{page} = 'place_hold';
524 my @targets = $cgi->param('hold_target');
525 $ctx->{hold_type} = $cgi->param('hold_type');
526 $ctx->{default_pickup_lib} = $e->requestor->home_ou; # unless changed below
528 return $self->post_hold_redirect unless @targets;
530 $logger->info("Looking at hold targets: @targets");
532 # if the staff client provides a patron barcode, fetch the patron
533 if (my $bc = $self->cgi->cookie("patron_barcode")) {
534 $ctx->{patron_recipient} = $U->simplereq(
535 "open-ils.actor", "open-ils.actor.user.fleshed.retrieve_by_barcode",
536 $self->editor->authtoken, $bc
537 ) or return Apache2::Const::HTTP_BAD_REQUEST;
539 $ctx->{default_pickup_lib} = $ctx->{patron_recipient}->home_ou;
542 my $request_lib = $e->requestor->ws_ou;
544 $ctx->{hold_data} = \@hold_data;
546 my $type_dispatch = {
548 my $recs = $e->batch_retrieve_biblio_record_entry(\@targets, {substream => 1});
549 for my $id (@targets) { # force back into the correct order
550 my ($rec) = grep {$_->id eq $id} @$recs;
551 push(@hold_data, {target => $rec, record => $rec});
555 my $vols = $e->batch_retrieve_asset_call_number([
558 "flesh_fields" => {"acn" => ["record"]}
560 ], {substream => 1});
562 for my $id (@targets) {
563 my ($vol) = grep {$_->id eq $id} @$vols;
564 push(@hold_data, {target => $vol, record => $vol->record});
568 my $copies = $e->batch_retrieve_asset_copy([
573 "acp" => ["call_number"]
576 ], {substream => 1});
578 for my $id (@targets) {
579 my ($copy) = grep {$_->id eq $id} @$copies;
580 push(@hold_data, {target => $copy, record => $copy->call_number->record});
584 my $isses = $e->batch_retrieve_serial_issuance([
588 "siss" => ["subscription"], "ssub" => ["record_entry"]
591 ], {substream => 1});
593 for my $id (@targets) {
594 my ($iss) = grep {$_->id eq $id} @$isses;
595 push(@hold_data, {target => $iss, record => $iss->subscription->record_entry});
600 }->{$ctx->{hold_type}}->();
602 # caller sent bad target IDs or the wrong hold type
603 return Apache2::Const::HTTP_BAD_REQUEST unless @hold_data;
605 # generate the MARC xml for each record
606 $_->{marc_xml} = XML::LibXML->new->parse_string($_->{record}->marc) for @hold_data;
608 my $pickup_lib = $cgi->param('pickup_lib');
609 # no pickup lib means no holds placement
610 return Apache2::Const::OK unless $pickup_lib;
612 $ctx->{hold_attempt_made} = 1;
614 # Give the original CGI params back to the user in case they
615 # want to try to override something.
616 $ctx->{orig_params} = $cgi->Vars;
617 delete $ctx->{orig_params}{submit};
618 delete $ctx->{orig_params}{hold_target};
620 my $usr = $e->requestor->id;
622 if ($ctx->{is_staff} and !$cgi->param("hold_usr_is_requestor")) {
623 # find the real hold target
625 $usr = $U->simplereq(
627 "open-ils.actor.user.retrieve_id_by_barcode_or_username",
628 $e->authtoken, $cgi->param("hold_usr"));
630 if (defined $U->event_code($usr)) {
631 $ctx->{hold_failed} = 1;
632 $ctx->{hold_failed_event} = $usr;
636 # First see if we should warn/block for any holds that
637 # might have locally available items.
638 for my $hdata (@hold_data) {
639 my ($local_block, $local_alert) = $self->local_avail_concern(
640 $hdata->{target}->id, $ctx->{hold_type}, $pickup_lib);
643 $hdata->{hold_failed} = 1;
644 $hdata->{hold_local_block} = 1;
645 } elsif ($local_alert) {
646 $hdata->{hold_failed} = 1;
647 $hdata->{hold_local_alert} = 1;
652 my $method = 'open-ils.circ.holds.test_and_create.batch';
653 $method .= '.override' if $cgi->param('override');
655 my @create_targets = map {$_->{target}->id} (grep { !$_->{hold_failed} } @hold_data);
657 if(@create_targets) {
659 my $bses = OpenSRF::AppSession->create('open-ils.circ');
660 my $breq = $bses->request(
664 pickup_lib => $pickup_lib,
665 hold_type => $ctx->{hold_type}
670 while (my $resp = $breq->recv) {
672 $resp = $resp->content;
673 $logger->info('batch hold placement result: ' . OpenSRF::Utils::JSON->perl2JSON($resp));
675 if ($U->event_code($resp)) {
676 $ctx->{general_hold_error} = $resp;
680 my ($hdata) = grep {$_->{target}->id eq $resp->{target}} @hold_data;
681 my $result = $resp->{result};
683 if ($U->event_code($result)) {
684 # e.g. permission denied
685 $hdata->{hold_failed} = 1;
686 $hdata->{hold_failed_event} = $result;
690 if(not ref $result and $result > 0) {
691 # successul hold returns the hold ID
693 $hdata->{hold_success} = $result;
696 # hold-specific failure event
697 $hdata->{hold_failed} = 1;
698 $hdata->{hold_failed_event} = $result->{last_event};
699 $hdata->{could_override} = $self->test_could_override($hdata->{hold_failed_event});
707 # stay on the current page and display the results
708 return Apache2::Const::OK if
709 (grep {$_->{hold_failed}} @hold_data) or $ctx->{general_hold_error};
711 # if successful, do some cleanup and return the
712 # user to the requesting page.
714 return $self->post_hold_redirect;
717 sub post_hold_redirect {
720 # XXX: Leave the barcode cookie in place. Otherwise, it's not
721 # possible to place more than one hold for the patron within
722 # a staff/patron session. This does leave the barcode to linger
723 # longer than is ideal, but normal staff work flow will cause the
724 # cookie to be replaced with each new patron anyway.
725 # TODO: See about getting the staff client to clear the cookie
726 return $self->generic_redirect;
728 # We also clear the patron_barcode (from the staff client)
729 # cookie at this point (otherwise it haunts the staff user
730 # later). XXX todo make sure this is best; also see that
731 # template when staff mode calls xulG.opac_hold_placed()
733 return $self->generic_redirect(
736 -name => "patron_barcode",
746 sub fetch_user_circs {
748 my $flesh = shift; # flesh bib data, etc.
749 my $circ_ids = shift;
753 my $e = $self->editor;
758 @circ_ids = @$circ_ids;
762 my $circ_data = $U->simplereq(
764 'open-ils.actor.user.checked_out',
769 @circ_ids = ( @{$circ_data->{overdue}}, @{$circ_data->{out}} );
771 if($limit or $offset) {
772 @circ_ids = grep { defined $_ } @circ_ids[0..($offset + $limit - 1)];
776 return [] unless @circ_ids;
781 circ => ['target_copy'],
782 acp => ['call_number'],
788 my $circs = $e->search_action_circulation(
789 [{id => \@circ_ids}, ($flesh) ? $qflesh : {}], {substream => 1});
792 for my $circ (@$circs) {
795 marc_xml => ($flesh and $circ->target_copy->call_number->id != -1) ?
796 XML::LibXML->new->parse_string($circ->target_copy->call_number->record->marc) :
797 undef # pre-cat copy, use the dummy title/author instead
802 # make sure the final list is in the correct order
804 for my $id (@circ_ids) {
807 (grep { $_->{circ}->id == $id } @circs)
811 return \@sorted_circs;
815 sub handle_circ_renew {
818 my $ctx = $self->ctx;
820 my @renew_ids = $self->cgi->param('circ');
822 my $circs = $self->fetch_user_circs(0, ($action eq 'renew') ? [@renew_ids] : undef);
824 # TODO: fire off renewal calls in batches to speed things up
826 for my $circ (@$circs) {
828 my $evt = $U->simplereq(
830 'open-ils.circ.renew',
831 $self->editor->authtoken,
833 patron_id => $self->editor->requestor->id,
834 copy_id => $circ->{circ}->target_copy,
839 # TODO return these, then insert them into the circ data
840 # blob that is shoved into the template for each circ
841 # so the template won't have to match them
842 push(@responses, {copy => $circ->{circ}->target_copy, evt => $evt});
849 sub load_myopac_circs {
851 my $e = $self->editor;
852 my $ctx = $self->ctx;
855 my $limit = $self->cgi->param('limit') || 0; # 0 == unlimited
856 my $offset = $self->cgi->param('offset') || 0;
857 my $action = $self->cgi->param('action') || '';
859 # perform the renewal first if necessary
860 my @results = $self->handle_circ_renew($action) if $action =~ /renew/;
862 $ctx->{circs} = $self->fetch_user_circs(1, undef, $limit, $offset);
864 my $success_renewals = 0;
865 my $failed_renewals = 0;
866 for my $data (@{$ctx->{circs}}) {
867 my ($resp) = grep { $_->{copy} == $data->{circ}->target_copy->id } @results;
870 my $evt = ref($resp->{evt}) eq 'ARRAY' ? $resp->{evt}->[0] : $resp->{evt};
871 $data->{renewal_response} = $evt;
872 $success_renewals++ if $evt->{textcode} eq 'SUCCESS';
873 $failed_renewals++ if $evt->{textcode} ne 'SUCCESS';
877 $ctx->{success_renewals} = $success_renewals;
878 $ctx->{failed_renewals} = $failed_renewals;
880 return Apache2::Const::OK;
883 sub load_myopac_circ_history {
885 my $e = $self->editor;
886 my $ctx = $self->ctx;
887 my $limit = $self->cgi->param('limit') || 15;
888 my $offset = $self->cgi->param('offset') || 0;
890 $ctx->{circ_history_limit} = $limit;
891 $ctx->{circ_history_offset} = $offset;
893 my $circ_ids = $e->json_query({
897 transform => 'action.usr_visible_circs',
902 where => {id => $e->requestor->id},
907 $ctx->{circs} = $self->fetch_user_circs(1, [map { $_->{id} } @$circ_ids]);
908 return Apache2::Const::OK;
911 # TODO: action.usr_visible_holds does not return cancelled holds. Should it?
912 sub load_myopac_hold_history {
914 my $e = $self->editor;
915 my $ctx = $self->ctx;
916 my $limit = $self->cgi->param('limit') || 15;
917 my $offset = $self->cgi->param('offset') || 0;
918 $ctx->{hold_history_limit} = $limit;
919 $ctx->{hold_history_offset} = $offset;
921 my $hold_ids = $e->json_query({
925 transform => 'action.usr_visible_holds',
930 where => {id => $e->requestor->id},
935 $ctx->{holds} = $self->fetch_user_holds([map { $_->{id} } @$hold_ids], 0, 1, 0);
936 return Apache2::Const::OK;
939 sub load_myopac_payment_form {
943 $r = $self->prepare_fines(undef, undef, [$self->cgi->param('xact'), $self->cgi->param('xact_misc')]) and return $r;
944 $r = $self->prepare_extended_user_info and return $r;
946 return Apache2::Const::OK;
949 # TODO: add other filter options as params/configs/etc.
950 sub load_myopac_payments {
952 my $limit = $self->cgi->param('limit') || 20;
953 my $offset = $self->cgi->param('offset') || 0;
954 my $e = $self->editor;
956 $self->ctx->{payment_history_limit} = $limit;
957 $self->ctx->{payment_history_offset} = $offset;
960 $args->{limit} = $limit if $limit;
961 $args->{offset} = $offset if $offset;
963 if (my $max_age = $self->ctx->{get_org_setting}->(
964 $e->requestor->home_ou, "opac.payment_history_age_limit"
966 my $min_ts = DateTime->now(
967 "time_zone" => DateTime::TimeZone->new("name" => "local"),
968 )->subtract("seconds" => interval_to_seconds($max_age))->iso8601();
970 $logger->info("XXX min_ts: $min_ts");
971 $args->{"where"} = {"payment_ts" => {">=" => $min_ts}};
974 $self->ctx->{payments} = $U->simplereq(
976 'open-ils.actor.user.payments.retrieve.atomic',
977 $e->authtoken, $e->requestor->id, $args);
979 return Apache2::Const::OK;
982 sub load_myopac_pay {
986 my @payment_xacts = ($self->cgi->param('xact'), $self->cgi->param('xact_misc'));
987 $logger->info("tpac paying fines for xacts @payment_xacts");
989 $r = $self->prepare_fines(undef, undef, \@payment_xacts) and return $r;
991 # balance_owed is computed specifically from the fines we're trying
992 # to pay in this case.
993 if ($self->ctx->{fines}->{balance_owed} <= 0) {
994 $self->apache->log->info(
995 sprintf("Can't pay non-positive balance. xacts selected: (%s)",
996 join(", ", map(int, $self->cgi->param("xact"), $self->cgi->param('xact_misc'))))
998 return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
1001 my $cc_args = {"where_process" => 1};
1003 $cc_args->{$_} = $self->cgi->param($_) for (qw/
1004 number cvv2 expire_year expire_month billing_first
1005 billing_last billing_address billing_city billing_state
1010 "cc_args" => $cc_args,
1011 "userid" => $self->ctx->{user}->id,
1012 "payment_type" => "credit_card_payment",
1013 "payments" => $self->prepare_fines_for_payment # should be safe after self->prepare_fines
1016 my $resp = $U->simplereq("open-ils.circ", "open-ils.circ.money.payment",
1017 $self->editor->authtoken, $args, $self->ctx->{user}->last_xact_id
1020 $self->ctx->{"payment_response"} = $resp;
1022 unless ($resp->{"textcode"}) {
1023 $self->ctx->{printable_receipt} = $U->simplereq(
1024 "open-ils.circ", "open-ils.circ.money.payment_receipt.print",
1025 $self->editor->authtoken, $resp->{payments}
1029 return Apache2::Const::OK;
1032 sub load_myopac_receipt_print {
1035 $self->ctx->{printable_receipt} = $U->simplereq(
1036 "open-ils.circ", "open-ils.circ.money.payment_receipt.print",
1037 $self->editor->authtoken, [$self->cgi->param("payment")]
1040 return Apache2::Const::OK;
1043 sub load_myopac_receipt_email {
1046 # The following ML method doesn't actually check whether the user in
1047 # question has an email address, so we do.
1048 if ($self->ctx->{user}->email) {
1049 $self->ctx->{email_receipt_result} = $U->simplereq(
1050 "open-ils.circ", "open-ils.circ.money.payment_receipt.email",
1051 $self->editor->authtoken, [$self->cgi->param("payment")]
1054 $self->ctx->{email_receipt_result} =
1055 new OpenILS::Event("PATRON_NO_EMAIL_ADDRESS");
1058 return Apache2::Const::OK;
1062 my ($self, $limit, $offset, $id_list) = @_;
1064 # XXX TODO: check for failure after various network calls
1066 # It may be unclear, but this result structure lumps circulation and
1067 # reservation fines together, and keeps grocery fines separate.
1068 $self->ctx->{"fines"} = {
1069 "circulation" => [],
1076 my $cstore = OpenSRF::AppSession->create('open-ils.cstore');
1078 # TODO: This should really be a ML call, but the existing calls
1079 # return an excessive amount of data and don't offer streaming
1081 my %paging = ($limit or $offset) ? (limit => $limit, offset => $offset) : ();
1083 my $req = $cstore->request(
1084 'open-ils.cstore.direct.money.open_billable_transaction_summary.search',
1086 usr => $self->editor->requestor->id,
1087 balance_owed => {'!=' => 0},
1088 ($id_list && @$id_list ? ("id" => $id_list) : ()),
1093 mobts => [qw/grocery circulation reservation/],
1094 bresv => ['target_resource_type'],
1098 circ => ['target_copy'],
1099 acp => ['call_number'],
1102 order_by => { mobts => 'xact_start' },
1107 my @total_keys = qw/total_paid total_owed balance_owed/;
1108 $self->ctx->{"fines"}->{@total_keys} = (0, 0, 0);
1110 while(my $resp = $req->recv) {
1111 my $mobts = $resp->content;
1112 my $circ = $mobts->circulation;
1115 if($mobts->grocery) {
1116 my @billings = sort { $a->billing_ts cmp $b->billing_ts } @{$mobts->grocery->billings};
1117 $last_billing = pop(@billings);
1120 # XXX TODO confirm that the following, and the later division by 100.0
1121 # to get a floating point representation once again, is sufficiently
1122 # "money-safe" math.
1123 $self->ctx->{"fines"}->{$_} += int($mobts->$_ * 100) for (@total_keys);
1125 my $marc_xml = undef;
1126 if ($mobts->xact_type eq 'reservation' and
1127 $mobts->reservation->target_resource_type->record) {
1128 $marc_xml = XML::LibXML->new->parse_string(
1129 $mobts->reservation->target_resource_type->record->marc
1131 } elsif ($mobts->xact_type eq 'circulation' and
1132 $circ->target_copy->call_number->id != -1) {
1133 $marc_xml = XML::LibXML->new->parse_string(
1134 $circ->target_copy->call_number->record->marc
1139 @{$self->ctx->{"fines"}->{$mobts->grocery ? "grocery" : "circulation"}},
1142 last_grocery_billing => $last_billing,
1143 marc_xml => $marc_xml
1150 $self->ctx->{"fines"}->{$_} /= 100.0 for (@total_keys);
1154 sub prepare_fines_for_payment {
1155 # This assumes $self->prepare_fines has already been run
1159 if ($self->ctx->{fines}) {
1160 push @results, [$_->{xact}->id, $_->{xact}->balance_owed] foreach (
1161 @{$self->ctx->{fines}->{circulation}},
1162 @{$self->ctx->{fines}->{grocery}}
1169 sub load_myopac_main {
1171 my $limit = $self->cgi->param('limit') || 0;
1172 my $offset = $self->cgi->param('offset') || 0;
1174 return $self->prepare_fines($limit, $offset) || Apache2::Const::OK;
1177 sub load_myopac_update_email {
1179 my $e = $self->editor;
1180 my $ctx = $self->ctx;
1181 my $email = $self->cgi->param('email') || '';
1182 my $current_pw = $self->cgi->param('current_pw') || '';
1184 # needed for most up-to-date email address
1185 if (my $r = $self->prepare_extended_user_info) { return $r };
1187 return Apache2::Const::OK
1188 unless $self->cgi->request_method eq 'POST';
1190 unless($email =~ /.+\@.+\..+/) { # TODO better regex?
1191 $ctx->{invalid_email} = $email;
1192 return Apache2::Const::OK;
1195 my $stat = $U->simplereq(
1197 'open-ils.actor.user.email.update',
1198 $e->authtoken, $email, $current_pw);
1200 if($U->event_equals($stat, 'INCORRECT_PASSWORD')) {
1201 $ctx->{password_incorrect} = 1;
1202 return Apache2::Const::OK;
1205 unless ($self->cgi->param("redirect_to")) {
1206 my $url = $self->apache->unparsed_uri;
1207 $url =~ s/update_email/prefs/;
1209 return $self->generic_redirect($url);
1212 return $self->generic_redirect;
1215 sub load_myopac_update_username {
1217 my $e = $self->editor;
1218 my $ctx = $self->ctx;
1219 my $username = $self->cgi->param('username') || '';
1220 my $current_pw = $self->cgi->param('current_pw') || '';
1222 $self->prepare_extended_user_info;
1224 my $allow_change = 1;
1226 my $lock_usernames = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.lock_usernames');
1227 if($lock_usernames == 1) {
1228 # Policy says no username changes
1231 # We want this further down.
1232 $regex_check = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.barcode_regex');
1233 my $username_unlimit = $self->ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.unlimit_usernames');
1234 if($username_unlimit != 1) {
1236 # Default is "starts with a number"
1237 $regex_check = '^\d+';
1239 # You already have a username?
1240 if($regex_check and $self->ctx->{user}->usrname !~ /$regex_check/) {
1245 if(!$allow_change) {
1246 my $url = $self->apache->unparsed_uri;
1247 $url =~ s/update_username/prefs/;
1249 return $self->generic_redirect($url);
1252 return Apache2::Const::OK
1253 unless $self->cgi->request_method eq 'POST';
1255 unless($username and $username !~ /\s/) { # any other username restrictions?
1256 $ctx->{invalid_username} = $username;
1257 return Apache2::Const::OK;
1260 # New username can't look like a barcode if we have a barcode regex
1261 if($regex_check and $username =~ /$regex_check/) {
1262 $ctx->{invalid_username} = $username;
1263 return Apache2::Const::OK;
1266 # New username has to look like a username if we have a username regex
1267 $regex_check = $ctx->{get_org_setting}->($e->requestor->home_ou, 'opac.username_regex');
1268 if($regex_check and $username !~ /$regex_check/) {
1269 $ctx->{invalid_username} = $username;
1270 return Apache2::Const::OK;
1273 if($username ne $e->requestor->usrname) {
1275 my $evt = $U->simplereq(
1277 'open-ils.actor.user.username.update',
1278 $e->authtoken, $username, $current_pw);
1280 if($U->event_equals($evt, 'INCORRECT_PASSWORD')) {
1281 $ctx->{password_incorrect} = 1;
1282 return Apache2::Const::OK;
1285 if($U->event_equals($evt, 'USERNAME_EXISTS')) {
1286 $ctx->{username_exists} = $username;
1287 return Apache2::Const::OK;
1291 my $url = $self->apache->unparsed_uri;
1292 $url =~ s/update_username/prefs/;
1294 return $self->generic_redirect($url);
1297 sub load_myopac_update_password {
1299 my $e = $self->editor;
1300 my $ctx = $self->ctx;
1302 return Apache2::Const::OK
1303 unless $self->cgi->request_method eq 'POST';
1305 my $current_pw = $self->cgi->param('current_pw') || '';
1306 my $new_pw = $self->cgi->param('new_pw') || '';
1307 my $new_pw2 = $self->cgi->param('new_pw2') || '';
1309 unless($new_pw eq $new_pw2) {
1310 $ctx->{password_nomatch} = 1;
1311 return Apache2::Const::OK;
1314 my $pw_regex = $ctx->{get_org_setting}->($e->requestor->home_ou, 'global.password_regex');
1317 # This regex duplicates the JSPac's default "digit, letter, and 7 characters" rule
1318 $pw_regex = '(?=.*\d+.*)(?=.*[A-Za-z]+.*).{7,}';
1321 if($pw_regex and $new_pw !~ /$pw_regex/) {
1322 $ctx->{password_invalid} = 1;
1323 return Apache2::Const::OK;
1326 my $evt = $U->simplereq(
1328 'open-ils.actor.user.password.update',
1329 $e->authtoken, $new_pw, $current_pw);
1332 if($U->event_equals($evt, 'INCORRECT_PASSWORD')) {
1333 $ctx->{password_incorrect} = 1;
1334 return Apache2::Const::OK;
1337 my $url = $self->apache->unparsed_uri;
1338 $url =~ s/update_password/prefs/;
1340 return $self->generic_redirect($url);
1343 sub load_myopac_bookbags {
1345 my $e = $self->editor;
1346 my $ctx = $self->ctx;
1348 my ($sorter, $modifier) = $self->_get_bookbag_sort_params("sort");
1349 $e->xact_begin; # replication...
1351 my $rv = $self->load_mylist;
1352 unless($rv eq Apache2::Const::OK) {
1357 $ctx->{bookbags} = $e->search_container_biblio_record_entry_bucket(
1359 {owner => $e->requestor->id, btype => 'bookbag'}, {
1360 order_by => {cbreb => 'name'},
1361 limit => $self->cgi->param('limit') || 10,
1362 offset => $self->cgi->param('offset') || 0
1368 if(!$ctx->{bookbags}) {
1370 return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
1373 # If the user wants a specific bookbag's items, load them.
1374 # XXX add bookbag item paging support
1376 if ($self->cgi->param("id")) {
1378 grep { $_->id eq $self->cgi->param("id") } @{$ctx->{bookbags}};
1382 return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
1385 my $query = $self->_prepare_bookbag_container_query(
1386 $bookbag->id, $sorter, $modifier
1389 # XXX we need to limit the number of records per bbag; use third arg
1390 # of bib_container_items_via_search() i think.
1391 my $items = $U->bib_container_items_via_search($bookbag->id, $query)
1392 or return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
1394 # Maybe save a little memory by creating only one XML::LibXML::Document
1395 # instance for each record, even if record is repeated across bookbags.
1397 foreach my $rec (map { $_->target_biblio_record_entry } @$items) {
1398 next if $ctx->{bookbags_marc_xml}{$rec->id};
1399 $ctx->{bookbags_marc_xml}{$rec->id} =
1400 (new XML::LibXML)->parse_string($rec->marc);
1403 $bookbag->items($items);
1407 return Apache2::Const::OK;
1411 # actions are create, delete, show, hide, rename, add_rec, delete_item, place_hold
1412 # CGI is action, list=list_id, add_rec/record=bre_id, del_item=bucket_item_id, name=new_bucket_name
1413 sub load_myopac_bookbag_update {
1414 my ($self, $action, $list_id, @hold_recs) = @_;
1415 my $e = $self->editor;
1416 my $cgi = $self->cgi;
1418 # save_notes is effectively another action, but is passed in a separate
1419 # CGI parameter for what are really just layout reasons.
1420 $action = 'save_notes' if $cgi->param('save_notes');
1421 $action ||= $cgi->param('action');
1423 $list_id ||= $cgi->param('list');
1425 my @add_rec = $cgi->param('add_rec') || $cgi->param('record');
1426 my @selected_item = $cgi->param('selected_item');
1427 my $shared = $cgi->param('shared');
1428 my $name = $cgi->param('name');
1429 my $description = $cgi->param('description');
1433 # This url intentionally leaves off the edit_notes parameter, but
1434 # may need to add some back in for paging.
1436 my $url = "https://" . $self->apache->hostname .
1437 $self->ctx->{opac_root} . "/myopac/lists?";
1439 $url .= 'sort=' . uri_escape($cgi->param("sort")) if $cgi->param("sort");
1441 if ($action eq 'create') {
1442 $list = Fieldmapper::container::biblio_record_entry_bucket->new;
1444 $list->description($description);
1445 $list->owner($e->requestor->id);
1446 $list->btype('bookbag');
1447 $list->pub($shared ? 't' : 'f');
1448 $success = $U->simplereq('open-ils.actor',
1449 'open-ils.actor.container.create', $e->authtoken, 'biblio', $list)
1451 } elsif($action eq 'place_hold') {
1453 # @hold_recs comes from anon lists redirect; selected_itesm comes from existing buckets
1454 unless (@hold_recs) {
1455 if (@selected_item) {
1456 my $items = $e->search_container_biblio_record_entry_bucket_item({id => \@selected_item});
1457 @hold_recs = map { $_->target_biblio_record_entry } @$items;
1461 return Apache2::Const::OK unless @hold_recs;
1462 $logger->info("placing holds from list page on: @hold_recs");
1464 my $url = $self->ctx->{opac_root} . '/place_hold?hold_type=T';
1465 $url .= ';hold_target=' . $_ for @hold_recs;
1466 return $self->generic_redirect($url);
1470 $list = $e->retrieve_container_biblio_record_entry_bucket($list_id);
1472 return Apache2::Const::HTTP_BAD_REQUEST unless
1473 $list and $list->owner == $e->requestor->id;
1476 if($action eq 'delete') {
1477 $success = $U->simplereq('open-ils.actor',
1478 'open-ils.actor.container.full_delete', $e->authtoken, 'biblio', $list_id);
1480 } elsif($action eq 'show') {
1481 unless($U->is_true($list->pub)) {
1483 $success = $U->simplereq('open-ils.actor',
1484 'open-ils.actor.container.update', $e->authtoken, 'biblio', $list);
1487 } elsif($action eq 'hide') {
1488 if($U->is_true($list->pub)) {
1490 $success = $U->simplereq('open-ils.actor',
1491 'open-ils.actor.container.update', $e->authtoken, 'biblio', $list);
1494 } elsif($action eq 'rename') {
1497 $success = $U->simplereq('open-ils.actor',
1498 'open-ils.actor.container.update', $e->authtoken, 'biblio', $list);
1501 } elsif($action eq 'add_rec') {
1502 foreach my $add_rec (@add_rec) {
1503 my $item = Fieldmapper::container::biblio_record_entry_bucket_item->new;
1504 $item->bucket($list_id);
1505 $item->target_biblio_record_entry($add_rec);
1506 $success = $U->simplereq('open-ils.actor',
1507 'open-ils.actor.container.item.create', $e->authtoken, 'biblio', $item);
1508 last unless $success;
1511 } elsif($action eq 'del_item') {
1512 foreach (@selected_item) {
1513 $success = $U->simplereq(
1515 'open-ils.actor.container.item.delete', $e->authtoken, 'biblio', $_
1517 last unless $success;
1519 } elsif ($action eq 'save_notes') {
1520 $success = $self->update_bookbag_item_notes;
1521 $url .= "&id=" . uri_escape($cgi->param("id")) if $cgi->param("id");
1524 return $self->generic_redirect($url) if $success;
1526 # XXX FIXME Bucket failure doesn't have a page to show the user anything
1527 # right now. User just sees a 404 currently.
1529 $self->ctx->{bucket_action} = $action;
1530 $self->ctx->{bucket_action_failed} = 1;
1531 return Apache2::Const::OK;
1534 sub update_bookbag_item_notes {
1536 my $e = $self->editor;
1538 my @note_keys = grep /^note-\d+/, keys(%{$self->cgi->Vars});
1539 my @item_keys = grep /^item-\d+/, keys(%{$self->cgi->Vars});
1541 # We're going to leverage an API call that's already been written to check
1542 # permissions appropriately.
1544 my $a = create OpenSRF::AppSession("open-ils.actor");
1545 my $method = "open-ils.actor.container.item_note.cud";
1547 for my $note_key (@note_keys) {
1550 my $id = ($note_key =~ /(\d+)/)[0];
1553 $e->retrieve_container_biblio_record_entry_bucket_item_note($id))) {
1554 my $event = $e->die_event;
1555 $self->apache->log->warn(
1556 "error retrieving cbrebin id $id, got event " .
1560 $self->ctx->{bucket_action_event} = $event;
1564 if (length($self->cgi->param($note_key))) {
1565 $note->ischanged(1);
1566 $note->note($self->cgi->param($note_key));
1568 $note->isdeleted(1);
1571 my $r = $a->request($method, $e->authtoken, "biblio", $note)->gather(1);
1573 if (defined $U->event_code($r)) {
1574 $self->apache->log->warn(
1575 "attempt to modify cbrebin " . $note->id .
1576 " returned event " . $r->{textcode}
1580 $self->ctx->{bucket_action_event} = $r;
1585 for my $item_key (@item_keys) {
1586 my $id = int(($item_key =~ /(\d+)/)[0]);
1587 my $text = $self->cgi->param($item_key);
1590 next unless length $text;
1592 my $note = new Fieldmapper::container::biblio_record_entry_bucket_item_note;
1597 my $r = $a->request($method, $e->authtoken, "biblio", $note)->gather(1);
1599 if (defined $U->event_code($r)) {
1600 $self->apache->log->warn(
1601 "attempt to create cbrebin for item " . $note->item .
1602 " returned event " . $r->{textcode}
1606 $self->ctx->{bucket_action_event} = $r;
1615 sub load_myopac_bookbag_print {
1618 $self->apache->content_type("text/plain; encoding=utf8");
1620 my $id = int($self->cgi->param("list"));
1622 my ($sorter, $modifier) = $self->_get_bookbag_sort_params("sort");
1625 $self->_prepare_bookbag_container_query($id, $sorter, $modifier);
1629 # Get the bookbag object itself, assuming we're allowed to.
1630 if ($self->editor->allowed("VIEW_CONTAINER")) {
1632 $bbag = $self->editor->retrieve_container_biblio_record_entry_bucket($id) or return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
1634 my $bookbags = $self->editor->search_container_biblio_record_entry_bucket(
1638 "owner" => $self->editor->requestor->id,
1642 ) or return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
1644 $bbag = pop @$bookbags;
1647 # If we have a bookbag we're allowed to look at, issue the A/T event
1648 # to get CSV, passing as a user param that search query we built before.
1650 $self->ctx->{csv} = $U->fire_object_event(
1651 undef, "container.biblio_record_entry_bucket.csv",
1652 $bbag, $self->editor->requestor->home_ou,
1653 undef, {"item_search" => $item_search}
1657 # Create a reasonable filename and set the content disposition to
1658 # provoke browser download dialogs.
1659 (my $filename = $bbag->id . $bbag->name) =~ s/[^a-z0-9_ -]//gi;
1661 $self->apache->headers_out->add(
1662 "Content-Disposition",
1663 "attachment;filename=$filename.csv"
1666 return Apache2::Const::OK;
1669 sub load_password_reset {
1671 my $cgi = $self->cgi;
1672 my $ctx = $self->ctx;
1673 my $barcode = $cgi->param('barcode');
1674 my $username = $cgi->param('username');
1675 my $email = $cgi->param('email');
1676 my $pwd1 = $cgi->param('pwd1');
1677 my $pwd2 = $cgi->param('pwd2');
1678 my $uuid = $ctx->{page_args}->[0];
1682 $logger->info("patron password reset with uuid $uuid");
1684 if ($pwd1 and $pwd2) {
1686 if ($pwd1 eq $pwd2) {
1688 my $response = $U->simplereq(
1690 'open-ils.actor.patron.password_reset.commit',
1693 $logger->info("patron password reset response " . Dumper($response));
1695 if ($U->event_code($response)) { # non-success event
1697 my $code = $response->{textcode};
1699 if ($code eq 'PATRON_NOT_AN_ACTIVE_PASSWORD_RESET_REQUEST') {
1700 $ctx->{pwreset} = {style => 'error', status => 'NOT_ACTIVE'};
1703 if ($code eq 'PATRON_PASSWORD_WAS_NOT_STRONG') {
1704 $ctx->{pwreset} = {style => 'error', status => 'NOT_STRONG'};
1709 $ctx->{pwreset} = {style => 'success', status => 'SUCCESS'};
1712 } else { # passwords not equal
1714 $ctx->{pwreset} = {style => 'error', status => 'NO_MATCH'};
1717 } else { # 2 password values needed
1719 $ctx->{pwreset} = {status => 'TWO_PASSWORDS'};
1722 } elsif ($barcode or $username) {
1724 my @params = $barcode ? ('barcode', $barcode) : ('username', $username);
1728 'open-ils.actor.patron.password_reset.request', @params);
1730 $ctx->{pwreset} = {status => 'REQUEST_SUCCESS'};
1733 $logger->info("patron password reset resulted in " . Dumper($ctx->{pwreset}));
1734 return Apache2::Const::OK;