First version, for githup; UNSTABLE, DO NOT USE!
This commit is contained in:
56
scripts/kampfrichter/check-user-freigaben.php
Normal file
56
scripts/kampfrichter/check-user-freigaben.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
if ( empty($_SESSION['access_granted_kampfrichter']) || $_SESSION['access_granted_kampfrichter'] !== true || empty($_SESSION['passcodekampfrichter_id']) || intval($_SESSION['passcodekampfrichter_id']) < 1 ) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ========== Access control setup ==========
|
||||
$userid = intval($_SESSION['passcodekampfrichter_id'] ?? 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 it’s 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;
|
||||
Reference in New Issue
Block a user