-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweeks.php
More file actions
87 lines (73 loc) · 2.02 KB
/
weeks.php
File metadata and controls
87 lines (73 loc) · 2.02 KB
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
<h1>TinyWebDB API and Weekly View</h1>
<h2> <a href=index.php>HOME</a> <a href=weeks.php>Weeks</a></h2>
<form method="POST" action="">
<?php
$data_Path = "./_data/";
$log_Path = "./_log/";
setlocale(LC_TIME, "ja_JP");
date_default_timezone_set('Asia/Tokyo');
$listLog = array();
$listTxt = array();
if ($handler = opendir($data_Path)) {
while (($sub = readdir($handler)) !== FALSE) {
if (substr($sub, -4, 4) == ".txt") {
$listTxt[] = $sub;
} elseif (substr($sub, 0, 10) == "tinywebdb_") {
$listLog[] = $sub;
}
}
closedir($handler);
}
echo "<h3>TinyWebDB Tags</h3>";
echo "<table border=1>";
echo "<thead><tr>";
echo "<th> Student </th>";
for($i = 1; $i<=15; $i++) {
echo "<th> W$i </th>";
}
echo "</tr></thead>\n";
$wlist = get_everydate("weeks");
if ($listTxt) {
sort($listTxt);
foreach ($listTxt as $sub) {
if ($sub == "weeks.txt" ) continue;
echo "<tr><td>" . substr($sub, 0, -4) . "</td>\n";
foreach($wlist as $w) {
get_attendate(substr($sub, 0, -4), $w);
}
}
echo "</tr>\n";
}
exit; // this stops rest steps
function get_everydate($id){
global $data_Path;
echo "<tr><td></td>\n";
$fh = fopen($data_Path . "$id.log", "r") or die("File not found.");
while (($buffer = fgets($fh)) !== false) {
$json = rtrim($buffer);
$obj = json_decode($json);
echo "<td>" . $obj->date . "</td>\n";
$wlist[] = $obj->date;
}
echo "</tr>\n";
return $wlist;
}
function get_attendate($id,$w){
global $data_Path;
$date = new DateTime("2022/$w 13:10:00");
$wdate = $date->format('U');
echo "<td>";
# echo $w . "|";
# echo $wdate . "|";
$fh = fopen($data_Path . "$id.log", "r") or die("---$data_Path$id.log File not found.");
while (($buffer = fgets($fh)) !== false) {
$json = rtrim($buffer);
$obj = json_decode($json);
$diff = $wdate - $obj->date;
if($diff > -1800 && $diff < 1800) {
echo 20 + intval($diff / 60);
break;
}
}
echo "</td>";
}