-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtimeview.php
82 lines (70 loc) · 2.5 KB
/
timeview.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
<?php
include_once('header.php');
include_once('_constants.php');
?>
<style type="text/css">
.mapuploadtable td {
font-size: 8px;
}
</style>
<script>
var times = [];
<?php
$earliest_timestamp = null;
$latest_timestamp = null;
$fn = fopen(LOG_FILE,"r");
while(!feof($fn)) {
$line = fgets($fn);
if (strpos($line, 'Wrote map') !== false) {
$linedatestring = substr($line, 0, strpos($line, 'Wrote') - 7);
$linemapnumber = str_replace(":", "", substr($line, strpos($line, 'map') + 4, 3));
$linedate = DateTime::createFromFormat('F d Y H:i:s', $linedatestring);
$linetimestamp = $linedate->getTimestamp() - ($linedate->getTimestamp() % (60 * 60));
if (!$earliest_timestamp) {
$earliest_timestamp = $linetimestamp;
}
$latest_timestamp = $linetimestamp;
print('if (!Array.isArray(times[' . $linetimestamp . "])) { times[" . $linetimestamp . "] = []; } times[" . $linetimestamp . "].push(" . $linemapnumber . ");" . PHP_EOL);
}
}
fclose($fn);
?>
var timestamp = <?=$earliest_timestamp?>;
var latest_timestamp = <?=$latest_timestamp?>;
function advanceTime() {
pipsToAdd = times[timestamp] ? times[timestamp] : [];
for (mapnum of pipsToAdd) {
$('#mapcell' + mapnum).append('⬜');
}
dateobj = new Date(timestamp * 1000);
$('#maptime').text(getReadableDate(dateobj));
if (timestamp >= latest_timestamp) {
clearInterval(stopwatch);
}
timestamp += 60 * 60;
}
function getReadableDate(dateobj) {
return dateobj.toDateString() + " " + dateobj.getHours() + ":00";
}
var stopwatch = setInterval(advanceTime, 50);
</script>
<div id="maptime"> </div>
<table class="mapuploadtable">
<?php
$catalog = @json_decode(file_get_contents(CATALOG_FILE), true);
if (empty($catalog)) {
$catalog = [];
}
$target_height = ceil(count($catalog)/3);
foreach($catalog as $mapdata) {
print('<tr><td width="20"><b>' . $mapdata['map_number'] . '</b></td><td width="200" id="mapcell' . $mapdata['map_number'] . '"></td>' . PHP_EOL);
print('<td width="20"><b>' . ($mapdata['map_number']+$target_height) . '</b></td><td width="200" id="mapcell' . ($mapdata['map_number']+$target_height) . '"></td>' . PHP_EOL);
print('<td width="20"><b>' . ($mapdata['map_number']+$target_height*2) . '</b></td><td width="200" id="mapcell' . ($mapdata['map_number']+$target_height*2) . '"></td></tr>' . PHP_EOL);
if ($mapdata['map_number'] == $target_height+9) {
break;
}
}
?>
</table>
<?php
include_once('./footer.php');