-
Notifications
You must be signed in to change notification settings - Fork 4
/
Application.php
1275 lines (1158 loc) · 45.6 KB
/
Application.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
namespace Vanderbilt\CareerDevLibrary;
use \Vanderbilt\FlightTrackerExternalModule\CareerDev;
use \Vanderbilt\FlightTrackerExternalModule\FlightTrackerExternalModule;
require_once(dirname(__FILE__)."/CareerDev.php");
require_once(dirname(__FILE__)."/FlightTrackerExternalModule.php");
class Application {
public static function getVersion() {
return CareerDev::getVersion();
}
public static function getActivePids() {
return REDCapManagement::getActiveProjects(self::getPids());
}
public static function getCredentialsDir() {
$options = [
"/app001/credentials",
"/Users/pearsosj/credentials",
"/Users/scottjpearson/credentials",
];
foreach ($options as $dir) {
if (file_exists($dir)) {
return $dir;
}
}
return "";
}
public static function getWarningEmailMinutes($pid) {
$value = self::getSetting("warning_minutes", $pid);
if (!$value) {
return 15;
} else {
return $value;
}
}
public static function isSuperUser() {
$isSuperUser = FALSE;
if (method_exists("\ExternalModules\ExternalModules", "isSuperUser")) {
$isSuperUser = \ExternalModules\ExternalModules::isSuperUser();
}
return ((defined("\SUPER_USER") && \SUPER_USER) || $isSuperUser);
}
public static function getRelevantChoices() {
return CareerDev::getRelevantChoices();
}
public static function getJQueryURL(): string {
$fileOrder = [
APP_PATH_DOCROOT."Resources/webpack/js/bundle.js" => APP_PATH_WEBROOT."Resources/webpack/js/bundle.js",
__DIR__."/js/jquery.min.js" => "getUrl",
];
foreach ($fileOrder as $file => $url) {
if (file_exists($file)) {
if ($url == "getUrl") {
# this should only rarely be called => save CPU cycles by lazy instantiation
$module = self::getModule();
return $module->getUrl("js/jquery.min.js");
} else {
return $url;
}
}
}
return "";
}
public static function getMetadataFiles($pid): array {
$files = [];
if (Application::getSetting("signup_project", $pid)) {
$files[] = __DIR__."/metadata.signup.json";
}
$files[] = __DIR__."/metadata.json";
if (CareerDev::isVanderbilt()) {
$files[] = __DIR__."/metadata.vanderbilt.json";
}
return $files;
}
public static function getPID($token) {
return CareerDev::getPID($token);
}
public static function has($instrument, $pid = "") {
return CareerDev::has($instrument, $pid);
}
public static function getFlightConnectorURL() {
return "https://redcap.vumc.org/external_modules/?prefix=flight_connector&page=map&pid=172928&h=5986967536b44df5&NOAUTH";
}
public static function getDataTable($pid) {
return method_exists('\REDCap', 'getDataTable') ? \REDCap::getDataTable($pid) : "redcap_data";
}
public static function getLogTable($pid) {
$module = self::getModule();
self::setPid($pid);
if ($module && method_exists($module, "getProject") && method_exists($module->getProject(), "getLogTable")) {
return $module->getProject()->getLogTable();
}
return "redcap_log_event";
}
public static function getApplicationColors($alphas = ["1.0"], $inHex = FALSE) {
$colors = [];
foreach ($alphas as $alpha) {
# Flight Tracker RGBs
$colors[] = "rgba(240, 86, 93, $alpha)";
$colors[] = "rgba(141, 198, 63, $alpha)";
$colors[] = "rgba(87, 100, 174, $alpha)";
$colors[] = "rgba(247, 151, 33, $alpha)";
$colors[] = "rgba(145, 148, 201, $alpha)";
}
if ($inHex) {
$hexColors = [];
foreach ($colors as $color) {
if (preg_match("/rgba\((\d+), (\d+), (\d+), ([\d\.]+)\)/", $color, $matches)) {
$rr = dechex((int) $matches[1]);
$gg = dechex((int) $matches[2]);
$bb = dechex((int) $matches[3]);
$alphaFrac = (float) $matches[4];
$aa = dechex((int) round($alphaFrac * 255));
} else if (preg_match("/rgb\((\d+), (\d+), (\d+)\)/", $color, $matches)) {
$rr = dechex((int) $matches[1]);
$gg = dechex((int) $matches[2]);
$bb = dechex((int) $matches[3]);
$aa = '';
} else {
throw new \Exception("Invalid pattern $color");
}
$hexColors[] = strtoupper("#$rr$gg$bb$aa");
}
return $hexColors;
} else {
return $colors;
}
}
public static function isVanderbilt() {
return CareerDev::isVanderbilt();
}
public static function getProjectTitle($pid = NULL) {
if (!$pid) {
$pid = Sanitizer::sanitizePid($_GET['pid'] ?? "");
}
if ($pid) {
return Download::projectTitle($pid);
}
return "";
}
public static function getGrantClasses() {
return CareerDev::getGrantClasses();
}
public static function reportException(\Exception $e) {
$html = "<div class='red'>Exception: ".$e->getMessage()."</div>";
return $html;
}
public static function makeIcon() {
$mime = "image/png";
$filename = __DIR__."/img/flight_tracker_icon.png";
$base64 = FileManagement::getBase64OfFile($filename, $mime);
return "<link rel='icon' type='$mime' href='$base64' />";
}
public static function setPid($pid) {
CareerDev::setPid($pid);
}
public static function unsetPid() {
CareerDev::unsetPid();
}
public static function checkOrResetToken($token, $pid) {
$allValidTokens = REDCapManagement::getToken($pid);
if (empty($allValidTokens)) {
throw new \Exception("No valid tokens for this project!");
}
if (!in_array($token, $allValidTokens)) {
$newToken = REDCapManagement::getToken($pid, self::getUsername());
if (!$newToken) {
$newToken = $allValidTokens[0];
}
self::saveSetting("token", $newToken, $pid);
return $newToken;
} else {
return $token;
}
}
public static function saveSystemSetting($field, $value) {
$module = self::getModule();
if ($module) {
$module->setSystemSetting($field, $value);
} else {
throw new \Exception("Could not find module!");
}
}
public static function getSystemSetting($field) {
$module = self::getModule();
if ($module) {
return $module->getSystemSetting($field) ?: "";
} else {
throw new \Exception("Could not find module!");
}
}
# TRUE iff &record= appended to end of page
public static function isRecordPage($link) {
$regexes = [
"/profile\.php/",
"/customGrants\.php/",
"/initial\.php/",
"/dashboard\//",
"/wrangler\//",
"/publications\/view\.php/",
];
foreach ($regexes as $regex) {
if (preg_match($regex, $link)) {
return TRUE;
}
}
return FALSE;
}
public static function refreshRecordSummary($token, $server, $pid, $recordId, $throwException = FALSE) {
CareerDev::refreshRecordSummary($token, $server, $pid, $recordId, $throwException);
}
public static function getProgramName() {
return CareerDev::getProgramName();
}
public static function generateCSRFToken() {
$module = self::getModule();
if (REDCapManagement::versionGreaterThanOrEqualTo(REDCAP_VERSION, "11.1.1")) {
return $module->getCSRFToken();
} else {
return "";
}
}
public static function generateCSRFTokenHTML() {
$csrfToken = self::generateCSRFToken();
if (!$csrfToken) {
return "";
}
return "<input type='hidden' id='redcap_csrf_token' name='redcap_csrf_token' value='$csrfToken' />";
}
public static function getUsername() {
if (defined('USERID')) {
return USERID;
}
global $userid;
if ($userid) {
return $userid;
}
$module = self::getModule();
if ($module) {
return $module->getUsername();
}
return "";
}
public static function getUnknown() {
return CareerDev::getUnknown();
}
public static function filterOutCopiedRecords($records) {
return CareerDev::filterOutCopiedRecords($records);
}
public static function getFeedbackEmail() {
return "[email protected]";
}
public static function getPatentFields($metadata) {
$possibleFields = [
"record_id",
"patent_number",
"patent_include",
"patent_title",
"patent_abstract",
"patent_date",
"patent_inventors",
"patent_inventor_ids",
"patent_assignees",
"patent_assignee_ids",
"patent_last_update",
];
return REDCapManagement::filterOutInvalidFields($metadata, $possibleFields);
}
public static function isPluginProject() {
return FALSE;
}
public static function log($mssg, $pid = FALSE) {
CareerDev::log($mssg, $pid);
}
public static function getBase64($relativeURL) {
$relativeURL = preg_replace("/^\//", "", $relativeURL);
$filename = __DIR__."/".$relativeURL;
if (file_exists($filename)) {
return FileManagement::getBase64OfFile($filename, mime_content_type($filename));
}
return "";
}
public static function getInstitutions($pid = NULL, $searchOnly = TRUE) {
return CareerDev::getInstitutions($pid, $searchOnly);
}
public static function getImportHTML() {
$version = CareerDev::getVersion();
$str = "";
$str .= "<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.8.2/css/all.css' integrity='sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay' crossorigin='anonymous' />";
$str .= "<link rel='stylesheet' href='".self::link("/css/w3.css")."' />";
$str .= "<script src='".self::link("/js/base.js")."&$version'></script>";
$baseUrl = $_SERVER['PHP_SELF'] ?? "";
$isExtModPage = (
(
preg_match("/ExternalModules/", $baseUrl)
|| preg_match("/external_modules/", $baseUrl)
)
&& preg_match("/".self::getPrefix()."/", $_SERVER['REQUEST_URI'] ?? "")
);
$isPluginPage = preg_match("/\/plugins\//", $baseUrl);
$isFTPage = $isPluginPage || $isExtModPage && (preg_match("/odules\/$/", $baseUrl) || preg_match("/odules\/index.php$/", $baseUrl));
if ($isExtModPage || $isPluginPage) {
if ($isFTPage) {
$str .= "<script src='".self::link("/js/jquery.min.js")."'></script>";
}
$str .= "<script src='".self::link("/js/jquery-ui.min.js")."'></script>";
$str .= "<script src='".self::link("/js/autocomplete.js")."&$version'></script>";
$str .= self::makeIcon();
$str .= "<link rel='stylesheet' href='".self::link("/css/jquery-ui.css")."' />";
$str .= "<link rel='stylesheet' href='".self::link("/css/career_dev.css")."&$version' />";
$str .= "<link rel='stylesheet' href='".self::link("/css/typekit.css")."&$version' />";
}
$str .= "<link rel='stylesheet' href='".self::link("/css/jquery.sweet-modal.min.css")."' />";
$str .= "<script src='".self::link("/js/jquery.sweet-modal.min.js")."'></script>";
$str .= "<script src='".self::link("/js/html2canvas.min.js")."'></script>";
$str .= "<script>function getCSRFToken() { return '".self::generateCSRFToken()."'; }</script>";
return $str;
}
public static function getHeader($tokenName = "", $token = "", $server = "", $pid = "") {
$pid = $pid ?: CareerDev::getPID();
$token = $token ?: self::getSetting("token", $pid);
$server = $server?: self::getSetting("server", $pid);
$tokenName = Download::shortProjectTitle($pid);
$module = self::getModule();
$museoSansLink = self::link("/fonts/exljbris - MuseoSans-500.otf");
$horizontalScrollbar = CareerDev::isREDCap() ? ":root { overflow-x: scroll; }" : "";
$str = "";
$str .= "
<style>
/* must add fonts here or they will not show up in REDCap menus */
@font-face { font-family: 'Museo Sans'; font-style: normal; font-weight: normal; src: url('$museoSansLink'); }
.w3-dropdown-hover { display: inline-block !important; float: none !important; }
.w3-dropdown-hover button,a.w3-bar-link { font-size: 12px; }
a.w3-bar-link { display: inline-block !important; float: none !important; }
.w3-bar { font-family: 'Museo Sans', Arial, Helvetica, sans-serif; text-align: center !important; }
a.w3-button,button.w3-button { padding: 6px 4px !important; }
a.w3-button,button.w3-button.with-image { padding: 8px 4px 6px 4px !important; }
a.w3-button { color: black !important; float: none !important; }
.w3-button a,.w3-dropdown-content a { color: white !important; font-size: 13px !important; }
.topHeaderWrapper { background-color: white; height: 80px; top: 0px; width: 100%; }
.topHeader { margin: 0 auto; max-width: 1200px; }
.topBar { font-family: 'Museo Sans', Arial, Helvetica, sans-serif; padding: 0px; }
.middleBar { font-family: 'Museo Sans', Arial, Helvetica, sans-serif; font-size: 13px; padding: 0 0 0 20px; text-align: left; float: left; max-width: 600px; }
a.nounderline { text-decoration: none; }
a.nounderline:hover { text-decoration: dotted; }
img.brandLogo { height: 40px; margin: 20px; }
#overlayFT { position: fixed; display: none; width: 100%; height: 100%; top: 0; left: 0; right: 0; bottom: 0; background-color: rgba(0,0,0,0.7); z-index: 2; cursor: pointer; text-align: center; vertical-align: middle; }
.warning { color: white; }
p.centered { text-align: center; margin-left: auto; margin-right: auto; }
/* Coordinated with career_dev.css */
p.recessed { color: #888888; font-size: 11px; margin: 4px 12px 4px 12px; }
.recessed,.recessed a { color: #888888; font-size: 11px; }
p.recessed,div.recessed { margin: 2px; }
$horizontalScrollbar
</style>";
$str .= self::getImportHTML();
$str .= "<header class='topHeaderWrapper'>";
$str .= "<div class='topHeader'>";
$str .= "<div class='topBar' style='float: left; padding-left: 5px;'><a href='https://redcap.vumc.org/plugins/career_dev/consortium/'><img alt='Flight Tracker for Scholars' src='".self::link("/img/flight_tracker_logo_small.png")."'></a></div>";
# logged in and on a record
if (Application::getUsername() && (isset($_GET['id']) || isset($_GET['record']))) {
$records = Download::records($token, $server);
$recordId = Sanitizer::getSanitizedRecord($_GET['id'] ?? $_GET['record'] ?? "", $records);
if ($recordId) {
$csrfToken = self::generateCSRFToken();
$url = self::link("/fetchDataNow.php");
$str .= "<div class='middleBar'><br/>";
$str .= "Fetch Data Now for this Scholar:";
$fetchConfig = [
"Summary" => "summary",
"Publications" => "publications",
"Grants" => "grants",
"Patents" => "patents",
];
foreach ($fetchConfig as $label => $fetchType) {
$str .= " <button onclick='fetchDataNow(\"$url\", \"$recordId\", \"$csrfToken\", \"$fetchType\"); return false;'>$label</button>";
}
$str .= "<br/>";
$str .= "Restart from Scratch for this Scholar:";
foreach ($fetchConfig as $label => $fetchType) {
if ($fetchType != "summary") {
$str .= " <button onclick='confirmRestartData(\"$url\", \"$recordId\", \"$csrfToken\", \"$fetchType\"); return false;'>$label</button>";
}
}
$str .= "<br/>";
$str .= "Match Without Institutions:";
foreach ($fetchConfig as $label => $fetchType) {
if (!in_array($fetchType, ["summary", "patents"])) {
$fetchType .= "_name";
$str .= " <button onclick='fetchDataNow(\"$url\", \"$recordId\", \"$csrfToken\", \"$fetchType\"); return false;'>$label</button>";
}
}
$str .= "</div>";
}
}
if ($base64 = $module->getBrandLogo()) {
$str .= "<div class='topBar' style='float:right;'><img src='$base64' class='brandLogo'></div>";
} else {
$configLink = self::link("config.php", $pid);
$str .= "<div class='topBar' style='float:right;'><p class='alignright darkgreytext padded nomargin bolded'>$tokenName<br/><a href='$configLink' title='Configure Application'><i class='fa fa-cog darkgreytext' style='font-size: 24px;'></i></a></p>";
}
$str .= "</div>";
$str .= "</header>";
$switches = new FeatureSwitches($token, $server, $pid);
$navBar = new NavigationBar();
$navBar->addFALink("home", "Home", CareerDev::getHomeLink());
$navBar->addFAMenu("clinic-medical", "General", CareerDev::getMenu("General", $pid));
if ($switches->isOnForProject("Grants")) {
$navBar->addMenu("<img src='".CareerDev::link("/img/grant_small.png")."'>Grants", CareerDev::getMenu("Grants"));
}
if ($switches->isOnForProject("Publications")) {
$navBar->addFAMenu("sticky-note", "Pubs", CareerDev::getMenu("Pubs", $pid));
}
$navBar->addFAMenu("table", "View", CareerDev::getMenu("View", $pid));
if (!CareerDev::isCopiedProject($pid)) {
$navBar->addFAMenu("calculator", "Wrangle", CareerDev::getMenu("Wrangler", $pid));
}
$navBar->addFAMenu("school", "Scholars", CareerDev::getMenu("Scholars", $pid));
$navBar->addMenu("<img src='".CareerDev::link("/img/redcap_translucent_small.png")."'>REDCap", CareerDev::getMenu("REDCap", $pid));
$navBar->addFAMenu("tachometer-alt", "Dashboards", CareerDev::getMenu("Dashboards", $pid));
$navBar->addFAMenu("filter", "Cohorts / Filters", CareerDev::getMenu("Cohorts", $pid));
$navBar->addFAMenu("chalkboard-teacher", "Mentors", CareerDev::getMenu("Mentors", $pid));
$navBar->addFAMenu("pen", "Resources", CareerDev::getMenu("Resources", $pid));
$navBar->addFAMenu("question-circle", "Help", CareerDev::getMenu("Help", $pid));
$str .= $navBar->getHTML();
return $str;
}
public static function getFooter() {
$px = 300;
$str = "";
$str .= "<style>
body { margin-bottom: 60px; }
footer { z-index: 1000000; position: fixed; left: 0; bottom: 0; width: 100%; background-color: white; }
.bottomBar { font-family: 'Museo Sans', Arial, Helvetica, sans-serif; padding: 5px; }
</style>";
$str .= "<footer class='bottomFooter'>";
$str .= "<div class='bottomBar' style='float: left;'>";
$str .= "<div class='recessed' style='width: $px"."px;'>Copyright Ⓒ ".date("Y")." <a class='nounderline' href='https://vumc.org/'>Vanderbilt University Medical Center</a></div>";
$str .= "<div class='recessed' style='width: $px"."px;'>from <a class='nounderline' href='https://edgeforscholars.org/'>Edge for Scholars</a></div>";
$str .= "<div class='recessed' style='width: $px"."px;'><a class='nounderline' href='https://projectredcap.org/'>Powered by REDCap</a></div>";
$str .= "</div>"; // bottomBar
$str .= "<div class='bottomBar' style='float: right;'><span class='recessed'>funded by</span><br>";
$str .= "<a href='https://ncats.nih.gov/ctsa'><img src='".self::link("/img/ctsa.png")."' style='height: 22px;'></a></div>";
$str .= "</div>"; // bottomBar
$str .= "</footer>"; // bottomFooter
return $str;
}
# call REDCap's AutoLogin
public static function keepAlive($pid) {
if (!class_exists('\Auth')) {
require_once APP_PATH_DOCROOT . 'Libraries/PEAR/Auth.php';
}
$oldPid = $_GET['pid'] ?? "";
$_GET['pid'] = $pid;
\Authentication::autoLogin(self::getUsername());
if ($oldPid) {
$_GET['pid'] = $oldPid;
} else {
unset($_GET['pid']);
}
}
public static function isTable1Project($mypid = FALSE) {
if ($mypid === FALSE) {
$mypid = $_GET['pid'] ?? "";
}
return ($mypid == self::getTable1PID());
}
public static function getTable1Title() {
return "Flight Tracker - NIH Training Table 1";
}
# gets the token for NIH Training Table 1
public static function getTable1Token() {
return self::getSystemSetting("table1Token");
}
# gets the project-id for NIH Training Table 1
public static function getTable1PID() {
$table1Pid = self::getSystemSetting("table1Pid");
if ($table1Pid && REDCapManagement::isActiveProject($table1Pid)) {
return $table1Pid;
} else {
$sql = "SELECT project_id FROM redcap_projects WHERE app_title = ? AND date_deleted IS NULL ORDER BY project_id LIMIT 1";
$module = self::getModule();
$q = $module->query($sql, [self::getTable1Title()]);
if ($row = $q->fetch_assoc()) {
$projectId = $row['project_id'];
self::saveSystemSetting("table1Pid", $projectId);
return $projectId;
} else {
return "";
}
}
}
public static function getTable1SurveyLink() {
$pid = self::getTable1PID();
if ($pid) {
return REDCapManagement::getPublicSurveyLink($pid, "table_1_rows");
}
return "";
}
public static function makePublicSignupHTML($pid, $additionalClasses = ""): string {
$surveyLink = REDCapManagement::getPublicSurveyLink($pid, "sign_up");
return "<p class='centered max-width $additionalClasses'>
<label for='signupUrl'>Public Signup Link: </label>
<input id='signupUrl' value='$surveyLink' onclick='this.select();' readonly='readonly' style='width: 90%; max-width: 450px; margin-right: 5px; margin-left: 5px;' />
<span class='smaller'><a href='javascript:;' onclick='copyToClipboard($(\"#signupUrl\"));'>Copy</a></span>
</p>";
}
public static function getPids() {
if (self::isVanderbilt()) {
if (self::isExternalModule()) {
$module = self::getModule();
$allPids = $module ? $module->getPids() : [];
$pids = [];
foreach ($allPids as $pid) {
if (!self::isTable1Project($pid) && !self::isSocialMediaProject($pid)) {
$pids[] = $pid;
}
}
} else {
$pids = [];
$prefix = CareerDev::getPrefix();
$module = self::getModule();
$sql = "
SELECT DISTINCT s.project_id AS pid
FROM redcap_external_module_settings AS s
INNER JOIN redcap_external_modules AS m
ON m.external_module_id = s.external_module_id
WHERE
s.key = 'enabled'
AND s.value='true'
AND m.directory_prefix = ?";
$q = $module->query($sql, [$prefix]);
while ($row = $q->fetch_assoc()) {
if ($row['pid'] && !self::isTable1Project($row['pid'])) {
$pids[] = $row['pid'];
}
}
}
} else {
$module = self::getModule();
$pids = $module->getPids();
}
for ($i = 0; $i < count($pids); $i++) {
$pids[$i] = (string) $pids[$i];
}
if (isset($_GET['match']) && is_string($_GET['match']) && preg_match("/:/", $_GET['match'])) {
list($pid, $recordId) = explode(":", Sanitizer::sanitize($_GET['match']));
if (!in_array($pid, $pids)) {
return [];
} else {
return [$pid];
}
}
return $pids;
}
public static function getActiveSourcePids() {
$pids = self::getPids();
$filteredPids = [];
foreach ($pids as $pid) {
if (
REDCapManagement::isActiveProject($pid)
&& !CareerDev::isCopiedProject($pid)
) {
$filteredPids[] = $pid;
}
}
return $filteredPids;
}
public static function getMenteeAgreementLink($pid) {
$defaultLink = self::link("mentor/intro.php", $pid, TRUE);
if (self::isPluginProject()) {
if (isset($_GET['test'])) {
echo "plugin project<br>";
}
global $info;
if (isset($info['prod']) && Application::isVanderbilt()) {
$sourcePid = $info['prod']['pid'];
return self::link("mentor/intro.php", $sourcePid, TRUE);
} else if (isset($info['localhost']) && Application::isLocalhost()) {
$sourcePid = $info['localhost']['pid'];
return self::link("mentor/intro.php", $sourcePid, TRUE);
}
self::log("Warning! Could not find prod in info!");
} else if (CareerDev::isCopiedProject($pid)) {
if ($sourcePid = CareerDev::getSourcePid($pid)) {
return self::link("mentor/intro.php", $sourcePid, TRUE);
}
self::log("Warning! Could not find sourcePid in copied project!");
}
return $defaultLink;
}
public static function isCopiedProject($tokenOrPid = "") {
return CareerDev::isCopiedProject($tokenOrPid);
}
public static function getSourcePid($destPid) {
return CareerDev::getSourcePid($destPid);
}
public static function getDefaultVanderbiltMenteeAgreementLink() {
return "https://medschool.vanderbilt.edu/msci/current-trainees/resources-for-funding-research-and-grant-assistance/";
}
public static function getEmailName($record) {
return CareerDev::getEmailName($record);
}
public static function getCitationFields($metadata) {
return REDCapManagement::screenForFields($metadata, self::$citationFields);
}
public static function getCustomFields($metadata) {
return REDCapManagement::screenForFields($metadata, self::$customFields);
}
public static function isSocialMediaProject($pid) {
return Application::isVanderbilt() && ($pid == 163109);
}
public static function getExporterFields($metadata) {
return REDCapManagement::screenForFields($metadata, CareerDev::$exporterFields);
}
public static function getServerEmail() {
return $_SERVER['SSL_SERVER_S_DN_Email'] ?? "";
}
public static function isMSTP($pid = NULL) {
if (!$pid) {
$pid = CareerDev::getPid();
}
if (Application::isVanderbilt() && ($pid == 149668)) { // TODO For now
return TRUE;
}
if (Application::isLocalhost() && ($pid == 17) && (self::getServerEmail() == "[email protected]")) {
return TRUE;
}
return FALSE;
}
public static function getMSTPHashFields() {
$roles = self::getMSTPConfig();
$fields = [];
foreach (array_keys($roles) as $role) {
$fields[] = self::MSTPRole2Field($role);
}
return $fields;
}
public static function MSTPRole2Field($role) {
return "mstpidp_review_".$role."_hash";
}
public static function getMSTPConfig() {
return [
"advisor" => "Faculty College Advisor",
"mentor" => "Research Mentor",
"comentor" => "Research Co-Mentor"
];
}
public static function getHelperInstitutions($pid) {
$ary = [];
if (Application::getSetting("omit_va", $pid) !== "1") {
$ary[] = "Veterans Health Administration";
}
if (self::isVanderbilt()) {
$ary[] = "Tennessee Valley Healthcare System";
}
return $ary;
}
public static function getInstitution($pid = NULL) {
$insts = self::getInstitutions($pid);
if (count($insts) > 0) {
return $insts[0];
}
return "";
}
public static function hasComposer() {
return file_exists(self::getComposerAutoloadLocation());
}
public static function isTestGroup($pid) {
return CareerDev::isTestGroup($pid);
}
public static function writeHTMLToDoc($html, $filename) {
if (self::hasComposer()) {
require_once(self::getComposerAutoloadLocation());
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
\PhpOffice\PhpWord\Shared\Html::addHtml($section, $html);
$saveFilename = APP_PATH_TEMP."publications_".bin2hex(random_bytes(10)).".docx";
$phpWord->save($saveFilename, 'Word2007');
$filename = REDCapManagement::makeSafeFilename($filename);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="'.$filename.'"');
readfile($saveFilename);
unlink($saveFilename);
}
}
public static function getComposerAutoloadLocation() {
return dirname(__FILE__)."/vendor/autoload.php";
}
public static function isWebBrowser() {
return $_SERVER['REQUEST_URI'] ?? "";
}
public static function isLocalhost() {
return CareerDev::isLocalhost();
}
public static function getModule() {
return CareerDev::getModule();
}
public static function link($loc, $pid = "", $withWebroot = FALSE) {
return CareerDev::link($loc, $pid, $withWebroot);
}
public static function isExternalModule() {
$module = self::getModule();
if (!$module) {
return FALSE;
}
$moduleClassWithNamespaceNodes = explode("\\", get_class($module));
$moduleClass = array_pop($moduleClassWithNamespaceNodes);
return $moduleClass == "FlightTrackerExternalModule";
}
public static function getAllSettings($pid = "") {
return CareerDev::getAllSettings($pid);
}
public static function increaseMemoryLimit($limit) {
ini_set("memory_limit", $limit);
}
public static function increaseProcessingMax($hours) {
require_once(APP_PATH_DOCROOT."Classes/System.php");
\System::increaseMaxExecTime($hours * 3600);
}
public static function saveCurrentDate($setting, $pid) {
CareerDev::saveCurrentDate($setting, $pid);
}
public static function getSettingKeys($pid) {
if ($_GET['pid'] == $pid) {
if ($module = self::getModule()){
$settings = $module->getProjectSettings($pid);
return array_keys($settings);
}
} else {
$prefix = CareerDev::getPrefix();
$module = self::getModule();
$sql = "SELECT DISTINCT(s.key) AS array_key
FROM redcap_external_module_settings AS s
INNER JOIN redcap_external_modules AS m
ON m.external_module_id = s.external_module_id
WHERE m.directory_prefix = ?
AND s.project_id = ?";
$q = $module->query($sql, [$prefix, $pid]);
$keys = [];
while ($row = $q->fetch_assoc($q)) {
$keys[] = $row['array_key'];
}
return $keys;
}
}
public static function getFlightTrackerModule() {
if (self::isExternalModule()) {
return self::getModule();
} else {
$prefix = CareerDev::getPrefix();
return \ExternalModules\ExternalModules::getModuleInstance($prefix);
}
}
public static function getPrefix() {
return CareerDev::getPrefix();
}
public static function isServer($server) {
return (SERVER_NAME == $server);
}
public static function getSetting($field, $pid = "") {
return CareerDev::getSetting($field, $pid);
}
public static function isTestServer($pid) {
if (Application::isLocalhost()) {
return TRUE;
}
if (!$pid) {
$pids = Application::getPids();
if (count($pids) > 1) {
$pid = $pids[0];
} else {
return FALSE; // best guess
}
}
$value = self::getSetting("server_class", $pid);
# TODO may want to consider removing ""; also consider "dev" as an option if specified
$testServerClasses = ["test", ""];
return in_array($value, $testServerClasses);
}
public static function saveSetting($field, $value, $pid = "") {
CareerDev::saveSetting($field, $value, $pid);
}
public static function getSites($all = TRUE) {
return CareerDev::getSites($all);
}
public static function getInternalKLength($pid = NULL) {
return CareerDev::getInternalKLength($pid);
}
public static function getK12KL2Length($pid = NULL) {
return CareerDev::getK12KL2Length($pid);
}
public static function getIndividualKLength($pid = NULL) {
return CareerDev::getIndividualKLength($pid);
}
public static function getProjectUsers($pid) {
return array_keys(\User::getProjectUsernames([], FALSE, $pid));
}
public static function getScholarPortalLink() {
return self::link("portal/index.php");
}
public static function applySecurityHeaders($pid) {
$serverList = Application::getSetting("safe_servers", $pid);
if (!$serverList) {
return;
}
$servers = preg_split("/\s*,\s*/", $serverList);
foreach ($servers as $server) {
if (trim($server) !== "*") {
header('Access-Control-Allow-Origin: https://'.$server);
if (!preg_match("/^www\./", $server)) {
header('Access-Control-Allow-Origin: https://www.'.$server);
}
}
}
}
public static $institutionFields = array(
"record_id",
"identifier_institution",
"identifier_institution_source",
"identifier_institution_sourcetype",
"identifier_left_job_title",
"identifier_left_date",
"identifier_left_date_source",
"identifier_left_date_sourcetype",
"identifier_left_job_category",
"promotion_institution",
"promotion_date",
"promotion_in_effect",
);
public static $summaryFields = [
"record_id",
"identifier_first_name",
"identifier_last_name",
"identifier_email",
"identifier_email_source",
"identifier_email_sourcetype",
"identifier_userid",
"identifier_institution",
"identifier_institution_source",
"identifier_institution_sourcetype",
"identifier_left_job_title",
"identifier_left_date",
"identifier_left_date_source",
"identifier_left_date_sourcetype",
"identifier_left_job_category",
"summary_degrees",
"summary_primary_dept",
"summary_gender",
"summary_race_ethnicity",
"summary_current_rank",
"summary_dob",
"summary_citizenship",
"summary_urm",
"summary_disability",
"summary_disadvantaged",
"summary_training_start",
"summary_training_end",
"summary_ever_internal_k",
"summary_ever_individual_k_or_equiv",
"summary_ever_k12_kl2",
"summary_ever_r01_or_equiv",
"summary_ever_external_k_to_r01_equiv",
"summary_ever_last_external_k_to_r01_equiv",
"summary_ever_first_any_k_to_r01_equiv",
"summary_ever_last_any_k_to_r01_equiv",
"summary_first_any_k",
"summary_first_external_k",
"summary_last_any_k",
"summary_last_external_k",
"summary_survey",
"summary_publication_count",
"summary_total_budgets",
"summary_award_source_1",
"summary_award_date_1",
"summary_award_end_date_1",
"summary_award_type_1",
"summary_award_title_1",
"summary_award_sponsorno_1",
"summary_award_age_1",
"summary_award_nih_mechanism_1",
"summary_award_total_budget_1",
"summary_award_direct_budget_1",
"summary_award_percent_effort_1",
"summary_award_role_1",
"summary_award_source_2",
"summary_award_date_2",