forked from Aspen-Discovery/aspen-discovery
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAJAX.php
9092 lines (8370 loc) · 291 KB
/
AJAX.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require_once ROOT_DIR . '/JSON_Action.php';
class MyAccount_AJAX extends JSON_Action {
const SORT_LAST_ALPHA = 'zzzzz';
function launch($method = null) {
$method = (isset($_GET['method']) && !is_array($_GET['method'])) ? $_GET['method'] : '';
switch ($method) {
case 'renewItem':
$method = 'renewCheckout';
break;
}
if (method_exists($this, $method)) {
parent::launch($method);
} else {
echo json_encode(['error' => 'invalid_method']);
}
}
/** @noinspection PhpUnused */
function getAddBrowseCategoryFromListForm() {
global $interface;
// Select List Creation using Object Editor functions
require_once ROOT_DIR . '/sys/Browse/SubBrowseCategories.php';
$temp = SubBrowseCategories::getObjectStructure('');
$temp['subCategoryId']['values'] = [0 => 'Select One'] + $temp['subCategoryId']['values'];
// add default option that denotes nothing has been selected to the options list
// (this preserves the keys' numeric values (which is essential as they are the Id values) as well as the array's order)
// btw addition of arrays is kinda a cool trick.
$interface->assign('propName', 'addAsSubCategoryOf');
$interface->assign('property', $temp['subCategoryId']);
// Display Page
$interface->assign('listId', strip_tags($_REQUEST['listId']));
return [
'title' => translate([
'text' => 'Add as Browse Category to Home Page',
'isAdminFacing' => 'true',
]),
'modalBody' => $interface->fetch('Browse/newBrowseCategoryForm.tpl'),
'modalButtons' => "<button class='tool btn btn-primary' onclick='$(\"#createBrowseCategory\").submit();'>" . translate([
'text' => 'Create Category',
'isAdminFacing' => 'true',
]) . "</button>",
];
}
/** @noinspection PhpUnused */
function addAccountLink(): array {
if (!UserAccount::isLoggedIn()) {
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to link accounts',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'Sorry, you must be logged in to manage accounts.',
'isPublicFacing' => true,
]),
];
} else {
$username = $_REQUEST['username'];
$password = $_REQUEST['password'];
$accountToLink = UserAccount::validateAccount($username, $password);
if (!UserAccount::isLoggedIn()) {
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to link accounts',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'You must be logged in to link accounts, please login again',
'isPublicFacing' => true,
]),
];
} elseif ($accountToLink) {
$user = UserAccount::getLoggedInUser();
$userPtype = $user->getPType();
if ($accountToLink->id != $user->id) {
$linkeePtype = $accountToLink->getPType();
if ($linkeePtype != null) {
require_once ROOT_DIR . '/sys/Account/PType.php';
$linkingSettingUser = PType::getAccountLinkingSetting($userPtype);
$linkingSettingLinkee = PType::getAccountLinkingSetting($linkeePtype);
if (($accountToLink->disableAccountLinking == 0) && ($linkingSettingUser != '1' && $linkingSettingUser != '3') && ($linkingSettingLinkee != '2' && $linkingSettingLinkee != '3')) {
$addResult = $user->addLinkedUser($accountToLink);
if ($addResult === true) {
$result = [
'success' => true,
'title' => translate([
'text' => 'Success',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'Successfully linked accounts.',
'isPublicFacing' => true,
]),
];
} else { // insert failure or user is blocked from linking account or account & account to link are the same account
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to link accounts',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'Sorry, we could not link to that account. Accounts cannot be linked if all libraries do not allow account linking. Please contact your local library if you have questions.',
'isPublicFacing' => true,
]),
];
}
} else {
if ($linkingSettingUser == '1' || $linkingSettingUser == '3') {
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to link accounts',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'Sorry, you are not permitted to link to others.',
'isPublicFacing' => true,
]),
];
} else if ($linkingSettingLinkee == '2' || $linkingSettingLinkee == '3') {
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to link accounts',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'Sorry, that account cannot be linked to.',
'isPublicFacing' => true,
]),
];
} else {
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to link accounts',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'Sorry, this user does not allow account linking.',
'isPublicFacing' => true,
]),
];
}
}
}else{
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to link accounts',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'Sorry, this user type cannot be linked to.',
'isPublicFacing' => true,
]),
];
}
} else {
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to link accounts',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'You cannot link to yourself.',
'isPublicFacing' => true,
]),
];
}
} else {
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to link accounts',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'The information for the user to link to was not correct.',
'isPublicFacing' => true,
]),
];
}
}
return $result;
}
/** @noinspection PhpUnused */
function removeManagingAccount(): array {
if (!UserAccount::isLoggedIn()) {
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to Remove Account Link',
'isAdminFacing' => 'true',
]),
'message' => translate([
'text' => 'Sorry, you must be logged in to manage accounts.',
'isPublicFacing' => true,
]),
];
} else {
$accountToRemove = $_REQUEST['idToRemove'];
$user = UserAccount::getLoggedInUser();
if ($user->removeManagingAccount($accountToRemove)) {
global $librarySingleton;
// Get Library Settings from the home library of the current user-account being displayed
$patronHomeLibrary = $librarySingleton->getPatronHomeLibrary($user);
if ($patronHomeLibrary->allowPinReset == 1) {
$result = [
'success' => true,
'title' => translate([
'text' => 'Linked Account Removed',
'isAdminFacing' => 'true',
]),
'message' => translate([
'text' => 'Successfully removed linked account. Removing this link does not guarantee the security of your account. If another user has your barcode and PIN/password they will still be able to access your account. Would you like to change your password?',
'isPublicFacing' => true,
]),
'modalButtons' => "<button type='button' class='tool btn btn-primary' onclick='AspenDiscovery.Account.redirectPinReset(); return false;'>" . translate([
'text' => "Request PIN Change",
'isPublicFacing' => true,
]) . "</button>",
];
} else {
$result = [
'success' => true,
'title' => translate([
'text' => 'Linked Account Removed',
'isAdminFacing' => 'true',
]),
'message' => translate([
'text' => 'Successfully removed linked account. Removing this link does not guarantee the security of your account. If another user has your barcode and PIN/password they will still be able to access your account. Please contact your library if you wish to update your PIN/Password.',
'isPublicFacing' => true,
]),
];
}
} else {
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to Remove Account Link',
'isAdminFacing' => 'true',
]),
'message' => translate([
'text' => 'Sorry, we could not remove that account.',
'isPublicFacing' => true,
]),
];
}
}
return $result;
}
/** @noinspection PhpUnused */
function removeAccountLink(): array {
if (!UserAccount::isLoggedIn()) {
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to Remove Account Link',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => translate([
'Sorry, you must be logged in to manage accounts.',
'isPublicFacing' => true,
]),
'isPublicFacing' => true,
]),
];
} else {
$accountToRemove = $_REQUEST['idToRemove'];
$user = UserAccount::getLoggedInUser();
if ($user->removeLinkedUser($accountToRemove)) {
$result = [
'success' => true,
'title' => translate([
'text' => 'Success',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => translate([
'text' => 'Successfully removed linked account.',
'isPublicFacing' => true,
]),
'isPublicFacing' => true,
]),
];
} else {
$result = [
'success' => false,
'title' => translate([
'text' => 'Unable to Remove Account Link',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => translate([
'text' => 'Sorry, we could remove that account.',
'isPublicFacing' => true,
]),
'isPublicFacing' => true,
]),
];
}
}
return $result;
}
//WHAT IS IN MODAL POPUP FOR LINK DISABLE
/** @noinspection PhpUnused */
function disableAccountLinkingInfo(): array {
$user = UserAccount::getActiveUserObj();
if ($user->disableAccountLinking == 1) {
return [
'title' => translate([
'text' => 'Enable Account Linking',
'isPublicFacing' => true,
]),
'modalBody' => translate([
'text' => 'Re-enabling account linking will allow others to link to your account. Do you want to continue?',
'isPublicFacing' => true,
]),
'modalButtons' => "<button type='button' class='tool btn btn-primary' onclick='AspenDiscovery.Account.toggleAccountLinkingAccept(); return false;'>" . translate([
'text' => "Accept",
'isPublicFacing' => true,
]) . "</button>",
];
} else {
return [
'title' => translate([
'text' => 'Disable Account Linking',
'isPublicFacing' => true,
]),
'modalBody' => translate([
'text' => 'Disabling account linking will sever any current links and prevent any new ones. Do you want to continue?',
'isPublicFacing' => true,
]),
'modalButtons' => "<button type='button' class='tool btn btn-primary' onclick='AspenDiscovery.Account.toggleAccountLinkingAccept(); return false;'>" . translate([
'text' => "Accept",
'isPublicFacing' => true,
]) . "</button>",
];
}
}
//USED UPON SUBMITTING
/** @noinspection PhpUnused */
function toggleAccountLinking() {
if (!UserAccount::isLoggedIn()) {
$result = [
'message' => translate([
'text' => 'Sorry, you must be logged in to manage accounts.',
'isPublicFacing' => true,
]),
];
} else {
$user = UserAccount::getActiveUserObj();
if ($user->disableAccountLinking == 1) {
$success = $user->accountLinkingToggle();
$result = [
'success' => $success,
'title' => translate([
'text' => 'Linking Enabled',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'Account linking has been enabled',
'isPublicFacing' => true,
]),
];
} else {
if ($user->disableAccountLinking == 0) {
$success = $user->accountLinkingToggle();
global $librarySingleton;
// Get Library Settings from the home library of the current user-account being displayed
$patronHomeLibrary = $librarySingleton->getPatronHomeLibrary($user);
if ($patronHomeLibrary->allowPinReset == 1) {
$result = [
'success' => $success,
'title' => translate([
'text' => 'Linking Disabled',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'Account linking has been disabled. Disabling account linking does not guarantee the security of your account. If another user has your barcode and PIN/password they will still be able to access your account. Would you like to change your password?',
'isPublicFacing' => true,
]),
'modalButtons' => "<button type='button' class='tool btn btn-primary' onclick='AspenDiscovery.Account.redirectPinReset(); return false;'>" . translate([
'text' => "Request PIN Change",
'isPublicFacing' => true,
]) . "</button>",
];
} else {
$result = [
'success' => $success,
'title' => translate([
'text' => 'Linking Disabled',
'isAdminFacing' => 'true',
]),
'message' => translate([
'text' => 'Account linking has been disabled. Disabling account linking does not guarantee the security of your account. If another user has your barcode and PIN/password they will still be able to access your account. Please contact your library if you wish to update your PIN/Password.',
'isPublicFacing' => true,
]),
];
}
} else {
$result = [
'success' => false,
'message' => translate([
'text' => 'Sorry, something went wrong and we were unable to process this request.',
'isPublicFacing' => true,
]),
];
}
}
}
return $result;
}
/** @noinspection PhpUnused */
function getTermsModalContent() {
$catalog = CatalogFactory::getCatalogConnectionInstance();
$selfRegTerms = $catalog->getSelfRegistrationTerms();
return [
'title' => translate([
'text' => 'Terms of Service',
'isPublicFacing' => true,
]),
'message' => $selfRegTerms->terms,
];
}
/** @noinspection PhpUnused */
function getAddAccountLinkForm() {
global $interface;
global $library;
$interface->assign('enableSelfRegistration', 0);
$interface->assign('usernameLabel', str_replace('Your', '', $library->loginFormUsernameLabel ? $library->loginFormUsernameLabel : 'Your Name'));
$interface->assign('passwordLabel', str_replace('Your', '', $library->loginFormPasswordLabel ? $library->loginFormPasswordLabel : 'Library Card Number'));
// Display Page
return [
'title' => translate([
'text' => 'Account to Manage',
'isPublicFacing' => true,
]),
'modalBody' => $interface->fetch('MyAccount/addAccountLink.tpl'),
'modalButtons' => "<button type='button' class='tool btn btn-primary' id = 'AddAccountSubmit' onclick='AspenDiscovery.Account.processAddLinkedUser(); return false;'>" . translate([
'text' => "Add Account",
'isPublicFacing' => true,
]) . "</button>",
];
}
/** @noinspection PhpUnused */
function allowAccountLink() {
require_once ROOT_DIR . '/sys/Account/UserMessage.php';
$activeUserId = UserAccount::getActiveUserId();
$userMessage = new UserMessage();
$userMessage->messageType = 'confirm_linked_accts';
$userMessage->userId = $activeUserId;
$userMessage->isDismissed = "0";
$userMessage->find();
while ($userMessage->fetch()) {
$userMessage->isDismissed = 1;
$userMessage->update();
}
return [
'success' => true,
'message' => 'Account Link Accepted',
];
}
/** @noinspection PhpUnused */
function getBulkAddToListForm() {
global $interface;
// Display Page
$interface->assign('listId', strip_tags($_REQUEST['listId']));
return [
'title' => translate([
'text' => 'Add titles to list',
'isPublicFacing' => true,
]),
'modalBody' => $interface->fetch('MyAccount/bulkAddToListPopup.tpl'),
'modalButtons' => "<button type='button' class='tool btn btn-primary' onclick='AspenDiscovery.Lists.processBulkAddForm(); return false;'>" . translate([
'text' => "Add To List",
'isPublicFacing' => true,
]) . "</button>",
];
}
/** @noinspection PhpUnused */
function saveSearch() {
$result = [
'success' => false,
'message' => 'Unknown error saving search',
];
$searchId = $_REQUEST['searchId'];
$title = $_REQUEST['title'];
$search = new SearchEntry();
$search->id = $searchId;
if ($search->find(true)) {
// Found, make sure this is a search from this user
if ($search->session_id == session_id() || $search->user_id == UserAccount::getActiveUserId()) {
if ($search->saved != 1) {
$search->user_id = UserAccount::getActiveUserId();
$search->saved = 1;
$search->title = $title;
if ($search->update() !== FALSE) {
$result['success'] = true;
$result['message'] = translate([
'text' => "Your search was saved successfully. You can view the saved search by clicking on Your Searches within the Account Menu.",
'isPublicFacing' => true,
]);
$result['modalButtons'] = "<a class='tool btn btn-primary' id='viewSavedSearches' href='/Search/History?require_login'>" . translate([
'text' => "View Saved Searches",
'isPublicFacing' => true,
]) . "</a>";
} else {
$result['message'] = translate([
'text' => "Sorry, we could not save that search for you. It may have expired.",
'isPublicFacing' => true,
]);
}
} else {
$result['success'] = true;
$result['message'] = translate([
'text' => "That search was already saved.",
'isPublicFacing' => true,
]);
$result['modalButtons'] = "<a class='tool btn btn-primary' id='viewSavedSearches' href='/Search/History?require_login'>" . translate([
'text' => "View Saved Searches",
'isPublicFacing' => true,
]) . "</a>";
}
} else {
$result['message'] = translate([
'text' => "Sorry, it looks like that search does not belong to you.",
'isPublicFacing' => true,
]);
}
} else {
$result['message'] = translate([
'text' => "Sorry, it looks like that search has expired.",
'isPublicFacing' => true,
]);
}
return $result;
}
/** @noinspection PhpUnused */
function getSaveSearchForm() {
global $interface;
$searchId = $_REQUEST['searchId'];
$interface->assign('searchId', $searchId);
require_once ROOT_DIR . '/services/Search/History.php';
History::getSearchForSaveForm($searchId);
return [
'title' => translate([
'text' => 'Save Search',
'isPublicFacing' => true,
]),
'modalBody' => $interface->fetch('MyAccount/saveSearch.tpl'),
'modalButtons' => "<button class='tool btn btn-primary' onclick='AspenDiscovery.Account.saveSearch(); return false;'>" . translate([
'text' => 'Save',
'isPublicFacing' => true,
]) . "</button>",
];
}
/** @noinspection PhpUnused */
function confirmCancelHold(): array {
$patronId = $_REQUEST['patronId'];
$recordId = $_REQUEST['recordId'];
$cancelId = $_REQUEST['cancelId'];
$isIll = $_REQUEST['isIll'];
$cancelButtonLabel = translate([
'text' => 'Confirm Cancel Hold',
'isPublicFacing' => true,
]);
return [
'title' => translate([
'text' => 'Cancel Hold',
'isPublicFacing' => true,
]),
'body' => translate([
'text' => "Are you sure you want to cancel this hold?",
'isPublicFacing' => true,
]),
'buttons' => "<button type='button' class='tool btn btn-primary' onclick='AspenDiscovery.Account.cancelHold(\"$patronId\", \"$recordId\", \"$cancelId\", \"$isIll\")'>$cancelButtonLabel</button>",
];
}
/** @noinspection PhpUnused */
function cancelHold(): array {
$result = [
'success' => false,
'title' => translate([
'text' => 'Cancelling hold failed',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'Error cancelling hold.',
'isPublicFacing' => true,
]),
];
if (!UserAccount::isLoggedIn()) {
$result['message'] = translate([
'text' => 'You must be logged in to cancel a hold. Please close this dialog and login again.',
'isPublicFacing' => true,
]);;
} else {
//Determine which user the hold is on so we can cancel it.
$patronId = $_REQUEST['patronId'];
$user = UserAccount::getLoggedInUser();
$patronOwningHold = $user->getUserReferredTo($patronId);
if ($patronOwningHold == false) {
$result['message'] = translate([
'text' => 'Sorry, you do not have access to cancel holds for the supplied user.',
'isPublicFacing' => true,
]);;
} else {
//MDN 9/20/2015 The recordId can be empty for INN-Reach holds
if (empty($_REQUEST['cancelId']) && empty($_REQUEST['recordId'])) {
$result['message'] = translate([
'text' => 'Information about the hold to be cancelled was not provided.',
'isPublicFacing' => true,
]);;
} else {
$cancelId = $_REQUEST['cancelId'];
$recordId = $_REQUEST['recordId'];
$isIll = $_REQUEST['isIll'] ?? false;
$result = $patronOwningHold->cancelHold($recordId, $cancelId, $isIll);
}
}
}
global $interface;
// if title come back a single item array, set as the title instead. likewise for message
if (isset($result['title'])) {
if (is_array($result['title']) && count($result['title']) == 1) {
$result['title'] = current($result['title']);
}
}
if (is_array($result['message']) && count($result['message']) == 1) {
$result['message'] = current($result['message']);
}
$interface->assign('cancelResults', $result);
return [
'title' => translate([
'text' => 'Cancel Hold',
'isPublicFacing' => true,
]),
'body' => $interface->fetch('MyAccount/cancelHold.tpl'),
'success' => $result['success'],
];
}
/** @noinspection PhpUnused */
function confirmCancelHoldSelected(): array {
$patronId = $_REQUEST['patronId'];
$recordId = $_REQUEST['recordId'];
$cancelId = $_REQUEST['cancelId'];
$cancelButtonLabel = translate([
'text' => 'Confirm Cancel Holds',
'isPublicFacing' => true,
]);
return [
'title' => translate([
'text' => 'Cancel Holds',
'isPublicFacing' => true,
]),
'body' => translate([
'text' => 'Are you sure you want to cancel selected holds?',
'isPublicFacing' => true,
]),
'buttons' => "<button type='button' class='tool btn btn-primary' onclick='AspenDiscovery.Account.cancelHoldSelected(\"$patronId\", \"$recordId\", \"$cancelId\")'>$cancelButtonLabel</button>",
];
}
function cancelHoldSelectedItems() {
$result = [
'success' => false,
'title' => translate([
'text' => 'Error',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'Error cancelling hold.',
'isPublicFacing' => true,
]),
];
if (!UserAccount::isLoggedIn()) {
$result['message'] = translate([
'text' => 'You must be logged in to cancel a hold. Please close this dialog and login again.',
'isPublicFacing' => true
]);
} else {
$success = 0;
$user = UserAccount::getLoggedInUser();
$allHolds = $user->getHolds(true, 'sortTitle', 'expire', 'all');
$allUnavailableHolds = $allHolds['unavailable'];
if (isset($_REQUEST['selected']) && is_array($_REQUEST['selected'])) {
$total = count($_REQUEST['selected']);
foreach ($_REQUEST['selected'] as $selected => $ignore) {
@list($patronId, $recordId, $cancelId) = explode('|', $selected);
$patronOwningHold = $user->getUserReferredTo($patronId);
if ($patronOwningHold == false) {
$tmpResult = [
'success' => false,
'title' => translate([
'text' => 'Error',
'isPublicFacing' => true,
]),
'message' => translate([
'text' => 'Sorry, it looks like you don\'t have access to that patron.',
'isPublicFacing' => true
]),
];
} else {
$holdType = 'unknown';
foreach ($allUnavailableHolds as $key) {
if ($key->sourceId == $recordId) {
$holdType = $key->source;
break;
}
}
if ($holdType == 'ils') {
$tmpResult = $user->cancelHold($recordId, $cancelId, $key->isIll);
if (!empty($tmpResult['success'])) {
$success++;
}
} elseif ($holdType == 'axis360') {
require_once ROOT_DIR . '/Drivers/Axis360Driver.php';
$driver = new Axis360Driver();
$tmpResult = $driver->cancelHold($user, $recordId);
if (!empty($tmpResult['success'])) {
$success++;
}
} elseif ($holdType == 'overdrive') {
require_once ROOT_DIR . '/Drivers/OverDriveDriver.php';
$driver = new OverDriveDriver();
$tmpResult = $driver->cancelHold($user, $recordId);
if (!empty($tmpResult['success'])) {
$success++;
}
} elseif ($holdType == 'cloud_library') {
require_once ROOT_DIR . '/Drivers/CloudLibraryDriver.php';
$driver = new CloudLibraryDriver();
$tmpResult = $driver->cancelHold($user, $recordId);
if (!empty($tmpResult['success'])) {
$success++;
}
}
$message = '<div class="alert alert-success">' . translate([
'text' => '%1% of %2% holds were cancelled',
1 => $success,
2 => $total,
'isPublicFacing' => true,
'inAttribute' => true,
]) . '</div>';
$tmpResult['message'] = $message;
$tmpResult['title'] = translate([
'text' => 'Success',
'isPublicFacing' => true,
]);
}
}
} else {
$tmpResult['message'] = translate([
'text' => 'No holds were selected to canceled',
'isPublicFacing' => true,
'inAttribute' => true,
]);
}
}
return $tmpResult;
}
/** @noinspection PhpUnused */
function cancelVdxRequest(): array {
$result = [
'success' => false,
'message' => translate([
'text' => 'Error cancelling request.',
'isPublicFacing' => true,
]),
];
if (!UserAccount::isLoggedIn()) {
$result['message'] = translate([
'text' => 'You must be logged in to cancel a request. Please close this dialog and login again.',
'isPublicFacing' => true,
]);;
} else {
//Determine which user the request is on so we can cancel it.
$patronId = $_REQUEST['patronId'];
$user = UserAccount::getLoggedInUser();
$patronOwningHold = $user->getUserReferredTo($patronId);
if ($patronOwningHold == false) {
$result['message'] = translate([
'text' => 'Sorry, you do not have access to cancel requests for the supplied user.',
'isPublicFacing' => true,
]);;
} else {
//MDN 9/20/2015 The recordId can be empty for INN-Reach holds
if (empty($_REQUEST['requestId']) || !isset($_REQUEST['cancelId'])) {
$result['message'] = translate([
'text' => 'Information about the requests to be cancelled was not provided.',
'isPublicFacing' => true,
]);;
} else {
$requestId = $_REQUEST['requestId'];
$cancelId = $_REQUEST['cancelId'];
$result = $patronOwningHold->cancelVdxRequest($requestId, $cancelId);
}
}
}
return $result;
}
/** @noinspection PhpUnused */
function confirmCancelHoldAll(): array {
$cancelButtonLabel = translate([
'text' => 'Confirm Cancel Holds',
'isPublicFacing' => true,
]);
return [
'title' => translate([
'text' => 'Cancel Holds',
'isPublicFacing' => true,
]),
'body' => translate([
'text' => 'Are you sure you want to cancel all holds?',
'isPublicFacing' => true,
]),
'buttons' => "<button type='button' class='tool btn btn-primary' onclick='AspenDiscovery.Account.cancelHoldAll()'>$cancelButtonLabel</button>",
];
}
function cancelAllHolds() {
$tmpResult = [
'success' => false,
'title' => translate([
'text' => 'Error',
'isPublicFacing' => true
]),
'message' => translate([
'text' => 'Unable to cancel all holds',
'isPublicFacing' => true
]),
];
$user = UserAccount::getLoggedInUser();
if ($user) {
$allHolds = $user->getHolds(true, 'sortTitle', 'expire', 'all');
$allUnavailableHolds = $allHolds['unavailable'];
$total = count($allUnavailableHolds);
$success = 0;
/** Hold $hold **/
foreach ($allUnavailableHolds as $hold) {
// cancel each hold
$recordId = $hold->sourceId;
$cancelId = $hold->cancelId;
$holdType = $hold->source;
$isIll = $hold->isIll;
if ($hold->cancelable) {
if ($holdType == 'ils') {
$tmpResult = $user->cancelHold($recordId, $cancelId, $isIll);
if ($tmpResult['success']) {
$success++;
}
} elseif ($holdType == 'axis360') {
require_once ROOT_DIR . '/Drivers/Axis360Driver.php';
$driver = new Axis360Driver();
$tmpResult = $driver->cancelHold($user, $recordId);
if ($tmpResult['success']) {
$success++;
}
} elseif ($holdType == 'overdrive') {
require_once ROOT_DIR . '/Drivers/OverDriveDriver.php';
$driver = new OverDriveDriver();
$tmpResult = $driver->cancelHold($user, $recordId);
if ($tmpResult['success']) {
$success++;
}
} elseif ($holdType == 'cloud_library') {
require_once ROOT_DIR . '/Drivers/CloudLibraryDriver.php';
$driver = new CloudLibraryDriver();
$tmpResult = $driver->cancelHold($user, $recordId);
if ($tmpResult['success']) {
$success++;
}
}
}
$message = '<div class="alert alert-success">' . translate([
'text' => '%1% of %2% holds were canceled',
1 => $success,
2 => $total,
'isPublicFacing' => true,
'inAttribute' => true,
]) . '</div>';
$tmpResult['message'] = $message;
$tmpResult['title'] = translate([
'text' => 'Success',
'isPublicFacing' => true
]);
}
} else {
$tmpResult['message'] = translate([
'text' => 'You must be logged in to cancel holds',
'isPublicFacing' => true,
'inAttribute' => true,
]);
}
return $tmpResult;
}
function freezeHold(): array {
$user = UserAccount::getLoggedInUser();
$result = [
'success' => false,
'message' => translate([
'text' => 'Error freezing hold.',
'isPublicFacing' => true,
]),
'title' => translate([
'text' => 'Error',
'isPublicFacing' => true,
]),
];
if (!$user) {
$result['message'] = translate([
'text' => 'You must be logged in to freeze a hold. Please close this dialog and login again.',
'isPublicFacing' => true,
]);
} elseif (!empty($_REQUEST['patronId'])) {
$patronId = $_REQUEST['patronId'];
$patronOwningHold = $user->getUserReferredTo($patronId);
if ($patronOwningHold == false) {
$result['message'] = translate([
'text' => 'Sorry, you do not have access to freeze holds for the supplied user.',
'isPublicFacing' => true,
]);
} else {
if (empty($_REQUEST['recordId']) || empty($_REQUEST['holdId'])) {
// We aren't getting all the expected data, so make a log entry & tell user.
global $logger;
$logger->log('Freeze Hold, no record or hold Id was passed in AJAX call.', Logger::LOG_ERROR);
$result['message'] = translate([
'text' => 'Information about the hold to be frozen was not provided.',
'isPublicFacing' => true,
]);
} else {
$recordId = $_REQUEST['recordId'];
$holdId = $_REQUEST['holdId'];
$reactivationDate = isset($_REQUEST['reactivationDate']) ? $_REQUEST['reactivationDate'] : null;
$result = $patronOwningHold->freezeHold($recordId, $holdId, $reactivationDate);
if ($result['success']) {
$message = '<div class="alert alert-success">' . $result['message'] . '</div>';
$result['message'] = $message;
$result['title'] = translate([