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 {
has not posted any tasks yet.
+has not posted any tasks yet.
has not completed any tasks yet.
+has not completed any tasks yet.
No applications yet.
+ +Contact the task owner on WhatsApp: = htmlspecialchars($task['whatsapp_number']) ?>
+Your application status is: = htmlspecialchars($user_application['status']) ?>
+ + + + +