rpg-westreiche/westreiche_website/views/admin_user_form.php

104 lines
5.3 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
/** @var array|null $target */
/** @var array $values */
/** @var string $error */
/** @var array|null $lastInvite */
/** @var array|null $activeInvite */
$isNew = $target === null;
$action = $isNew ? url('/admin/users/new') : url('/admin/users/' . (int) $target['id']);
?>
<div class="page-head">
<div>
<h1><?= $isNew ? 'Konto anlegen' : 'Konto: ' . e((string) $target['username']) ?></h1>
<p class="lede">
Entweder ein Startpasswort vergeben oder eine Einladung erzeugen – dann setzt die Person
ihr Passwort selbst über den Link.
</p>
</div>
<a class="btn btn-ghost" href="<?= e(url('/admin/users')) ?>">Zur Übersicht</a>
</div>
<?php if ($error !== ''): ?>
<p class="alert alert-error"><?= e($error) ?></p>
<?php endif; ?>
<section class="panel">
<form method="post" action="<?= e($action) ?>" class="form-grid">
<?= csrf_field() ?>
<div class="grid-3">
<label class="field">
<span>Benutzername</span>
<input type="text" name="username" value="<?= e((string) $values['username']) ?>" required minlength="3" maxlength="60" autocomplete="off">
</label>
<label class="field">
<span>E-Mail (optional, auch Login)</span>
<input type="email" name="email" value="<?= e((string) $values['email']) ?>" maxlength="190" autocomplete="off">
</label>
<label class="field">
<span>Anzeigename</span>
<input type="text" name="display_name" value="<?= e((string) $values['display_name']) ?>" maxlength="120">
</label>
<label class="field">
<span>Rolle</span>
<select name="role">
<option value="user"<?= $values['role'] === 'user' ? ' selected' : '' ?>>Spieler</option>
<option value="admin"<?= $values['role'] === 'admin' ? ' selected' : '' ?>>Spielleiter (alle Rechte)</option>
</select>
</label>
<?php if (!$isNew): ?>
<label class="field">
<span>Status</span>
<select name="status">
<option value="active"<?= ($values['status'] ?? 'active') === 'active' ? ' selected' : '' ?>>aktiv</option>
<option value="disabled"<?= ($values['status'] ?? '') === 'disabled' ? ' selected' : '' ?>>deaktiviert</option>
</select>
</label>
<?php endif; ?>
<label class="field">
<span><?= $isNew ? 'Startpasswort (optional)' : 'Neues Passwort (optional)' ?></span>
<input type="password" name="password" minlength="8" autocomplete="new-password">
</label>
</div>
<?php if ($isNew): ?>
<label class="field" style="grid-auto-flow:column; align-items:center; gap:.5rem; justify-content:start">
<input type="checkbox" name="send_invite" value="1" checked>
<span style="margin:0">Statt Passwort eine Einladung erzeugen (empfohlen)</span>
</label>
<?php endif; ?>
<div class="actions">
<button class="btn btn-primary" type="submit"><?= $isNew ? 'Konto anlegen' : 'Speichern' ?></button>
</div>
</form>
</section>
<?php if (!$isNew): ?>
<section class="panel">
<h2>Einladung / Passwort zurücksetzen</h2>
<?php if (is_array($lastInvite)): ?>
<p class="muted"><?php if (!empty($lastInvite['sent'])): ?>Per E-Mail an <strong><?= e((string) $lastInvite['to']) ?></strong> gesendet – <?php else: ?>Neuer Link<?php endif; ?>gültig bis
<?= e((new DateTimeImmutable((string) $lastInvite['expires_at'], new DateTimeZone('UTC')))->setTimezone(new DateTimeZone('Europe/Berlin'))->format('d.m.Y H:i')) ?> Uhr:</p>
<div class="copy-box"><span id="invite-url"><?= e((string) $lastInvite['url']) ?></span>
<button class="btn btn-small" type="button" data-copy="#invite-url">Kopieren</button>
</div>
<?php elseif (is_array($activeInvite ?? null)): ?>
<p class="muted">Es ist bereits ein Einladungslink offen (bis
<?= e((new DateTimeImmutable((string) $activeInvite['expires_at'], new DateTimeZone('UTC')))->setTimezone(new DateTimeZone('Europe/Berlin'))->format('d.m.Y H:i')) ?> Uhr).
Der Link selbst ist aus Sicherheitsgründen nicht gespeichert – ein neuer macht den alten ungültig.</p>
<?php endif; ?>
<form method="post" action="<?= e(url('/admin/users/' . (int) $target['id'] . '/invite')) ?>">
<?= csrf_field() ?>
<button class="btn" type="submit" data-confirm="Neuen Einladungslink erzeugen? Das bisherige Passwort wird ungültig.">
Einladungslink erzeugen
</button>
</form>
<?php if (auth_user() !== null && (int) auth_user()['id'] !== (int) $target['id']): ?>
<hr class="divider">
<form method="post" action="<?= e(url('/admin/users/' . (int) $target['id'] . '/delete')) ?>">
<?= csrf_field() ?>
<button class="btn btn-danger" type="submit" data-confirm="Konto samt Charakteren löschen?">Konto löschen</button>
</form>
<?php endif; ?>
</section>
<?php endif; ?>