-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathallocate_member_process.php
More file actions
47 lines (42 loc) · 1.5 KB
/
Copy pathallocate_member_process.php
File metadata and controls
47 lines (42 loc) · 1.5 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'] !== 'Project Leader') {
header('Location: login.php');
exit();
}
require 'db.php.inc';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$taskId = $_POST['task_id'];
$teamMemberId = $_POST['team_member'];
$role = $_POST['role'];
$contribution = $_POST['contribution'];
try {
$stmt = $pdo->prepare("
SELECT SUM(contribution_percentage) AS total
FROM task_allocations
WHERE task_id = :task_id
");
$stmt->execute([':task_id' => $taskId]);
$totalContribution = $stmt->fetch(PDO::FETCH_ASSOC)['total'] ?? 0;
if (($totalContribution + $contribution) > 100) {
header("Location: allocate_member.php?task_id=$taskId&error=Contribution exceeds 100%");
exit();
}
$stmt = $pdo->prepare("
INSERT INTO task_allocations (task_id, user_id, role, contribution_percentage, start_date,end_date)
VALUES (:task_id, :user_id, :role, :contribution, NOW(), NOW())
");
$stmt->execute([
':task_id' => $taskId,
':user_id' => $teamMemberId,
':role' => $role,
':contribution' => $contribution
]);
header("Location: allocate_member.php?task_id=$taskId&success=1");
exit();
} catch (PDOException $e) {
header("Location: allocate_member.php?task_id=$taskId&error=" . $e->getMessage());
exit();
}
}
?>