94 lines
2.8 KiB
PHP
94 lines
2.8 KiB
PHP
<?php
|
|
session_start();
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
require_once 'db/config.php';
|
|
require_once 'header.php';
|
|
|
|
// Function to run migrations
|
|
function run_migrations() {
|
|
try {
|
|
$pdo = db();
|
|
$migration_dir = 'db/migrations';
|
|
$files = glob($migration_dir . '/*.sql');
|
|
foreach ($files as $file) {
|
|
try {
|
|
$sql = file_get_contents($file);
|
|
$pdo->exec($sql);
|
|
} catch (PDOException $e) {
|
|
// Ignore errors, like column already exists
|
|
}
|
|
}
|
|
} catch (PDOException $e) {
|
|
// In a real app, you'd log this error.
|
|
// For now, we'll just output a generic error.
|
|
die("Database migration failed: " . $e->getMessage());
|
|
}
|
|
}
|
|
|
|
// Run migrations
|
|
run_migrations();
|
|
|
|
// Fetch tasks
|
|
$tasks = [];
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT * FROM tasks WHERE user_id = ? ORDER BY created_at DESC");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$tasks = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
echo '<div class="alert alert-danger">Database error: Could not fetch tasks.</div>';
|
|
}
|
|
|
|
$tasks_by_status = [
|
|
'To Do' => [],
|
|
'In Progress' => [],
|
|
'Done' => []
|
|
];
|
|
|
|
foreach ($tasks as $task) {
|
|
if (isset($tasks_by_status[$task['status']])) {
|
|
$tasks_by_status[$task['status']][] = $task;
|
|
}
|
|
}
|
|
|
|
?>
|
|
|
|
<?php if (isset($_GET['success'])) : ?>
|
|
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
|
Task added successfully!
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php if (isset($_GET['error'])) : ?>
|
|
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
|
<strong>Error:</strong> <?php echo htmlspecialchars($_GET['error']); ?>
|
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
|
|
<div class="kanban-board">
|
|
<?php foreach ($tasks_by_status as $status => $tasks_in_status): ?>
|
|
<div id="kanban-column-<?php echo str_replace(' ', '-', strtolower($status)); ?>" class="kanban-column" data-status="<?php echo htmlspecialchars($status); ?>">
|
|
<h3><?php echo htmlspecialchars($status); ?></h3>
|
|
<?php foreach ($tasks_in_status as $task): ?>
|
|
<div class="task-card" data-id="<?php echo $task['id']; ?>">
|
|
<h5><?php echo htmlspecialchars($task['title']); ?></h5>
|
|
<p><?php echo htmlspecialchars($task['description']); ?></p>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php if (empty($tasks_in_status)): ?>
|
|
<div class="text-center text-muted">No tasks yet.</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
|
|
<?php
|
|
require_once 'footer.php';
|
|
?>
|