From dc54701498ee18c773831f5dbcc2308d3cea4e8b Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sat, 22 Nov 2025 14:03:37 +0000 Subject: [PATCH] N7 finsh finsh --- accept-application.php | 67 ++++++++++ assets/css/main.css | 43 +++++++ db/migrate.php | 40 ++++++ db/migrations.log | 4 + db/migrations/004_add_whatsapp_to_users.sql | 1 + .../005_add_status_to_applications.sql | 1 + delete-task.php | 50 ++++++++ index.php | 2 +- manage-tasks.php | 9 +- profile.php | 46 ++++++- task-details.php | 118 ++++++++++++++++++ 11 files changed, 373 insertions(+), 8 deletions(-) create mode 100644 accept-application.php create mode 100644 db/migrate.php create mode 100644 db/migrations.log create mode 100644 db/migrations/004_add_whatsapp_to_users.sql create mode 100644 db/migrations/005_add_status_to_applications.sql create mode 100644 delete-task.php create mode 100644 task-details.php diff --git a/accept-application.php b/accept-application.php new file mode 100644 index 0000000..bd4ca66 --- /dev/null +++ b/accept-application.php @@ -0,0 +1,67 @@ +beginTransaction(); + +try { + // Get application and task details, and ensure the current user owns the task + $stmt = $pdo->prepare( + "SELECT a.id as application_id, a.task_id, t.user_id as task_owner_id + FROM applications a + JOIN tasks t ON a.task_id = t.id + WHERE a.id = ? AND t.user_id = ?" + ); + $stmt->execute([$application_id, $user_id]); + $application_info = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$application_info) { + // If no result, either application doesn't exist or user doesn't own the task. + throw new Exception("Authorization failed or application not found."); + } + + $task_id = $application_info['task_id']; + + // 1. Update the accepted application's status to 'accepted' + $stmt = $pdo->prepare("UPDATE applications SET status = 'accepted' WHERE id = ?"); + $stmt->execute([$application_id]); + + // 2. Update the task's status to 'assigned' + $stmt = $pdo->prepare("UPDATE tasks SET status = 'assigned' WHERE id = ?"); + $stmt->execute([$task_id]); + + // 3. Reject all other pending applications for this task + $stmt = $pdo->prepare("UPDATE applications SET status = 'rejected' WHERE task_id = ? AND id != ? AND status = 'pending'"); + $stmt->execute([$task_id, $application_id]); + + // If all queries were successful, commit the transaction + $pdo->commit(); + + header("Location: /task-details.php?id=" . $task_id . "&message=application_accepted"); + exit; + +} catch (Exception $e) { + // If any query fails, roll back the transaction + $pdo->rollBack(); + error_log($e->getMessage()); + // Redirect with a generic error. Avoid exposing specific DB errors. + header("Location: /task-details.php?id=" . ($task_id ?? 0) . "&message=acceptance_failed"); + exit; +} diff --git a/assets/css/main.css b/assets/css/main.css index 5369c30..5c81af5 100644 --- a/assets/css/main.css +++ b/assets/css/main.css @@ -306,3 +306,46 @@ color: white; border-top: 1px solid #dee2e6; color: #6c757d; } + +/* Manage Task Card Improvements */ +.task-manage-card { + display: flex; + justify-content: space-between; + align-items: center; + transition: background-color 0.3s; +} + +.task-manage-card:hover { + background-color: #f8f9fa; +} + +.task-info h2 { + margin-top: 0; + margin-bottom: 0.25rem; +} + +.task-info h2 a { + text-decoration: none; + color: #0d6efd; +} + +.task-info p { + margin-bottom: 0; + color: #6c757d; +} + +.task-actions { + display: flex; + gap: 0.5rem; +} + +.btn-sm { + padding: 0.25rem 0.75rem; + font-size: 0.875rem; + border-radius: 0.25rem; +} + +.task-card h3 a { + text-decoration: none; + color: inherit; +} diff --git a/db/migrate.php b/db/migrate.php new file mode 100644 index 0000000..7a86657 --- /dev/null +++ b/db/migrate.php @@ -0,0 +1,40 @@ +exec($sql); + file_put_contents($log_file, $file . PHP_EOL, FILE_APPEND); + echo "Migration $file executed successfully.\n"; + } catch (PDOException $e) { + echo "Error executing migration $file: " . $e->getMessage() . "\n"; + // Stop on error + return; + } + } + } + } + + echo "All migrations are up to date.\n"; +} + +run_migrations(); + diff --git a/db/migrations.log b/db/migrations.log new file mode 100644 index 0000000..852c551 --- /dev/null +++ b/db/migrations.log @@ -0,0 +1,4 @@ +001_create_users_table.sql +002_create_tasks_table.sql +003_create_applications_table.sql +004_add_whatsapp_to_users.sql diff --git a/db/migrations/004_add_whatsapp_to_users.sql b/db/migrations/004_add_whatsapp_to_users.sql new file mode 100644 index 0000000..90194e8 --- /dev/null +++ b/db/migrations/004_add_whatsapp_to_users.sql @@ -0,0 +1 @@ +ALTER TABLE users ADD COLUMN whatsapp_number VARCHAR(255) DEFAULT NULL; \ No newline at end of file diff --git a/db/migrations/005_add_status_to_applications.sql b/db/migrations/005_add_status_to_applications.sql new file mode 100644 index 0000000..cff92c8 --- /dev/null +++ b/db/migrations/005_add_status_to_applications.sql @@ -0,0 +1 @@ +ALTER TABLE applications ADD COLUMN status VARCHAR(50) NOT NULL DEFAULT 'pending'; \ No newline at end of file diff --git a/delete-task.php b/delete-task.php new file mode 100644 index 0000000..67fbb7d --- /dev/null +++ b/delete-task.php @@ -0,0 +1,50 @@ +prepare('SELECT user_id FROM tasks WHERE id = :task_id'); + $stmt->bindParam(':task_id', $taskId, PDO::PARAM_INT); + $stmt->execute(); + $task = $stmt->fetch(PDO::FETCH_ASSOC); + + if (!$task || $task['user_id'] != $userId) { + header("Location: manage-tasks.php?error=unauthorized"); + exit(); + } + + // Delete applications for the task + $stmt = $pdo->prepare('DELETE FROM applications WHERE task_id = :task_id'); + $stmt->bindParam(':task_id', $taskId, PDO::PARAM_INT); + $stmt->execute(); + + // Delete the task + $stmt = $pdo->prepare('DELETE FROM tasks WHERE id = :task_id'); + $stmt->bindParam(':task_id', $taskId, PDO::PARAM_INT); + $stmt->execute(); + + header("Location: manage-tasks.php?success=task_deleted"); + exit(); + +} catch (PDOException $e) { + // Log the error and redirect + error_log("Delete task failed: " . $e->getMessage()); + header("Location: manage-tasks.php?error=db_error"); + exit(); +} diff --git a/index.php b/index.php index bc88c2e..08c1d1d 100644 --- a/index.php +++ b/index.php @@ -158,7 +158,7 @@ try {
-

+

Posted by: diff --git a/manage-tasks.php b/manage-tasks.php index 02dac87..492cea5 100644 --- a/manage-tasks.php +++ b/manage-tasks.php @@ -39,15 +39,18 @@ include 'shared/header.php';
- +
-

+

...

Status:
- +
+ Delete +
+
diff --git a/profile.php b/profile.php index dc35e54..c87fe75 100644 --- a/profile.php +++ b/profile.php @@ -11,9 +11,23 @@ if (!$profileId) { $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 = "Failed to update WhatsApp number."; + } +} + + // Fetch user information try { - $stmt = $pdo->prepare('SELECT id, full_name, email, created_at FROM users WHERE id = :id'); + $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) { @@ -56,11 +70,35 @@ include 'shared/header.php';

Member Since:

+ +
Your WhatsApp number has been updated successfully.
+ + +
+ + + + +
+
+

My Contact Information

+
+
+ + + This will only be shared with users whose applications you accept. +
+ +
+
+
+ +

Posted Tasks

-

has not posted any tasks yet.

+

has not posted any tasks yet.

-

+

Status:

Payout: $

@@ -80,7 +118,7 @@ include 'shared/header.php';

Completed Tasks

-

has not completed any tasks yet.

+

has not completed any tasks yet.

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'; +?> + +
+
+
+

+
+
+

Posted by:

+

Budget: $

+
+

+
+ +
+ + +
+
+

Applicants

+
+
+ +
Please add your WhatsApp number to your profile before accepting applications.
+ + + +

No applications yet.

+ +
    + +
  • +
    + + +
    + + Accept + +
  • + +
+ +
+
+ +
+
+

My Application

+
+
+ + +
+

Congratulations! Your application was accepted.

+

Contact the task owner on WhatsApp:

+
+ +

Your application status is:

+ + +
+ + +
+ +
+
+ +
+ + \ No newline at end of file