42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
|
/**
|
|
* Vorschau "Ansicht als Gruppe" starten und beenden (includes/permissions.php, role_preview()).
|
|
* Prueft die echten Rechte - waehrend der Vorschau hat man roles.manage ja gerade nicht.
|
|
*/
|
|
define('ROLE_PREVIEW_ALLOW_POST', true);
|
|
require_once __DIR__ . '/../includes/bootstrap.php';
|
|
require_login();
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
redirect('/admin/roles.php');
|
|
}
|
|
verify_csrf();
|
|
|
|
$action = (string) ($_POST['action'] ?? '');
|
|
|
|
if ($action === 'stop') {
|
|
unset($_SESSION['role_preview']);
|
|
set_flash('success', 'Vorschau beendet - du siehst die Website wieder mit deinen eigenen Rechten.');
|
|
redirect('/admin/roles.php#vorschau');
|
|
}
|
|
|
|
if (!role_preview_can()) {
|
|
show_not_found();
|
|
}
|
|
|
|
if ($action === 'start') {
|
|
$ids = array_values(array_unique(array_filter(array_map('intval', (array) ($_POST['roles'] ?? [])))));
|
|
if ($ids) {
|
|
$placeholders = implode(',', array_fill(0, count($ids), '?'));
|
|
$stmt = db()->prepare("SELECT id FROM roles WHERE id IN ($placeholders)");
|
|
$stmt->execute($ids);
|
|
$ids = array_map('intval', $stmt->fetchAll(PDO::FETCH_COLUMN));
|
|
}
|
|
$_SESSION['role_preview'] = ['user_id' => (int) current_user()['id'], 'roles' => $ids, 'started' => time()];
|
|
set_flash('success', $ids
|
|
? 'Vorschau gestartet - so sieht die Website mit diesen Gruppen aus.'
|
|
: 'Vorschau gestartet - so sieht die Website für ein freigeschaltetes Konto ohne Gruppe aus.');
|
|
redirect('/dashboard.php');
|
|
}
|
|
|
|
set_flash('error', 'Unbekannte Aktion.');
|
|
redirect('/admin/roles.php');
|