36018-vm/task-details.php
Flatlogic Bot 893c62c0ac 77
2025-11-22 14:20:01 +00:00

119 lines
5.1 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 = __('task_details_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_label') ?>:</strong> <a href="profile.php?id=<?php echo $task['user_id']; ?>"><?php echo htmlspecialchars($task['full_name']); ?></a></p>
<p><strong><?= __('budget_label') ?>:</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_label') ?>: <?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_title') ?></h3>
</div>
<div class="card-body">
<?php if (empty($task['whatsapp_number'])): ?>
<div class="alert alert-warning"><?= __('add_whatsapp_prompt') ?></div>
<?php endif; ?>
<?php if (empty($applications)): ?>
<p><?= __('no_applicants_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_button') ?></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_title') ?></h3>
</div>
<div class="card-body">
<?php if ($user_application): ?>
<?php if ($user_application['status'] === 'accepted'): ?>
<div class="alert alert-success">
<h4><?= __('application_accepted_message') ?></h4>
<p><?= sprintf(__('contact_owner_whatsapp'), htmlspecialchars($task['whatsapp_number'])) ?></p>
</div>
<?php else: ?>
<p><?= __('application_status_label') ?>: <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') ?></button>
</form>
<?php endif; ?>
</div>
</div>
<?php endif; ?>
</div>
<?php
require_once 'shared/footer.php';
?>