-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_task_process.php
More file actions
47 lines (41 loc) · 1.41 KB
/
update_task_process.php
File metadata and controls
47 lines (41 loc) · 1.41 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
<?php
session_start();
if (!isset($_SESSION['user']) || $_SESSION['user']['role'] !== 'Team Member') {
header('Location: login.php');
exit();
}
require 'db.php.inc';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$taskId = $_POST['task_id'];
$progress = $_POST['progress'];
$status = $_POST['status'];
$errors = [];
if ($progress == 100 && $status !== 'Completed') {
$errors[] = "Status must be 'Completed' when progress is 100%.";
} elseif ($progress > 0 && $progress < 100 && $status !== 'In Progress') {
$errors[] = "Status must be 'In Progress' when progress is between 1% and 99%.";
} elseif ($progress == 0 && $status !== 'Pending') {
$errors[] = "Status must be 'Pending' when progress is 0%.";
}
if (!empty($errors)) {
header("Location: update_task.php?task_id=$taskId&error=" . urlencode(implode(', ', $errors)));
exit();
}
try {
$stmt = $pdo->prepare("
UPDATE tasks
SET progress = :progress, status = :status
WHERE task_id = :task_id
");
$stmt->execute([
':progress' => $progress,
':status' => $status,
':task_id' => $taskId
]);
header("Location: update_task.php?task_id=$taskId&message=Task updated successfully.");
exit();
} catch (PDOException $e) {
die("Database error: " . $e->getMessage());
}
}
?>