| Current Path : /home/emeraadmin/public_html/4d695/ |
| Current File : /home/emeraadmin/public_html/4d695/mark_subtask_as_completed.php.tar |
home/emeraadmin/public_html/pages/emeraadmin/mark_subtask_as_completed.php 0000644 00000003014 15167742127 0023231 0 ustar 00 <?php
// Enable error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
require_once '../../Classes/Database.php';
require_once '../../Service/SubtaskService.php';
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Decode the JSON input to get the subtask IDs
$input = json_decode(file_get_contents('php://input'), true);
if (isset($input['subtaskIds']) && is_array($input['subtaskIds'])) {
$subtaskIds = $input['subtaskIds'];
$errors = [];
// Create TaskService instance
$SubtaskService = new SubtaskService();
// Iterate over the subtask IDs and mark them as complete
foreach ($subtaskIds as $subtaskId) {
$result = $SubtaskService->markSubtaskAsComplete($subtaskId);
if (!$result) {
$errors[] = "Failed to mark subtask ID: $subtaskId as complete";
}
}
if (empty($errors)) {
$response = [
'status' => 'success',
'subtaskIds' => $subtaskIds
];
} else {
$response = [
'status' => 'error',
'message' => 'Some subtasks could not be marked as complete.',
'errors' => $errors
];
}
header('Content-Type: application/json');
echo json_encode($response);
} else {
echo json_encode(['status' => 'error', 'message' => 'Invalid input']);
}
} else {
echo 'invalid_request';
}
?>