-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrowse.php
120 lines (109 loc) · 4.17 KB
/
browse.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
112
113
114
115
116
117
118
119
120
<?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']);
$id = $_POST['id'];
$query = "UPDATE tasks SET task = '$task' WHERE id = $id";
mysqli_query($conn, $query);
header("Location: browse.php");
}
// 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: browse.php');
exit;
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
// Get all the tasks from the database
$query = "SELECT tasks.id as task_id, tasks.task, tasks.status, MIN(log.timestamp) as created_at, MAX(CASE WHEN log.event = 'completed' THEN log.timestamp ELSE NULL END) as completed_at
FROM tasks
LEFT JOIN log ON tasks.id = log.task_id
GROUP BY tasks.id";
$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">
<body>
<div class="grid ">
<div class="headerbox">
<div class="headermenu">
<?php include 'menu.php'; ?>
</div>
</div>
<div class="tasklist">
<table>
<tr>
<th>ID</th>
<th>Creation Date</th>
<th>Completion Date</th>
<th>Task</th>
<th>Status</th>
<th>Action</th>
</tr>
<?php while ($task = mysqli_fetch_assoc($tasks)) { ?>
<tr>
<td class="tdtid">
<?php echo $task['task_id']; ?>
</td>
<td>
<?php echo $task['created_at']; ?>
</td>
<td>
<?php echo $task['completed_at']; ?>
</td>
<td>
<?php echo $task['task']; ?>
</td>
<td>
<?php echo $task['status']; ?>
</td>
<td class="tdtaction">
<?php if ($task['status'] == 'incomplete') { ?>
<button class="btn edit"
onclick="window.location.href='edit.php?edit_task=<?php echo $task['task_id']; ?>'">Edit</button>
<button class="btn finish"
onclick="window.location.href='browse.php?fin_task=<?php echo $task['task_id']; ?>'">Finish</button>
<?php } ?>
<?php if ($task['status'] == 'completed') { ?>
<button class="btn edit"
onclick="window.location.href='edit.php?edit_task=<?php echo $task['task_id']; ?>'">Edit</button>
<button class="btn reopen"
onclick="window.location.href='browse.php?reopen_task=<?php echo $task['task_id']; ?>'">Reopen</button>
<?php } ?>
</td>
</tr>
<?php } ?>
</table>
</div>
</body>
</html>