118 lines
5.0 KiB
PHP
118 lines
5.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
$pdo = db();
|
|
|
|
$task_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
|
|
|
|
if (!$task_id) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
// Fetch task details along with owner's full name and whatsapp number
|
|
$stmt = $pdo->prepare("SELECT t.*, u.full_name, u.whatsapp_number FROM tasks t JOIN users u ON t.user_id = u.id WHERE t.id = ?");
|
|
$stmt->execute([$task_id]);
|
|
$task = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
if (!$task) {
|
|
header("Location: index.php");
|
|
exit;
|
|
}
|
|
|
|
$is_owner = isset($_SESSION['user_id']) && $_SESSION['user_id'] == $task['user_id'];
|
|
|
|
$applications = [];
|
|
if ($is_owner) {
|
|
$stmt = $pdo->prepare("SELECT a.*, u.full_name FROM applications a JOIN users u ON a.user_id = u.id WHERE a.task_id = ? ORDER BY a.created_at DESC");
|
|
$stmt->execute([$task_id]);
|
|
$applications = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
$user_application = null;
|
|
if (isset($_SESSION['user_id']) && !$is_owner) {
|
|
$stmt = $pdo->prepare("SELECT * FROM applications WHERE task_id = ? AND user_id = ?");
|
|
$stmt->execute([$task_id, $_SESSION['user_id']]);
|
|
$user_application = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
$pageTitle = htmlspecialchars($task['title']);
|
|
require_once 'shared/header.php';
|
|
?>
|
|
|
|
<div class="container mt-5">
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-primary text-white">
|
|
<h1 class="card-title h3"><?php echo htmlspecialchars($task['title']); ?></h1>
|
|
</div>
|
|
<div class="card-body">
|
|
<p><strong>Posted by:</strong> <a href="profile.php?id=<?php echo $task['user_id']; ?>"><?php echo htmlspecialchars($task['full_name']); ?></a></p>
|
|
<p><strong>Budget:</strong> $<?php echo htmlspecialchars(number_format((float)$task['budget'], 2)); ?></p>
|
|
<hr>
|
|
<p class="card-text"><?php echo nl2br(htmlspecialchars($task['description'])); ?></p>
|
|
</div>
|
|
<div class="card-footer text-muted">
|
|
Posted on: <?php echo date('F j, Y, g:i a', strtotime($task['created_at'])); ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($is_owner): ?>
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3>Applicants</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if (empty($task['whatsapp_number'])): ?>
|
|
<div class="alert alert-warning">Please <a href="/profile.php?id=<?= $_SESSION['user_id'] ?>">add your WhatsApp number</a> to your profile before accepting applications.</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (empty($applications)): ?>
|
|
<p>No applications yet.</p>
|
|
<?php else: ?>
|
|
<ul class="list-group">
|
|
<?php foreach ($applications as $application): ?>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<div>
|
|
<a href="/profile.php?id=<?= $application['user_id'] ?>"><?= htmlspecialchars($application['full_name']) ?></a>
|
|
<span class="badge status-<?= htmlspecialchars($application['status']) ?>"><?= htmlspecialchars($application['status']) ?></span>
|
|
</div>
|
|
<?php if ($application['status'] === 'pending' && !empty($task['whatsapp_number'])): ?>
|
|
<a href="accept-application.php?id=<?= $application['id'] ?>" class="btn btn-success btn-sm">Accept</a>
|
|
<?php endif; ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php elseif (isset($_SESSION['user_id'])): ?>
|
|
<div class="card">
|
|
<div class="card-header">
|
|
<h3>My Application</h3>
|
|
</div>
|
|
<div class="card-body">
|
|
<?php if ($user_application): ?>
|
|
<?php if ($user_application['status'] === 'accepted'): ?>
|
|
<div class="alert alert-success">
|
|
<h4>Congratulations! Your application was accepted.</h4>
|
|
<p>Contact the task owner on WhatsApp: <strong><?= htmlspecialchars($task['whatsapp_number']) ?></strong></p>
|
|
</div>
|
|
<?php else: ?>
|
|
<p>Your application status is: <span class="badge status-<?= htmlspecialchars($user_application['status']) ?>"><?= htmlspecialchars($user_application['status']) ?></span></p>
|
|
<?php endif; ?>
|
|
<?php else: ?>
|
|
<form action="apply.php" method="POST">
|
|
<input type="hidden" name="task_id" value="<?= $task['id'] ?>">
|
|
<button type="submit" class="btn btn-primary">Apply Now</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php
|
|
require_once 'shared/footer.php';
|
|
?>
|