-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtrash.php
More file actions
370 lines (333 loc) · 18.3 KB
/
trash.php
File metadata and controls
370 lines (333 loc) · 18.3 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
<?php
session_start(); // เริ่มต้นเซสชั่น
// เชื่อมต่อฐานข้อมูล
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "todolist";
$conn = new mysqli($servername, $username, $password, $dbname);
// ตรวจสอบการเชื่อมต่อ
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// ตรวจสอบว่า user_id มีค่าหรือไม่ใน session
if (isset($_SESSION['user_id'])) {
$user_id = $_SESSION['user_id'];
// คำสั่ง SQL ดึงเฉพาะโน้ตที่ถูกลบ (status = 'deleted')
$sql = "SELECT task.*, users.name, users.email
FROM task
JOIN users ON task.user_id = users.user_id
WHERE task.user_id = '$user_id' AND task.status = 'deleted'
ORDER BY task.status_at DESC";
$result = $conn->query($sql);
// ตรวจสอบว่ามีข้อมูลหรือไม่
if ($result && $result->num_rows > 0) {
$row = $result->fetch_assoc(); // ดึงข้อมูลผู้ใช้
$user_name = $row['name'];
$user_email = $row['email'];
} else {
$user_name = "No name found";
$user_email = "No email found";
}
} else {
echo "Error: User not logged in.";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Jotify - Trash</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css"/>
<link rel="stylesheet" href="css/trash.css">
<!-- SweetAlert2 -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script><!-- เรียกใช้ SweetAlert2 -->
</head>
<body>
<!-- เเถบบาร์ด้านบน -->
<header>
<div class="logo">
<img src="img/Jotify.png" alt="">
</div>
<div class="noti-user">
<div class="noti">
<i class="fa-solid fa-bell"></i>
</div>
<div class="user_pro" id="userBtn">
<i class="fa-solid fa-circle-user"></i></i>
</div>
</div>
</header>
<!-- ป๊อปอัพโปรไฟล์ -->
<div class="profile-overlay" id="profileOverlay">
<div id="profilePopup" class="popup" style="display: none; position: absolute; top: 90px; right: 45px; background: #EFF0F2; padding: 10px; border-radius: 10px; box-shadow: 0px 0px 10px rgba(0,0,0,0.1);">
<div class="head">
<div class="usename">
<i class="fa-solid fa-circle-user"></i> <p><?php echo $user_name; ?></p>
</div>
<i class="fa-solid fa-xmark" id="closeProfilePopup" style="cursor: pointer;" ></i>
</div>
<?php echo $user_email; ?><br><br>
<form method="POST" action="loginform.php">
<button><i class="fa-solid fa-right-from-bracket"></i> Log out</button>
</form>
</div>
<!-- profilePopup -->
</div>
<!-- profile-overlay -->
<div class="container">
<!-- เเถบบาร์ด้านข้าง -->
<div class="bar flex-column p-4" style="width: 280px; height: 1024px;">
<div class="text-center py-4">
<!-- <a href="/" class="d-flex align-items-center mb-3 mb-md-0 me-md-auto link-body-emphasis text-decoration-none"> -->
<button class="add-task-btn" id="addTaskBtn">
<i class="fa-solid fa-plus"></i>
</button>
<!-- </a> -->
</div>
<hr>
<ul class="nav nav-pills flex-column px-0">
<li class="nav-item mb-3">
<a href="home.php" class="nav-link link-body-emphasis custom-nav">
<i class="fa-solid fa-house"></i> Home
</a>
</li>
<li class="mb-3">
<a href="neardeath.php" class="nav-link link-body-emphasis custom-nav">
<i class="fa-solid fa-circle-exclamation"></i> Near Death
</a>
</li>
<li class="mb-3">
<a href="calendar.php" class="nav-link link-body-emphasis custom-nav">
<i class="fa-solid fa-calendar-days"></i> Calendar
</a>
</li>
<li class="mb-3">
<a href="trash.php" class="nav-link active custom-nav">
<i class="fa-solid fa-trash"></i> Trash
</a>
</li>
<li class="mb-3">
<a href="done.php" class="nav-link link-body-emphasis custom-nav">
<i class="fa-solid fa-check"></i> Done
</a>
</li>
</ul>
</div>
<div class="content">
<!-- เเสดงโน๊ต -->
<div class="dashboard_note" id="dashboard">
<h1>Deleted Notes</h1><br>
<div class="note-container">
<?php
// เชื่อมต่อฐานข้อมูล
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "todolist";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// คิวรี่ดึงโน๊ตที่มีสถานะเป็น "delete"
$sql = "SELECT * FROM task WHERE user_id = ? AND status = 'deleted' ORDER BY status_at DESC";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $_SESSION['user_id']);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$count = 0;
while ($row = $result->fetch_assoc()) {
$count++;
?>
<div class="note-item">
<div class="note-title">
<h3 style="font-size: 30px; color: #333333;"><?php echo htmlspecialchars($row['title']); ?></h3>
<div class="task_status" style="background-color: <?php echo htmlspecialchars($row['color']); ?>"></div>
</div>
<hr style="width: 266px; margin: 20px auto; border: 1px solid #000000;">
<div class="note-content">
<p><?php echo nl2br(htmlspecialchars($row['note'])); ?></p>
</div>
<div class="note-footer">
<div class="foot-left">
<i class="fa-solid fa-clock-rotate-left"></i>
<span>
<?php
// คำนวณวันที่เหลือจากวันที่ที่ถูกลบ
$deleted_at = strtotime($row['status_at']);
$current_time = time(); // เวลา ณ ปัจจุบัน
$time_left = 30 * 24 * 60 * 60 - ($current_time - $deleted_at); // คำนวณเวลาที่เหลือ (30 วัน)
if ($time_left > 0) {
$days_left = floor($time_left / (60 * 60 * 24)); // จำนวนวันที่เหลือ
echo "กู้คืนได้ภายใน " . $days_left . " วัน";
} else {
echo "หมดเวลาสำหรับการกู้คืนแล้ว";
}
?>
</span>
</div>
<!-- foot-left -->
<button class="recover" data-task-id="<?php echo $row['task_id']; ?>">
<i class="fa-solid fa-rotate"></i>
</button>
</div>
</div>
<?php
}
} else {
echo "<p>No deleted notes</p>";
}
$stmt->close();
$conn->close();
?>
</div>
</div>
<!-- ส่วนกดเพิ่มโน๊ต -->
<div class="modal-overlay" id="modalOverlay">
<div class="modal-content modal-task"><br>
<form action="connect+processDB/add_note.php" method="POST">
<h1>Title</h1>
<div class="nametask">
<input type="text" placeholder="ป้อนชื่อรายการ..." name="title" required>
<div class="color-picker">
<button type="button" class="color-option" style="background: #238300;" data-color="#238300"></button>
<button type="button" class="color-option" style="background: #CC0000;" data-color="#CC0000"></button>
<button type="button" class="color-option" style="background: #D1A209;" data-color="#D1A209"></button>
<button type="button" class="color-option" ></button>
</div>
<input type="hidden" name="color" id="selectedColor">
</div>
<h2>Task a Note</h2>
<div class="note-container">
<textarea name="takenote" placeholder="Text..."></textarea>
<label for="imageUpload" class="upload-icon">
<i class="fa-solid fa-file-image"></i>
</label>
<input type="file" id="imageUpload" accept="image/*" style="display: none;" name="note">
<!-- แสดงรูปที่อัปโหลด -->
<!-- <div id="imagePreviewContainer"></div> -->
</div>
<h3>Time out date</h3>
<div class="but-add">
<input type="date" name="timeout_date">
<div class="group_button">
<button class="add" id="add">Add +</button>
<button class="cancle" id="cancle">Cancle</button>
</div>
</div>
</form>
</div>
<!-- modal-content -->
</div>
<!-- modal-overlay -->
</div>
<!-- container -->
<script>
//========================================================================================================================//
// เปิดป๊อปอัพโปรไฟล์
const profileOverlay = document.getElementById("profileOverlay");
document.getElementById('userBtn').addEventListener('click', function () {
const popup = document.getElementById('profilePopup');
// ตรวจสอบว่าป๊อปอัพแสดงอยู่หรือไม่
if (popup.style.display === 'none' || popup.style.display === '') {
popup.style.display = 'block'; // แสดงป๊อปอัพ
profileOverlay.style.display = 'block'; // แสดง overlay
} else {
popup.style.display = 'none'; // ซ่อนป๊อปอัพ
profileOverlay.style.display = 'none'; // ซ่อน overlay
}
});
// ปิดป๊อปอัพโปรไฟล์เมื่อกดปุ่ม close
document.getElementById('closeProfilePopup').addEventListener('click', function() {
document.getElementById('profilePopup').style.display = 'none'; // ซ่อนป๊อปอัพ
profileOverlay.style.display = 'none'; // ซ่อน overlay
});
// ปิดป๊อปอัพโปรไฟล์เมื่อคลิกภายนอก
document.addEventListener('click', function (event) {
const popup = document.getElementById('profilePopup');
const userBtn = document.getElementById('userBtn');
if (!userBtn.contains(event.target) && !popup.contains(event.target)) {
popup.style.display = 'none'; // ซ่อนป๊อปอัพ
profileOverlay.style.display = 'none'; // ซ่อน overlay
}
});
//========================================================================================================================//
const addTaskBtn = document.getElementById("addTaskBtn");
const modalOverlay = document.getElementById("modalOverlay");
const closeModal = document.getElementById("cancle");
// เปิด popup add note
addTaskBtn.addEventListener("click", function() {
this.classList.toggle("active");
modalOverlay.style.display = modalOverlay.style.display === "flex" ? "none" : "flex";
});
// ปิด popup add note
closeModal.addEventListener("click", function() {
modalOverlay.style.display = "none";
addTaskBtn.classList.remove("active");
});
// ปิด popup add note เมื่อคลิกนอกกรอบ
modalOverlay.addEventListener("click", function(event) {
if (event.target === modalOverlay) {
modalOverlay.style.display = "none";
addTaskBtn.classList.remove("active");
}
});
//========================================================================================================================//
// ป้อปอัพกู้โน๊ต
$(document).ready(function() {
$(".recover").click(function() {
var taskId = $(this).data("task-id"); // ดึง task_id จากปุ่มที่คลิก
// ใช้ SweetAlert2 สำหรับป๊อปอัพยืนยัน
Swal.fire({
title: 'คุณแน่ใจหรือไม่<br>ที่จะกู้คืนโน๊ตนี้?',
text: "การกู้คืนจะนำโน๊ตกลับไปยังหน้าหลัก",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#38b100',
cancelButtonColor: '#CC0000',
confirmButtonText: 'ยืนยัน',
cancelButtonText: 'ยกเลิก'
}).then((result) => {
if (result.isConfirmed) {
// ส่งคำขอ AJAX เพื่อกู้คืนโน๊ต
$.ajax({
url: "connect+processDB/recover_task.php", // ปรับ URL ตามไฟล์ PHP ที่ใช้
type: "POST",
data: { task_id: taskId },
success: function(response) {
if (response.trim() === "success") {
Swal.fire(
'สำเร็จ!',
'กู้คืนสำเร็จ!',
'success'
).then(() => {
location.reload(); // โหลดหน้าใหม่เพื่อแสดงการเปลี่ยนแปลง
});
} else {
Swal.fire(
'เกิดข้อผิดพลาด!',
'ไม่สามารถกู้คืนได้',
'error'
);
}
},
error: function(xhr, status, error) {
console.error("AJAX Error: ", error);
Swal.fire(
'เกิดข้อผิดพลาด!',
'ไม่สามารถเชื่อมต่อกับเซิร์ฟเวอร์ได้',
'error'
);
}
});
}
});
});
});
</script>
</body>
</html>