-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask_confirmation_process.php
More file actions
59 lines (54 loc) · 2.26 KB
/
task_confirmation_process.php
File metadata and controls
59 lines (54 loc) · 2.26 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
<?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'];
$action = $_POST['action'];
try {
if ($action === 'accept') {
$progressStmt = $pdo->prepare("SELECT progress FROM tasks WHERE task_id = :task_id");
$progressStmt->execute([':task_id' => $taskId]);
$progress = $progressStmt->fetchColumn();
if ($progress !== false) {
if ($progress < 100 && $progress > 0) {
$stmt = $pdo->prepare("UPDATE tasks SET status = 'In Progress' WHERE task_id = :task_id");
$message = "Task successfully accepted and activated.";
} elseif ($progress == 100) {
$stmt = $pdo->prepare("UPDATE tasks SET status = 'Completed' WHERE task_id = :task_id");
$message = "Task successfully accepted and marked as completed.";
} else {
$stmt = $pdo->prepare("UPDATE tasks SET status = 'Pending' WHERE task_id = :task_id");
$message = "Task successfully accepted and is pending.";
}
$stmt->execute([':task_id' => $taskId]);
} else {
throw new Exception("Task not found.");
}
} elseif ($action === 'reject') {
$stmt = $pdo->prepare("DELETE FROM task_allocations WHERE task_id = :task_id AND user_id = :user_id");
$stmt->execute([
':task_id' => $taskId,
':user_id' => $_SESSION['user']['user_id']
]);
$message = "Task assignment rejected.";
} else {
throw new Exception("Invalid action.");
}
if (!isset($_SESSION['task_confirmations'])) {
$_SESSION['task_confirmations'] = [];
}
$_SESSION['task_confirmations'][] = $taskId;
$_SESSION['message'] = $message;
header("Location: accept_task.php");
exit();
} catch (PDOException $e) {
die("Database error: " . $e->getMessage());
} catch (Exception $e) {
die("Error: " . $e->getMessage());
}
}
?>