-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
134 lines (102 loc) · 5.1 KB
/
index.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
<?php
/** @var \UIOWA\ProjectAggregator\ProjectAggregator $module */
require_once APP_PATH_DOCROOT . 'ProjectGeneral/header.php';
$note = $module->getProjectSetting('aggregate-note');
$sourceProjects = [];
if (isset($_GET['pid']) && filter_var($_GET['pid'], FILTER_VALIDATE_INT)) {
$sanitizedPid = htmlentities(strip_tags($_GET['pid'], ENT_QUOTES));
$sourceProjects = $module->getSourceProjects($sanitizedPid, true);
$totalProjectCount = count($sourceProjects);
$totalRecordCount = 0;
$noRecordsCount = 0;
foreach ($sourceProjects as $index => $project) {
if ($project['record_count'] == 0) {
unset($sourceProjects[$index]);
$noRecordsCount++;
}
else {
$totalRecordCount += $project['record_count'];
}
}
$sql = "
SELECT c.cron_enabled, c.cron_frequency, c.cron_last_run_start
FROM redcap_crons c
LEFT JOIN redcap_external_modules m ON m.external_module_id = c.external_module_id
WHERE m.directory_prefix = 'project_aggregator'
";
$cronInfo = db_fetch_assoc(db_query($sql));
$projectUrl =
(isset($_SERVER['HTTPS']) ? 'https://' : 'http://') .
SERVER_NAME .
APP_PATH_WEBROOT .
'ProjectSetup/index.php?pid=';
$serializedProjects = htmlentities(json_encode($sourceProjects,true),ENT_QUOTES, 'UTF-8');
$serializedCronInfo = htmlentities(json_encode($cronInfo),ENT_QUOTES, 'UTF-8');
?>
<script>
let UIOWA_ProjectAggregator = {
requestUrl: '<?= $module->getUrl('requestHandler.php') ?>',
projects: JSON.parse('<?= str_replace(""", '"', $serializedProjects) ?>'),
projectUrl: '<?= $projectUrl ?>',
note: '<?= $note ?>',
cronInfo: JSON.parse('<?= str_replace(""", '"', $serializedCronInfo) ?>'),
noRecordsCount: '<?= $noRecordsCount ?>',
totalRecordsCount: '<?= $totalRecordsCount ?>',
htmlString: ``,
redcap_csrf_token: '<?= $module->getCSRFToken(); ?>'
};
function generateTable() {
UIOWA_ProjectAggregator.htmlString = `<div style="width: 70%;">
<h3>Project Aggregator</h3>
<br />
<p>
${UIOWA_ProjectAggregator.projects.length} projects tagged "<b>${UIOWA_ProjectAggregator.note}</b>" were found. Please review before initiating the aggregation process to ensure the expected data will be included. Any projects with import errors will be skipped.
</p>`
if(UIOWA_ProjectAggregator.cronInfo.cron_enabled === 'ENABLED') {
UIOWA_ProjectAggregator.htmlString += `<p>
This process is set to run automatically once every 24 hours. ${UIOWA_ProjectAggregator.cronInfo.cron_last_run_start} it was last run at <span class="cron-timestamp">${UIOWA_ProjectAggregator.cronInfo.cron_last_run_start}</span>.
</p>`
}
UIOWA_ProjectAggregator.htmlString += `<table class="table table-striped table-bordered">
<thead>
<tr class="table-primary">
<th scope="col">PID</th>
<th scope="col">Project Title</th>
<th scope="col">Record Count</th>
<th scope="col">Import Errors</th>
</tr>
</thead>
<tbody id="projects-table">`
for(let i = 0; i < UIOWA_ProjectAggregator.projects.length; i++) {
UIOWA_ProjectAggregator.htmlString += `<tr class="project-row">
<td class="pid centered">${UIOWA_ProjectAggregator.projects[i].project_id}</td>
<td><a href="${UIOWA_ProjectAggregator.projectUrl}${UIOWA_ProjectAggregator.projects[i].project_id}">${UIOWA_ProjectAggregator.projects[i].app_title}</a></td>
<td class="centered">${UIOWA_ProjectAggregator.projects[i].record_count}</td>
<td class="centered"><div class='aggregateProgress'></div></td>
</tr>
`
}
if(UIOWA_ProjectAggregator.noRecordsCount > 0) {
UIOWA_ProjectAggregator.htmlString += ` <tr>
<td colspan="4" style="text-align: center">
${UIOWA_ProjectAggregator.noRecordsCount} project(s) with no data
</td>
</tr>`
}
UIOWA_ProjectAggregator.htmlString += `</tbody>
</table>
<div style="text-align: right">
<button id="start" class="btn btn-primary"><span>Import ${UIOWA_ProjectAggregator.totalRecordsCount} Records</span></button>
</div>
</div>`
return UIOWA_ProjectAggregator.htmlString
}
function renderTable() {
$( "#center").append( generateTable());
}
renderTable()
</script>
<script src="<?= $module->getUrl("/projectAggregator.js") ?>"></script>
<link href="<?= $module->getUrl("/style.css") ?>" rel="stylesheet">
<?php
}