-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch_task_progress.php
More file actions
76 lines (73 loc) · 2.54 KB
/
search_task_progress.php
File metadata and controls
76 lines (73 loc) · 2.54 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
<?php
session_start();
if (!isset($_SESSION['user']) || $_SESSION['user']['role'] !== 'Team Member') {
header('Location: login.php');
exit();
}
require 'db.php.inc';
$tasks = [];
if ($_SERVER['REQUEST_METHOD'] === 'GET' && isset($_GET['search'])) {
$search = $_GET['search'];
try {
$stmt = $pdo->prepare("
SELECT t.task_id, t.task_name, p.title AS project_name, t.progress, t.status
FROM tasks t
JOIN projects p ON t.project_id = p.project_id
JOIN task_allocations ta ON t.task_id = ta.task_id
WHERE ta.user_id = :user_id AND
(t.task_id LIKE :search OR t.task_name LIKE :search OR p.title LIKE :search)
");
$stmt->execute([':user_id' => $_SESSION['user']['user_id'], ':search' => "%$search%"]);
$tasks = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Database error: " . $e->getMessage());
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Search Tasks</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php include 'header.php'; ?>
<main>
<h2>Search and Update Task Progress</h2>
<?php include 'sidebar.php';?>
<form method="GET" action="search_task_progress.php">
<input type="text" name="search" placeholder="Search by Task ID, Name, or Project" value="<?= $_GET['search'] ?? '' ?>">
<button type="submit">Search</button>
</form>
<?php if (!empty($tasks)): ?>
<table>
<thead>
<tr>
<th>Task ID</th>
<th>Task Name</th>
<th>Project</th>
<th>Progress (%)</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($tasks as $task): ?>
<tr>
<td><?= $task['task_id'] ?></td>
<td><?= $task['task_name'] ?></td>
<td><?= $task['project_name'] ?></td>
<td><?=$task['progress'] ?>%</td>
<td><?= $task['status'] ?></td>
<td><a href="update_task.php?task_id=<?= $task['task_id'] ?>">Update</a></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php elseif (isset($_GET['search'])): ?>
<p>No tasks found for your search .</p>
<?php endif; ?>
</main>
<?php include 'footer.php';?>
</body>
</html>