Files
intranet/web/intranet_repo/projects/kalli/kalli.php
T

218 lines
13 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/* Name: kalli.php
Beschreibung: Kalli: Eintragungsassistent */
require_once $_SERVER['DOCUMENT_ROOT'] . '/intranet_repo/general_files/initialise.php';
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/util/kalli_helpers.php';
$csrfToken = kalliCsrfToken();
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !kalliCsrfIsValid($_POST['csrf_token'] ?? null)) {
http_response_code(400);
exit('Ungültige Anfrage. Bitte laden Sie die Seite neu.');
}
$permissionGroups = is_array($groups ?? null) ? $groups : [];
$catalog = kalliBuildCatalog(kalliFetchCatalogRows($pdo), $permissionGroups);
$formValues = kalliFormValues($_SERVER['REQUEST_METHOD'] === 'POST' ? $_POST : []);
$formError = null;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
try {
$entry = kalliValidateEntry($_POST, $catalog);
$xlsxDirectory = intranet_env('CKAL_XLSX_DIR', '/data/ckal-xlsx');
kalliWriteCalendarFile($entry, is_array($user) ? $user : [], $xlsxDirectory);
header('Location: /intranet_repo/projects/intranet/index.php?kalli_success=1', true, 303);
exit();
} catch (InvalidArgumentException $exception) {
$formError = $exception->getMessage();
} catch (Throwable $exception) {
error_log('Kalli: XLSX-Erzeugung fehlgeschlagen: ' . $exception->getMessage());
$formError = 'Die Eintragung konnte nicht gespeichert werden. Bitte versuchen Sie es erneut oder kontaktieren Sie uns.';
}
}
?>
<!DOCTYPE html>
<html lang="de" dir="ltr">
<head>
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/intranet_repo/projects/_central/php/html_head.php'; ?>
<link rel="stylesheet" href="/intranet_repo/projects/_central/layouts/kalli.css">
<script src="/intranet_repo/projects/_central/scripts/kalli.js" defer></script>
</head>
<body class="theme-blue">
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/intranet_repo/projects/_central/php/header.php'; ?>
<?php include $g_phpSnippetsPath . 'overlay_message.php'; ?>
<div class="header_title ht_kalli text_white" id="header_title">
<span class="header_title_text">Kalli: Eintragungsassistent</span>
</div>
<div class="content" id="base">
<div class="kalli-wizard">
<div class="kalli-progress" aria-label="Fortschritt">
<?php foreach (['Terminart', 'Zeitraum', 'Informationen', 'Übersicht'] as $index => $label): ?>
<?php if ($index > 0): ?><div class="kalli-progress-line"></div><?php endif; ?>
<div class="kalli-progress-step<?= $index === 0 ? ' active' : '' ?>" data-step="<?= $index + 1 ?>">
<div class="kalli-progress-circle"><?= $index + 1 ?></div>
<span class="kalli-progress-label"><?= kalliHtml($label) ?></span>
</div>
<?php endforeach; ?>
</div>
<?php if ($formError !== null): ?>
<div class="kalli-validation-error" role="alert"><?= kalliHtml($formError) ?></div>
<?php endif; ?>
<form id="kalliForm" action="/intranet_repo/projects/kalli/kalli.php" method="post">
<input type="hidden" name="csrf_token" value="<?= kalliHtml($csrfToken) ?>">
<section class="kalli-step" id="kalliStep1">
<div class="kalli-modal-body">
<div class="kalli-section-title">Terminart auswählen</div>
<div class="kalli-category-grid">
<?php foreach ($catalog['categories'] as $category): ?>
<div class="kalli-category">
<div class="kalli-category-label"><?= kalliHtml($category['name']) ?></div>
<?php foreach ($category['types'] as $type): ?>
<?php $displayLabel = $type['display_label'] !== '' ? $type['display_label'] : $type['name']; ?>
<label class="kalli-radio-item">
<input type="radio" name="group" value="<?= kalliHtml($type['name']) ?>"<?= $formValues['group'] === $type['name'] ? ' checked' : '' ?>>
<span><?= kalliHtml($displayLabel) ?></span>
</label>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>
<?php if ($catalog['allow_custom']): ?>
<div class="kalli-custom-section">
<div class="kalli-category-label kalli-category-label--custom">Terminart nicht aufgelistet?</div>
<p class="kalli-custom-hint">Nur ausfüllen, wenn die Terminart oben nicht vorhanden ist.</p>
<div class="kalli-custom-options">
<label class="kalli-radio-item">
<input type="radio" name="group" value="<?= KALLI_CUSTOM_PUBLIC ?>" data-kalli-custom="1"<?= $formValues['group'] === KALLI_CUSTOM_PUBLIC ? ' checked' : '' ?>>
<span>Öffentlich</span>
</label>
<label class="kalli-radio-item">
<input type="radio" name="group" value="<?= KALLI_CUSTOM_INTERNAL ?>" data-kalli-custom="1"<?= $formValues['group'] === KALLI_CUSTOM_INTERNAL ? ' checked' : '' ?>>
<span>Intern</span>
</label>
</div>
<input class="kalli-field" type="text" name="userinput" id="kalliUserInput" value="<?= kalliHtml($formValues['userinput']) ?>" placeholder="Titel (nur für benutzerdefinierte Termine)">
</div>
<?php endif; ?>
</div>
<div class="kalli-modal-actions">
<div></div>
<div class="kalli-modal-actions-right">
<button type="button" class="kalli-btn kalli-btn-primary" data-kalli-next="2">Weiter</button>
</div>
</div>
</section>
<section class="kalli-step" id="kalliStep2" hidden>
<div class="kalli-modal-body">
<div class="kalli-section-title">Zeitraum festlegen</div>
<div class="kalli-field-grid">
<div class="kalli-field-group">
<label class="kalli-label" for="kalliDateS">Datum <span class="kalli-required">*</span></label>
<input class="kalli-field" type="date" name="date_s" id="kalliDateS" value="<?= kalliHtml($formValues['date_s']) ?>" aria-required="true">
</div>
<div class="kalli-field-group">
<label class="kalli-label" for="kalliDateE">Enddatum <span class="kalli-label-note">(falls mehrtägig)</span></label>
<input class="kalli-field" type="date" name="date_e" id="kalliDateE" value="<?= kalliHtml($formValues['date_e']) ?>">
</div>
<div class="kalli-field-group">
<label class="kalli-label" for="kalliTimeS">Zeit von <span class="kalli-label-note">(optional)</span></label>
<input class="kalli-field" type="time" name="time_s" id="kalliTimeS" value="<?= kalliHtml($formValues['time_s']) ?>">
</div>
<div class="kalli-field-group">
<label class="kalli-label" for="kalliTimeE">Zeit bis <span class="kalli-label-note">(optional)</span></label>
<input class="kalli-field" type="time" name="time_e" id="kalliTimeE" value="<?= kalliHtml($formValues['time_e']) ?>">
</div>
</div>
</div>
<div class="kalli-modal-actions">
<div class="kalli-modal-actions-left">
<button type="button" class="kalli-btn" data-kalli-prev="1">Zurück</button>
</div>
<div class="kalli-modal-actions-right">
<button type="button" class="kalli-btn kalli-btn-primary" data-kalli-next="3">Weiter</button>
</div>
</div>
</section>
<section class="kalli-step" id="kalliStep3" hidden>
<div class="kalli-modal-body">
<div class="kalli-section-title">Zusätzliche Informationen</div>
<div class="kalli-field-grid kalli-field-grid-single">
<div class="kalli-field-group">
<label class="kalli-label" for="kalliFurtherText">Textfeld <span class="kalli-label-note">(optional)</span></label>
<input class="kalli-field" type="text" name="further_text" id="kalliFurtherText" value="<?= kalliHtml($formValues['further_text']) ?>" placeholder="z.B. betreffende Person, etc.">
</div>
<div class="kalli-field-group">
<label class="kalli-label" for="kalliLocation">Ort <span class="kalli-label-note">(optional)</span></label>
<input class="kalli-field" type="text" name="location" id="kalliLocation" value="<?= kalliHtml($formValues['location']) ?>">
</div>
<div class="kalli-field-group">
<label class="kalli-label" for="kalliResponsibility">Verantwortliche/r <span class="kalli-label-note">(optional)</span></label>
<input class="kalli-field" type="text" name="responsibility" id="kalliResponsibility" value="<?= kalliHtml($formValues['responsibility']) ?>">
</div>
</div>
</div>
<div class="kalli-modal-actions">
<div class="kalli-modal-actions-left">
<button type="button" class="kalli-btn" data-kalli-prev="2">Zurück</button>
</div>
<div class="kalli-modal-actions-right">
<button type="button" class="kalli-btn kalli-btn-primary" data-kalli-next="4">Weiter</button>
</div>
</div>
</section>
<section class="kalli-step" id="kalliStep4" hidden>
<div class="kalli-modal-body">
<div class="kalli-section-title">Übersicht – Bitte prüfen Sie Ihre Eingaben</div>
<div class="kalli-summary">
<div class="kalli-summary-row">
<span class="kalli-summary-label">Terminart</span>
<span class="kalli-summary-value" id="sumGroup">–</span>
</div>
<div class="kalli-summary-row">
<span class="kalli-summary-label">Datum</span>
<span class="kalli-summary-value" id="sumDateS">–</span>
</div>
<?php foreach ([
['sumDateERow', 'Enddatum', 'sumDateE'],
['sumTimeSRow', 'Zeit von', 'sumTimeS'],
['sumTimeERow', 'Zeit bis', 'sumTimeE'],
['sumTextRow', 'Textfeld', 'sumText'],
['sumLocRow', 'Ort', 'sumLoc'],
['sumRespRow', 'Verantwortlich', 'sumResp'],
] as [$rowId, $label, $valueId]): ?>
<div class="kalli-summary-row" id="<?= $rowId ?>" hidden>
<span class="kalli-summary-label"><?= kalliHtml($label) ?></span>
<span class="kalli-summary-value" id="<?= $valueId ?>">–</span>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="kalli-modal-actions">
<div class="kalli-modal-actions-left">
<button type="button" class="kalli-btn" data-kalli-prev="3">Zurück</button>
</div>
<div class="kalli-modal-actions-right">
<button type="submit" name="submit" value="1" class="kalli-btn kalli-btn-submit">Eintragung absenden</button>
</div>
</div>
</section>
</form>
</div>
</div>
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/intranet_repo/projects/_central/php/footer.php'; ?>
</body>
</html>