36018-vm/manage-tasks.php
2025-11-22 13:52:11 +00:00

57 lines
1.8 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
$userId = $_SESSION['user_id'];
try {
$pdo = db();
$stmt = $pdo->prepare(
'SELECT id, title, description, status, created_at
FROM tasks
WHERE user_id = :user_id
ORDER BY created_at DESC'
);
$stmt->bindParam(':user_id', $userId, PDO::PARAM_INT);
$stmt->execute();
$tasks = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Database error: Could not retrieve your tasks.");
}
$pageTitle = "Manage Your Tasks";
include 'shared/header.php';
?>
<div class="container">
<div class="page-header">
<h1>Manage Your Tasks</h1>
<p>Here are the tasks you've posted. Click on a task to view and manage applications.</p>
</div>
<?php if (empty($tasks)): ?>
<div class="alert alert-info">You have not posted any tasks yet. <a href="post-task.php">Post one now!</a></div>
<?php else: ?>
<div class="tasks-list">
<?php foreach ($tasks as $task): ?>
<a href="manage-task.php?id=<?php echo $task['id']; ?>" class="task-manage-card">
<div class="task-info">
<h2><?php echo htmlspecialchars($task['title']); ?></h2>
<p><?php echo htmlspecialchars(substr($task['description'], 0, 100)); ?>...</p>
</div>
<div class="task-status-manage">
Status: <span class="status-badge status-<?php echo strtolower(htmlspecialchars($task['status'])); ?>"><?php echo htmlspecialchars($task['status']); ?></span>
</div>
</a>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<?php include 'shared/footer.php'; ?>