philippurbschat.de/home/views/admin/user_form.php

126 lines
No EOL
8.2 KiB
PHP

<?php require_once __DIR__ . '/../inc/admin_header.php'; ?>
<?php
$baseUrl = rtrim(Config::get('BASE_URL', 'https://philippurbschat.de/'), '/');
$userProjects = $user['projects'] ?? [];
$modules = $allModules ?? ModuleService::getAll();
?>
<div class="max-w-4xl w-full mx-auto mt-6 px-4 sm:px-6">
<div class="mb-6 flex items-center justify-between">
<h1 class="text-2xl font-bold text-slate-100 font-mono tracking-tight flex items-center gap-2">
<span class="text-emerald-500">></span> <?= htmlspecialchars($title) ?>
</h1>
<a href="<?= $baseUrl ?>/admin/users" class="text-slate-500 hover:text-emerald-400 font-mono text-xs sm:text-sm transition-colors">
< Zurück zur Benutzerliste
</a>
</div>
<div class="bg-slate-900/80 border border-slate-700/50 rounded-2xl shadow-2xl p-6 sm:p-8 backdrop-blur-sm relative overflow-hidden">
<div class="absolute top-0 left-0 w-full h-1 bg-gradient-to-r from-transparent via-emerald-500/40 to-transparent"></div>
<form action="<?= $baseUrl ?>/admin/user_save" method="POST" class="space-y-6 relative z-10">
<input type="hidden" name="csrf_token" value="<?= Security::csrf() ?>">
<?php if ($user): ?>
<input type="hidden" name="id" value="<?= $user['id'] ?>">
<?php endif; ?>
<!-- User Credentials -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-slate-400 font-mono text-xs uppercase tracking-wider mb-2">Name</label>
<input type="text" name="name" value="<?= htmlspecialchars($user['name'] ?? '') ?>" required placeholder="z.B. Philipp" class="w-full bg-slate-950/80 border border-slate-700/80 rounded-xl p-3 text-slate-200 text-sm focus:outline-none focus:border-emerald-500 transition-colors font-mono">
</div>
<div>
<label class="block text-slate-400 font-mono text-xs uppercase tracking-wider mb-2">E-Mail (Login)</label>
<input type="email" name="email" value="<?= htmlspecialchars($user['email'] ?? '') ?>" required placeholder="user@beispiel.de" class="w-full bg-slate-950/80 border border-slate-700/80 rounded-xl p-3 text-slate-200 text-sm focus:outline-none focus:border-emerald-500 transition-colors font-mono">
</div>
<div>
<label class="block text-slate-400 font-mono text-xs uppercase tracking-wider mb-2">
Passwort <?= $user ? '<span class="text-[10px] text-slate-500">(Leer lassen für keine Änderung)</span>' : '' ?>
</label>
<input type="password" name="password" <?= $user ? '' : 'required' ?> minlength="8" placeholder="Mindestens 8 Zeichen" class="w-full bg-slate-950/80 border border-slate-700/80 rounded-xl p-3 text-slate-200 text-sm focus:outline-none focus:border-emerald-500 transition-colors font-mono">
</div>
<div>
<label class="block text-slate-400 font-mono text-xs uppercase tracking-wider mb-2">Status</label>
<select name="status" class="w-full bg-slate-950/80 border border-slate-700/80 rounded-xl p-3 text-slate-200 text-sm focus:outline-none focus:border-emerald-500 transition-colors font-mono">
<option value="Active" <?= ($user['status'] ?? 'Active') === 'Active' ? 'selected' : '' ?>>Active (Aktiviert)</option>
<option value="Inactive" <?= ($user['status'] ?? '') === 'Inactive' ? 'selected' : '' ?>>Inactive (Gesperrt)</option>
</select>
</div>
</div>
<!-- Admin Checkbox -->
<div class="flex items-center gap-3 bg-slate-950/60 p-4 rounded-xl border border-slate-800">
<input type="checkbox" name="is_admin" id="is_admin" value="1" <?= (!empty($user['is_admin'])) ? 'checked' : '' ?> class="w-4 h-4 accent-fuchsia-500 bg-slate-900 border-slate-700 rounded cursor-pointer" onchange="toggleAdminNotice(this)">
<div>
<label for="is_admin" class="text-slate-200 font-mono text-sm font-bold cursor-pointer">
Benutzer ist Administrator (Vollzugriff)
</label>
<p class="text-[11px] text-slate-500 font-mono">Admins haben automatisch Zugriff auf alle Module, Einstellungen und den Admin-Bereich.</p>
</div>
</div>
<!-- Module Permission Matrix -->
<div>
<div class="flex flex-wrap items-center justify-between mb-3 gap-2">
<div>
<label class="block text-slate-300 font-mono text-xs uppercase tracking-wider font-bold">
Modul-Berechtigungen
</label>
<p class="text-[11px] text-slate-500 font-mono">Wähle aus, auf welche Projekte dieser Benutzer Zugriff hat.</p>
</div>
<div class="flex items-center gap-2">
<button type="button" onclick="selectAllModules(true)" class="text-[11px] font-mono text-emerald-400 hover:text-emerald-300 px-2 py-1 bg-emerald-500/10 rounded border border-emerald-500/20 transition-colors cursor-pointer">Alle auswählen</button>
<button type="button" onclick="selectAllModules(false)" class="text-[11px] font-mono text-slate-400 hover:text-slate-300 px-2 py-1 bg-slate-800 rounded border border-slate-700 transition-colors cursor-pointer">Keine</button>
</div>
</div>
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 gap-3">
<?php foreach ($modules as $slug => $mod):
$isChecked = in_array($slug, $userProjects, true);
?>
<label class="flex items-start gap-3 p-3.5 bg-slate-950/70 border border-slate-800 hover:border-emerald-500/50 rounded-xl cursor-pointer transition-all group">
<input type="checkbox" name="projects[]" value="<?= htmlspecialchars($slug) ?>" <?= $isChecked ? 'checked' : '' ?> class="module-checkbox mt-1 w-4 h-4 accent-emerald-500">
<div class="flex-1 min-w-0">
<div class="flex items-center justify-between gap-1 mb-1">
<span class="text-sm font-bold text-slate-200 font-mono tracking-wider uppercase">
<?= htmlspecialchars($mod['name']) ?>
</span>
<span class="text-[10px] font-mono px-1.5 py-0.5 rounded bg-slate-900 border border-slate-800 text-slate-400 shrink-0">
<?= htmlspecialchars($mod['badge'] ?? $slug) ?>
</span>
</div>
<p class="text-[11px] text-slate-500 font-mono line-clamp-2"><?= htmlspecialchars($mod['description']) ?></p>
</div>
</label>
<?php endforeach; ?>
</div>
</div>
<!-- Submit Buttons -->
<div class="pt-4 border-t border-slate-800 flex items-center justify-between">
<a href="<?= $baseUrl ?>/admin/users" class="text-slate-500 hover:text-slate-300 font-mono text-xs uppercase tracking-wider">
Abbrechen
</a>
<button type="submit" class="bg-cyan-500/10 border border-cyan-500/30 text-cyan-400 hover:bg-cyan-500/20 hover:text-cyan-300 font-bold font-mono uppercase tracking-wider py-3 px-6 rounded-xl transition-all duration-300 shadow-[0_0_15px_rgba(6,182,212,0.15)] cursor-pointer">
Benutzer speichern →
</button>
</div>
</form>
</div>
</div>
<script>
function selectAllModules(check) {
document.querySelectorAll('.module-checkbox').forEach(function(cb) {
cb.checked = check;
});
}
function toggleAdminNotice(adminCheckbox) {
// If admin is checked, all checkboxes are accessible anyway
}
</script>
<?php require_once __DIR__ . '/../inc/admin_footer.php'; ?>