-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathget-logs.php
49 lines (40 loc) · 1.16 KB
/
get-logs.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
<?php
$start = $module->requireDateParameter('start', 'Y-m-d');
$end = $module->requireDateParameter('end', 'Y-m-d');
$end = date('Y-m-d', strtotime($end . ' + 1 day'));
$hasDetailsClause = "details != ''";
if(version_compare(REDCAP_VERSION, '10.8.2', '<')){
// This REDCap version does not support functions or comparisons in select log queries.
// Just always show the details button on older versions.
$hasDetailsClause = 1;
}
$results = $module->queryLogs("
select log_id, timestamp, message, failure, $hasDetailsClause as hasDetails
where timestamp >= ? and timestamp < ?
order by log_id desc
", [$start, $end]);
$allowedHtml = [
'<div>',
'</div>',
"<div class='remote-project-title'>",
'<b>',
'</b>',
"<a href='",
"' target='_blank'>",
'</a>',
];
$rows = [];
while($row = $results->fetch_assoc()){
$escapedRow = [];
foreach($row as $key=>$value){
$escapedRow[$key] = htmlentities($value, ENT_QUOTES);
}
foreach($allowedHtml as $s){
$escapedRow['message'] = str_replace(htmlentities($s, ENT_QUOTES), html_entity_decode($s, ENT_QUOTES), $escapedRow['message']);
}
$rows[] = $escapedRow;
}
?>
{
"data": <?=json_encode($rows, JSON_PRETTY_PRINT)?>
}