-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_task.php
More file actions
144 lines (131 loc) · 6.46 KB
/
create_task.php
File metadata and controls
144 lines (131 loc) · 6.46 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
session_start();
if (!isset($_SESSION['user']) || $_SESSION['user']['role'] !== 'Project Leader') {
header('Location: login.php');
exit();
}
require 'db.php.inc';
$errors = [];
$successMessage = "";
$stmt = $pdo->prepare("
SELECT project_id, title
FROM projects
WHERE team_leader_id = :team_leader_id
");
$stmt->execute([':team_leader_id' => $_SESSION['user']['user_id']]);
$projects = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$taskName = $_POST['task_name'] ?? '';
$description = $_POST['description'] ?? '';
$projectId = $_POST['project_id'] ?? '';
$startDate = $_POST['start_date'] ?? '';
$endDate = $_POST['end_date'] ?? '';
$effort = $_POST['effort'] ?? '';
$status = $_POST['status'] ?? 'Pending';
$priority = $_POST['priority'] ?? '';
if (empty($taskName)) $errors['task_name'] = "Task Name is required.";
if (empty($description)) $errors['description'] = "Description is required.";
if (empty($projectId)) $errors['project_id'] = "Project is required.";
if (empty($startDate) || empty($endDate)) $errors['dates'] = "Start Date and End Date are required.";
if ($effort <= 0) $errors['effort'] = "Effort must be a positive number.";
if (empty($priority)) $errors['priority'] = "Priority is required.";
if (empty($errors)) {
try {
$stmt = $pdo->prepare("
INSERT INTO tasks (task_name, description, project_id, start_date, end_date, effort, status, priority)
VALUES (:task_name, :description, :project_id, :start_date, :end_date, :effort, :status, :priority)
");
$stmt->execute([
':task_name' => $taskName,
':description' => $description,
':project_id' => $projectId,
':start_date' => $startDate,
':end_date' => $endDate,
':effort' => $effort,
':status' => $status,
':priority' => $priority
]);
$successMessage = "Task '$taskName' successfully created.";
} catch (PDOException $e) {
$errors['database'] = "Database error: " . $e->getMessage();
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create Task</title>
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<?php include 'header.php'; ?>
<main>
<?php include 'sidebar.php'; ?>
<section class="form-section">
<h2>Create Task</h2>
<?php if ($successMessage): ?>
<div class="success"><?= $successMessage ?></div>
<?php endif; ?>
<form method="POST" action="create_task.php" >
<label for="task_name">Task Name</label>
<input type="text" id="task_name" name="task_name" value="<?= $_POST['task_name'] ?? '' ?>">
<?php if(!empty($errors['task_name'])):?>
<div class="error"><?= $errors['task_name'] ?? '' ?></div>
<?php endif ;?>
<label for="description">Description</label>
<textarea id="description" name="description" rows="4"><?= $_POST['description'] ?? '' ?></textarea>
<?php if(!empty($errors['description'])):?>
<div class="error"><?= $errors['description'] ?? '' ?></div>
<?php endif ;?>
<label for="project_id">Project</label>
<select id="project_id" name="project_id">
<option value="">-- Select Project --</option>
<?php foreach ($projects as $project): ?>
<option value="<?=$project['project_id'] ?>" <?= ($_POST['project_id'] ?? '') == $project['project_id'] ? 'selected' : '' ?>>
<?= $project['title'] ?>
</option>
<?php endforeach; ?>
</select>
<?php if(!empty($errors['project_id'])):?>
<div class="error"><?= $errors['project_id'] ?? '' ?></div>
<?php endif ;?>
<label for="start_date">Start Date</label>
<input type="date" id="start_date" name="start_date" value="<?= $_POST['start_date'] ?? '' ?>">
<?php if(!empty($errors['start_date'])):?>
<div class="error"><?= $errors['start_date'] ?? '' ?></div>
<?php endif ;?>
<label for="end_date">End Date</label>
<input type="date" id="end_date" name="end_date" value="<?= $_POST['end_date'] ?? '' ?>">
<?php if(!empty($errors['end_date'])):?>
<div class="error"><?= $errors['end_date'] ?? '' ?></div>
<?php endif ;?>
<label for="effort">Effort (man-months)</label>
<input type="number" id="effort" name="effort" value="<?= $_POST['effort'] ?? '' ?>" >
<?php if(!empty($errors['effort'])):?>
<div class="error"><?= $errors['effort'] ?? '' ?></div>
<?php endif ;?>
<label for="status">Status</label>
<select id="status" name="status">
<option value="Pending" <?= ($_POST['status'] ?? '') === 'Pending' ? 'selected' : '' ?>>Pending</option>
<option value="In Progress" <?= ($_POST['status'] ?? '') === 'In Progress' ? 'selected' : '' ?>>In Progress</option>
<option value="Completed" <?= ($_POST['status'] ?? '') === 'Completed' ? 'selected' : '' ?>>Completed</option>
</select>
<label for="priority">Priority</label>
<select id="priority" name="priority">
<option value="Low" <?= ($_POST['priority'] ?? '') === 'Low' ? 'selected' : '' ?>>Low</option>
<option value="Medium" <?= ($_POST['priority'] ?? '') === 'Medium' ? 'selected' : '' ?>>Medium</option>
<option value="High" <?= ($_POST['priority'] ?? '') === 'High' ? 'selected' : '' ?>>High</option>
</select>
<?php if(!empty($errors['priority'])):?>
<div class="error"><?= $errors['priority'] ?? '' ?></div>
<?php endif ;?>
<button type="submit" class="btn-primary">Create Task</button>
</form>
</section>
</main>
<?php include 'footer.php'; ?>
</body>
</html>