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;
8 use OpenSRF::Utils::JSON;
10 #$Data::Dumper::Indent = 0;
11 my $U = 'OpenILS::Application::AppUtils';
13 sub prepare_extended_user_info {
16 $self->ctx->{user} = $self->editor->retrieve_actor_user([
17 $self->ctx->{user}->id,
21 au => [qw/card home_ou addresses ident_type billing_address/]
25 ]) or return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
31 # user : au object, fleshed
32 sub load_myopac_prefs {
34 return $self->prepare_extended_user_info || Apache2::Const::OK;
37 sub load_myopac_prefs_notify {
39 my $e = $self->editor;
41 my $user_prefs = $self->fetch_optin_prefs;
42 $user_prefs = $self->update_optin_prefs($user_prefs)
43 if $self->cgi->request_method eq 'POST';
45 $self->ctx->{opt_in_settings} = $user_prefs;
47 return Apache2::Const::OK;
50 sub fetch_optin_prefs {
52 my $e = $self->editor;
54 # fetch all of the opt-in settings the user has access to
55 # XXX: user's should in theory have options to opt-in to notices
56 # for remote locations, but that opens the door for a large
57 # set of generally un-used opt-ins.. needs discussion
58 my $opt_ins = $U->simplereq(
60 'open-ils.actor.event_def.opt_in.settings.atomic',
61 $e->authtoken, $e->requestor->home_ou);
63 # fetch user setting values for each of the opt-in settings
64 my $user_set = $U->simplereq(
66 'open-ils.actor.patron.settings.retrieve',
69 [map {$_->name} @$opt_ins]
72 return [map { {cust => $_, value => $user_set->{$_->name} } } @$opt_ins];
75 sub update_optin_prefs {
77 my $user_prefs = shift;
78 my $e = $self->editor;
79 my @settings = $self->cgi->param('setting');
82 # apply now-true settings
83 for my $applied (@settings) {
84 # see if setting is already applied to this user
85 next if grep { $_->{cust}->name eq $applied and $_->{value} } @$user_prefs;
86 $newsets{$applied} = OpenSRF::Utils::JSON->true;
89 # remove now-false settings
90 for my $pref (grep { $_->{value} } @$user_prefs) {
91 $newsets{$pref->{cust}->name} = undef
92 unless grep { $_ eq $pref->{cust}->name } @settings;
97 'open-ils.actor.patron.settings.update',
98 $e->authtoken, $e->requestor->id, \%newsets);
100 # update the local prefs to match reality
101 for my $pref (@$user_prefs) {
102 $pref->{value} = $newsets{$pref->{cust}->name}
103 if exists $newsets{$pref->{cust}->name};
109 sub load_myopac_prefs_settings {
111 return $self->prepare_extended_user_info || Apache2::Const::OK;
114 sub fetch_user_holds {
116 my $hold_ids = shift;
117 my $ids_only = shift;
119 my $available = shift;
123 my $e = $self->editor;
125 my $circ = OpenSRF::AppSession->create('open-ils.circ');
129 $hold_ids = $circ->request(
130 'open-ils.circ.holds.id_list.retrieve.authoritative',
135 $hold_ids = [ grep { defined $_ } @$hold_ids[$offset..($offset + $limit - 1)] ] if $limit or $offset;
139 return $hold_ids if $ids_only or @$hold_ids == 0;
142 suppress_notices => 1,
143 suppress_transits => 1,
145 suppress_patron_details => 1,
146 include_bre => $flesh ? 1 : 0
149 # ----------------------------------------------------------------
150 # Collect holds in batches of $batch_size for faster retrieval
154 my $mk_req_batch = sub {
156 my $top_idx = $batch_idx + $batch_size;
157 while($batch_idx < $top_idx) {
158 my $hold_id = $hold_ids->[$batch_idx++];
159 last unless $hold_id;
160 my $ses = OpenSRF::AppSession->create('open-ils.circ');
161 my $req = $ses->request(
162 'open-ils.circ.hold.details.retrieve',
163 $e->authtoken, $hold_id, $args);
164 push(@ses, {ses => $ses, req => $req});
170 my(@collected, @holds, @ses);
173 @ses = $mk_req_batch->() if $first;
174 last if $first and not @ses;
177 # If desired by the caller, filter any holds that are not available.
179 @collected = grep { $_->{hold}->{status} == 4 } @collected;
181 while(my $blob = pop(@collected)) {
182 $blob->{marc_xml} = XML::LibXML->new->parse_string($blob->{hold}->{bre}->marc) if $flesh;
187 for my $req_data (@ses) {
188 push(@collected, {hold => $req_data->{req}->gather(1)});
189 $req_data->{ses}->kill_me;
192 @ses = $mk_req_batch->();
193 last unless @collected or @ses;
197 # put the holds back into the original server sort order
199 for my $id (@$hold_ids) {
200 push @sorted, grep { $_->{hold}->{hold}->id == $id } @holds;
206 sub handle_hold_update {
209 my $e = $self->editor;
212 my @hold_ids = $self->cgi->param('hold_id'); # for non-_all actions
213 @hold_ids = @{$self->fetch_user_holds(undef, 1)} if $action =~ /_all/;
215 my $circ = OpenSRF::AppSession->create('open-ils.circ');
217 if($action =~ /cancel/) {
219 for my $hold_id (@hold_ids) {
220 my $resp = $circ->request(
221 'open-ils.circ.hold.cancel', $e->authtoken, $hold_id, 6 )->gather(1); # 6 == patron-cancelled-via-opac
224 } elsif ($action =~ /activate|suspend/) {
227 for my $hold_id (@hold_ids) {
228 my $vals = {id => $hold_id};
230 if($action =~ /activate/) {
231 $vals->{frozen} = 'f';
232 $vals->{thaw_date} = undef;
234 } elsif($action =~ /suspend/) {
235 $vals->{frozen} = 't';
236 # $vals->{thaw_date} = TODO;
238 push(@$vlist, $vals);
241 $circ->request('open-ils.circ.hold.update.batch.atomic', $e->authtoken, undef, $vlist)->gather(1);
242 } elsif ($action eq 'edit') {
245 my $val = {"id" => $_};
246 $val->{"frozen"} = $self->cgi->param("frozen");
247 $val->{"pickup_lib"} = $self->cgi->param("pickup_lib");
249 for my $field (qw/expire_time thaw_date/) {
250 # XXX TODO make this support other date formats, not just
252 next unless $self->cgi->param($field) =~
253 m:^(\d{2})/(\d{2})/(\d{4})$:;
254 $val->{$field} = "$3-$1-$2";
260 'open-ils.circ.hold.update.batch.atomic',
261 $e->authtoken, undef, \@vals
262 )->gather(1); # LFW XXX test for failure
263 $url = 'https://' . $self->apache->hostname . $self->ctx->{opac_root} . '/myopac/holds';
267 return defined($url) ? $self->generic_redirect($url) : undef;
270 sub load_myopac_holds {
272 my $e = $self->editor;
273 my $ctx = $self->ctx;
276 my $limit = $self->cgi->param('limit') || 0;
277 my $offset = $self->cgi->param('offset') || 0;
278 my $action = $self->cgi->param('action') || '';
279 my $available = int($self->cgi->param('available') || 0);
281 my $hold_handle_result;
282 $hold_handle_result = $self->handle_hold_update($action) if $action;
284 $ctx->{holds} = $self->fetch_user_holds(undef, 0, 1, $available, $limit, $offset);
286 return defined($hold_handle_result) ? $hold_handle_result : Apache2::Const::OK;
289 sub load_place_hold {
291 my $ctx = $self->ctx;
292 my $e = $self->editor;
293 my $cgi = $self->cgi;
294 $self->ctx->{page} = 'place_hold';
296 $ctx->{hold_target} = $cgi->param('hold_target');
297 $ctx->{hold_type} = $cgi->param('hold_type');
298 $ctx->{default_pickup_lib} = $e->requestor->home_ou; # XXX staff
300 if ($ctx->{hold_type} eq 'T') {
301 $ctx->{record} = $e->retrieve_biblio_record_entry($ctx->{hold_target});
302 } elsif ($ctx->{hold_type} eq 'I') {
303 my $iss = $e->retrieve_serial_issuance([
304 $ctx->{hold_target}, {
307 "siss" => ["subscription"], "ssub" => ["record_entry"]
311 $ctx->{record} = $iss->subscription->record_entry;
315 $ctx->{marc_xml} = XML::LibXML->new->parse_string($ctx->{record}->marc);
317 if(my $pickup_lib = $cgi->param('pickup_lib')) {
320 patronid => $e->requestor->id,
321 titleid => $ctx->{hold_target}, # XXX
322 pickup_lib => $pickup_lib,
326 my $allowed = $U->simplereq(
328 'open-ils.circ.title_hold.is_possible',
332 if($allowed->{success} == 1) {
333 my $hold = Fieldmapper::action::hold_request->new;
335 $hold->pickup_lib($pickup_lib);
336 $hold->requestor($e->requestor->id);
337 $hold->usr($e->requestor->id); # XXX staff
338 $hold->target($ctx->{hold_target});
339 $hold->hold_type($ctx->{hold_type});
340 # frozen, expired, etc..
342 my $stat = $U->simplereq(
344 'open-ils.circ.holds.create',
348 if($stat and $stat > 0) {
349 # if successful, return the user to the requesting page
350 $self->apache->log->info("Redirecting back to " . $cgi->param('redirect_to'));
351 return $self->generic_redirect;
354 $ctx->{hold_failed} = 1;
356 } else { # hold *check* failed
357 $ctx->{hold_failed} = 1; # XXX process the events, etc
358 $ctx->{hold_failed_event} = $allowed->{last_event};
362 $logger->info('hold permit result ' . OpenSRF::Utils::JSON->perl2JSON($allowed));
365 return Apache2::Const::OK;
369 sub fetch_user_circs {
371 my $flesh = shift; # flesh bib data, etc.
372 my $circ_ids = shift;
376 my $e = $self->editor;
381 @circ_ids = @$circ_ids;
385 my $circ_data = $U->simplereq(
387 'open-ils.actor.user.checked_out',
392 @circ_ids = ( @{$circ_data->{overdue}}, @{$circ_data->{out}} );
394 if($limit or $offset) {
395 @circ_ids = grep { defined $_ } @circ_ids[0..($offset + $limit - 1)];
399 return [] unless @circ_ids;
401 my $cstore = OpenSRF::AppSession->create('open-ils.cstore');
406 circ => ['target_copy'],
407 acp => ['call_number'],
413 my $circs = $e->search_action_circulation(
414 [{id => \@circ_ids}, ($flesh) ? $qflesh : {}], {substream => 1});
417 for my $circ (@$circs) {
420 marc_xml => ($flesh and $circ->target_copy->call_number->id != -1) ?
421 XML::LibXML->new->parse_string($circ->target_copy->call_number->record->marc) :
422 undef # pre-cat copy, use the dummy title/author instead
427 # make sure the final list is in the correct order
429 for my $id (@circ_ids) {
432 (grep { $_->{circ}->id == $id } @circs)
436 return \@sorted_circs;
440 sub handle_circ_renew {
443 my $ctx = $self->ctx;
445 my @renew_ids = $self->cgi->param('circ');
447 my $circs = $self->fetch_user_circs(0, ($action eq 'renew') ? [@renew_ids] : undef);
449 # TODO: fire off renewal calls in batches to speed things up
451 for my $circ (@$circs) {
453 my $evt = $U->simplereq(
455 'open-ils.circ.renew',
456 $self->editor->authtoken,
458 patron_id => $self->editor->requestor->id,
459 copy_id => $circ->{circ}->target_copy,
464 # TODO return these, then insert them into the circ data
465 # blob that is shoved into the template for each circ
466 # so the template won't have to match them
467 push(@responses, {copy => $circ->{circ}->target_copy, evt => $evt});
474 sub load_myopac_circs {
476 my $e = $self->editor;
477 my $ctx = $self->ctx;
480 my $limit = $self->cgi->param('limit') || 0; # 0 == unlimited
481 my $offset = $self->cgi->param('offset') || 0;
482 my $action = $self->cgi->param('action') || '';
484 # perform the renewal first if necessary
485 my @results = $self->handle_circ_renew($action) if $action =~ /renew/;
487 $ctx->{circs} = $self->fetch_user_circs(1, undef, $limit, $offset);
489 my $success_renewals = 0;
490 my $failed_renewals = 0;
491 for my $data (@{$ctx->{circs}}) {
492 my ($resp) = grep { $_->{copy} == $data->{circ}->target_copy->id } @results;
495 my $evt = ref($resp->{evt}) eq 'ARRAY' ? $resp->{evt}->[0] : $resp->{evt};
496 $data->{renewal_response} = $evt;
497 $success_renewals++ if $evt->{textcode} eq 'SUCCESS';
498 $failed_renewals++ if $evt->{textcode} ne 'SUCCESS';
502 $ctx->{success_renewals} = $success_renewals;
503 $ctx->{failed_renewals} = $failed_renewals;
505 return Apache2::Const::OK;
508 sub load_myopac_circ_history {
510 my $e = $self->editor;
511 my $ctx = $self->ctx;
512 my $limit = $self->cgi->param('limit') || 15;
513 my $offset = $self->cgi->param('offset') || 0;
515 $ctx->{circ_history_limit} = $limit;
516 $ctx->{circ_history_offset} = $offset;
518 my $circs = $e->json_query({
519 from => ['action.usr_visible_circs', $e->requestor->id],
520 #limit => $limit || 25,
521 #offset => $offset || 0,
524 # XXX: order-by in the json_query above appears to do nothing, so in-query
525 # paging is not reallly an option. do the sorting/paging here
527 # sort newest to oldest
528 $circs = [ sort { $b->{xact_start} cmp $a->{xact_start} } @$circs ];
529 my @ids = map { $_->{id} } @$circs;
531 # find the selected page and trim cruft
532 @ids = @ids[$offset..($offset + $limit - 1)] if $limit;
533 @ids = grep { defined $_ } @ids;
535 $ctx->{circs} = $self->fetch_user_circs(1, \@ids);
536 #$ctx->{circs} = $self->fetch_user_circs(1, [map { $_->{id} } @$circs], $limit, $offset);
538 return Apache2::Const::OK;
541 # TODO: action.usr_visible_holds does not return cancelled holds. Should it?
542 sub load_myopac_hold_history {
544 my $e = $self->editor;
545 my $ctx = $self->ctx;
546 my $limit = $self->cgi->param('limit') || 15;
547 my $offset = $self->cgi->param('offset') || 0;
548 $ctx->{hold_history_limit} = $limit;
549 $ctx->{hold_history_offset} = $offset;
552 my $holds = $e->json_query({
553 from => ['action.usr_visible_holds', $e->requestor->id],
554 limit => $limit || 25,
555 offset => $offset || 0
558 $ctx->{holds} = $self->fetch_user_holds([map { $_->{id} } @$holds], 0, 1, 0, $limit, $offset);
560 return Apache2::Const::OK;
563 sub load_myopac_payment_form {
567 $r = $self->prepare_fines(undef, undef, [$self->cgi->param('xact')]) and return $r;
568 $r = $self->prepare_extended_user_info and return $r;
570 return Apache2::Const::OK;
573 # TODO: add other filter options as params/configs/etc.
574 sub load_myopac_payments {
576 my $limit = $self->cgi->param('limit') || 20;
577 my $offset = $self->cgi->param('offset') || 0;
578 my $e = $self->editor;
580 $self->ctx->{payment_history_limit} = $limit;
581 $self->ctx->{payment_history_offset} = $offset;
584 $args->{limit} = $limit if $limit;
585 $args->{offset} = $offset if $offset;
587 $self->ctx->{payments} = $U->simplereq(
589 'open-ils.actor.user.payments.retrieve.atomic',
590 $e->authtoken, $e->requestor->id, $args);
592 return Apache2::Const::OK;
595 sub load_myopac_pay {
599 $r = $self->prepare_fines(undef, undef, [$self->cgi->param('xact')]) and
602 # balance_owed is computed specifically from the fines we're trying
603 # to pay in this case.
604 if ($self->ctx->{fines}->{balance_owed} <= 0) {
605 $self->apache->log->info(
606 sprintf("Can't pay non-positive balance. xacts selected: (%s)",
607 join(", ", map(int, $self->cgi->param("xact"))))
609 return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
612 my $cc_args = {"where_process" => 1};
614 $cc_args->{$_} = $self->cgi->param($_) for (qw/
615 number cvv2 expire_year expire_month billing_first
616 billing_last billing_address billing_city billing_state
621 "cc_args" => $cc_args,
622 "userid" => $self->ctx->{user}->id,
623 "payment_type" => "credit_card_payment",
624 "payments" => $self->prepare_fines_for_payment # should be safe after self->prepare_fines
627 my $resp = $U->simplereq("open-ils.circ", "open-ils.circ.money.payment",
628 $self->editor->authtoken, $args, $self->ctx->{user}->last_xact_id
631 $self->ctx->{"payment_response"} = $resp;
633 unless ($resp->{"textcode"}) {
634 $self->ctx->{printable_receipt} = $U->simplereq(
635 "open-ils.circ", "open-ils.circ.money.payment_receipt.print",
636 $self->editor->authtoken, $resp->{payments}
640 return Apache2::Const::OK;
644 my ($self, $limit, $offset, $id_list) = @_;
646 # XXX TODO: check for failure after various network calls
648 # It may be unclear, but this result structure lumps circulation and
649 # reservation fines together, and keeps grocery fines separate.
650 $self->ctx->{"fines"} = {
658 my $cstore = OpenSRF::AppSession->create('open-ils.cstore');
660 # TODO: This should really be a ML call, but the existing calls
661 # return an excessive amount of data and don't offer streaming
663 my %paging = ($limit or $offset) ? (limit => $limit, offset => $offset) : ();
665 my $req = $cstore->request(
666 'open-ils.cstore.direct.money.open_billable_transaction_summary.search',
668 usr => $self->editor->requestor->id,
669 balance_owed => {'!=' => 0},
670 ($id_list && @$id_list ? ("id" => $id_list) : ()),
675 mobts => [qw/grocery circulation reservation/],
676 bresv => ['target_resource_type'],
680 circ => ['target_copy'],
681 acp => ['call_number'],
684 order_by => { mobts => 'xact_start' },
689 my @total_keys = qw/total_paid total_owed balance_owed/;
690 $self->ctx->{"fines"}->{@total_keys} = (0, 0, 0);
692 while(my $resp = $req->recv) {
693 my $mobts = $resp->content;
694 my $circ = $mobts->circulation;
697 if($mobts->grocery) {
698 my @billings = sort { $a->billing_ts cmp $b->billing_ts } @{$mobts->grocery->billings};
699 $last_billing = pop(@billings);
702 # XXX TODO confirm that the following, and the later division by 100.0
703 # to get a floating point representation once again, is sufficiently
705 $self->ctx->{"fines"}->{$_} += int($mobts->$_ * 100) for (@total_keys);
707 my $marc_xml = undef;
708 if ($mobts->xact_type eq 'reservation' and
709 $mobts->reservation->target_resource_type->record) {
710 $marc_xml = XML::LibXML->new->parse_string(
711 $mobts->reservation->target_resource_type->record->marc
713 } elsif ($mobts->xact_type eq 'circulation' and
714 $circ->target_copy->call_number->id != -1) {
715 $marc_xml = XML::LibXML->new->parse_string(
716 $circ->target_copy->call_number->record->marc
721 @{$self->ctx->{"fines"}->{$mobts->grocery ? "grocery" : "circulation"}},
724 last_grocery_billing => $last_billing,
725 marc_xml => $marc_xml
730 $self->ctx->{"fines"}->{$_} /= 100.0 for (@total_keys);
734 sub prepare_fines_for_payment {
735 # This assumes $self->prepare_fines has already been run
739 if ($self->ctx->{fines}) {
740 push @results, [$_->{xact}->id, $_->{xact}->balance_owed] foreach (
741 @{$self->ctx->{fines}->{circulation}},
742 @{$self->ctx->{fines}->{grocery}}
749 sub load_myopac_main {
751 my $limit = $self->cgi->param('limit') || 0;
752 my $offset = $self->cgi->param('offset') || 0;
754 return $self->prepare_fines($limit, $offset) || Apache2::Const::OK;
757 sub load_myopac_update_email {
759 my $e = $self->editor;
760 my $ctx = $self->ctx;
761 my $email = $self->cgi->param('email') || '';
763 return Apache2::Const::OK
764 unless $self->cgi->request_method eq 'POST';
766 unless($email =~ /.+\@.+\..+/) { # TODO better regex?
767 $ctx->{invalid_email} = $email;
768 return Apache2::Const::OK;
771 my $stat = $U->simplereq(
773 'open-ils.actor.user.email.update',
774 $e->authtoken, $email);
776 my $url = $self->apache->unparsed_uri;
777 $url =~ s/update_email/prefs/;
779 return $self->generic_redirect($url);
782 sub load_myopac_update_username {
784 my $e = $self->editor;
785 my $ctx = $self->ctx;
786 my $username = $self->cgi->param('username') || '';
788 return Apache2::Const::OK
789 unless $self->cgi->request_method eq 'POST';
791 unless($username and $username !~ /\s/) { # any other username restrictions?
792 $ctx->{invalid_username} = $username;
793 return Apache2::Const::OK;
796 if($username ne $e->requestor->usrname) {
798 my $evt = $U->simplereq(
800 'open-ils.actor.user.username.update',
801 $e->authtoken, $username);
803 if($U->event_equals($evt, 'USERNAME_EXISTS')) {
804 $ctx->{username_exists} = $username;
805 return Apache2::Const::OK;
809 my $url = $self->apache->unparsed_uri;
810 $url =~ s/update_username/prefs/;
812 return $self->generic_redirect($url);
815 sub load_myopac_update_password {
817 my $e = $self->editor;
818 my $ctx = $self->ctx;
820 return Apache2::Const::OK
821 unless $self->cgi->request_method eq 'POST';
823 my $current_pw = $self->cgi->param('current_pw') || '';
824 my $new_pw = $self->cgi->param('new_pw') || '';
825 my $new_pw2 = $self->cgi->param('new_pw2') || '';
827 unless($new_pw eq $new_pw2) {
828 $ctx->{password_nomatch} = 1;
829 return Apache2::Const::OK;
832 my $pw_regex = $ctx->{get_org_setting}->($e->requestor->home_ou, 'global.password_regex');
834 if($pw_regex and $new_pw !~ /$pw_regex/) {
835 $ctx->{password_invalid} = 1;
836 return Apache2::Const::OK;
839 my $evt = $U->simplereq(
841 'open-ils.actor.user.password.update',
842 $e->authtoken, $new_pw, $current_pw);
845 if($U->event_equals($evt, 'INCORRECT_PASSWORD')) {
846 $ctx->{password_incorrect} = 1;
847 return Apache2::Const::OK;
850 my $url = $self->apache->unparsed_uri;
851 $url =~ s/update_password/prefs/;
853 return $self->generic_redirect($url);
856 sub load_myopac_bookbags {
858 my $e = $self->editor;
859 my $ctx = $self->ctx;
861 $e->xact_begin; # replication...
863 my $rv = $self->load_mylist;
864 unless($rv eq Apache2::Const::OK) {
870 order_by => {cbreb => 'name'},
871 limit => $self->cgi->param('limit') || 10,
872 offset => $self->cgi->param('offset') || 0
875 $ctx->{bookbags} = $e->search_container_biblio_record_entry_bucket([
876 {owner => $self->editor->requestor->id, btype => 'bookbag'},
877 # XXX what to do about the possibility of really large bookbags here?
878 {"flesh" => 1, "flesh_fields" => {"cbreb" => ["items"]}, %$args}
881 if(!$ctx->{bookbags}) {
883 return Apache2::Const::HTTP_INTERNAL_SERVER_ERROR;
886 # get unique record IDs
888 foreach my $bbag (@{$ctx->{bookbags}}) {
890 map { $_->target_biblio_record_entry } @{$bbag->items}
892 $rec_ids{$rec_id} = 1;
896 $ctx->{bookbags_marc_xml} = $self->fetch_marc_xml_by_id([keys %rec_ids]);
899 return Apache2::Const::OK;
903 # actions are create, delete, show, hide, rename, add_rec, delete_item
904 # CGI is action, list=list_id, add_rec/record=bre_id, del_item=bucket_item_id, name=new_bucket_name
905 sub load_myopac_bookbag_update {
906 my ($self, $action, $list_id) = @_;
907 my $e = $self->editor;
908 my $cgi = $self->cgi;
910 $action ||= $cgi->param('action');
911 $list_id ||= $cgi->param('list');
913 my @add_rec = $cgi->param('add_rec') || $cgi->param('record');
914 my @del_item = $cgi->param('del_item');
915 my $shared = $cgi->param('shared');
916 my $name = $cgi->param('name');
920 if($action eq 'create') {
921 $list = Fieldmapper::container::biblio_record_entry_bucket->new;
923 $list->owner($e->requestor->id);
924 $list->btype('bookbag');
925 $list->pub($shared ? 't' : 'f');
926 $success = $U->simplereq('open-ils.actor',
927 'open-ils.actor.container.create', $e->authtoken, 'biblio', $list)
931 $list = $e->retrieve_container_biblio_record_entry_bucket($list_id);
933 return Apache2::Const::HTTP_BAD_REQUEST unless
934 $list and $list->owner == $e->requestor->id;
937 if($action eq 'delete') {
938 $success = $U->simplereq('open-ils.actor',
939 'open-ils.actor.container.full_delete', $e->authtoken, 'biblio', $list_id);
941 } elsif($action eq 'show') {
942 unless($U->is_true($list->pub)) {
944 $success = $U->simplereq('open-ils.actor',
945 'open-ils.actor.container.update', $e->authtoken, 'biblio', $list);
948 } elsif($action eq 'hide') {
949 if($U->is_true($list->pub)) {
951 $success = $U->simplereq('open-ils.actor',
952 'open-ils.actor.container.update', $e->authtoken, 'biblio', $list);
955 } elsif($action eq 'rename') {
958 $success = $U->simplereq('open-ils.actor',
959 'open-ils.actor.container.update', $e->authtoken, 'biblio', $list);
962 } elsif($action eq 'add_rec') {
963 foreach my $add_rec (@add_rec) {
964 my $item = Fieldmapper::container::biblio_record_entry_bucket_item->new;
965 $item->bucket($list_id);
966 $item->target_biblio_record_entry($add_rec);
967 $success = $U->simplereq('open-ils.actor',
968 'open-ils.actor.container.item.create', $e->authtoken, 'biblio', $item);
969 last unless $success;
972 } elsif($action eq 'del_item') {
973 foreach (@del_item) {
974 $success = $U->simplereq(
976 'open-ils.actor.container.item.delete', $e->authtoken, 'biblio', $_
978 last unless $success;
982 return $self->generic_redirect if $success;
984 $self->ctx->{bucket_action} = $action;
985 $self->ctx->{bucket_action_failed} = 1;
986 return Apache2::Const::OK;