Files
WKVS/scripts/kampfrichter/check-user-freigaben.php

50 lines
1.5 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
// ========== Access control setup ==========
$userid = intval($_SESSION['user_id_kampfrichter'] ?? 0);
$arrayfreigaben = [];
if ($userid > 0) {
$stmt = $mysqli->prepare("SELECT freigabe, username FROM $tableInternUsers WHERE id = ?");
$stmt->bind_param("s", $userid);
$stmt->execute();
$result = $stmt->get_result();
if ($result) {
$dbarray = $result->fetch_assoc(); // $programme is an array
}
$freigabe_json = $dbarray['freigabe'];
$username = $dbarray['username'];
$stmt->close();
// Only decode if its a string
if (is_string($freigabe_json) && $freigabe_json !== '') {
$arrayfreigaben = json_decode($freigabe_json, true) ?: [];
$arrayfreigaben = $arrayfreigaben['freigabenKampfrichter'] ?? [];
}
}
if (!empty($arrayfreigaben)) {
$key = array_search('admin', $arrayfreigaben, true);
if ($key !== false) {
unset($arrayfreigaben[$key]);
array_unshift($arrayfreigaben, 'admin');
$arrayfreigaben = array_values($arrayfreigaben);
}
$selectedfreigabe = $_SESSION['selectedFreigabeKampfrichter'] ?? $arrayfreigaben[0];
if (!in_array($selectedfreigabe, $arrayfreigaben, true)) {
$selectedfreigabe = $arrayfreigaben[0];
}
$_SESSION['selectedFreigabeKampfrichter'] = $selectedfreigabe;
} else {
echo 'Keine gültigen Freigaben! Sie wurden abgemeldet.';
$_SESSION['access_granted_kampfrichter'] = false;
$_SESSION['logoDisplay'] = true;
exit;
}
$selecteduser = $selectedfreigabe;