140 lines
6.2 KiB
PHP
140 lines
6.2 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
$profileId = $_GET['id'] ?? null;
|
|
|
|
if (!$profileId) {
|
|
header("Location: index.php");
|
|
exit();
|
|
}
|
|
|
|
$pdo = db();
|
|
|
|
// Handle WhatsApp number update
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_SESSION['user_id']) && $_SESSION['user_id'] == $profileId) {
|
|
$whatsapp_number = $_POST['whatsapp_number'] ?? '';
|
|
try {
|
|
$stmt = $pdo->prepare('UPDATE users SET whatsapp_number = :whatsapp_number WHERE id = :id');
|
|
$stmt->execute([':whatsapp_number' => $whatsapp_number, ':id' => $profileId]);
|
|
header("Location: profile.php?id=$profileId&message=whatsapp_updated");
|
|
exit();
|
|
} catch (PDOException $e) {
|
|
$update_error = "whatsapp_update_failed";
|
|
}
|
|
}
|
|
|
|
|
|
// Fetch user information
|
|
try {
|
|
$stmt = $pdo->prepare('SELECT id, full_name, email, created_at, whatsapp_number FROM users WHERE id = :id');
|
|
$stmt->execute([':id' => $profileId]);
|
|
$profileUser = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
die("Database error: Could not retrieve user profile.");
|
|
}
|
|
|
|
if (!$profileUser) {
|
|
// Handle user not found
|
|
header("Location: index.php?message=user_not_found");
|
|
exit();
|
|
}
|
|
|
|
// Fetch tasks posted by the user
|
|
try {
|
|
$stmt = $pdo->prepare('SELECT * FROM tasks WHERE user_id = :user_id ORDER BY created_at DESC');
|
|
$stmt->execute([':user_id' => $profileId]);
|
|
$postedTasks = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
die("Database error: Could not retrieve posted tasks.");
|
|
}
|
|
|
|
// Fetch tasks the user has completed (i.e., their application was accepted)
|
|
try {
|
|
$stmt = $pdo->prepare(
|
|
'SELECT t.* FROM tasks t JOIN applications a ON t.id = a.task_id WHERE a.user_id = :user_id AND a.status = \'accepted\' ORDER BY t.created_at DESC'
|
|
);
|
|
$stmt->execute([':user_id' => $profileId]);
|
|
$completedTasks = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
die("Database error: Could not retrieve completed tasks.");
|
|
}
|
|
|
|
$pageTitle = sprintf(__('profile_title'), htmlspecialchars($profileUser['full_name']));
|
|
include 'shared/header.php';
|
|
?>
|
|
|
|
<div class="container profile-page">
|
|
<div class="page-header">
|
|
<h1><?php echo htmlspecialchars($profileUser['full_name']); ?></h1>
|
|
<p><strong><?= sprintf(__('member_since'), date('F j, Y', strtotime($profileUser['created_at']))) ?></strong></p>
|
|
</div>
|
|
|
|
<?php if (isset($_GET['message']) && $_GET['message'] === 'whatsapp_updated'): ?>
|
|
<div class="alert alert-success"><?= __('whatsapp_updated_success') ?></div>
|
|
<?php endif; ?>
|
|
<?php if (isset($update_error)): ?>
|
|
<div class="alert alert-danger"><?= htmlspecialchars(__($update_error)) ?></div>
|
|
<?php endif; ?>
|
|
|
|
|
|
<?php if (isset($_SESSION['user_id']) && $_SESSION['user_id'] == $profileUser['id']): ?>
|
|
<div class="card mb-4" style="margin-bottom: 2rem; background-color: #fff; border: 1px solid #dee2e6; border-radius: 0.75rem; padding: 1.5rem; box-shadow: 0 2px 4px rgba(0,0,0,0.05);">
|
|
<div class="card-body">
|
|
<h2 class="card-title" style="font-size: 1.75rem; margin-bottom: 1.5rem; border-bottom: 2px solid #dee2e6; padding-bottom: 0.5rem; color: #0d6efd;"><?= __('my_contact_info') ?></h2>
|
|
<form action="profile.php?id=<?= $profileUser['id'] ?>" method="POST">
|
|
<div class="form-group">
|
|
<label for="whatsapp_number"><?= __('whatsapp_number_label') ?></label>
|
|
<input type="text" class="form-control" id="whatsapp_number" name="whatsapp_number" value="<?= htmlspecialchars($profileUser['whatsapp_number'] ?? '') ?>" placeholder="<?= __('whatsapp_placeholder') ?>">
|
|
<small class="form-text text-muted"><?= __('whatsapp_help_text') ?></small>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary" style="margin-top: 1rem;"><?= __('save_button') ?></button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
|
|
<div class="profile-section">
|
|
<h2><?= __('posted_tasks') ?></h2>
|
|
<?php if (empty($postedTasks)): ?>
|
|
<p><?= sprintf(__('no_posted_tasks'), htmlspecialchars($profileUser['full_name'])) ?></p>
|
|
<?php else: ?>
|
|
<div class="task-list">
|
|
<?php foreach ($postedTasks as $task):
|
|
// Check if task status is not null before using it in strtolower
|
|
$taskStatus = $task['status'] ?? 'unknown';
|
|
?>
|
|
<div class="task-card-profile">
|
|
<h4><a href="task-details.php?id=<?php echo $task['id']; ?>"><?php echo htmlspecialchars($task['title']); ?></a></h4>
|
|
<p><strong><?= __('task_status') ?>:</strong> <span class="status-badge status-<?php echo strtolower(htmlspecialchars($taskStatus)); ?>"><?php echo htmlspecialchars($taskStatus); ?></span></p>
|
|
<p><strong><?= __('task_payout') ?>:</strong> $<?php echo htmlspecialchars($task['payout']); ?></p>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<div class="profile-section">
|
|
<h2><?= __('completed_tasks') ?></h2>
|
|
<?php if (empty($completedTasks)): ?>
|
|
<p><?= sprintf(__('no_completed_tasks'), htmlspecialchars($profileUser['full_name'])) ?></p>
|
|
<?php else: ?>
|
|
<div class="task-list">
|
|
<?php foreach ($completedTasks as $task):
|
|
// Check if task status is not null before using it in strtolower
|
|
$taskStatus = $task['status'] ?? 'unknown';
|
|
?>
|
|
<div class="task-card-profile">
|
|
<h4><?php echo htmlspecialchars($task['title']); ?></h4>
|
|
<p><strong><?= __('task_status') ?>:</strong> <span class="status-badge status-<?php echo strtolower(htmlspecialchars($taskStatus)); ?>"><?php echo htmlspecialchars($taskStatus); ?></span></p>
|
|
<p><strong><?= __('task_payout') ?>:</strong> $<?php echo htmlspecialchars($task['payout']); ?></p>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php include 'shared/footer.php'; ?>
|