-
Notifications
You must be signed in to change notification settings - Fork 55
/
index.functions.php
63 lines (59 loc) · 1.66 KB
/
index.functions.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
<?php
// FUNCTIONS
function ReadArray($array) {
foreach($array as $key=>$value) {
$name = $array[$key]['name'];
if (isset($array[$key]['hostid'])) {
$id = $array[$key]['hostid'];
}
elseif (isset($array[$key]['groupid'])) {
$id = $array[$key]['groupid'];
}
else {
$id = $name;
}
echo "<option value=\"$id\">$name</option>\n";
}
}
function array_flatten($array) {
$output = array();
array_walk_recursive($array, function ($current) use (&$output) {
$output[] = $current;
});
return $output;
}
function listdir_by_date($path){
$dir = opendir($path);
$list = array();
while($file = readdir($dir)){
if ($file != '.' and $file != '..'){
// add the filename, to be sure not to
// overwrite a array key
$ctime = filemtime("$path/$file") . ',' . $file;
$list[$ctime] = $file;
}
}
closedir($dir);
krsort($list);
return $list;
}
function ListOldReports($dir) {
global $z_user, $hosts, $host_groups;
#$dir_files = array_diff(scandir($dir), array('..', '.'));
$dir_files = listdir_by_date($dir);
echo "<thead>";
echo "<tr><th>Report timestamp</th><th align=\"left\">Report</th></tr>\n";
echo "</thead>";
echo "<tbody>";
foreach ($dir_files as $fdate => $fname) {
$fdate = explode(",",$fdate);
$fdate = date("Y.m.d H:i:s", $fdate[0]);
$name=substr(str_replace("_"," ",$fname), 0, -4);
$name=substr(str_replace("--","/",$name), 0, 99);
if ((in_array($name, array_flatten($hosts)) or (in_array($name, array_flatten($host_groups))))) {
echo "<tr><td>$fdate</td><td align=\"left\"><a href=\"reports/$fname\">$name</a></td></tr>\n";
}
}
echo "</tbody>";
}
?>