-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
73 lines (66 loc) · 1.93 KB
/
index.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
<?php
$todos=[];
if (file_exists('todo.txt')) {
$file = file_get_contents('todo.txt');
$todos = unserialize($file);
};
if (isset($_POST['todo'])) {
$data = $_POST['todo'];
$todos[] = [
'todo' => $data,
'status' => 0
];
saveData($todos);
};
if (isset($_GET['status'])) {
$todos[$_GET['key']]['status'] = $_GET['status'];
saveData($todos);
};
if (isset($_GET['hapus'])) {
unset($todos[$_GET['key']]);
saveData($todos);
};
function saveData($todos){
file_put_contents('todo.txt', serialize($todos));
header('Location: index.php');
};
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ToDo</title>
</head>
<body>
<header>
<center>
<h3>ToDo App</h3>
</center>
</header>
<main>
<form method="POST">
<label for="todo">Apa kegiatanmu di hari ini?</label>
<input type="text" name="todo">
<button type="submit">Simpan</button>
</form>
<ul>
<?php foreach ($todos as $key => $value): ?>
<li>
<input type="checkbox" name="todo" onclick="window.location.href='index.php?status=<?php echo($value['status']== 1) ? '0' : '1'; ?>&key=<?php echo $key; ?>'" <?php if ($value['status'] == 1) echo 'checked'; ?>>
<label>
<?php
if ($value['status'] == 1) {
echo '<del>'.$value['todo'].'</del>';
} else {
echo $value['todo'];
};
?>
</label>
<a href="index.php?hapus=1&key=<?php echo $key; ?>" onclick="return confirm('Apa kamu yakin ingin menghapus todo ini?')">Hapus</a>
</li>
<?php endforeach; ?>
</ul>
</main>
</body>
</html>