blob: 2bb8de8f5f29de56c307a991ba037c82d06456cf (
plain)
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
|
<?php
$ARGS = $_GET;
if(count($ARGS) == 0) {
$ARGS = json_decode($_COOKIE["tasks"], true);
} else if($ARGS["clear"] == "t") {
setcookie("tasks", "", time() - 1, "/");
} else {
setcookie("tasks", json_encode($ARGS), time() + (86400 * 30 * 12), "/"); // 1 day * 30 * 12
}
?>
<html>
<head>
<style>
.text {
margin: 5px;
}
.done_t {
text-decoration-line: line-through;
}
.hidden {
display: none;
}
</style>
</head>
<body>
<form action="index.php" method="get">
<?php
$tasks = $ARGS["tasks"] ?? "0";
if($ARGS["task_text"] != "") {
$ARGS["task_". $tasks ."_text"] = $ARGS["task_text"];
$tasks++;
}
$delete = $ARGS["task_delete"] ?? -1;
$edit = $ARGS["task_edit"] ?? -1;
echo "Task: <input type=\"text\" name=\"task_text\">";
echo "<input type=\"submit\" value=\"Add Task\"> <br>";
echo "<ul>";
for($i = 0, $j = 0; $i < $tasks; $i++, $j++)
{
if($i == $delete) {
$j--;
continue;
}
if($j == $edit) {
$editing = true;
} else {
$editing = false;
}
$task_text = $ARGS["task_". $i ."_text"] ?? "ERROR: No Task";
$done = $ARGS["task_". $i ."_done"] ?? "f";
$isdone = $done == "t";
echo "<li> <p>";
echo "<input type=\"hidden\" name=\"task_". $j ."_done\" value=\"". $done ."\">";
echo "<button type=\"submit\" name=\"task_". $j ."_done\" value=\"". ($isdone ? "f" : "t") ."\">". ($isdone ? "Not Done" : "Done" ) ."</button>";
echo "<button type=\"submit\" name=\"task_delete\" value=\"". $j ."\">Delete</button>";
echo "<button type=\"submit\" name=\"task_edit\" value=\"". ($editing ? "" : $j) ."\">". ($editing ? "Save" : "Edit") ."</button>";
echo "<input class=\"". ($editing ? "" : "hidden") ."\" name=\"task_". $j ."_text\" value=\"". $task_text ."\">";
echo "<span class=\"". ($editing ? "hidden" : "") ." text done_". $done ."\">". $task_text ."</span>";
echo "</p> </li>";
}
echo "</ul>";
if($delete != -1) $tasks--;
echo "<input type=\"hidden\" name=\"tasks\" value=\"". $tasks ."\">";
?>
</form>
<form action="index.php" method="get">
<button type="submit" name="clear" value="t">Delete Everything</button>
</form>
</body>
</html>
|