71 lines
2.2 KiB
PHP
71 lines
2.2 KiB
PHP
<?php
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
|
|
session_start();
|
|
|
|
require_once 'db/config.php';
|
|
|
|
$message = '';
|
|
if (isset($_SESSION['message'])) {
|
|
$message = $_SESSION['message'];
|
|
unset($_SESSION['message']);
|
|
}
|
|
|
|
$pdo = db();
|
|
|
|
// Create table if it doesn't exist
|
|
$pdo->exec("CREATE TABLE IF NOT EXISTS projects (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
title VARCHAR(255) NOT NULL,
|
|
description TEXT,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
);");
|
|
|
|
$stmt = $pdo->query("SELECT * FROM projects ORDER BY created_at DESC");
|
|
$projects = $stmt->fetchAll();
|
|
|
|
include 'includes/header.php';
|
|
?>
|
|
|
|
<div class="container py-5">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h2">Projects</h1>
|
|
<a href="create_project.php" class="btn btn-primary">Create New Project</a>
|
|
</div>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="alert alert-success">
|
|
<?php echo htmlspecialchars($message); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (count($projects) > 0): ?>
|
|
<div class="row">
|
|
<?php foreach ($projects as $project): ?>
|
|
<div class="col-md-4 mb-4">
|
|
<div class="card h-100">
|
|
<div class="card-body">
|
|
<h5 class="card-title"><?php echo htmlspecialchars($project['title']); ?></h5>
|
|
<p class="card-text"><?php echo nl2br(htmlspecialchars($project['description'])); ?></p>
|
|
</div>
|
|
<div class="card-footer text-muted">
|
|
<small>Created on: <?php echo date('M d, Y', strtotime($project['created_at'])); ?></small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<div class="card text-center">
|
|
<div class="card-body">
|
|
<p class="card-text">No projects found. Get started by creating a new one!</p>
|
|
<a href="create_project.php" class="btn btn-primary">Create a Project</a>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php include 'includes/footer.php'; ?>
|