Files
intranet/web/intranet_repo/projects/contentpanel/insertion/util/view.php
T

64 lines
3.2 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
// Shared markup for the repeated fields and POST metadata; all values are escaped.
function contentpanel_field(string $name, string $label, array $attributes = [], bool $full = false): void
{
$attributes += ['type' => 'text', 'id' => $name, 'name' => $name, 'class' => 'sb-field'];
$required = !empty($attributes['required']);
?>
<div class="sb-field-group<?= $full ? ' sb-form-full' : '' ?>">
<label class="sb-label" for="<?= contentpanel_html($attributes['id']) ?>">
<?= contentpanel_html($label) ?>
<span class="<?= $required ? 'sb-required' : 'sb-optional' ?>"><?= $required ? '*' : '(optional)' ?></span>
</label>
<input<?php foreach ($attributes as $key => $value): ?>
<?php if ($value !== false): ?> <?= contentpanel_html($key) ?>="<?= contentpanel_html($value === true ? $key : $value) ?>"<?php endif; ?>
<?php endforeach; ?>>
</div>
<?php
}
function contentpanel_hidden(string $action, array $values = []): void
{
foreach (['csrf_token' => contentpanel_csrf_token(), 'action' => $action] + $values as $name => $value) {
echo '<input type="hidden" name="' . contentpanel_html($name) . '" value="' . contentpanel_html($value) . '">';
}
}
function contentpanel_flash(?array $flash, string $tab): void
{
if (($flash['tab'] ?? '') === $tab && !empty($flash['message'])) {
echo '<div role="status" class="sb-alert' . (($flash['type'] ?? '') === 'error' ? ' sb-alert-error' : '')
. '">' . contentpanel_html($flash['message']) . '</div>';
}
}
function contentpanel_entries(array $entries, string $action): void
{
?>
<div class="sb-entry-list">
<?php if (!$entries): ?><div class="sb-empty">Keine Einträge vorhanden.</div><?php endif; ?>
<?php foreach ($entries as $entry): ?>
<?php
$date = contentpanel_format_display_date($entry['date']);
if (!empty($entry['end_date'])) $date .= ' – ' . contentpanel_format_display_date($entry['end_date']);
$meta = implode(' · ', array_filter([
empty($entry['time']) ? '' : substr($entry['time'], 0, 5) . ' Uhr', $entry['location'] ?? '',
]));
?>
<div class="sb-entry">
<div class="sb-entry-info">
<div class="sb-entry-date"><?= contentpanel_html($date) ?></div>
<div class="sb-entry-title"><?= contentpanel_html($entry['title']) ?></div>
<?php if (!empty($entry['subtitle'])): ?><div class="sb-entry-subtitle"><?= contentpanel_html($entry['subtitle']) ?></div><?php endif; ?>
<?php if ($meta !== ''): ?><div class="sb-entry-meta"><?= contentpanel_html($meta) ?></div><?php endif; ?>
</div>
<form method="post" action="insert.php">
<?php contentpanel_hidden($action, ['id' => $entry['id']]); ?>
<button type="submit" class="sb-btn sb-btn-danger" data-confirm="Eintrag wirklich löschen?">Löschen</button>
</form>
</div>
<?php endforeach; ?>
</div>
<?php
}