Files
awo-hamburg-intranet/module/tasks/endpoints/user/submit_form.php

49 lines
1.3 KiB
PHP
Raw Normal View History

<?php
declare(strict_types=1);
require_once dirname(dirname(__DIR__)) . '/bootstrap.php';
if (!TaskCertRequest::isPost()) {
TaskCertResponse::error('Methode nicht erlaubt', 405);
}
$auth = TaskCertAuthContext::fromGlobals();
if (!$auth->isLoggedIn()) {
TaskCertResponse::error('Nicht eingeloggt', 401);
}
TaskCertCsrf::assertValidFromRequest(true);
$assignmentId = TaskCertRequest::postInt('assignment_id', 0);
$methodId = TaskCertRequest::postInt('method_id', 0);
$values = TaskCertRequest::postArray('values');
$files = [];
if (isset($_FILES['files']) && is_array($_FILES['files'])) {
$files = TaskUploadStorage::normalizeFilesInput($_FILES['files']);
}
if ($assignmentId <= 0 || $methodId <= 0) {
TaskCertResponse::error('Ungültige assignment_id oder method_id', 400);
}
try {
$services = task_cert_services();
$submissionId = $services['completionService']->submitForm($assignmentId, $methodId, $values, $files);
$redirectTo = TaskCertRequest::postString('redirect_to', '');
if ($redirectTo !== '') {
TaskCertResponse::redirect($redirectTo);
}
TaskCertResponse::json([
'success' => true,
'submission_id' => $submissionId,
]);
} catch (Throwable $throwable) {
TaskCertResponse::json([
'success' => false,
'error' => $throwable->getMessage(),
], 400);
}