First version, for githup; UNSTABLE, DO NOT USE!
This commit is contained in:
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
session_start();
|
||||
|
||||
if (empty($_SESSION['access_granted_kampfrichter']) || $_SESSION['access_granted_kampfrichter'] !== true || empty($_SESSION['passcodekampfrichter_id']) || $_SESSION['passcodekampfrichter_id'] < 1) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
// ---------- Get and sanitize input ----------
|
||||
$id = intval($_POST['personId']) ?? 0;
|
||||
$geraetId = intval($_POST['geraetId']) ?? 0;
|
||||
$jahr = isset($_POST['jahr']) ? preg_replace('/[^0-9]/', '', $_POST['jahr']) : '';
|
||||
$anfrageType = $_POST['type'] ?? '';
|
||||
|
||||
$allowedTypes = ["neu", "start", "result"];
|
||||
|
||||
if (!in_array($anfrageType, $allowedTypes)) {
|
||||
echo json_encode(['success' => false, 'message' => "Operation nicht gestattet."]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($anfrageType !== "start" && ($id < 1 || intval($jahr) < 1)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Personen ID ist nicht valide.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($geraetId < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid discipline']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$type = 'kr';
|
||||
|
||||
$data = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($data['success'] === false){
|
||||
echo json_encode(['success' => false, 'message' => $data['message']]);
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
$stmt = $mysqli->prepare("SELECT `name` FROM $tableGeraete WHERE `id` = ? LIMIT 1");
|
||||
$stmt->bind_param("s", $geraetId);
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $stmt->get_result();
|
||||
|
||||
if ($result->num_rows === 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid discipline']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$geraetData = $result->fetch_assoc();
|
||||
$geraetName = $geraetData['name'];
|
||||
|
||||
$stmt->close();
|
||||
|
||||
$folder = realpath($baseDir . '/displays/json');
|
||||
|
||||
if ($folder === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Could not find displays folder.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$filename = 'display_' . strtolower($geraetName) . '.json';
|
||||
$filepath = $folder . '/' . $filename;
|
||||
|
||||
if (!is_writable($folder)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Folder not writable']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$jsonString = file_get_contents($filepath);
|
||||
|
||||
// decode JSON, fallback to empty array if invalid
|
||||
$oldjson = json_decode($jsonString, true) ?? [];
|
||||
|
||||
switch ($anfrageType) {
|
||||
case "neu":
|
||||
$stmt = $mysqli->prepare("SELECT * FROM `$tableTurnerinnen` WHERE id = ? LIMIT 1");
|
||||
$stmt->bind_param("i", $id);
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$rows = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
if (!$rows || !is_array($rows) || count($rows) !== 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Row fetch failed']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$row = $rows[0];
|
||||
|
||||
// safely get value, default 0 if missing
|
||||
$olduniqueid = $oldjson['uniqueid'] ?? 0;
|
||||
$uniqueid = $olduniqueid + 1;
|
||||
|
||||
$data = ["noteLinks" => '',
|
||||
"noteRechts" => '',
|
||||
"id" => $id,
|
||||
"name" => $row['name'],
|
||||
"vorname" => $row['vorname'],
|
||||
"programm" => $row['programm'],
|
||||
"verein" => $row['verein'],
|
||||
"start" => false,
|
||||
"musik" => 'nan',
|
||||
"uniqueid" => $uniqueid];
|
||||
$jsonData = json_encode($data);
|
||||
break;
|
||||
case "start":
|
||||
if (array_key_exists("start", $oldjson)) {
|
||||
$oldjson["start"] = true;
|
||||
|
||||
$jsonData = json_encode($oldjson);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => 'Turnerin nicht auf Display '.json_encode($oldjson).'; '.$jsonString]);
|
||||
exit;
|
||||
}
|
||||
break;
|
||||
case "result":
|
||||
// 1. Get IDs and filter out empty values
|
||||
$noteLinksId = db_get_var($mysqli, "SELECT `value` FROM $tableVar WHERE `name` = ?", ['displayIdNoteL']);
|
||||
$noteRechtsId = db_get_var($mysqli, "SELECT `value` FROM $tableVar WHERE `name` = ?", ['displayIdNoteR']);
|
||||
|
||||
// Create an array of IDs that actually exist
|
||||
$validIds = array_filter([$noteLinksId, $noteRechtsId]);
|
||||
|
||||
$noten = [];
|
||||
$notenConfig = [];
|
||||
|
||||
if (!empty($validIds)) {
|
||||
// 2. Fetch Noten (Only if we have IDs to look for)
|
||||
$placeholders = implode(',', array_fill(0, count($validIds), '?'));
|
||||
|
||||
$sqlNoten = "SELECT `value`, `note_bezeichnung_id` FROM $tableNoten
|
||||
WHERE person_id = ? AND `jahr` = ? AND `geraet_id` = ?
|
||||
AND `note_bezeichnung_id` IN ($placeholders)";
|
||||
|
||||
$stmt = $mysqli->prepare($sqlNoten);
|
||||
// Combine standard params with our dynamic ID list
|
||||
$params = array_merge([$id, $jahr, $geraetId], $validIds);
|
||||
$types = str_repeat('s', count($params));
|
||||
$stmt->bind_param($types, ...$params);
|
||||
$stmt->execute();
|
||||
$notenDB = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
|
||||
$noten = array_column($notenDB, 'value', 'note_bezeichnung_id');
|
||||
$stmt->close();
|
||||
|
||||
// 3. Fetch Config
|
||||
$sqlConfig = "SELECT `id`, `default_value`, `nullstellen`, `prefix_display`
|
||||
FROM $tableNotenBezeichnungen WHERE `id` IN ($placeholders)";
|
||||
|
||||
$stmt = $mysqli->prepare($sqlConfig);
|
||||
$typesConfig = str_repeat('s', count($validIds));
|
||||
$stmt->bind_param($typesConfig, ...$validIds);
|
||||
$stmt->execute();
|
||||
$notenConfigDB = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
|
||||
$notenConfig = array_column($notenConfigDB, null, 'id');
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
// 4. Helper function to safely format the output without crashing
|
||||
$formatNote = function($id) use ($noten, $notenConfig) {
|
||||
if (!$id || !isset($notenConfig[$id])) {
|
||||
return ""; // Return empty string if ID is not set or not found in DB
|
||||
}
|
||||
|
||||
$conf = $notenConfig[$id];
|
||||
$val = $noten[$id] ?? $conf['default_value'] ?? 0;
|
||||
$prec = $conf['nullstellen'] ?? 2;
|
||||
$pre = $conf['prefix_display'] ?? '';
|
||||
|
||||
return $pre . number_format((float)$val, (int)$prec, '.', '');
|
||||
};
|
||||
|
||||
// 5. Assign to JSON
|
||||
$oldjson["noteLinks"] = $formatNote($noteLinksId);
|
||||
$oldjson["noteRechts"] = $formatNote($noteRechtsId);
|
||||
|
||||
$jsonData = json_encode($oldjson);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
// Write file
|
||||
if (file_put_contents($filepath, $jsonData) === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Failed to write JSON file'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ---------- Return JSON ----------
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'JSON updated successfully for ' . $geraetName,
|
||||
'data' => json_decode($jsonData, true),
|
||||
'nameGeraet' => strtolower($geraetName)
|
||||
]);
|
||||
exit;
|
||||
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
session_start();
|
||||
|
||||
if (empty($_SESSION['access_granted_kampfrichter']) || $_SESSION['access_granted_kampfrichter'] !== true || empty($_SESSION['passcodekampfrichter_id']) || $_SESSION['passcodekampfrichter_id'] < 1) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
$type = 'kr';
|
||||
|
||||
$data = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($data['success'] === false){
|
||||
echo json_encode(['success' => false, 'message' => $data['message']]);
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
// ---------- Get and sanitize input ----------
|
||||
$id = isset($_POST['id']) ? intval($_POST['id']) : 0;
|
||||
$discipline = isset($_POST['discipline']) ? preg_replace('/[^a-zA-Z0-9 _-]/', '', $_POST['discipline']) : '';
|
||||
|
||||
|
||||
$stmt = $mysqli->prepare("SELECT `name` FROM $tableGeraete ORDER BY start_index ASC");
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$allowed_disciplines = array_map(
|
||||
'strtolower',
|
||||
array_column($result->fetch_all(MYSQLI_ASSOC), 'name')
|
||||
);
|
||||
|
||||
$stmt->close();
|
||||
|
||||
if (!in_array($discipline, $allowed_disciplines)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid discipline']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ---------- Step 2: Get values from DB ----------
|
||||
|
||||
$result = $mysqli->query("SELECT * FROM `$tableTurnerinnen` WHERE id = $id");
|
||||
$row = $result->fetch_assoc();
|
||||
if (!$row) {
|
||||
echo json_encode(['success' => false, 'message' => 'Row fetch failed']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$folder = realpath($baseDir . '/displays/json');
|
||||
if ($folder === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Could not find displays folder.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$filename = 'display_' . $discipline . '.json';
|
||||
$filepath = $folder . '/' . $filename;
|
||||
|
||||
if (!is_writable($folder)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Folder not writable: ' . $folder]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$jsonString = file_get_contents($filepath);
|
||||
|
||||
// decode JSON, fallback to empty array if invalid
|
||||
$oldjson = json_decode($jsonString, true) ?? [];
|
||||
|
||||
|
||||
if (array_key_exists("note", $oldjson) && array_key_exists("dnote", $oldjson)) {
|
||||
$oldjson["note"] = (float)$row['note '.$discipline];
|
||||
$oldjson["dnote"] = (float)$row['d-note '.$discipline];
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'ERROR: JSON keys "note" or "dnote" do not exist'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$jsonData = json_encode($oldjson);
|
||||
|
||||
// Write file
|
||||
if (file_put_contents($filepath, $jsonData) === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Failed to write JSON file: ' . $filepath
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ---------- Return JSON ----------
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'JSON updated successfully for '.$discipline,
|
||||
]);
|
||||
exit;
|
||||
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
session_start();
|
||||
|
||||
if (empty($_SESSION['access_granted_kampfrichter']) || $_SESSION['access_granted_kampfrichter'] !== true || empty($_SESSION['passcodekampfrichter_id']) || $_SESSION['passcodekampfrichter_id'] < 1) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
// ---------- Get and sanitize input ----------
|
||||
$discipline = isset($_GET['discipline']) ? preg_replace('/[^a-zA-Z0-9 _-]/', '', $_GET['discipline']) : '';
|
||||
|
||||
$type = 'kr';
|
||||
|
||||
$data = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($data['success'] === false){
|
||||
echo json_encode(['success' => false, 'message' => $data['message']]);
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
$stmt = $mysqli->prepare("SELECT `name` FROM $tableGeraete ORDER BY start_index ASC");
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$allowed_disciplines = array_map(
|
||||
'strtolower',
|
||||
array_column($result->fetch_all(MYSQLI_ASSOC), 'name')
|
||||
);
|
||||
|
||||
$stmt->close();
|
||||
|
||||
if (!in_array($discipline, $allowed_disciplines)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid discipline']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$folder = realpath($baseDir . '/displays/json');
|
||||
if ($folder === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Could not find displays folder.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$filename = 'display_' . $discipline . '.json';
|
||||
$filepath = $folder . '/' . $filename;
|
||||
|
||||
if (!is_writable($folder)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Folder not writable']);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$jsonString = file_get_contents($filepath);
|
||||
|
||||
// decode JSON, fallback to empty array if invalid
|
||||
$oldjson = json_decode($jsonString, true) ?? [];
|
||||
|
||||
if (array_key_exists("start", $oldjson)) {
|
||||
$oldjson["start"] = true;
|
||||
|
||||
$jsonData = json_encode($oldjson);
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => 'Turnerin nicht auf Display '.json_encode($oldjson).'; '.$jsonString]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
// Write file
|
||||
if (file_put_contents($filepath, $jsonData) === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Failed to write JSON file'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ---------- Return JSON ----------
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'JSON updated successfully for '.$discipline,
|
||||
'disable_start_button' => true
|
||||
]);
|
||||
exit;
|
||||
@@ -0,0 +1,122 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
session_start();
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
$type = 'kr';
|
||||
|
||||
$data = include $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($data['success'] === false){
|
||||
echo json_encode(['success' => false, 'message' => $data['message']]);
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
// ---------- Get and sanitize input ----------
|
||||
$id = isset($_GET['id']) ? intval($_GET['id']) : 0;
|
||||
$discipline = isset($_GET['discipline']) ? preg_replace('/[^a-zA-Z0-9 _-]/', '', $_GET['discipline']) : '';
|
||||
|
||||
$stmt = $mysqli->prepare("SELECT `name` FROM $tableGeraete ORDER BY start_index ASC");
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$allowed_disciplines = array_map(
|
||||
'strtolower',
|
||||
array_column($result->fetch_all(MYSQLI_ASSOC), 'name')
|
||||
);
|
||||
|
||||
$stmt->close();
|
||||
|
||||
if (!in_array($discipline, $allowed_disciplines)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid discipline']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ---------- Step 2: Get values from DB ----------
|
||||
|
||||
$result = $mysqli->query("SELECT name, vorname, verein, programm FROM `$tableTurnerinnen` WHERE id = $id");
|
||||
$row = $result->fetch_assoc();
|
||||
if (!$row) {
|
||||
echo json_encode(['success' => false, 'message' => 'Row fetch failed']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$folder = realpath($baseDir . '/displays/json');
|
||||
if ($folder === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Could not find displays folder. Tried: ' . __DIR__ . '/../displays'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$filename = 'display_' . $discipline . '.json';
|
||||
$filepath = $folder . '/' . $filename;
|
||||
|
||||
if (!is_writable($folder)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Folder not writable: ' . $folder]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (file_put_contents($filepath, $jsonData) === false) {
|
||||
echo json_encode(['success' => false, 'message' => 'Failed to write file: ' . $filepath]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$jsonString = file_get_contents($folder . $filename);
|
||||
|
||||
// decode JSON, fallback to empty array if invalid
|
||||
$oldjson = json_decode($jsonString, true) ?? [];
|
||||
|
||||
// safely get value, default 0 if missing
|
||||
$olduniqueid = $oldjson['uniqueid'] ?? 0;
|
||||
$uniqueid = $olduniqueid + 1;
|
||||
|
||||
$data = ["note" => 'nan',
|
||||
"dnote" => 'nan',
|
||||
"id" => $id,
|
||||
"name" => $row['name'],
|
||||
"vorname" => $row['vorname'],
|
||||
"programm" => $row['programm'],
|
||||
"verein" => $row['verein'],
|
||||
"start" => false,
|
||||
"musik" => 'nan',
|
||||
"uniqueid" => $uniqueid];
|
||||
$jsonData = json_encode($data);
|
||||
|
||||
|
||||
// Encode JSON with readable formatting
|
||||
$jsonData = json_encode($data);
|
||||
|
||||
// Write file
|
||||
if (file_put_contents($filepath, $jsonData) === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Failed to write JSON file: ' . $filepath
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// ---------- Return JSON ----------
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'JSON updated successfully for '.$discipline,
|
||||
'disable_turnerin_button' => true,
|
||||
'enable_result_button' => true
|
||||
]);
|
||||
exit;
|
||||
Reference in New Issue
Block a user