36998-vm/index.php
Flatlogic Bot ce816a917b beta
2025-12-16 14:45:12 +00:00

159 lines
7.2 KiB
PHP

<?php
// Load database configuration and setup script
require_once 'db/config.php';
require_once 'db/setup.php';
// Run setup to ensure table exists
setup_database();
// Fetch all projects to display
$projects = [];
try {
$pdo = db();
$stmt = $pdo->query("SELECT id, name, client, start_date, status FROM projects ORDER BY created_at DESC");
$projects = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
// For a real app, log this error and show a friendly message.
$error_message = "Error fetching projects: " . $e->getMessage();
}
function getStatusClass($status) {
switch (strtolower($status)) {
case 'in progress':
return 'status-in-progress';
case 'completed':
return 'status-completed';
case 'not started':
default:
return 'status-not-started';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - ConstructApp</title>
<!-- SEO & Meta -->
<meta name="description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'A custom ERP for the construction industry.'); ?>">
<meta property="og:title" content="ConstructApp">
<meta property="og:description" content="<?php echo htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'Project management, accounting, and more.'); ?>">
<meta property="og:image" content="<?php echo htmlspecialchars($_SERVER['PROJECT_IMAGE_URL'] ?? ''); ?>">
<meta name="twitter:card" content="summary_large_image">
<!-- Bootstrap 5 CDN -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<!-- Bootstrap Icons -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<!-- Custom CSS -->
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg">
<div class="container">
<a class="navbar-brand" href="#">
<i class="bi bi-building"></i>
ConstructApp
</a>
</div>
</nav>
<main class="container main-content">
<div class="page-header d-flex justify-content-between align-items-center">
<h1>Projects</h1>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addProjectModal">
<i class="bi bi-plus-lg"></i> Add New Project
</button>
</div>
<?php if (isset($error_message)): ?>
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
<?php endif; ?>
<?php if (isset($_GET['success']) && $_GET['success'] == 'added'): ?>
<div class="alert alert-success alert-dismissible fade show" role="alert">
Project added successfully!
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
</div>
<?php endif; ?>
<div class="card">
<div class="card-body">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Project Name</th>
<th>Client</th>
<th>Start Date</th>
<th>Status</th>
<th></th>
</tr>
</thead>
<tbody>
<?php if (empty($projects)): ?>
<tr>
<td colspan="5" class="text-center py-5">
<p class="mb-0">No projects yet. Click "Add New Project" to get started!</p>
</td>
</tr>
<?php else: ?>
<?php foreach ($projects as $project): ?>
<tr>
<td><strong><?php echo htmlspecialchars($project['name']); ?></strong></td>
<td><?php echo htmlspecialchars($project['client']); ?></td>
<td><?php echo htmlspecialchars(date("M j, Y", strtotime($project['start_date']))); ?></td>
<td><span class="status <?php echo getStatusClass($project['status']); ?>"><?php echo htmlspecialchars($project['status']); ?></span></td>
<td><a href="#" class="btn btn-sm btn-outline-secondary"><i class="bi bi-pencil"></i></a></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
</tbody>
</table>
</div>
</div>
</div>
</main>
<!-- Add Project Modal -->
<div class="modal fade" id="addProjectModal" tabindex="-1" aria-labelledby="addProjectModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<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>
<form action="add_project.php" method="POST">
<div class="modal-body">
<div class="mb-3">
<label for="project_name" class="form-label">Project Name</label>
<input type="text" class="form-control" id="project_name" name="project_name" required>
</div>
<div class="mb-3">
<label for="client_name" class="form-label">Client Name</label>
<input type="text" class="form-control" id="client_name" name="client_name">
</div>
<div class="mb-3">
<label for="start_date" class="form-label">Start Date</label>
<input type="date" class="form-control" id="start_date" name="start_date" required>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-primary">Save Project</button>
</div>
</form>
</div>
</div>
</div>
<!-- Bootstrap 5 JS Bundle -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
</body>
</html>