35429-vm/projects.php
2025-11-02 20:12:50 +00:00

121 lines
5.8 KiB
PHP

<?php
require_once 'db/config.php';
require_once 'includes/header.php';
try {
$pdo = db();
$stmt_projects = $pdo->query("SELECT projects.*, clients.name as client_name FROM projects LEFT JOIN clients ON projects.client_id = clients.id ORDER BY projects.name ASC");
$projects = $stmt_projects->fetchAll(PDO::FETCH_ASSOC);
$stmt_clients = $pdo->query("SELECT id, name FROM clients ORDER BY name ASC");
$clients = $stmt_clients->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
echo '<div class="alert alert-danger">Error fetching data: ' . $e->getMessage() . '</div>';
$projects = [];
$clients = [];
}
?>
<div class="container mt-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<h1 class="h2">Projects</h1>
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addProjectModal">
Add Project
</button>
</div>
<div class="card">
<div class="card-body">
<table class="table table-hover">
<thead class="table-light">
<tr>
<th>Name</th>
<th>Client</th>
<th>Status</th>
<th>Start Date</th>
<th>End Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php if (empty($projects)): ?>
<tr>
<td colspan="6" class="text-center">No projects found.</td>
</tr>
<?php else: ?>
<?php foreach ($projects as $project): ?>
<tr>
<td><?php echo htmlspecialchars($project['name']); ?></td>
<td><?php echo htmlspecialchars($project['client_name'] ?? 'N/A'); ?></td>
<td><span class="badge bg-<?php echo strtolower(str_replace(' ', '-', $project['status'])) == 'in-progress' ? 'primary' : (strtolower($project['status']) == 'completed' ? 'success' : 'secondary'); ?>"><?php echo htmlspecialchars($project['status']); ?></span></td>
<td><?php echo htmlspecialchars($project['start_date']); ?></td>
<td><?php echo htmlspecialchars($project['end_date']); ?></td>
<td>
<!-- Actions like edit/delete can be added here -->
</td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
<!-- Add Project Modal -->
<div class="modal fade" id="addProjectModal" tabindex="-1" aria-labelledby="addProjectModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="addProjectModalLabel">Add New Project</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form action="add_project.php" method="POST">
<div class="mb-3">
<label for="name" class="form-label">Project Name</label>
<input type="text" class="form-control" id="name" name="name" required>
</div>
<div class="mb-3">
<label for="description" class="form-label">Description</label>
<textarea class="form-control" id="description" name="description"></textarea>
</div>
<div class="mb-3">
<label for="client_id" class="form-label">Client</label>
<select class="form-select" id="client_id" name="client_id">
<option value="">Select a client</option>
<?php foreach ($clients as $client): ?>
<option value="<?php echo $client['id']; ?>"><?php echo htmlspecialchars($client['name']); ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="mb-3">
<label for="status" class="form-label">Status</label>
<select class="form-select" id="status" name="status">
<option value="Not Started" selected>Not Started</option>
<option value="In Progress">In Progress</option>
<option value="Completed">Completed</option>
</select>
</div>
<div class="row">
<div class="col-md-6 mb-3">
<label for="start_date" class="form-label">Start Date</label>
<input type="date" class="form-control" id="start_date" name="start_date">
</div>
<div class="col-md-6 mb-3">
<label for="end_date" class="form-label">End Date</label>
<input type="date" class="form-control" id="end_date" name="end_date">
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="submit" class="btn btn-primary">Save Project</button>
</div>
</form>
</div>
</div>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>