« Back to History
create_task.php
|
20260723_000646.php
Initial Domain Snapshot
Copy Code
<?php declare(strict_types=1); require_once __DIR__ . '/db.php'; if ($_SERVER['REQUEST_METHOD'] !== 'POST') { sendJsonResponse([ 'success' => false, 'message' => 'Invalid request method.', ], 405); } $input = array_merge($_POST, getJsonInput()); $title = trim((string) ($input['title'] ?? '')); $description = trim((string) ($input['description'] ?? '')); $status = trim((string) ($input['status'] ?? 'todo')); $priority = trim((string) ($input['priority'] ?? 'medium')); $dayStart = (int) ($input['day_start'] ?? 0); $dayEndRaw = trim((string) ($input['day_end'] ?? '')); $dayEnd = $dayEndRaw === '' ? null : (int) $dayEndRaw; $allowedStatuses = ['todo', 'in_progress', 'done']; $allowedPriorities = ['low', 'medium', 'high']; if ($title === '') { sendJsonResponse([ 'success' => false, 'message' => 'Title is required.', 'data' => new stdClass(), ], 422); } if (!in_array($status, $allowedStatuses, true)) { sendJsonResponse([ 'success' => false, 'message' => 'Invalid status.', 'data' => new stdClass(), ], 422); } if (!in_array($priority, $allowedPriorities, true)) { sendJsonResponse([ 'success' => false, 'message' => 'Invalid priority.', 'data' => new stdClass(), ], 422); } if ($dayStart < 1 || $dayStart > 31) { sendJsonResponse([ 'success' => false, 'message' => 'Start day must be between 1 and 31.', 'data' => new stdClass(), ], 422); } if ($dayEnd !== null && ($dayEnd < 1 || $dayEnd > 31)) { sendJsonResponse([ 'success' => false, 'message' => 'End day must be between 1 and 31.', 'data' => new stdClass(), ], 422); } if ($dayEnd !== null && $dayEnd < $dayStart) { sendJsonResponse([ 'success' => false, 'message' => 'End day must be greater than or equal to start day.', 'data' => new stdClass(), ], 422); } try { $connection = getDatabaseConnection(); $statement = $connection->prepare( 'INSERT INTO pull_tasks (title, description, status, priority, day_start, day_end, due_date) VALUES (:title, :description, :status, :priority, :day_start, :day_end, NULL)' ); $statement->execute([ ':title' => $title, ':description' => $description !== '' ? $description : null, ':status' => $status, ':priority' => $priority, ':day_start' => $dayStart, ':day_end' => $dayEnd, ]); $taskId = (int) $connection->lastInsertId(); $taskStatement = $connection->prepare( 'SELECT id, title, description, status, priority, day_start, day_end, due_date, created_at FROM pull_tasks WHERE id = :id' ); $taskStatement->execute([':id' => $taskId]); sendJsonResponse([ 'success' => true, 'message' => 'Task created', 'data' => [ 'task' => $taskStatement->fetch() ?: new stdClass(), ], ], 201); } catch (Throwable $exception) { sendJsonResponse([ 'success' => false, 'message' => $exception->getMessage(), 'data' => new stdClass(), ], 500); }