-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
102 lines (90 loc) · 3.43 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
<?php
require('db.php')
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</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" style="border-color:#ff6666;" name="title" placeholder="This field is required">
<button type="submit">Add +</button>
<?php }else{?>
<input type="text" name="title" placeholder="What do you need to do?">
<button type="submit">Add +</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" 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 }?>
<small>created: <?php echo $todo['date_time']?></small>
</div>
<?php } ?>
</div>
</div>
<script src="js/jquery-3.6.3.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>