180 lines
5.5 KiB
PHP
180 lines
5.5 KiB
PHP
<?php
|
|
$pageTitle = 'Welcome to CashTask';
|
|
require_once __DIR__ . '/shared/header.php';
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$message = $_GET['message'] ?? null;
|
|
$message_map = [
|
|
'already_applied' => [
|
|
'text' => 'You have already applied for this task.',
|
|
'type' => 'warning'
|
|
],
|
|
'owner_cannot_apply' => [
|
|
'text' => 'You cannot apply for your own task.',
|
|
'type' => 'warning'
|
|
],
|
|
'applied_successfully' => [
|
|
'text' => 'You have successfully applied for the task.',
|
|
'type' => 'success'
|
|
],
|
|
'application_failed' => [
|
|
'text' => 'There was an error submitting your application.',
|
|
'type' => 'danger'
|
|
]
|
|
];
|
|
|
|
// Fetch tasks from the database
|
|
try {
|
|
$search = $_GET['search'] ?? '';
|
|
$category = $_GET['category'] ?? '';
|
|
$location = $_GET['location'] ?? '';
|
|
|
|
$sql = "SELECT t.*, u.id as user_id_poster, u.full_name as user_name FROM tasks t JOIN users u ON t.user_id = u.id WHERE t.status = 'open'";
|
|
$params = [];
|
|
|
|
if (!empty($search)) {
|
|
$sql .= " AND (t.title LIKE :search OR t.description LIKE :search)";
|
|
$params[':search'] = '%' . $search . '%';
|
|
}
|
|
|
|
if (!empty($category)) {
|
|
$sql .= " AND t.category LIKE :category";
|
|
$params[':category'] = '%' . $category . '%';
|
|
}
|
|
|
|
if (!empty($location)) {
|
|
$sql .= " AND t.location LIKE :location";
|
|
$params[':location'] = '%' . $location . '%';
|
|
}
|
|
|
|
$sql .= " ORDER BY t.created_at DESC";
|
|
|
|
$stmt = db()->prepare($sql);
|
|
$stmt->execute($params);
|
|
$tasks = $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
// Handle database error gracefully
|
|
error_log($e->getMessage());
|
|
$tasks = [];
|
|
}
|
|
|
|
?>
|
|
|
|
<style>
|
|
.alert {
|
|
padding: 1rem;
|
|
margin-bottom: 1rem;
|
|
border-radius: 0.25rem;
|
|
}
|
|
.alert-success {
|
|
color: #155724;
|
|
background-color: #d4edda;
|
|
border-color: #c3e6cb;
|
|
}
|
|
.alert-warning {
|
|
color: #856404;
|
|
background-color: #fff3cd;
|
|
border-color: #ffeeba;
|
|
}
|
|
.alert-danger {
|
|
color: #721c24;
|
|
background-color: #f8d7da;
|
|
border-color: #f5c6cb;
|
|
}
|
|
.search-form {
|
|
display: flex;
|
|
gap: 1rem;
|
|
margin-bottom: 2rem;
|
|
}
|
|
.search-form input {
|
|
flex-grow: 1;
|
|
padding: 0.75rem;
|
|
border: 1px solid #ced4da;
|
|
border-radius: 0.25rem;
|
|
}
|
|
.task-grid {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
|
gap: 1.5rem;
|
|
}
|
|
|
|
.task-card {
|
|
background-color: #ffffff;
|
|
border-radius: 0.75rem;
|
|
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
|
|
padding: 1.5rem;
|
|
transition: all 0.2s ease-in-out;
|
|
}
|
|
|
|
.task-card:hover {
|
|
transform: translateY(-4px);
|
|
box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
.task-card h3 {
|
|
margin-top: 0;
|
|
font-size: 1.25rem;
|
|
}
|
|
|
|
.task-meta {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-top: 1rem;
|
|
color: #6c757d;
|
|
}
|
|
|
|
.task-payout {
|
|
font-size: 1.5rem;
|
|
font-weight: 700;
|
|
color: #14b8a6;
|
|
}
|
|
</style>
|
|
|
|
<?php if (isset($message_map[$message])): ?>
|
|
<div class="alert alert-<?= $message_map[$message]['type'] ?>">
|
|
<?= htmlspecialchars($message_map[$message]['text']) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<div class="hero-section" style="text-align: center; padding: 4rem 0;">
|
|
<h1 style="font-size: 3rem; font-weight: 700;"><?= __('hero_title') ?></h1>
|
|
<p style="font-size: 1.25rem; color: #6c757d; margin-bottom: 2rem;"><?= __('hero_subtitle') ?></p>
|
|
<a href="/signup.php" class="btn btn-primary"><?= __('post_task') ?></a>
|
|
</div>
|
|
|
|
<h2><?= __('available_tasks') ?></h2>
|
|
|
|
<form action="index.php" method="GET" class="search-form">
|
|
<input type="text" name="search" placeholder="<?= __('search_keywords') ?>" value="<?= htmlspecialchars($_GET['search'] ?? '') ?>">
|
|
<input type="text" name="category" placeholder="<?= __('search_category') ?>" value="<?= htmlspecialchars($_GET['category'] ?? '') ?>">
|
|
<input type="text" name="location" placeholder="<?= __('search_location') ?>" value="<?= htmlspecialchars($_GET['location'] ?? '') ?>">
|
|
<button type="submit" class="btn"><?= __('search') ?></button>
|
|
</form>
|
|
|
|
<div class="task-grid">
|
|
<?php if (empty($tasks)): ?>
|
|
<p><?= __('no_tasks_found_criteria') ?></p>
|
|
<?php else: ?>
|
|
<?php foreach ($tasks as $task): ?>
|
|
<div class="task-card">
|
|
<h3><a href="task-details.php?id=<?= $task['id'] ?>"><?= htmlspecialchars($task['title']) ?></a></h3>
|
|
<div class="task-meta">
|
|
<span><?= htmlspecialchars($task['category']) ?> • <?= htmlspecialchars($task['location']) ?></span>
|
|
<span><?= __('posted_by') ?>: <a href="profile.php?id=<?= $task['user_id_poster'] ?>"><strong><?= htmlspecialchars($task['user_name']) ?></strong></a></span>
|
|
</div>
|
|
<div class="task-payout">$<?= htmlspecialchars((string)$task['payout']) ?></div>
|
|
<?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] != $task['user_id']): ?>
|
|
<form action="apply.php" method="POST" style="margin-top: 1rem;">
|
|
<input type="hidden" name="task_id" value="<?= $task['id'] ?>">
|
|
<button type="submit" class="btn btn-primary"><?= __('apply') ?></button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<?php
|
|
require_once __DIR__ . '/shared/footer.php';
|
|
?>
|