]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/SMS.pm
SMS texting
[Evergreen.git] / Open-ILS / src / perlmods / lib / OpenILS / WWW / EGCatLoader / SMS.pm
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 OpenILS::Event;
9 use OpenSRF::Utils::JSON;
10 use Data::Dumper;
11 $Data::Dumper::Indent = 0;
12 use DateTime;
13 my $U = 'OpenILS::Application::AppUtils';
14
15 sub load_sms_cn {
16     my $self = shift;
17     my $ctx = $self->ctx;
18     my $gos = $ctx->{get_org_setting};
19     my $e = $self->editor;
20     my $cgi = $self->cgi;
21
22     my $org_unit = $cgi->param('loc') || $ctx->{aou_tree}->()->id;
23
24     $self->_load_user_with_prefs() if($e->checkauth);
25
26     $ctx->{page} = 'sms_cn';
27     $ctx->{sms_carrier} = $cgi->param('sms_carrier');
28     $ctx->{sms_notify} = $cgi->param('sms_notify');
29     $ctx->{copy_id} = $cgi->param('copy_id');
30     $ctx->{query} = $cgi->param('query');
31     $ctx->{origin} = $cgi->param('origin');
32
33     my $acn_results = $e->json_query({
34         select => {
35             acp => ['call_number']
36         },
37         from => 'acp',
38         where => {id => $ctx->{copy_id}}
39     });
40
41     my $acn_ids = [map { $_->{call_number} } @$acn_results];
42     $ctx->{acn_ids} = $acn_ids;
43
44     my $resp = $U->simplereq('open-ils.cat', 'open-ils.cat.acn.send_sms_text',
45         $e->authtoken, $org_unit,
46         $ctx->{sms_carrier}, $ctx->{sms_notify},
47         $acn_ids
48     );
49
50     $ctx->{event} = $resp;
51
52     $ctx->{orig_params} = $cgi->Vars;
53
54     return Apache2::Const::OK;
55 }
56
57