-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
97 lines (90 loc) · 3.29 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
<?php
// Connect to database
require_once '../../1xtodo-dbcon.php';
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Reopen task
if (isset($_GET['reopen_task'])) {
$id = $_GET['reopen_task'];
$query = "UPDATE tasks SET status = 'incomplete' WHERE id = $id";
mysqli_query($conn, $query);
$log_event = "Task reopened: " . $id;
$query = "INSERT INTO log (task_id, event) VALUES ($id, '$log_event')";
mysqli_query($conn, $query);
}
// Check if the form has been submitted
if (isset($_POST['submit'])) {
$task = mysqli_real_escape_string($conn, $_POST['task']);
$query = "INSERT INTO tasks (task) VALUES ('$task')";
mysqli_query($conn, $query);
$log_event = "Task added: " . $task;
$query = "INSERT INTO log (task_id, event) VALUES (LAST_INSERT_ID(), '$log_event')";
mysqli_query($conn, $query);
}
// Check if the finish task button has been clicked
if (isset($_GET['fin_task'])) {
$id = $_GET['fin_task'];
$query = "UPDATE tasks SET status = 'complete' WHERE id = $id";
mysqli_query($conn, $query);
$log_event = "Task finished: " . $id;
$query = "INSERT INTO log (task_id, event) VALUES ($id, '$log_event')";
mysqli_query($conn, $query);
}
// Change task status to "completed"
if (isset($_GET['fin_task'])) {
$id = $_GET['fin_task'];
$sql = "UPDATE tasks SET status='completed' WHERE id=$id";
if (mysqli_query($conn, $sql)) {
header('Location: index.php');
exit;
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
// Get all the incomplete tasks from the database
$query = "SELECT * FROM tasks WHERE status = 'incomplete'";
$tasks = mysqli_query($conn, $query);
?>
<!DOCTYPE html>
<html>
<head>
<title>Task List</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="lib/bootstrap-icons-1.10.3/fonts/bootstrap-icons.css">
</head>
<body>
<div class="grid ">
<div class="headerbox">
<div class="headermenu">
<?php include 'menu.php'; ?>
</div>
</div>
<form action="index.php" method="post">
<input type="text" name="task" placeholder="Add a task...">
<input type="submit" name="submit" value="Add Task">
</form>
<div class="tasklist">
<table>
<tr>
<th>Task</th>
<th>Status</th>
<th>Action</th>
</tr>
<?php while ($task = mysqli_fetch_assoc($tasks)) { ?>
<tr>
<td><?php echo $task['task']; ?></td>
<td><?php echo $task['status']; ?></td>
<td class="tdtaction">
<?php if ($task['status'] == 'incomplete') { ?>
<button class="btn finish" onclick="window.location.href='index.php?fin_task=<?php echo $task['id']; ?>'">Finish</button>
<button class="btn edit" onclick="window.location.href='edit.php?edit_task=<?php echo $task['id']; ?>'">Edit</button>
<?php } ?>
<?php if ($task['status'] == 'completed') { ?>
<a href="index.php?reopen_task=<?php echo $task['id']; ?>">Reopen</a>
<?php } ?>
</td>
</tr>
<?php } ?>
</table>
</body>
</html>