-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask.php
More file actions
142 lines (133 loc) · 4.76 KB
/
task.php
File metadata and controls
142 lines (133 loc) · 4.76 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
<?php
session_start();
require_once 'config.php';
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Task Manager</title>
<link rel="stylesheet" href="style.css">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<div class="navbar">
<div><a href="index.php"><strong>Task Manager</strong></a></div>
<div>
<?php if (isset($_SESSION['user_id'])): ?>
<a href="logout.php">Logout</a>
<?php else: ?>
<a href="login.php">Login</a>
<a href="register.php">Register</a>
<?php endif; ?>
</div>
</div>
<div class="container">
<h2>Your Tasks</h2>
<a href="create_task.php" class="button" id="create-task-btn">+ Create New Task</a>
<br>
<div id="task-list"></div>
</div>
<script>
function loadTasks() {
$.ajax({
url: 'get_tasks.php',
method: 'GET',
success: function(data) {
$('#task-list').html(data);
},
error: function(xhr) {
console.error("AJAX Load Error:", xhr.responseText);
}
});
}
$(document).ready(function () {
loadTasks();
setInterval(loadTasks, 5000);
});
function markAsCompleted(taskId, button) {
$.ajax({
url: 'mark_complete.php',
method: 'POST',
data: { task_id: taskId },
success: function(response) {
if (response.success) {
const row = button.closest('tr');
row.classList.add('completed');
button.remove();
const completedLabel = document.createElement('span');
completedLabel.textContent = '✔ Completed';
row.querySelector('td.status').appendChild(completedLabel);
} else {
alert('Failed to mark as completed.');
}
},
error: function(xhr) {
console.error("Error:", xhr.responseText);
alert('Something went wrong.');
}
});
}
function deleteTask(taskId) {
if (confirm("Are you sure you want to delete this task?")) {
$.ajax({
url: 'delete_task.php',
method: 'POST',
data: { task_id: taskId },
success: function(response) {
const result = JSON.parse(response);
if (result.success) {
alert(result.message);
loadTasks();
} else {
alert(result.message);
}
},
error: function(xhr) {
console.error("Error:", xhr.responseText);
alert('Something went wrong.');
}
});
}
}
function editTask(taskId, currentTaskName) {
const newTaskName = prompt("Edit task name:", currentTaskName);
if (newTaskName) {
const newDueDate = prompt("Edit due date:", "YYYY-MM-DD");
if (newDueDate) {
$.ajax({
url: 'edit_task.php',
method: 'POST',
data: {
task_id: taskId,
task_title: newTaskName,
due_date: newDueDate
},
success: function(response) {
const result = JSON.parse(response);
if (result.success) {
alert(result.message);
loadTasks();
} else {
alert(result.message);
}
},
error: function(xhr) {
console.error("Error:", xhr.responseText);
alert('Something went wrong.');
}
});
} else {
alert("Please provide a valid due date.");
}
} else {
alert("Please provide a valid task title.");
}
}
</script>
</body>
</html>