| Current Path : /home/emeraadmin/public_html/4d695/ |
| Current File : /home/emeraadmin/public_html/4d695/rejecttask.php.tar |
home/emeraadmin/public_html/pages/subcontractor/rejecttask.php 0000644 00000002530 15170146727 0020751 0 ustar 00 <?php
session_start();
require_once '../../Classes/Database.php';
require_once '../../Service/TaskService.php';
require_once '../../Classes/Task.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['taskId']) && isset($_POST['companyId'])) {
$taskId = $_POST['taskId'];
$companyId = $_POST['companyId'];
$taskService = new TaskService();
$task = $taskService->getTaskByIdAsObject($taskId);
if ($task) {
$task->setAssignedTo(null);
$task->setIsAssigned(0);
// Get existing not accepted users
$temp = $task->getNotAcceptedUsers();
$notAcceptedUsers = array_filter(explode(',', $temp));
// Add the new companyId if not already in the list
if (!in_array($companyId, $notAcceptedUsers)) {
$notAcceptedUsers[] = $companyId;
}
// Convert the array back to a string
$task->setNotAcceptedUsers(implode(',', $notAcceptedUsers));
if ($taskService->rejectTask($task)) {
echo 'success';
} else {
echo 'error';
}
} else {
echo 'task_not_found';
}
} else {
echo 'invalid_data';
}
} else {
echo 'invalid_request';
}
?>