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 my $U = 'OpenILS::Application::AppUtils';
13 sub prepare_extended_user_info {
17 $self->ctx->{user} = $self->editor->retrieve_actor_user([
18 $self->ctx->{user}->id,
22 au => [qw/card home_ou addresses ident_type billing_address/, @extra_flesh]
26 ]) or return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
32 # user : au object, fleshed
33 sub load_myopac_prefs {
35 return $self->prepare_extended_user_info || Apache2::Const::OK;
38 sub load_myopac_prefs_notify {
40 my $e = $self->editor;
42 my $user_prefs = $self->fetch_optin_prefs;
43 $user_prefs = $self->update_optin_prefs($user_prefs)
44 if $self->cgi->request_method eq 'POST';
46 $self->ctx->{opt_in_settings} = $user_prefs;
48 return Apache2::Const::OK;
51 sub fetch_optin_prefs {
53 my $e = $self->editor;
55 # fetch all of the opt-in settings the user has access to
56 # XXX: user's should in theory have options to opt-in to notices
57 # for remote locations, but that opens the door for a large
58 # set of generally un-used opt-ins.. needs discussion
59 my $opt_ins = $U->simplereq(
61 'open-ils.actor.event_def.opt_in.settings.atomic',
62 $e->authtoken, $e->requestor->home_ou);
64 # fetch user setting values for each of the opt-in settings
65 my $user_set = $U->simplereq(
67 'open-ils.actor.patron.settings.retrieve',
70 [map {$_->name} @$opt_ins]
73 return [map { {cust => $_, value => $user_set->{$_->name} } } @$opt_ins];
76 sub update_optin_prefs {
78 my $user_prefs = shift;
79 my $e = $self->editor;
80 my @settings = $self->cgi->param('setting');
83 # apply now-true settings
84 for my $applied (@settings) {
85 # see if setting is already applied to this user
86 next if grep { $_->{cust}->name eq $applied and $_->{value} } @$user_prefs;
87 $newsets{$applied} = OpenSRF::Utils::JSON->true;
90 # remove now-false settings
91 for my $pref (grep { $_->{value} } @$user_prefs) {
92 $newsets{$pref->{cust}->name} = undef
93 unless grep { $_ eq $pref->{cust}->name } @settings;
98 'open-ils.actor.patron.settings.update',
99 $e->authtoken, $e->requestor->id, \%newsets);
101 # update the local prefs to match reality
102 for my $pref (@$user_prefs) {
103 $pref->{value} = $newsets{$pref->{cust}->name}
104 if exists $newsets{$pref->{cust}->name};
110 sub _load_user_with_prefs {
112 my $stat = $self->prepare_extended_user_info('settings');
113 return $stat if $stat; # not-OK
115 $self->ctx->{user_setting_map} = {
116 map { $_->name => OpenSRF::Utils::JSON->JSON2perl($_->value) }
117 @{$self->ctx->{user}->settings}
123 sub load_myopac_prefs_settings {
126 my $stat = $self->_load_user_with_prefs;
127 return $stat if $stat;
129 return Apache2::Const::OK
130 unless $self->cgi->request_method eq 'POST';
132 # some setting values from the form don't match the
133 # required value/format for the db, so they have to be
134 # individually translated.
137 my $set_map = $self->ctx->{user_setting_map};
139 my $key = 'opac.hits_per_page';
140 my $val = $self->cgi->param($key);
141 $settings{$key}= $val unless $$set_map{$key} eq $val;
143 my $now = DateTime->now->strftime('%F');
144 for $key (qw/history.circ.retention_start history.hold.retention_start/) {
145 $val = $self->cgi->param($key);
146 if($val and $val eq 'on') {
147 # Set the start time to 'now' unless a start time already exists for the user
148 $settings{$key} = $now unless $$set_map{$key};
150 # clear the start time if one previously existed for the user
151 $settings{$key} = undef if $$set_map{$key};
155 # Send the modified settings off to be saved
158 'open-ils.actor.patron.settings.update',
159 $self->editor->authtoken, undef, \%settings);
161 # re-fetch user prefs
162 $self->ctx->{updated_user_settings} = \%settings;
163 return $self->_load_user_with_prefs || Apache2::Const::OK;
166 sub fetch_user_holds {
168 my $hold_ids = shift;
169 my $ids_only = shift;
171 my $available = shift;
175 my $e = $self->editor;
177 my $circ = OpenSRF::AppSession->create('open-ils.circ');
181 $hold_ids = $circ->request(
182 'open-ils.circ.holds.id_list.retrieve.authoritative',
187 $hold_ids = [ grep { defined $_ } @$hold_ids[$offset..($offset + $limit - 1)] ] if $limit or $offset;
191 return $hold_ids if $ids_only or @$hold_ids == 0;
194 suppress_notices => 1,
195 suppress_transits => 1,
197 suppress_patron_details => 1,
198 include_bre => $flesh ? 1 : 0
201 # ----------------------------------------------------------------
202 # Collect holds in batches of $batch_size for faster retrieval
206 my $mk_req_batch = sub {
208 my $top_idx = $batch_idx + $batch_size;
209 while($batch_idx < $top_idx) {
210 my $hold_id = $hold_ids->[$batch_idx++];
211 last unless $hold_id;
212 my $ses = OpenSRF::AppSession->create('open-ils.circ');
213 my $req = $ses->request(
214 'open-ils.circ.hold.details.retrieve',
215 $e->authtoken, $hold_id, $args);
216 push(@ses, {ses => $ses, req => $req});
222 my(@collected, @holds, @ses);
225 @ses = $mk_req_batch->() if $first;
226 last if $first and not @ses;
229 # If desired by the caller, filter any holds that are not available.
231 @collected = grep { $_->{hold}->{status} == 4 } @collected;
233 while(my $blob = pop(@collected)) {
234 $blob->{marc_xml} = XML::LibXML->new->parse_string($blob->{hold}->{bre}->marc) if $flesh;
239 for my $req_data (@ses) {
240 push(@collected, {hold => $req_data->{req}->gather(1)});
241 $req_data->{ses}->kill_me;
244 @ses = $mk_req_batch->();
245 last unless @collected or @ses;
249 # put the holds back into the original server sort order
251 for my $id (@$hold_ids) {
252 push @sorted, grep { $_->{hold}->{hold}->id == $id } @holds;
258 sub handle_hold_update {
261 my $e = $self->editor;
264 my @hold_ids = $self->cgi->param('hold_id'); # for non-_all actions
265 @hold_ids = @{$self->fetch_user_holds(undef, 1)} if $action =~ /_all/;
267 my $circ = OpenSRF::AppSession->create('open-ils.circ');
269 if($action =~ /cancel/) {
271 for my $hold_id (@hold_ids) {
272 my $resp = $circ->request(
273 'open-ils.circ.hold.cancel', $e->authtoken, $hold_id, 6 )->gather(1); # 6 == patron-cancelled-via-opac
276 } elsif ($action =~ /activate|suspend/) {
279 for my $hold_id (@hold_ids) {
280 my $vals = {id => $hold_id};
282 if($action =~ /activate/) {
283 $vals->{frozen} = 'f';
284 $vals->{thaw_date} = undef;
286 } elsif($action =~ /suspend/) {
287 $vals->{frozen} = 't';
288 # $vals->{thaw_date} = TODO;
290 push(@$vlist, $vals);
293 $circ->request('open-ils.circ.hold.update.batch.atomic', $e->authtoken, undef, $vlist)->gather(1);
294 } elsif ($action eq 'edit') {
297 my $val = {"id" => $_};
298 $val->{"frozen"} = $self->cgi->param("frozen");
299 $val->{"pickup_lib"} = $self->cgi->param("pickup_lib");
301 for my $field (qw/expire_time thaw_date/) {
302 # XXX TODO make this support other date formats, not just
304 next unless $self->cgi->param($field) =~
305 m:^(\d{2})/(\d{2})/(\d{4})$:;
306 $val->{$field} = "$3-$1-$2";
312 'open-ils.circ.hold.update.batch.atomic',
313 $e->authtoken, undef, \@vals
314 )->gather(1); # LFW XXX test for failure
315 $url = 'https://' . $self->apache->hostname . $self->ctx->{opac_root} . '/myopac/holds';
319 return defined($url) ? $self->generic_redirect($url) : undef;
322 sub load_myopac_holds {
324 my $e = $self->editor;
325 my $ctx = $self->ctx;
328 my $limit = $self->cgi->param('limit') || 0;
329 my $offset = $self->cgi->param('offset') || 0;
330 my $action = $self->cgi->param('action') || '';
331 my $available = int($self->cgi->param('available') || 0);
333 my $hold_handle_result;
334 $hold_handle_result = $self->handle_hold_update($action) if $action;
336 $ctx->{holds} = $self->fetch_user_holds(undef, 0, 1, $available, $limit, $offset);
338 return defined($hold_handle_result) ? $hold_handle_result : Apache2::Const::OK;
341 sub load_place_hold {
343 my $ctx = $self->ctx;
344 my $e = $self->editor;
345 my $cgi = $self->cgi;
346 $self->ctx->{page} = 'place_hold';
348 $ctx->{hold_target} = $cgi->param('hold_target');
349 $ctx->{hold_type} = $cgi->param('hold_type');
350 $ctx->{default_pickup_lib} = $e->requestor->home_ou; # XXX staff
352 if ($ctx->{hold_type} eq 'T') {
353 $ctx->{record} = $e->retrieve_biblio_record_entry($ctx->{hold_target});
354 } elsif ($ctx->{hold_type} eq 'I') {
355 my $iss = $e->retrieve_serial_issuance([
356 $ctx->{hold_target}, {
359 "siss" => ["subscription"], "ssub" => ["record_entry"]
363 $ctx->{record} = $iss->subscription->record_entry;
367 $ctx->{marc_xml} = XML::LibXML->new->parse_string($ctx->{record}->marc);
369 if (my $pickup_lib = $cgi->param('pickup_lib')) {
370 my $requestor = $e->requestor->id;
373 if ((not $ctx->{"is_staff"}) or
374 ($cgi->param("hold_usr_is_requestor"))) {
377 my $actor = create OpenSRF::AppSession("open-ils.actor");
378 $usr = $actor->request(
379 "open-ils.actor.user.retrieve_id_by_barcode_or_username",
380 $e->authtoken, $cgi->param("hold_usr")
383 if (defined $U->event_code($usr)) {
384 $ctx->{hold_failed} = 1;
385 $ctx->{hold_failed_event} = $usr;
391 titleid => $ctx->{hold_target}, # XXX
392 pickup_lib => $pickup_lib,
396 my $allowed = $U->simplereq(
398 'open-ils.circ.title_hold.is_possible',
402 if($allowed->{success} == 1) {
403 my $hold = Fieldmapper::action::hold_request->new;
405 $hold->pickup_lib($pickup_lib);
406 $hold->requestor($requestor);
408 $hold->target($ctx->{hold_target});
409 $hold->hold_type($ctx->{hold_type});
410 # frozen, expired, etc..
412 my $stat = $U->simplereq(
414 'open-ils.circ.holds.create',
418 if($stat and $stat > 0) {
419 # if successful, return the user to the requesting page
420 $self->apache->log->info("Redirecting back to " . $cgi->param('redirect_to'));
421 return $self->generic_redirect;
424 $ctx->{hold_failed} = 1;
426 } else { # hold *check* failed
427 $ctx->{hold_failed} = 1; # XXX process the events, etc
428 $ctx->{hold_failed_event} = $allowed->{last_event};
432 $logger->info('hold permit result ' . OpenSRF::Utils::JSON->perl2JSON($allowed));
435 return Apache2::Const::OK;
439 sub fetch_user_circs {
441 my $flesh = shift; # flesh bib data, etc.
442 my $circ_ids = shift;
446 my $e = $self->editor;
451 @circ_ids = @$circ_ids;
455 my $circ_data = $U->simplereq(
457 'open-ils.actor.user.checked_out',
462 @circ_ids = ( @{$circ_data->{overdue}}, @{$circ_data->{out}} );
464 if($limit or $offset) {
465 @circ_ids = grep { defined $_ } @circ_ids[0..($offset + $limit - 1)];
469 return [] unless @circ_ids;
471 my $cstore = OpenSRF::AppSession->create('open-ils.cstore');
476 circ => ['target_copy'],
477 acp => ['call_number'],
483 my $circs = $e->search_action_circulation(
484 [{id => \@circ_ids}, ($flesh) ? $qflesh : {}], {substream => 1});
487 for my $circ (@$circs) {
490 marc_xml => ($flesh and $circ->target_copy->call_number->id != -1) ?
491 XML::LibXML->new->parse_string($circ->target_copy->call_number->record->marc) :
492 undef # pre-cat copy, use the dummy title/author instead
497 # make sure the final list is in the correct order
499 for my $id (@circ_ids) {
502 (grep { $_->{circ}->id == $id } @circs)
506 return \@sorted_circs;
510 sub handle_circ_renew {
513 my $ctx = $self->ctx;
515 my @renew_ids = $self->cgi->param('circ');
517 my $circs = $self->fetch_user_circs(0, ($action eq 'renew') ? [@renew_ids] : undef);
519 # TODO: fire off renewal calls in batches to speed things up
521 for my $circ (@$circs) {
523 my $evt = $U->simplereq(
525 'open-ils.circ.renew',
526 $self->editor->authtoken,
528 patron_id => $self->editor->requestor->id,
529 copy_id => $circ->{circ}->target_copy,
534 # TODO return these, then insert them into the circ data
535 # blob that is shoved into the template for each circ
536 # so the template won't have to match them
537 push(@responses, {copy => $circ->{circ}->target_copy, evt => $evt});
544 sub load_myopac_circs {
546 my $e = $self->editor;
547 my $ctx = $self->ctx;
550 my $limit = $self->cgi->param('limit') || 0; # 0 == unlimited
551 my $offset = $self->cgi->param('offset') || 0;
552 my $action = $self->cgi->param('action') || '';
554 # perform the renewal first if necessary
555 my @results = $self->handle_circ_renew($action) if $action =~ /renew/;
557 $ctx->{circs} = $self->fetch_user_circs(1, undef, $limit, $offset);
559 my $success_renewals = 0;
560 my $failed_renewals = 0;
561 for my $data (@{$ctx->{circs}}) {
562 my ($resp) = grep { $_->{copy} == $data->{circ}->target_copy->id } @results;
565 my $evt = ref($resp->{evt}) eq 'ARRAY' ? $resp->{evt}->[0] : $resp->{evt};
566 $data->{renewal_response} = $evt;
567 $success_renewals++ if $evt->{textcode} eq 'SUCCESS';
568 $failed_renewals++ if $evt->{textcode} ne 'SUCCESS';
572 $ctx->{success_renewals} = $success_renewals;
573 $ctx->{failed_renewals} = $failed_renewals;
575 return Apache2::Const::OK;
578 sub load_myopac_circ_history {
580 my $e = $self->editor;
581 my $ctx = $self->ctx;
582 my $limit = $self->cgi->param('limit') || 15;
583 my $offset = $self->cgi->param('offset') || 0;
585 $ctx->{circ_history_limit} = $limit;
586 $ctx->{circ_history_offset} = $offset;
588 my $circs = $e->json_query({
589 from => ['action.usr_visible_circs', $e->requestor->id],
590 #limit => $limit || 25,
591 #offset => $offset || 0,
594 # XXX: order-by in the json_query above appears to do nothing, so in-query
595 # paging is not reallly an option. do the sorting/paging here
597 # sort newest to oldest
598 $circs = [ sort { $b->{xact_start} cmp $a->{xact_start} } @$circs ];
599 my @ids = map { $_->{id} } @$circs;
601 # find the selected page and trim cruft
602 @ids = @ids[$offset..($offset + $limit - 1)] if $limit;
603 @ids = grep { defined $_ } @ids;
605 $ctx->{circs} = $self->fetch_user_circs(1, \@ids);
606 #$ctx->{circs} = $self->fetch_user_circs(1, [map { $_->{id} } @$circs], $limit, $offset);
608 return Apache2::Const::OK;
611 # TODO: action.usr_visible_holds does not return cancelled holds. Should it?
612 sub load_myopac_hold_history {
614 my $e = $self->editor;
615 my $ctx = $self->ctx;
616 my $limit = $self->cgi->param('limit') || 15;
617 my $offset = $self->cgi->param('offset') || 0;
618 $ctx->{hold_history_limit} = $limit;
619 $ctx->{hold_history_offset} = $offset;
622 my $holds = $e->json_query({
623 from => ['action.usr_visible_holds', $e->requestor->id],
624 limit => $limit || 25,
625 offset => $offset || 0
628 $ctx->{holds} = $self->fetch_user_holds([map { $_->{id} } @$holds], 0, 1, 0, $limit, $offset);
630 return Apache2::Const::OK;
633 sub load_myopac_payment_form {
637 $r = $self->prepare_fines(undef, undef, [$self->cgi->param('xact')]) and return $r;
638 $r = $self->prepare_extended_user_info and return $r;
640 return Apache2::Const::OK;
643 # TODO: add other filter options as params/configs/etc.
644 sub load_myopac_payments {
646 my $limit = $self->cgi->param('limit') || 20;
647 my $offset = $self->cgi->param('offset') || 0;
648 my $e = $self->editor;
650 $self->ctx->{payment_history_limit} = $limit;
651 $self->ctx->{payment_history_offset} = $offset;
654 $args->{limit} = $limit if $limit;
655 $args->{offset} = $offset if $offset;
657 $self->ctx->{payments} = $U->simplereq(
659 'open-ils.actor.user.payments.retrieve.atomic',
660 $e->authtoken, $e->requestor->id, $args);
662 return Apache2::Const::OK;
665 sub load_myopac_pay {
669 $r = $self->prepare_fines(undef, undef, [$self->cgi->param('xact')]) and
672 # balance_owed is computed specifically from the fines we're trying
673 # to pay in this case.
674 if ($self->ctx->{fines}->{balance_owed} <= 0) {
675 $self->apache->log->info(
676 sprintf("Can't pay non-positive balance. xacts selected: (%s)",
677 join(", ", map(int, $self->cgi->param("xact"))))
679 return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
682 my $cc_args = {"where_process" => 1};
684 $cc_args->{$_} = $self->cgi->param($_) for (qw/
685 number cvv2 expire_year expire_month billing_first
686 billing_last billing_address billing_city billing_state
691 "cc_args" => $cc_args,
692 "userid" => $self->ctx->{user}->id,
693 "payment_type" => "credit_card_payment",
694 "payments" => $self->prepare_fines_for_payment # should be safe after self->prepare_fines
697 my $resp = $U->simplereq("open-ils.circ", "open-ils.circ.money.payment",
698 $self->editor->authtoken, $args, $self->ctx->{user}->last_xact_id
701 $self->ctx->{"payment_response"} = $resp;
703 unless ($resp->{"textcode"}) {
704 $self->ctx->{printable_receipt} = $U->simplereq(
705 "open-ils.circ", "open-ils.circ.money.payment_receipt.print",
706 $self->editor->authtoken, $resp->{payments}
710 return Apache2::Const::OK;
713 sub load_myopac_receipt_print {
716 $self->ctx->{printable_receipt} = $U->simplereq(
717 "open-ils.circ", "open-ils.circ.money.payment_receipt.print",
718 $self->editor->authtoken, [$self->cgi->param("payment")]
721 return Apache2::Const::OK;
724 sub load_myopac_receipt_email {
727 # The following ML method doesn't actually check whether the user in
728 # question has an email address, so we do.
729 if ($self->ctx->{user}->email) {
730 $self->ctx->{email_receipt_result} = $U->simplereq(
731 "open-ils.circ", "open-ils.circ.money.payment_receipt.email",
732 $self->editor->authtoken, [$self->cgi->param("payment")]
735 $self->ctx->{email_receipt_result} =
736 new OpenILS::Event("PATRON_NO_EMAIL_ADDRESS");
739 return Apache2::Const::OK;
743 my ($self, $limit, $offset, $id_list) = @_;
745 # XXX TODO: check for failure after various network calls
747 # It may be unclear, but this result structure lumps circulation and
748 # reservation fines together, and keeps grocery fines separate.
749 $self->ctx->{"fines"} = {
757 my $cstore = OpenSRF::AppSession->create('open-ils.cstore');
759 # TODO: This should really be a ML call, but the existing calls
760 # return an excessive amount of data and don't offer streaming
762 my %paging = ($limit or $offset) ? (limit => $limit, offset => $offset) : ();
764 my $req = $cstore->request(
765 'open-ils.cstore.direct.money.open_billable_transaction_summary.search',
767 usr => $self->editor->requestor->id,
768 balance_owed => {'!=' => 0},
769 ($id_list && @$id_list ? ("id" => $id_list) : ()),
774 mobts => [qw/grocery circulation reservation/],
775 bresv => ['target_resource_type'],
779 circ => ['target_copy'],
780 acp => ['call_number'],
783 order_by => { mobts => 'xact_start' },
788 my @total_keys = qw/total_paid total_owed balance_owed/;
789 $self->ctx->{"fines"}->{@total_keys} = (0, 0, 0);
791 while(my $resp = $req->recv) {
792 my $mobts = $resp->content;
793 my $circ = $mobts->circulation;
796 if($mobts->grocery) {
797 my @billings = sort { $a->billing_ts cmp $b->billing_ts } @{$mobts->grocery->billings};
798 $last_billing = pop(@billings);
801 # XXX TODO confirm that the following, and the later division by 100.0
802 # to get a floating point representation once again, is sufficiently
804 $self->ctx->{"fines"}->{$_} += int($mobts->$_ * 100) for (@total_keys);
806 my $marc_xml = undef;
807 if ($mobts->xact_type eq 'reservation' and
808 $mobts->reservation->target_resource_type->record) {
809 $marc_xml = XML::LibXML->new->parse_string(
810 $mobts->reservation->target_resource_type->record->marc
812 } elsif ($mobts->xact_type eq 'circulation' and
813 $circ->target_copy->call_number->id != -1) {
814 $marc_xml = XML::LibXML->new->parse_string(
815 $circ->target_copy->call_number->record->marc
820 @{$self->ctx->{"fines"}->{$mobts->grocery ? "grocery" : "circulation"}},
823 last_grocery_billing => $last_billing,
824 marc_xml => $marc_xml
829 $self->ctx->{"fines"}->{$_} /= 100.0 for (@total_keys);
833 sub prepare_fines_for_payment {
834 # This assumes $self->prepare_fines has already been run
838 if ($self->ctx->{fines}) {
839 push @results, [$_->{xact}->id, $_->{xact}->balance_owed] foreach (
840 @{$self->ctx->{fines}->{circulation}},
841 @{$self->ctx->{fines}->{grocery}}
848 sub load_myopac_main {
850 my $limit = $self->cgi->param('limit') || 0;
851 my $offset = $self->cgi->param('offset') || 0;
853 return $self->prepare_fines($limit, $offset) || Apache2::Const::OK;
856 sub load_myopac_update_email {
858 my $e = $self->editor;
859 my $ctx = $self->ctx;
860 my $email = $self->cgi->param('email') || '';
862 return Apache2::Const::OK
863 unless $self->cgi->request_method eq 'POST';
865 unless($email =~ /.+\@.+\..+/) { # TODO better regex?
866 $ctx->{invalid_email} = $email;
867 return Apache2::Const::OK;
870 my $stat = $U->simplereq(
872 'open-ils.actor.user.email.update',
873 $e->authtoken, $email);
875 my $url = $self->apache->unparsed_uri;
876 $url =~ s/update_email/prefs/;
878 return $self->generic_redirect($url);
881 sub load_myopac_update_username {
883 my $e = $self->editor;
884 my $ctx = $self->ctx;
885 my $username = $self->cgi->param('username') || '';
887 return Apache2::Const::OK
888 unless $self->cgi->request_method eq 'POST';
890 unless($username and $username !~ /\s/) { # any other username restrictions?
891 $ctx->{invalid_username} = $username;
892 return Apache2::Const::OK;
895 if($username ne $e->requestor->usrname) {
897 my $evt = $U->simplereq(
899 'open-ils.actor.user.username.update',
900 $e->authtoken, $username);
902 if($U->event_equals($evt, 'USERNAME_EXISTS')) {
903 $ctx->{username_exists} = $username;
904 return Apache2::Const::OK;
908 my $url = $self->apache->unparsed_uri;
909 $url =~ s/update_username/prefs/;
911 return $self->generic_redirect($url);
914 sub load_myopac_update_password {
916 my $e = $self->editor;
917 my $ctx = $self->ctx;
919 return Apache2::Const::OK
920 unless $self->cgi->request_method eq 'POST';
922 my $current_pw = $self->cgi->param('current_pw') || '';
923 my $new_pw = $self->cgi->param('new_pw') || '';
924 my $new_pw2 = $self->cgi->param('new_pw2') || '';
926 unless($new_pw eq $new_pw2) {
927 $ctx->{password_nomatch} = 1;
928 return Apache2::Const::OK;
931 my $pw_regex = $ctx->{get_org_setting}->($e->requestor->home_ou, 'global.password_regex');
933 if($pw_regex and $new_pw !~ /$pw_regex/) {
934 $ctx->{password_invalid} = 1;
935 return Apache2::Const::OK;
938 my $evt = $U->simplereq(
940 'open-ils.actor.user.password.update',
941 $e->authtoken, $new_pw, $current_pw);
944 if($U->event_equals($evt, 'INCORRECT_PASSWORD')) {
945 $ctx->{password_incorrect} = 1;
946 return Apache2::Const::OK;
949 my $url = $self->apache->unparsed_uri;
950 $url =~ s/update_password/prefs/;
952 return $self->generic_redirect($url);
955 sub load_myopac_bookbags {
957 my $e = $self->editor;
958 my $ctx = $self->ctx;
960 $e->xact_begin; # replication...
962 my $rv = $self->load_mylist;
963 unless($rv eq Apache2::Const::OK) {
969 order_by => {cbreb => 'name'},
970 limit => $self->cgi->param('limit') || 10,
971 offset => $self->cgi->param('offset') || 0
974 $ctx->{bookbags} = $e->search_container_biblio_record_entry_bucket([
975 {owner => $self->editor->requestor->id, btype => 'bookbag'},
976 # XXX what to do about the possibility of really large bookbags here?
977 {"flesh" => 1, "flesh_fields" => {"cbreb" => ["items"]}, %$args}
980 if(!$ctx->{bookbags}) {
982 return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
985 # get unique record IDs
987 foreach my $bbag (@{$ctx->{bookbags}}) {
989 map { $_->target_biblio_record_entry } @{$bbag->items}
991 $rec_ids{$rec_id} = 1;
995 $ctx->{bookbags_marc_xml} = $self->fetch_marc_xml_by_id([keys %rec_ids]);
998 return Apache2::Const::OK;
1002 # actions are create, delete, show, hide, rename, add_rec, delete_item
1003 # CGI is action, list=list_id, add_rec/record=bre_id, del_item=bucket_item_id, name=new_bucket_name
1004 sub load_myopac_bookbag_update {
1005 my ($self, $action, $list_id) = @_;
1006 my $e = $self->editor;
1007 my $cgi = $self->cgi;
1009 $action ||= $cgi->param('action');
1010 $list_id ||= $cgi->param('list');
1012 my @add_rec = $cgi->param('add_rec') || $cgi->param('record');
1013 my @del_item = $cgi->param('del_item');
1014 my $shared = $cgi->param('shared');
1015 my $name = $cgi->param('name');
1019 if($action eq 'create') {
1020 $list = Fieldmapper::container::biblio_record_entry_bucket->new;
1022 $list->owner($e->requestor->id);
1023 $list->btype('bookbag');
1024 $list->pub($shared ? 't' : 'f');
1025 $success = $U->simplereq('open-ils.actor',
1026 'open-ils.actor.container.create', $e->authtoken, 'biblio', $list)
1030 $list = $e->retrieve_container_biblio_record_entry_bucket($list_id);
1032 return Apache2::Const::HTTP_BAD_REQUEST unless
1033 $list and $list->owner == $e->requestor->id;
1036 if($action eq 'delete') {
1037 $success = $U->simplereq('open-ils.actor',
1038 'open-ils.actor.container.full_delete', $e->authtoken, 'biblio', $list_id);
1040 } elsif($action eq 'show') {
1041 unless($U->is_true($list->pub)) {
1043 $success = $U->simplereq('open-ils.actor',
1044 'open-ils.actor.container.update', $e->authtoken, 'biblio', $list);
1047 } elsif($action eq 'hide') {
1048 if($U->is_true($list->pub)) {
1050 $success = $U->simplereq('open-ils.actor',
1051 'open-ils.actor.container.update', $e->authtoken, 'biblio', $list);
1054 } elsif($action eq 'rename') {
1057 $success = $U->simplereq('open-ils.actor',
1058 'open-ils.actor.container.update', $e->authtoken, 'biblio', $list);
1061 } elsif($action eq 'add_rec') {
1062 foreach my $add_rec (@add_rec) {
1063 my $item = Fieldmapper::container::biblio_record_entry_bucket_item->new;
1064 $item->bucket($list_id);
1065 $item->target_biblio_record_entry($add_rec);
1066 $success = $U->simplereq('open-ils.actor',
1067 'open-ils.actor.container.item.create', $e->authtoken, 'biblio', $item);
1068 last unless $success;
1071 } elsif($action eq 'del_item') {
1072 foreach (@del_item) {
1073 $success = $U->simplereq(
1075 'open-ils.actor.container.item.delete', $e->authtoken, 'biblio', $_
1077 last unless $success;
1081 return $self->generic_redirect if $success;
1083 $self->ctx->{bucket_action} = $action;
1084 $self->ctx->{bucket_action_failed} = 1;
1085 return Apache2::Const::OK;