-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
111 lines (104 loc) · 3.96 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
require 'db_conn.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>To-Do List</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="main-section">
<div class="add-section">
<form action="app/add.php" method="POST" autocomplete="off">
<?php if(isset($_GET['mess']) && $_GET['mess'] == 'error'){ ?>
<input type="text"
name="title"
style="border-color: #ff6666"
placeholder="This field is required" />
<button type="submit">Add <span>+</span></button>
<?php }else{ ?>
<div class="text1">
<input type="text"
name="title"
placeholder="Task" />
</div>
<button type="submit">Add <span>+</span></button>
<?php } ?>
</form>
</div>
<?php
$todos = $conn->query("SELECT * FROM todos ORDER BY id DESC");
?>
<div class="show-todo-section">
<?php if($todos->rowCount() <= 0){ ?>
<div class="todo-item">
<div class="empty">
<img src="img/f.png" width="100%" />
<img src="img/Ellipsis.gif" width="80px">
</div>
</div>
<?php } ?>
<?php while($todo = $todos->fetch(PDO::FETCH_ASSOC)) { ?>
<div class="todo-item">
<span id="<?php echo $todo['id']; ?>"
class="remove-to-do">x</span>
<?php if($todo['checked']){ ?>
<input type="checkbox"
class="check-box"
data-todo-id ="<?php echo $todo['id']; ?>"
checked />
<h2 class="checked"><?php echo $todo['title'] ?></h2>
<?php }else { ?>
<input type="checkbox"
data-todo-id ="<?php echo $todo['id']; ?>"
class="check-box" />
<h2><?php echo $todo['title'] ?></h2>
<?php } ?>
<br>
<small>created: <?php echo $todo['date_time'] ?></small>
</div>
<?php } ?>
</div>
</div>
<script src="js/jquery-3.2.1.min.js"></script>
<script>
$(document).ready(function(){
$('.remove-to-do').click(function(){
const id = $(this).attr('id');
$.post("app/remove.php",
{
id: id
},
(data) => {
if(data){
$(this).parent().hide(600);
}
}
);
});
$(".check-box").click(function(e){
const id = $(this).attr('data-todo-id');
$.post('app/check.php',
{
id: id
},
(data) => {
if(data != 'error'){
const h2 = $(this).next();
if(data === '1'){
h2.removeClass('checked');
}else {
h2.addClass('checked');
}
}
}
);
});
});
</script>
</body>
</html>