Show sourcecode
The following files exists in this folder. Click to view.
add-words.php
api/
components/
include.php
index.php
ini/
login.php
logout.php
practice.php
progress.php
public/
scripts/
util/
word.php
progress.php
79 lines ASCII Windows (CRLF)
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
<!DOCTYPE html>
<?php
include "include.php";
include "util/practice.php";
login_guard();
$tries = quick_statment(("
SELECT try_record.time, try_record.success, translation.word_id, word.word
FROM try_record
INNER JOIN translation ON try_record.translation_id = translation.id
INNER JOIN word ON translation.word_id = word.id
WHERE word.user_id = ? ORDER BY translation.word_id
"), "i", user_id());
function word_progress($word, $nextCheckpoint)
{
$progress = ($nextCheckpoint - time()) / (3600);
$progress = min(1, max(0, $progress));
$r = (1 - $progress) * 255;
$g = $progress * 255;
if ($nextCheckpoint > time()) {
$r = 0;
$g = 255;
}
return [
"word" => $word,
"nextCheckpoint" => $nextCheckpoint,
"color" => "rgb(" . $r . "," . $g . ",0)"
];
}
$wordProgresses = [];
$buffer = [];
foreach ($tries as $try) {
$len = count($buffer);
// switching to new word
if ($len > 0 && $buffer[$len - 1]["word_id"] != $try["word_id"]) {
$nextCheckpoint = next_checkpoint($buffer);
$last = $buffer[$len - 1];
$wordProgresses[] = word_progress($last["word"], $nextCheckpoint);
//echo $next_checkpoint . " - " . $last["word"] . "<br>";
$buffer = [];
}
$buffer[] = $try;
}
$nextCheckpoint = next_checkpoint($buffer);
$last = $buffer[$len - 1];
$wordProgresses[] = word_progress($last["word"], $nextCheckpoint);
//echo $next_checkpoint . " - " . $last["word"] . "<br>";
$buffer = [];
?>
<html lang="en">
<head>
<?php include "components/head.php" ?>
</head>
<body>
<?php include "components/header.php" ?>
<div class="progress-container">
<?php
foreach ($wordProgresses as $wordProgress) {
echo encase($wordProgress["word"] . " next checkpoint: " . gmdate("Y-m-d\TH:i:s\Z", $wordProgress["nextCheckpoint"]), "p", "", "background-color: " . $wordProgress["color"]);
} ?>
</div>
</body>
</html>