First version, for githup; UNSTABLE, DO NOT USE!
This commit is contained in:
@@ -0,0 +1,321 @@
|
||||
<?php
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
session_start();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/csrf_functions.php';
|
||||
|
||||
if (!verify_csrf()) {
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate editId from POST
|
||||
if (isset($_POST['editId'])) {
|
||||
$editId = intval($_POST['editId']);
|
||||
if ($editId === false || $editId < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Falsche Personen ID']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$editId = filter_var($editId, FILTER_VALIDATE_INT);
|
||||
|
||||
if ($editId === false) {
|
||||
echo json_encode(['success' => true]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
$type = 'kr';
|
||||
|
||||
$data = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if (!($data['success'] ?? false)) {
|
||||
echo json_encode(['success' => false, 'message' => $data['message']]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$isAdmin = (($_SESSION['selectedFreigabeKampfrichter'] ?? '') === 'admin') ? true : false;
|
||||
|
||||
$disciplines = db_select($mysqli, $tableGeraete, 'id', '', [], 'start_index ASC');
|
||||
|
||||
$disciplines = array_column($disciplines, "id");
|
||||
|
||||
if (!$isAdmin) {
|
||||
|
||||
$discipline = intval($_POST['geraet']) ?? 0;
|
||||
|
||||
if (!in_array($discipline, $disciplines)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Falsche Geräte ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$disciplines = [$discipline];
|
||||
|
||||
|
||||
$stmt = $mysqli->prepare("
|
||||
SELECT
|
||||
t.name,
|
||||
t.vorname,
|
||||
t.programm,
|
||||
p.id as programm_id,
|
||||
agg.abteilung,
|
||||
agg.geraeteIndex,
|
||||
agg.startIndex
|
||||
FROM $tableTurnerinnen t
|
||||
LEFT JOIN $tableProgramme p ON p.programm = t.programm
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
ta.turnerin_id,
|
||||
GROUP_CONCAT(DISTINCT a.name SEPARATOR ', ') AS abteilung,
|
||||
GROUP_CONCAT(DISTINCT g.start_index SEPARATOR ', ') AS geraeteIndex,
|
||||
ta.turnerin_index AS startIndex
|
||||
FROM $tableTurnerinnenAbt ta
|
||||
INNER JOIN $tableAbt a
|
||||
ON a.id = ta.abteilung_id
|
||||
LEFT JOIN $tableGeraete g
|
||||
ON g.id = ta.geraet_id
|
||||
GROUP BY ta.turnerin_id
|
||||
) agg ON agg.turnerin_id = t.id
|
||||
WHERE t.id = ?
|
||||
");
|
||||
|
||||
} else {
|
||||
$stmt = $mysqli->prepare("SELECT t.`name`, t.`vorname`, t.`programm`, p.id as programm_id FROM $tableTurnerinnen t LEFT JOIN $tableProgramme p ON p.programm = t.programm WHERE t.id = ?");
|
||||
}
|
||||
|
||||
$stmt->bind_param('i', $editId);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$dbresult = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
$stmt->close();
|
||||
|
||||
if (!$dbresult || !is_array($dbresult) || count($dbresult) < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Falsche Personen ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$now = new DateTime();
|
||||
|
||||
$jahr = ($now->format('n') > 6) ? $now->modify('+1 year')->format('Y') : $now->format('Y');
|
||||
|
||||
if ($isAdmin) {
|
||||
$stmt = $mysqli->prepare("SELECT `note_bezeichnung_id`, `value`, `geraet_id`, `run_number` FROM $tableNoten WHERE `person_id` = ? AND `jahr` = ?");
|
||||
|
||||
$stmt->bind_param('ss', $editId, $jahr);
|
||||
} else {
|
||||
$stmt = $mysqli->prepare("SELECT `note_bezeichnung_id`, `value`, `geraet_id`, `run_number` FROM $tableNoten WHERE `person_id` = ? AND `geraet_id` = ? AND `jahr` = ?");
|
||||
|
||||
$stmt->bind_param('sss', $editId, $discipline, $jahr);
|
||||
}
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$notenDB = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
|
||||
$indexedNotenDB = [];
|
||||
foreach ($notenDB as $sn) {
|
||||
$indexedNotenDB[$sn['geraet_id']][$sn['note_bezeichnung_id']][$sn['run_number']] = $sn['value'];
|
||||
}
|
||||
|
||||
|
||||
$stmt->close();
|
||||
|
||||
$stmt = $mysqli->prepare("SELECT `id`, `default_value`, `nullstellen`, `pro_geraet`, `geraete_json`, `anzahl_laeufe_json` FROM $tableNotenBezeichnungen");
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$notenConfig = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
$stmt->close();
|
||||
|
||||
$noten = [];
|
||||
|
||||
$row = $dbresult[0];
|
||||
|
||||
$programm_id = $row['programm_id'];
|
||||
|
||||
foreach ($disciplines as $d) {
|
||||
foreach ($notenConfig as $snC) {
|
||||
$allowedGeraete = !empty($snC['geraete_json']) ? json_decode($snC['geraete_json'], true) : [];
|
||||
$isProGeraet = ($snC['pro_geraet'] === 1);
|
||||
|
||||
if (!$isProGeraet && !in_array($d, $allowedGeraete)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Determine number of runs for this program
|
||||
$anzRunsConfig = !empty($snC['anzahl_laeufe_json']) ? json_decode($snC['anzahl_laeufe_json'], true) : [];
|
||||
|
||||
$runs = $anzRunsConfig[$programm_id] ?? $anzRunsConfig['default'] ?? 1;
|
||||
|
||||
for ($r = 1; $r <= $runs; $r++) {
|
||||
$value = $indexedNotenDB[$d][$snC['id']][$r] ?? $snC['default_value'] ?? 0;
|
||||
$noten[$d][$snC['id']][$r] = number_format($value, $snC['nullstellen'] ?? 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$titel = $row['vorname'].' '.$row['name'].', '.$row['programm'];
|
||||
|
||||
if (!$isAdmin) {
|
||||
|
||||
// $entries = db_select($mysqli, $tableTurnerinnen, 'name, vorname, programm, id', 'abteilung = ? AND startgeraet = ?', [$row['abteilung'], $row['startgeraet']]);
|
||||
|
||||
$stmt = $mysqli->prepare("
|
||||
SELECT
|
||||
t.name,
|
||||
t.vorname,
|
||||
t.programm,
|
||||
t.id,
|
||||
agg.abteilung,
|
||||
agg.geraeteIndex,
|
||||
agg.startIndex
|
||||
FROM $tableTurnerinnen t
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
ta.turnerin_id,
|
||||
GROUP_CONCAT(DISTINCT a.name SEPARATOR ', ') AS abteilung,
|
||||
GROUP_CONCAT(DISTINCT g.start_index SEPARATOR ', ') AS geraeteIndex,
|
||||
ta.turnerin_index AS startIndex
|
||||
FROM $tableTurnerinnenAbt ta
|
||||
INNER JOIN $tableAbt a
|
||||
ON a.id = ta.abteilung_id
|
||||
LEFT JOIN $tableGeraete g
|
||||
ON g.id = ta.geraet_id
|
||||
GROUP BY ta.turnerin_id
|
||||
) agg ON agg.turnerin_id = t.id
|
||||
WHERE agg.abteilung = ? AND agg.geraeteIndex = ?
|
||||
ORDER BY t.id DESC
|
||||
");
|
||||
|
||||
|
||||
$bezahlt = 2;
|
||||
$bezahltoverride = 5;
|
||||
|
||||
$stmt->bind_param('ss', $row['abteilung'], $row['geraeteIndex']);
|
||||
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$entries = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
$stmt->close();
|
||||
|
||||
if (!$entries || !is_array($entries) || count($entries) < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'No DB Result for next Turnerin']);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
$maxstartindex = count($entries);
|
||||
|
||||
if ($maxstartindex < 1) {
|
||||
$maxstartindex = 1;
|
||||
}
|
||||
|
||||
$csti = (int)$row['startIndex'];
|
||||
$nsti = $csti + 1;
|
||||
|
||||
if ($nsti > $maxstartindex){
|
||||
$nsti -= $maxstartindex;
|
||||
}
|
||||
|
||||
$rohstartindex = intval($row['startIndex']);
|
||||
$varstartgeraet = intval($row['geraeteIndex']);
|
||||
|
||||
$aktsubabt = $_SESSION['currentsubabt'];
|
||||
|
||||
foreach ($disciplines as $index => $sdiscipline) {
|
||||
if (isset($sdiscipline) && $sdiscipline === $discipline) {
|
||||
$indexuser = $index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
$calculedstartindex = $rohstartindex - $indexuser;
|
||||
|
||||
$calculedstartindex = $calculedstartindex >= 1 ? $calculedstartindex : $calculedstartindex + $maxstartindex;
|
||||
|
||||
|
||||
$nrow = null;
|
||||
|
||||
if ($calculedstartindex !== count($entries)){
|
||||
$nrow = null;
|
||||
|
||||
foreach ($entries as $entry) {
|
||||
if ($entry['startIndex'] == $nsti) {
|
||||
$nrow = $entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($nrow) {
|
||||
$nturnerin = [
|
||||
'name' => $nrow['vorname'].' '.$nrow['name'].', '.$nrow['programm'],
|
||||
'id' => $nrow['id']
|
||||
];
|
||||
} else {
|
||||
$nturnerin = [
|
||||
'name' => '--- nächste Gruppe ---',
|
||||
'id' => 0
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($isAdmin) {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'id' => $editId,
|
||||
'programm_id' => $programm_id,
|
||||
'titel' => $titel,
|
||||
'noten' => $noten
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'id' => $editId,
|
||||
'programm_id' => $programm_id,
|
||||
'titel' => $titel,
|
||||
'noten' => $noten,
|
||||
'nturnerin' => $nturnerin
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
327
www/intern/scripts/kampfrichter/ajax/ajax-neu_protokoll.php
Normal file
327
www/intern/scripts/kampfrichter/ajax/ajax-neu_protokoll.php
Normal file
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
|
||||
/*ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
// Show all errors except deprecation notices (these come from vendor libraries
|
||||
// that aren't yet typed for newer PHP versions). Long-term fix: update
|
||||
// dependencies to versions compatible with your PHP runtime.
|
||||
error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);*/
|
||||
|
||||
// Start session if not already started
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Check access
|
||||
if (empty($_SESSION['access_granted_kampfrichter']) || $_SESSION['access_granted_kampfrichter'] !== true ||
|
||||
empty($_SESSION['passcodekampfrichter_id']) || $_SESSION['passcodekampfrichter_id'] < 1) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate POST input
|
||||
if (!isset($_POST['abteilung'])) {
|
||||
http_response_code(400);
|
||||
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-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
|
||||
$abteilung = trim($_POST['abteilung']);
|
||||
|
||||
$disciplines = db_select($mysqli, $tableGeraete, '*', '', [], 'start_index ASC');
|
||||
|
||||
|
||||
|
||||
// Load TCPDF
|
||||
require $baseDir . '/wp-content/uploads/TCPDF-main/tcpdf.php';
|
||||
|
||||
$current_year = (date('n') > 6) ? date('Y') + 1 : date('Y');
|
||||
|
||||
class MYPDF extends TCPDF
|
||||
{
|
||||
public $current_year;
|
||||
public $abteilung;
|
||||
// Page header
|
||||
public function Header()
|
||||
{
|
||||
$image_file = 'https://kutu-tage-beider-basel.testseite-fh-ht.ch/wp-content/uploads/2025/06/ktbb-logo.png';
|
||||
$this->SetY(15);
|
||||
$this->SetFont('helvetica', 'B', 20);
|
||||
$this->Cell(0, 0, 'Protokoll Kutu-Tage beider Basel ' . $this->current_year . ' Abt. ' . $this->abteilung, 0, false, 'L', 0, '', 0, false, 'M', 'M');
|
||||
$this->Image($image_file, 272, 5, 15, '', 'PNG', '', 'T', false, 300, '', false, false, 0, false, false, false);
|
||||
}
|
||||
|
||||
// Page footer
|
||||
public function Footer()
|
||||
{
|
||||
$this->SetY(-15);
|
||||
$this->SetFont('helvetica', 'I', 8);
|
||||
$this->Cell(0, 10, 'Seite ' . $this->getAliasNumPage() . ' von ' . $this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
|
||||
}
|
||||
}
|
||||
|
||||
$pdf = new MYPDF('L', 'mm', 'A4', true, 'UTF-8', false);
|
||||
//$pdf->AddFont('outfit-bold', '', 'outfitb.php');
|
||||
|
||||
|
||||
$pdf->current_year = $current_year;
|
||||
$pdf->abteilung = $abteilung;
|
||||
|
||||
$pdf->SetCreator(PDF_CREATOR);
|
||||
$pdf->SetAuthor('Turnerinnen System');
|
||||
$pdf->SetTitle("KTBB_Protokoll_Abt." . $abteilung . "_" . $current_year . ".pdf");
|
||||
$pdf->SetMargins(10, 20, 10);
|
||||
$pdf->SetAutoPageBreak(TRUE, 10);
|
||||
$pdf->SetFont('helvetica', '', 9);
|
||||
|
||||
$startindex = 0;
|
||||
|
||||
foreach ($disciplines as $singledisciplin){
|
||||
|
||||
$startindex ++;
|
||||
|
||||
$name_kampfrichterin1 = 'Nicht eingetragen';
|
||||
$name_kampfrichterin2 = 'Nicht eingetragen';
|
||||
|
||||
// Prepare SQL statement
|
||||
$stmt = $mysqli->prepare("
|
||||
SELECT * FROM $tableKrProtokoll
|
||||
WHERE abteilung = ?
|
||||
AND geraet = ?
|
||||
");
|
||||
$stmt->bind_param('ss', $abteilung, $singledisciplin['name']);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$krresults = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
foreach ($krresults as $krresult){
|
||||
if ($krresult['aufgabe'] == 1){
|
||||
$name_kampfrichterin1 = $krresult['name'];
|
||||
} elseif ($krresult['aufgabe'] == 2){
|
||||
$name_kampfrichterin2 = $krresult['name'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($disciplines as $shiftstartindex => $subdisciplin){
|
||||
|
||||
$pdf->AddPage();
|
||||
|
||||
$pdf->Ln(10);
|
||||
$pdf->SetFont('', 'B', 14);
|
||||
$pdf->Cell(0, 0, ucfirst($singledisciplin['name']), 0, 1, 'L');
|
||||
$pdf->Ln(3);
|
||||
$pdf->SetFont('', 'I', 9);
|
||||
$newshiftindex = $shiftstartindex + 1;
|
||||
$pdf->Cell(0, 0, 'Gruppe '. $newshiftindex , 0, 1, 'L');
|
||||
$pdf->SetFont('', '');
|
||||
|
||||
$pdf->Ln(5);
|
||||
|
||||
$pdf->Cell(0, 0, '1. Kampfrichterin: ' . $name_kampfrichterin1, 0, 1, 'L');
|
||||
$pdf->Ln(2);
|
||||
$pdf->Cell(0, 0, '2. Kampfrichterin: ' . $name_kampfrichterin2, 0, 1, 'L');
|
||||
$pdf->Ln(8);
|
||||
|
||||
$startg = $shiftstartindex - $startindex;
|
||||
|
||||
if ($startg < 1) {
|
||||
$startg += 4; // shift into positive range
|
||||
}
|
||||
|
||||
// Prepare SQL statement
|
||||
|
||||
$stmt = $mysqli->prepare("
|
||||
SELECT
|
||||
t.*,
|
||||
agg.abteilung,
|
||||
agg.geraete_index,
|
||||
agg.start_index
|
||||
FROM $tableTurnerinnen t
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
ta.turnerin_id,
|
||||
GROUP_CONCAT(DISTINCT a.name SEPARATOR ', ') AS abteilung,
|
||||
GROUP_CONCAT(DISTINCT g.start_index SEPARATOR ', ') AS geraete_index,
|
||||
ta.turnerin_index AS start_index
|
||||
FROM $tableTurnerinnenAbt ta
|
||||
INNER JOIN $tableAbt a
|
||||
ON a.id = ta.abteilung_id
|
||||
LEFT JOIN $tableGeraete g
|
||||
ON g.id = ta.geraet_id
|
||||
GROUP BY ta.turnerin_id
|
||||
) agg ON agg.turnerin_id = t.id
|
||||
WHERE (t.bezahlt = ? OR t.bezahltoverride = ?) AND agg.abteilung = ? AND agg.geraete_index = ?
|
||||
ORDER BY agg.start_index DESC
|
||||
");
|
||||
|
||||
$bezahlt1 = '2';
|
||||
$bezahlt2 = '5';
|
||||
$stmt->bind_param('ssss', $bezahlt1, $bezahlt2, $abteilung, $startg);
|
||||
$stmt->execute();
|
||||
$result = $stmt->get_result();
|
||||
$entries = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
|
||||
if (!empty($entries)) {
|
||||
$maxindex = $entries[0]['start_index'];
|
||||
|
||||
// Recalculate
|
||||
foreach ($entries as &$singleorderentry) {
|
||||
$singleorderentry['start_index'] -= $shiftstartindex;
|
||||
if ($singleorderentry['start_index'] < 1) {
|
||||
$singleorderentry['start_index'] += $maxindex;
|
||||
}
|
||||
}
|
||||
unset($singleorderentry); // break the reference
|
||||
|
||||
// Reorder by recalculated startindex (ascending)
|
||||
usort($entries, function($a, $b) {
|
||||
return $a['start_index'] <=> $b['start_index'];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Define columns (including discipline sub-columns)
|
||||
$columns = [
|
||||
'start_index' => ['header' => 'Str.'],
|
||||
'name' => ['header' => 'Name'],
|
||||
'vorname' => ['header' => 'Vorname'],
|
||||
'programm' => ['header' => 'Programm'],
|
||||
'geburtsdatum' => ['header' => 'Jg.'],
|
||||
'verein' => ['header' => 'Verein'],
|
||||
'e1 note '.strtolower($subdisciplin['name']) => ['header' => 'E1 Note '.ucfirst($subdisciplin['name'])],
|
||||
'e2 note '.strtolower($subdisciplin['name']) => ['header' => 'E2 Note '.ucfirst($subdisciplin['name'])],
|
||||
'e note '.strtolower($subdisciplin['name']) => ['header' => 'E Note '.ucfirst($subdisciplin['name'])],
|
||||
'd-note '.strtolower($subdisciplin['name']) => ['header' => 'D Note '.ucfirst($subdisciplin['name'])],
|
||||
'neutrale abzuege '.strtolower($subdisciplin['name']) => ['header' => 'N. Abzüge '.ucfirst($subdisciplin['name'])],
|
||||
'note '.strtolower($subdisciplin['name']) => ['header' => 'Note '.ucfirst($subdisciplin['name'])],
|
||||
];
|
||||
|
||||
// Initialize max widths with header widths (+4 mm padding)
|
||||
foreach ($columns as $key => &$col) {
|
||||
$col['max_width'] = $pdf->GetStringWidth($col['header']) + 4;
|
||||
}
|
||||
|
||||
// Calculate max width of each column based on all data
|
||||
foreach ($entries as $r) {
|
||||
foreach ($columns as $key => &$col) {
|
||||
isset($r[$key]) ? $r[$key] : '';
|
||||
$text = '';
|
||||
|
||||
// Handle different column types
|
||||
if ($key === 'start_index' && !empty($r['start_index'])) {
|
||||
$text = (int)$r[$key];
|
||||
} elseif ($key === 'geburtsdatum' && !empty($r['geburtsdatum'])) {
|
||||
$text = (new DateTime($r['geburtsdatum']))->format('Y');
|
||||
} elseif (strpos($key, 'd-note') === 0 && isset($r[$key]) && is_numeric($r[$key])) {
|
||||
$text = number_format((float)$r[$key], 2, '.', ''); // 2 decimals
|
||||
} elseif (isset($r[$key]) && is_numeric($r[$key])) {
|
||||
$text = number_format((float)$r[$key], 3, '.', ''); // 3 decimals
|
||||
} elseif (isset($r[$key])) {
|
||||
$text = (string)$r[$key];
|
||||
} else {
|
||||
$text = '';
|
||||
}
|
||||
|
||||
// Calculate width with padding
|
||||
$w = $pdf->GetStringWidth($text) + 4;
|
||||
|
||||
// Update max width
|
||||
if ($w > $col['max_width']) {
|
||||
$col['max_width'] = $w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($col);
|
||||
$columns['geburtsdatum']['max_width'] = $pdf->GetStringWidth("0000") + 4;
|
||||
|
||||
// Print first header row
|
||||
$pdf->SetFont('', 'B');
|
||||
foreach ($columns as $key => $col) {
|
||||
if (
|
||||
$key === 'd-note' || // only column with dash
|
||||
strpos($key, 'note') === 0 || // matches 'note...' at start
|
||||
strpos($key, 'e note') === 0 || // matches 'e-note...'
|
||||
strpos($key, 'e1 note') === 0 || // matches 'e1 note ...'
|
||||
strpos($key, 'e2 note') === 0 || // matches 'e2 note ...'
|
||||
strpos($key, 'neutrale abzuege') === 0 ||
|
||||
$key === 'geburtsdatum' ||
|
||||
$key === 'start_index'
|
||||
) {
|
||||
$align = 'C';
|
||||
} else {
|
||||
$align = 'L';
|
||||
}
|
||||
|
||||
$pdf->Cell($col['max_width'], 7, $col['header'], 0, 0, $align);
|
||||
}
|
||||
|
||||
|
||||
// Move to next line after headers
|
||||
$pdf->Ln();
|
||||
|
||||
|
||||
$pdf->SetFont('', '');
|
||||
foreach ($entries as $r) {
|
||||
foreach ($columns as $key => $col) {
|
||||
// Determine alignment
|
||||
if (strpos($key, 'note') === 0 || strpos($key, 'e note') === 0 || strpos($key, 'd-note') === 0 || strpos($key, 'neutrale abzuege') === 0 || $key === 'start_index' || $key === 'geburtsdatum' || strpos($key, 'e1 note') === 0 || strpos($key, 'e2 note') === 0){
|
||||
$align = 'C';
|
||||
} else {
|
||||
$align = 'L';
|
||||
}
|
||||
|
||||
// Format the value based on type
|
||||
if ($key === 'geburtsdatum' && !empty($r['geburtsdatum'])) {
|
||||
$text = (new DateTime($r['geburtsdatum']))->format('Y');
|
||||
} elseif (strpos($key, 'note') === 0 || strpos($key, 'e note') === 0 || strpos($key, 'd-note') === 0 || strpos($key, 'neutrale abzuege') === 0 || $key === 'gesamt' || strpos($key, 'e1 note') === 0 || strpos($key, 'e2 note') === 0){
|
||||
$text = isset($r[$key]) ? number_format((float)$r[$key], 3) : '';
|
||||
} else {
|
||||
$text = isset($r[$key]) ? $r[$key] : '';
|
||||
}
|
||||
|
||||
$pdf->Cell($col['max_width'], 6, $text, 1, 0, $align);
|
||||
}
|
||||
|
||||
$pdf->Ln(); // Move to next row
|
||||
}
|
||||
|
||||
$pdf->SetY(-50);
|
||||
if ($name_kampfrichterin1 !== 'Nicht eingetragen' || $name_kampfrichterin2 !== 'Nicht eingetragen'){
|
||||
$pdf->SetFont('', 'B');
|
||||
$pdf->Cell(0, 28, 'Unterschrift:', 0, 1, 'L');
|
||||
$pdf->SetFont('', '');
|
||||
if ($name_kampfrichterin1 !== 'Nicht eingetragen'){
|
||||
$pdf->Cell(120, 8, $name_kampfrichterin1.': ___________________________________________', 0, 0, 'L');
|
||||
}
|
||||
if ($name_kampfrichterin2 !== 'Nicht eingetragen'){
|
||||
$pdf->Cell(90, 8, $name_kampfrichterin2.': ___________________________________________', 0, 0, 'L');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Close statement
|
||||
$stmt->close();
|
||||
|
||||
$pdf->Output("Protokoll_Kutu-Tage_beider_Basel_{$current_year}_Abt_{$abteilung}.pdf", 'D');
|
||||
|
||||
|
||||
|
||||
exit;
|
||||
606
www/intern/scripts/kampfrichter/ajax/ajax-neu_rangliste.php
Normal file
606
www/intern/scripts/kampfrichter/ajax/ajax-neu_rangliste.php
Normal file
@@ -0,0 +1,606 @@
|
||||
<?php
|
||||
|
||||
use TCPDF;
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
// Show all errors except deprecation notices (these come from vendor libraries
|
||||
// that aren't yet typed for newer PHP versions). Long-term fix: update
|
||||
// dependencies to versions compatible with your PHP runtime.
|
||||
error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
|
||||
|
||||
// Start session if not already started
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
// Check access
|
||||
if (empty($_SESSION['access_granted_kampfrichter']) || $_SESSION['access_granted_kampfrichter'] !== true ||
|
||||
empty($_SESSION['passcodekampfrichter_id']) || $_SESSION['passcodekampfrichter_id'] < 1) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate POST input
|
||||
/*
|
||||
if (!isset($_POST['prog']) && !isset($_POST['type'])) {
|
||||
http_response_code(400);
|
||||
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';
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
|
||||
|
||||
$programm = trim($_POST['prog'] ?? 'p6a');
|
||||
$buttontype = trim($_POST['type'] ?? 'export_programm');
|
||||
$upperprogramm = strtoupper($programm);
|
||||
|
||||
$stmt = $mysqli->prepare("SELECT `id`, `name` FROM $tableGeraete ORDER BY start_index ASC");
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$geraete = $result->fetch_all(MYSQLI_ASSOC);
|
||||
$disciplines = array_map(
|
||||
'strtolower',
|
||||
array_column($geraete, 'name')
|
||||
);
|
||||
|
||||
$stmt->close();
|
||||
|
||||
// Determine current year
|
||||
$current_year = date('Y');
|
||||
$monat = date('n');
|
||||
if ($monat > 6) $current_year++;
|
||||
|
||||
// Prepare SQL statement
|
||||
$stmt = $mysqli->prepare("
|
||||
SELECT * FROM $tableTurnerinnen
|
||||
WHERE LOWER(programm) = LOWER(?)
|
||||
AND (bezahlt = ? OR bezahltoverride = ?)
|
||||
ORDER BY rang ASC
|
||||
");
|
||||
$bezahlt1 = '2';
|
||||
$bezahlt2 = '5';
|
||||
$stmt->bind_param('sss', $programm, $bezahlt1, $bezahlt2);
|
||||
$stmt->execute();
|
||||
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$personen = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
// Close statement
|
||||
$stmt->close();
|
||||
|
||||
// 1. Get the IDs from the first query results
|
||||
$turnerinnenIds = array_column($personen, 'id');
|
||||
|
||||
if (!empty($turnerinnenIds)) {
|
||||
// 2. Create a string of placeholders: ?,?,?
|
||||
$placeholders = implode(',', array_fill(0, count($turnerinnenIds), '?'));
|
||||
|
||||
// 3. Prepare the IN statement
|
||||
$sqlNoten = "SELECT * FROM $tableNoten WHERE person_id IN ($placeholders) AND `jahr` = ?";
|
||||
$stmtNoten = $mysqli->prepare($sqlNoten);
|
||||
|
||||
// --- FIX STARTS HERE ---
|
||||
|
||||
// 1. Combine all values into one flat array for binding
|
||||
$paramsArray = array_merge($turnerinnenIds, [$current_year]);
|
||||
|
||||
// 2. Build the types string
|
||||
// 'i' for every ID, plus 'i' (or 's') for the year
|
||||
$types = str_repeat('i', count($turnerinnenIds)) . 's';
|
||||
|
||||
// 3. Unpack the combined array into the bind_param function
|
||||
$stmtNoten->bind_param($types, ...$paramsArray);
|
||||
|
||||
// --- FIX ENDS HERE ---
|
||||
|
||||
$stmtNoten->execute();
|
||||
$notenResult = $stmtNoten->get_result();
|
||||
$notenEntries = $notenResult->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
$stmtNoten->close(); // Close inside the IF to avoid errors if IDs were empty
|
||||
} else {
|
||||
$notenEntries = [];
|
||||
}
|
||||
|
||||
$rangNote = intval(db_get_var($mysqli, "SELECT `value` FROM $tableVar WHERE `name` = ?", ['rangNote']));
|
||||
|
||||
var_dump($rangNote);
|
||||
|
||||
$orderBestRang = db_get_var($mysqli, "SELECT `value` FROM $tableVar WHERE `name` = ?", ['orderBestRang']);
|
||||
|
||||
$okValuesOrderBestRang = ["ASC", "DESC"];
|
||||
|
||||
if (!in_array($orderBestRang, $okValuesOrderBestRang)) {
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
$alleNoten = db_select($mysqli, $tableNotenBezeichnungen, "id, default_value, nullstellen, pro_geraet, geraete_json, zeige_auf_rangliste, name", "zeige_auf_rangliste = ? OR id = ?", ['1', $rangNote]);
|
||||
|
||||
$displayedNoten = [];
|
||||
|
||||
foreach ($alleNoten as $sN) {
|
||||
if (intval($sN['zeige_auf_rangliste']) === 1) {
|
||||
$displayedNoten[$sN['id']] = $sN;
|
||||
}
|
||||
}
|
||||
|
||||
$ascArrayDefaultValues = array_column($alleNoten, 'default_value', 'id');
|
||||
$ascArrayGeraeteJSON = array_column($alleNoten, 'geraete_json', 'id');
|
||||
|
||||
foreach ($ascArrayGeraeteJSON as $key => $saagj) {
|
||||
$ascArrayGeraeteJSON[$key] = json_decode($saagj, true) ?? [];
|
||||
}
|
||||
|
||||
// 1. Initialize the structure for every person
|
||||
$indexedNotenArray = [];
|
||||
foreach ($personen as $sp) {
|
||||
$pId = $sp['id'];
|
||||
foreach ($geraete as $g) {
|
||||
$indexedNotenArray[$pId][$g['id']] = [];
|
||||
}
|
||||
$indexedNotenArray[$pId][0] = []; // Total/Overall device per person
|
||||
}
|
||||
|
||||
// 2. Fill with existing database values
|
||||
$sortArray = [];
|
||||
foreach ($notenEntries as $sn) {
|
||||
$pId = $sn['person_id'];
|
||||
$gId = $sn['geraet_id'];
|
||||
$nId = $sn['note_bezeichnung_id'];
|
||||
$val = $sn['value'];
|
||||
|
||||
$indexedNotenArray[$pId][$gId][$nId] = $val;
|
||||
|
||||
// Check if this specific note is the one we rank by
|
||||
// Usually ranking happens on Device 0 (Total) for the $rangNote ID
|
||||
if (intval($nId) === $rangNote && intval($gId) === 0) {
|
||||
$sortArray[$pId] = $val; // FIXED: used = instead of ===
|
||||
}
|
||||
}
|
||||
|
||||
// Load TCPDF
|
||||
require $baseDir . '/../composer/vendor/autoload.php';
|
||||
|
||||
// Optional: load custom font
|
||||
$fontfile = $baseDir . '/wp-content/uploads/fonts/Inter-Regular.ttf'; // adjust path
|
||||
if (file_exists($fontfile)) {
|
||||
$fontname = TCPDF_FONTS::addTTFfont($fontfile, 'TrueTypeUnicode', '', 32);
|
||||
}
|
||||
|
||||
class MYPDF extends TCPDF
|
||||
{
|
||||
public $current_year;
|
||||
public $programm;
|
||||
public $upperprogramm;
|
||||
public $columns;
|
||||
public $disciplines;
|
||||
// Page header
|
||||
|
||||
public $headerBottomY = 0;
|
||||
|
||||
public function Header()
|
||||
{
|
||||
$image_file = 'https://kutu-tage-beider-basel.testseite-fh-ht.chhttps://kutu-tage-beider-basel.testseite-fh-ht.ch/wp-content/uploads/2025/06/ktbb-logo.png';
|
||||
$this->SetY(15);
|
||||
$this->SetFont('helvetica', 'B', 20);
|
||||
$this->Cell(0, 0, 'Rangliste Kutu-Tage beider Basel ' . $this->current_year, 0, 1, 'L', 0, '', 0, false, 'M', 'M');
|
||||
$preimageX = $this->GetX();
|
||||
$preimageY = $this->GetY();
|
||||
$this->Image($image_file, 272, 5, 15, '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
|
||||
|
||||
$this->SetX($preimageX);
|
||||
$this->SetY($preimageY);
|
||||
|
||||
$this->SetFont('helvetica', '', 11);
|
||||
$this->Cell(0, 10, 'Programm: ' . $this->upperprogramm, 0, 1, 'L');
|
||||
$this->Ln(5);
|
||||
|
||||
$columns = $this->columns;
|
||||
$disciplines = $this->disciplines;
|
||||
|
||||
// Print first header row
|
||||
$preheaderX = $this->GetX();
|
||||
$preheaderY = $this->GetY();
|
||||
$this->SetFont('', 'B');
|
||||
$this->Cell($columns['rang']['max_width'], 7, $columns['rang']['header'], 0, 0, 'C');
|
||||
$this->Cell($columns['name']['max_width'], 7, $columns['name']['header'], 0, 0, 'L');
|
||||
$this->Cell($columns['vorname']['max_width'], 7, $columns['vorname']['header'], 0, 0, 'L');
|
||||
$this->Cell($columns['geburtsdatum']['max_width'], 7, $columns['geburtsdatum']['header'], 0, 0, 'C');
|
||||
$this->Cell($columns['verein']['max_width'], 7, $columns['verein']['header'], 0, 0, 'L');
|
||||
$startX = $this->GetX();
|
||||
$startY = $this->GetY();
|
||||
$this->SetLineWidth(0.2);
|
||||
|
||||
// Loop through disciplines for rotated headers
|
||||
foreach ($disciplines as $d) {
|
||||
$w = $columns["d-note $d"]['max_width'] + $columns["note $d"]['max_width'];
|
||||
$ws = $columns["note $d"]['max_width'];
|
||||
|
||||
$x = $this->GetX();
|
||||
$y = $this->GetY() + 7;
|
||||
|
||||
// Start transformation for rotation
|
||||
$this->StartTransform();
|
||||
|
||||
// Rotate around top-left of cell
|
||||
$this->Rotate(45, $x, $y);
|
||||
|
||||
// Draw a line **above the first data row**
|
||||
$lineY = $startY + 7; // adjust 7 depending on cell height
|
||||
$this->Line($x, $lineY, $x + $ws, $lineY);
|
||||
|
||||
// Print the rotated header text
|
||||
$this->Cell($w, 7, ucfirst($d), 0, 0, 'L');
|
||||
|
||||
$this->StopTransform();
|
||||
|
||||
$this->SetX($x + $w);
|
||||
}
|
||||
|
||||
$w = $columns["gesamt"]['max_width'];
|
||||
$ws = $w;
|
||||
|
||||
$x = $this->GetX();
|
||||
$y = $this->GetY() + 7;
|
||||
|
||||
// Start transformation for rotation
|
||||
$this->StartTransform();
|
||||
|
||||
// Rotate around top-left of cell
|
||||
$this->Rotate(45, $x, $y);
|
||||
|
||||
// Draw a line **above the first data row**
|
||||
$lineY = $startY + 7; // adjust 7 depending on cell height
|
||||
|
||||
$this->SetLineWidth(0.6);
|
||||
|
||||
$this->Line($x, $lineY, $x + $ws, $lineY);
|
||||
|
||||
$this->SetLineWidth(0.2);
|
||||
|
||||
|
||||
// Print the rotated header text
|
||||
$this->Cell($w, 7, $columns['gesamt']['header'], 0, 0, 'L');
|
||||
|
||||
$this->StopTransform();
|
||||
|
||||
$this->SetX($x + $w);
|
||||
|
||||
$afterheaderX = $this->GetX();
|
||||
|
||||
$this->Ln();
|
||||
|
||||
$xheaderline = $preheaderX;
|
||||
$yheaderline = $this->GetY();
|
||||
|
||||
$this->headerBottomY = $this->GetY();
|
||||
}
|
||||
|
||||
// Page footer
|
||||
public function Footer()
|
||||
{
|
||||
$this->SetY(-15);
|
||||
$this->SetFont('helvetica', 'I', 8);
|
||||
$this->Cell(0, 10, 'Seite ' . $this->getAliasNumPage() . ' von ' . $this->getAliasNbPages(), 0, false, 'C', 0, '', 0, false, 'T', 'M');
|
||||
$this->SetFont('', '');
|
||||
$this->Cell(0, 10, $_SERVER['HTTP_HOST'], 0, 0, 'R', false, 'https://'.$_SERVER['HTTP_HOST'].'/ergebnis/'.$this->current_year, 0, false, 'T', 'M');
|
||||
|
||||
$this->SetLineWidth(0.6);
|
||||
$this->Line(10, $this->headerBottomY, 297 - 10, $this->headerBottomY);
|
||||
|
||||
$this->SetLineWidth(0.2);
|
||||
|
||||
$this->SetY(0);
|
||||
$this->SetX(5);
|
||||
|
||||
$this->SetFillColor(255, 255, 255); // white
|
||||
|
||||
$this->Cell(5, 190, '', 0, 0, 'L', true);
|
||||
|
||||
$this->SetY(0);
|
||||
$this->SetX(297 - 10);
|
||||
|
||||
$this->Cell(5, 190, '', 0, 0, 'L', true);
|
||||
}
|
||||
}
|
||||
|
||||
$pdf = new MYPDF('L', 'mm', 'A4', true, 'UTF-8', false);
|
||||
$pdf->current_year = $current_year;
|
||||
$pdf->programm = $programm;
|
||||
$pdf->upperprogramm = $upperprogramm;
|
||||
|
||||
$pdf->SetCreator(PDF_CREATOR);
|
||||
$pdf->SetAuthor('WKVS-FH');
|
||||
$pdf->SetTitle("KTBB_Ergebnisse_" . $programm . "_" . $current_year . ".pdf");
|
||||
|
||||
$pdf->SetAutoPageBreak(TRUE, 10);
|
||||
$pdf->SetFont('helvetica', '', 11);
|
||||
|
||||
|
||||
// Define columns (including discipline sub-columns)
|
||||
$columns = [
|
||||
'rang' => [ 0 => ['header' => 'Rang']],
|
||||
'name' => [ 0 => ['header' => 'Name']],
|
||||
'vorname' => [ 0 => ['header' => 'Vorname']],
|
||||
'geburtsdatum' => [ 0 => ['header' => 'Jg.']],
|
||||
'verein' => [ 0 => ['header' => 'Verein']],
|
||||
];
|
||||
|
||||
foreach ($displayedNoten as $sdN) {
|
||||
if (intval($sdN['pro_geraet']) === 1) {
|
||||
foreach ($geraete as $g) {
|
||||
$columns[$sdN['name']][$g['id']] = ['header' => $sdN['name'], 'nullstellen' => $sdN['nullstellen'] ?? 2];
|
||||
}
|
||||
} else {
|
||||
$allowed = $ascArrayGeraeteJSON[$sdN['id']] ?? [];
|
||||
foreach ($allowed as $gId) {
|
||||
$columns[$sdN['name']][$gId] = ['header' => $sdN['name'], 'nullstellen' => $sdN['nullstellen'] ?? 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize max widths with header widths (+4 mm padding)
|
||||
foreach ($columns as $key => $col) {
|
||||
foreach ($col as $skey => $scol) {
|
||||
$columns[$key][$skey]['max_width'] = $pdf->GetStringWidth($scol['header']) + 8;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Fill missing defaults and finalize the sortArray
|
||||
foreach ($personen as $sp) {
|
||||
$pId = $sp['id'];
|
||||
|
||||
// We check all possible devices (including 0)
|
||||
foreach ($indexedNotenArray[$pId] as $sG => $currentNoten) {
|
||||
|
||||
foreach ($alleNoten as $noteDef) {
|
||||
$neni = $noteDef['id'];
|
||||
|
||||
// Skip if note already exists for this person/device
|
||||
if (isset($currentNoten[$neni])) continue;
|
||||
|
||||
// Logic for "Pro Gerät" vs "Specific/Total"
|
||||
$isProGeraet = (intval($noteDef['pro_geraet']) === 1);
|
||||
$allowedGeraete = $ascArrayGeraeteJSON[$neni] ?? [];
|
||||
|
||||
if ($isProGeraet) {
|
||||
if ($sG === 0) continue;
|
||||
} else {
|
||||
if (!in_array($sG, $allowedGeraete)) continue;
|
||||
}
|
||||
|
||||
// Assign default value
|
||||
$defaultValue = $ascArrayDefaultValues[$neni] ?? 0;
|
||||
|
||||
$string = nuber_format($defaultValue, $noteDef['nullstellen']);
|
||||
|
||||
$indexedNotenArray[$pId][$sG][$neni] = $string;
|
||||
|
||||
$width = $pdf->GetStringWidth($string) + 4;
|
||||
|
||||
if ($w > $columns[$noteDef['name']][$sG]['max_width']) {
|
||||
$columns[$noteDef['name']][$sG] = $w;
|
||||
}
|
||||
|
||||
// If this missing note was our ranking note, add default to sortArray
|
||||
if ($neni === $rangNote && $sG === 0) {
|
||||
$sortArray[$pId] = $defaultValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function calculateRanks(array $scoreArray, $direction = 'DESC') {
|
||||
// 1. Sort the scores while preserving keys
|
||||
if ($direction === 'DESC') {
|
||||
arsort($scoreArray); // High scores first
|
||||
} else {
|
||||
asort($scoreArray); // Low scores first
|
||||
}
|
||||
|
||||
$ranks = [];
|
||||
$currentRank = 0;
|
||||
$lastScore = null;
|
||||
$skipped = 0;
|
||||
|
||||
foreach ($scoreArray as $pId => $score) {
|
||||
if ($score !== $lastScore) {
|
||||
$currentRank += ($skipped + 1);
|
||||
$skipped = 0;
|
||||
} else {
|
||||
$skipped++;
|
||||
}
|
||||
|
||||
$ranks[$pId] = $currentRank;
|
||||
$lastScore = $score;
|
||||
}
|
||||
return $ranks;
|
||||
}
|
||||
|
||||
// 4. Calculate Ranks
|
||||
// FIXED: Passing $orderBestRang (the string "ASC"/"DESC") instead of the array
|
||||
$ranks = calculateRanks($sortArray, $orderBestRang);
|
||||
|
||||
// Calculate max width of each column based on all data
|
||||
foreach ($personen as $p) {
|
||||
foreach ($columns as $key => &$col) {
|
||||
if (isset($p[$key])) {
|
||||
$text = $p[$key];
|
||||
} else {
|
||||
$text = '';
|
||||
}
|
||||
$w = $pdf->GetStringWidth($text) + 4;
|
||||
// Add some padding
|
||||
if ($w > $col['max_width']) {
|
||||
$col['max_width'] = $w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($col);
|
||||
$columns['geburtsdatum'][0]['max_width'] = $pdf->GetStringWidth("0000") + 8;
|
||||
|
||||
$tablew = 297 - 20; // total table width (A4 landscape in mm)
|
||||
|
||||
// Step 1: Calculate total width of fixed columns
|
||||
$fixedWidth = 0;
|
||||
|
||||
/*
|
||||
// Discipline columns (each discipline has two columns: "d-note" and "note")
|
||||
foreach ($disciplines as $d) {
|
||||
$fixedWidth += $columns["d-note $d"]['max_width'] + $columns["note $d"]['max_width'];
|
||||
}
|
||||
|
||||
// Other fixed columns
|
||||
$fixedColumns = ['geburtsdatum','rang','gesamt'];
|
||||
foreach ($fixedColumns as $col) {
|
||||
$fixedWidth += $columns[$col]['max_width'];
|
||||
}
|
||||
|
||||
// Step 2: Compute extra space for flexible columns
|
||||
$flexCols = ['name','vorname','verein']; // columns that can grow
|
||||
$flexTotal = 0;
|
||||
|
||||
// Compute current total width of flexible columns
|
||||
foreach ($flexCols as $col) {
|
||||
$flexTotal += $columns[$col]['max_width'];
|
||||
}
|
||||
|
||||
// Available width for flexible columns
|
||||
$effTableWidth = $tablew - $fixedWidth;
|
||||
$extraWidth = $effTableWidth - $flexTotal;
|
||||
|
||||
// Step 3: Distribute extra width proportionally among flexible columns
|
||||
if ($extraWidth > 0) {
|
||||
foreach ($flexCols as $col) {
|
||||
$columns[$col]['max_width'] += ($columns[$col]['max_width'] / $flexTotal) * $extraWidth;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
$pdf->columns = $columns;
|
||||
$pdf->disciplines = $disciplines;
|
||||
|
||||
$pdf->AddPage();
|
||||
|
||||
// After AddPage(), the header has been drawn
|
||||
$margin_top = $pdf->headerBottomY;
|
||||
|
||||
// Now adjust your margins if needed
|
||||
$pdf->SetMargins(10, $margin_top, 10); // +5 mm padding below header
|
||||
$pdf->SetY($margin_top); // Move cursor below header manually
|
||||
|
||||
|
||||
$mbs = false;
|
||||
$mbl = false;
|
||||
$pdf->SetFont('', '');
|
||||
$index = 0;
|
||||
foreach ($personen as $r) {
|
||||
|
||||
$pdf->SetTextColor(0, 0, 0);
|
||||
|
||||
$rang = $ranks[$r['id']];
|
||||
|
||||
if ($rang == 1) {
|
||||
$pdf->SetFillColor(255, 235, 128);
|
||||
} elseif($rang == 2) {
|
||||
$pdf->SetFillColor(224, 224, 224);
|
||||
} elseif($$rang == 3) {
|
||||
$pdf->SetFillColor(230, 191, 153);
|
||||
} elseif ($index % 2 == 0) {
|
||||
$pdf->SetFillColor(255, 255, 255); // white
|
||||
} else {
|
||||
$pdf->SetFillColor(240, 240, 240); // light gray
|
||||
}
|
||||
|
||||
|
||||
$pdf->SetFont('', 'B');
|
||||
/*
|
||||
if ($buttontype === 'export_programm_bm') {
|
||||
if (($r['verein'] === 'BTV Basel' || $r['verein'] === 'TV Basel') && $mbs === false){
|
||||
$pdf->SetFillColor(0, 0, 0);
|
||||
$pdf->SetTextColor(255, 255, 255);
|
||||
$mbs = true;
|
||||
} elseif (($r['verein'] === 'Kutu Regio Basel') && $mbl === false) {
|
||||
$pdf->SetFillColor(255, 0, 0);
|
||||
$pdf->SetTextColor(255, 255, 255);
|
||||
$mbl = true;
|
||||
}
|
||||
}*/
|
||||
|
||||
$pdf->Cell($columns['rang'][0]['max_width'], 8, $rang, 'B', 0, 'C', true);
|
||||
|
||||
$pdf->SetFont('', '');
|
||||
$pdf->Cell($columns['name'][0]['max_width'], 8, $r['name'], 'B', 0, 'L', true);
|
||||
$pdf->Cell($columns['vorname'][0]['max_width'], 8, $r['vorname'], 'B', 0, 'L', true);
|
||||
$pdf->Cell($columns['geburtsdatum'][0]['max_width'], 8, (new DateTime($r['geburtsdatum']))->format("Y"), 'B', 0, 'C', true);
|
||||
$pdf->Cell($columns['verein'][0]['max_width'], 8, $r['verein'], 'B', 0, 'L', true);
|
||||
|
||||
|
||||
foreach ($disciplines as $d) {
|
||||
$d_note = isset($r["d-note $d"]) ?
|
||||
number_format((float)$r["d-note $d"], 2) : '';
|
||||
$note = isset($r["note $d"]) ? number_format((float)$r["note $d"], 3) : '';
|
||||
$pdf->SetFont('', '', 9);
|
||||
$pdf->Cell($columns["d-note $d"]['max_width'], 8, $d_note, 'LB', 0, 'C', true);
|
||||
$pdf->SetFont('', '', 11);
|
||||
$pdf->Cell($columns["note $d"]['max_width'], 8, $note, 'B', 0, 'C', true);
|
||||
}
|
||||
|
||||
$gesamt = isset($r["gesamtpunktzahl"]) ? number_format((float)$r["gesamtpunktzahl"], 3) : '';
|
||||
|
||||
$pdf->SetFont('', 'B');
|
||||
$pdf->Cell($columns['gesamt'][0]['max_width'], 8, $gesamt, 'B', 0, 'C', true);
|
||||
$pdf->SetFont('', '');
|
||||
|
||||
$x = $pdf->GetX() - $columns['gesamt'][0]['max_width'];
|
||||
$y = $pdf->GetY();
|
||||
|
||||
$pdf->SetLineWidth(0.6);
|
||||
$pdf->Line($x, $y, $x, $y + 7.7);
|
||||
|
||||
$pdf->SetLineWidth(0.2);
|
||||
$pdf->Ln();
|
||||
|
||||
$index++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$pdf->SetFont('', '', 7);
|
||||
$textanzturnerinnen = (count($entries) > 1) ? 'Turnerinnen': 'Turnerin';
|
||||
$pdf->Cell(20, 6, count($entries).' '.$textanzturnerinnen, 0, 0, 'L');
|
||||
|
||||
if ($buttontype === 'export_programm' || $buttontype === 'export_programm_bm') {
|
||||
$pdf->Output("KTBB_Ergebnisse_" . $programm . "_" . $current_year . ".pdf", 'D');
|
||||
exit;
|
||||
} elseif ($buttontype === 'upload_programm') {
|
||||
$dir = $baseDir . '/wp-content/ergebnisse/';
|
||||
if (!file_exists($dir)) mkdir($dir, 0755, true);
|
||||
$localPath = $dir . "KTBB_Ergebnisse_" . $programm . "_" . $current_year . ".pdf";
|
||||
if (file_exists($localPath)) unlink($localPath);
|
||||
$pdf->Output($localPath, 'F');
|
||||
$_SESSION['form_message'] = '<div class="success">PDF wurde hochgeladen</div>';
|
||||
exit;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
// Show all errors except deprecation notices (these come from vendor libraries
|
||||
// that aren't yet typed for newer PHP versions). Long-term fix: update
|
||||
// dependencies to versions compatible with your PHP runtime.
|
||||
error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
|
||||
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($_GET['id']) ? intval($_GET['id']) : 0;
|
||||
$discipline = isset($_GET['discipline']) ? preg_replace('/[^a-zA-Z0-9 _-]/', '', $_GET['discipline']) : '';
|
||||
|
||||
if ($discipline !== 'boden') {
|
||||
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 t.bodenmusik, agg.filePath FROM `$tableTurnerinnen` t LEFT JOIN (SELECT a.id, a.file_path AS filePath FROM $tableAudiofiles a) agg ON agg.id = t.bodenmusik WHERE t.id = $id");
|
||||
$row = $result->fetch_assoc();
|
||||
if (!$row || !isset($row['bodenmusik'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'Row fetch failed '.$id]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($row['bodenmusik'] === "0" || $row['filePath'] == null) {
|
||||
echo json_encode(['success' => false, 'message' => 'Keine Musik']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$folder = realpath($baseDir . '/displays/json');
|
||||
if ($folder === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Could not find displays folder.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$filename = 'audio.json';
|
||||
$filepath = $folder . '/' . $filename;
|
||||
|
||||
if (!is_writable($folder)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Folder not writable: ']);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
if (!is_file($filepath)){
|
||||
file_put_contents($filepath, []);
|
||||
}
|
||||
|
||||
|
||||
$jsonString = file_get_contents($filepath);
|
||||
|
||||
// decode JSON, fallback to empty array if invalid
|
||||
$oldjson = json_decode($jsonString, true) ?? [];
|
||||
|
||||
|
||||
$oldjson["musik"] = $row['filePath'];
|
||||
$oldjson["start"] = true;
|
||||
|
||||
$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,
|
||||
'disable_musik_button' => true
|
||||
]);
|
||||
exit;
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
$discipline = 'boden';
|
||||
|
||||
$folder = realpath($baseDir . '/displays/json');
|
||||
if ($folder === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Could not find displays folder.'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$filename = 'audio.json';
|
||||
$filepath = $folder . '/' . $filename;
|
||||
|
||||
if (!is_writable($folder)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Folder not writable']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!is_file($filepath)){
|
||||
file_put_contents($filepath, []);
|
||||
}
|
||||
|
||||
$jsonString = file_get_contents($filepath);
|
||||
|
||||
// decode JSON, fallback to empty array if invalid
|
||||
$oldjson = json_decode($jsonString, true) ?? [];
|
||||
|
||||
$oldjson["start"] = false;
|
||||
|
||||
$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,
|
||||
'disable_musik_button' => true
|
||||
]);
|
||||
exit;
|
||||
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
ini_set('display_errors', '1');
|
||||
ini_set('display_startup_errors', '1');
|
||||
error_reporting(E_ALL);
|
||||
|
||||
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';
|
||||
|
||||
$abteilung = isset($_POST['abteilung']) ? strval($_POST['abteilung']) : '1';
|
||||
$aufgabe = isset($_POST['aufgabe']) ? strval($_POST['aufgabe']) : '2';
|
||||
$name = isset($_POST['name']) ? strval($_POST['name']) : 'RK';
|
||||
$geraet = isset($_POST['geraet']) ? strtolower($_POST['geraet']) : 'boden';
|
||||
|
||||
if ($abteilung === ''){
|
||||
echo json_encode(['success' => false, 'message' => 'Keine Abteilung angegeben.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($aufgabe === ''){
|
||||
echo json_encode(['success' => false, 'message' => 'Keine Aufgabe angegeben.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!is_numeric($aufgabe)){
|
||||
echo json_encode(['success' => false, 'message' => 'Keine valide Aufgabe. (is not numeric)']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($name === ''){
|
||||
echo json_encode(['success' => false, 'message' => 'Kein Namen angegeben']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $mysqli->prepare("SELECT `name` FROM $tableGeraete ORDER BY start_index ASC");
|
||||
|
||||
if (!$stmt->execute()) {
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$disciplines = array_map(
|
||||
'strtolower',
|
||||
array_column($result->fetch_all(MYSQLI_ASSOC), 'name')
|
||||
);
|
||||
|
||||
$stmt->close();
|
||||
|
||||
if (!in_array($geraet, $disciplines)){
|
||||
echo json_encode(['success' => false, 'message' => 'Invalides Gerät: '.$geraet]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $mysqli->prepare("SELECT * FROM $tableKrProtokoll WHERE abteilung = ? AND geraet = ? AND aufgabe = ? LIMIT 1");
|
||||
$stmt->bind_param("sss", $abteilung, $geraet, $aufgabe);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->get_result();
|
||||
|
||||
$row = $result->fetch_assoc();
|
||||
|
||||
if ($row){
|
||||
$updatestmt = $mysqli->prepare("UPDATE $tableKrProtokoll SET name = ? WHERE id = ?");
|
||||
$updatestmt->bind_param("si", $name, $row['id']);
|
||||
|
||||
if (!$updatestmt->execute()) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Insert ERROR: ' . $updatestmt->error
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Updated: updated']);
|
||||
exit;
|
||||
} else {
|
||||
$insertstmt = $mysqli->prepare("INSERT INTO $tableKrProtokoll (abteilung, geraet, name, aufgabe) VALUES (?, ?, ?, ?)");
|
||||
$insertstmt->bind_param("ssss", $abteilung, $geraet, $name, $aufgabe);
|
||||
|
||||
if (!$insertstmt->execute()) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Insert ERROR: ' . $insertstmt->error
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Updated: inserted']);
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
$new_value = $_POST['freigabe'] ?? '';
|
||||
|
||||
$type = $_POST['type'] ?? 'nan';
|
||||
|
||||
$allowedTypes = ['kampfrichter', 'trainer'];
|
||||
|
||||
if (in_array($type, $allowedTypes)) {
|
||||
|
||||
|
||||
$accessKey = "access_granted_" . $type;
|
||||
$idKey = "passcode" . $type . "_id";
|
||||
|
||||
// 3. Check if they have access
|
||||
$hasAccess = isset($_SESSION[$accessKey]) &&
|
||||
$_SESSION[$accessKey] === true &&
|
||||
!empty($_SESSION[$idKey]) &&
|
||||
$_SESSION[$idKey] > 0;
|
||||
|
||||
|
||||
if (!$hasAccess) {
|
||||
echo json_encode(['success' => false, 'message' => 'no permissions']);
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
echo json_encode(['success' => false, 'message' => 'no permissions']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!$new_value) {
|
||||
echo json_encode('Invalid Input');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($type === 'kampfrichter'){
|
||||
$_SESSION['selectedFreigabeKampfrichter'] = $new_value;
|
||||
}
|
||||
|
||||
if ($type === 'trainer'){
|
||||
$_SESSION['selectedFreigabeTrainer'] = $new_value;
|
||||
}
|
||||
|
||||
// ---------- Return JSON ----------
|
||||
echo json_encode(['success' => true, 'message' => 'SESSION updated']);
|
||||
exit;
|
||||
@@ -0,0 +1,252 @@
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
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-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
|
||||
$person_id = isset($_POST['personId']) ? intval($_POST['personId']) : 0;
|
||||
$field_type_id = intval($_POST['fieldTypeId'] ?? 0);
|
||||
$gereat_id = intval($_POST['gereatId'] ?? 0);
|
||||
$jahr = isset($_POST['jahr']) ? intval($_POST['jahr']) : 0;
|
||||
$run_number = isset($_POST['run']) ? intval($_POST['run']) : 1;
|
||||
|
||||
if (!isset($_POST['value'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'Kein Value angegeben']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$valueNoteUpdate = floatval($_POST['value']);
|
||||
|
||||
if ($person_id < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalide Personen-ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($jahr < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalides Jahr']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($gereat_id < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalide Geraet-ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$geratExistiert = db_get_var($mysqli, "SELECT 1 FROM $tableGeraete WHERE id = ? LIMIT 1", [$gereat_id]);
|
||||
|
||||
if (!$geratExistiert) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalide Geraet-ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($field_type_id < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalide Notentyp-ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$noteConfig = db_select($mysqli, $tableNotenBezeichnungen, "*", "id = ?", [$field_type_id]);
|
||||
|
||||
if (count($noteConfig) !== 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalide Notentyp-ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$singleNoteConfig = $noteConfig[0];
|
||||
|
||||
if ($singleNoteConfig['max_value'] !== null && $valueNoteUpdate > $singleNoteConfig['max_value']) {
|
||||
echo json_encode(['success' => false, 'message' => "Wert zu hoch (max " . $singleNoteConfig['max_value'].")"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($singleNoteConfig['min_value'] !== null && $valueNoteUpdate < $singleNoteConfig['min_value']){
|
||||
echo json_encode(['success' => false, 'message' => "Wert zu niedrig (min " . $singleNoteConfig['min_value'].")"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO $tableNoten (`value`, `person_id`, `note_bezeichnung_id`, `geraet_id`, `jahr`, `run_number`)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)";
|
||||
|
||||
$stmt = $mysqli->prepare($sql);
|
||||
|
||||
$stmt->bind_param("siiiii", $valueNoteUpdate, $person_id, $field_type_id, $gereat_id, $jahr, $run_number);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$stmt->close();
|
||||
|
||||
if ($singleNoteConfig['berechnung_json'] === null) {
|
||||
echo json_encode(['success' => true, 'message' => "Wert aktualisiert"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . "/../scripts/string-calculator/string-calculator-functions.php";
|
||||
|
||||
$updateNoten = [];
|
||||
|
||||
$notenRechner = new NotenRechner();
|
||||
|
||||
try {
|
||||
$abhaenigeRechnungen = json_decode($singleNoteConfig['berechnung_json']);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => true, 'message' => "Wert aktualisiert, fehler bei der Berechnung der weiteren Werte"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$geraete = db_select($mysqli, $tableGeraete, "id");
|
||||
|
||||
// Alle Werte werden von der Datenbank geholt und werden, wenn nicht vorhanden, durch den Standartwert ersetzt.
|
||||
|
||||
$alleNoten = db_select($mysqli, $tableNotenBezeichnungen, "id, berechnung, default_value, nullstellen, pro_geraet, geraete_json, anzahl_laeufe_json");
|
||||
|
||||
$noten = db_select($mysqli, $tableNoten, "`value`, `note_bezeichnung_id`, `geraet_id`, `run_number`", "`person_id` = ? AND `jahr` = ?", [$person_id, $jahr]);
|
||||
|
||||
$ascArrayDefaultValues = array_column($alleNoten, 'default_value', 'id');
|
||||
$ascArrayProGeraet = array_column($alleNoten, 'pro_geraet', 'id');
|
||||
$ascArrayGeraeteJSON = array_column($alleNoten, 'geraete_json', 'id');
|
||||
$ascArrayAnzahlLaeufeJSON = array_column($alleNoten, 'anzahl_laeufe_json', 'id');
|
||||
$ascArrayRechnungen = array_column($alleNoten, 'berechnung', 'id');
|
||||
|
||||
|
||||
// $proGeraet = intval($calc['pro_geraet']) !== 1;
|
||||
|
||||
|
||||
$indexedNotenArray = [];
|
||||
|
||||
foreach ($ascArrayGeraeteJSON as $key => $saagj) {
|
||||
$ascArrayGeraeteJSON[$key] = json_decode($saagj, true);
|
||||
}
|
||||
|
||||
foreach ($ascArrayAnzahlLaeufeJSON as $key => $saalj) {
|
||||
$ascArrayAnzahlLaeufeJSON[$key] = json_decode($saalj, true) ?? [];
|
||||
}
|
||||
|
||||
foreach ($geraete as $g) {
|
||||
$indexedNotenArray[$g['id']] = [];
|
||||
}
|
||||
|
||||
$indexedNotenArray[0] = [];
|
||||
|
||||
foreach ($noten as $sn) {
|
||||
$indexedNotenArray[$sn['geraet_id']][$sn['note_bezeichnung_id']][$sn['run_number']] = $sn['value'];
|
||||
}
|
||||
|
||||
$alleNotenIds = array_column($alleNoten, 'id') ?? [];
|
||||
|
||||
foreach ($indexedNotenArray as $sG => $siNA) {
|
||||
$existierendeNotenIds = array_keys($siNA) ?? [];
|
||||
|
||||
$nichtExistierendeNotenIds = array_diff($alleNotenIds, $existierendeNotenIds) ?? [];
|
||||
|
||||
foreach ($nichtExistierendeNotenIds as $neni) {
|
||||
if (!isset($ascArrayDefaultValues[$neni])) { continue; }
|
||||
if (intval($ascArrayProGeraet[$neni]) === 1 && intval($sG) === 0) { continue; }
|
||||
if (intval($ascArrayProGeraet[$neni]) !== 1 && (!is_array($ascArrayGeraeteJSON[$neni]) || !in_array($sG, $ascArrayGeraeteJSON[$neni]))) { continue; }
|
||||
|
||||
// For non-existent notes, we fill all runs with default value
|
||||
// We set Run 1 by default, and if more are configured, also those
|
||||
$indexedNotenArray[$sG][$neni][1] = $ascArrayDefaultValues[$neni];
|
||||
|
||||
// Check for more runs in config? (Actually, this might be overkill for defaults,
|
||||
// but the calculator might need them)
|
||||
}
|
||||
}
|
||||
|
||||
// We only want to save the IDs that were actually recalculated
|
||||
$idsToSave = [];
|
||||
|
||||
foreach ($abhaenigeRechnungen as $sRechnung) {
|
||||
if ($sRechnung[1] !== "A" && intval($sRechnung[1]) !== $gereat_id) { continue; }
|
||||
|
||||
$rechnung = $ascArrayRechnungen[$sRechnung[0]] ?? null;
|
||||
|
||||
$gereadIdArrays = ($sRechnung[1] === "A") ? $gereat_id : $sRechnung[1];
|
||||
|
||||
$targetNoteId = $sRechnung[0];
|
||||
$isProGeraet = (intval($ascArrayProGeraet[$targetNoteId]) === 1);
|
||||
$allowedGeraete = $ascArrayGeraeteJSON[$targetNoteId] ?? [];
|
||||
|
||||
if ($isProGeraet) {
|
||||
$gereadIdArrays = $gereat_id;
|
||||
} elseif (in_array($gereat_id, $allowedGeraete)) {
|
||||
$gereadIdArrays = $gereat_id;
|
||||
} else {
|
||||
$gereadIdArrays = 0;
|
||||
}
|
||||
|
||||
if ($rechnung === null) {
|
||||
echo json_encode(['success' => true, 'message' => "Wert aktualisiert, Fehler: Rechnung" . $sRechnung[0] . "nicht gefunden"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$calcResult = $notenRechner->berechneStringComplex($rechnung, $indexedNotenArray, $gereat_id);
|
||||
if ($calcResult['success'] !== true) {
|
||||
echo json_encode(['success' => true, 'message' => "Wert aktualisiert, Rechenfehler: " . ($calcResult['value'] ?? '')]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Update the local array (Always Run 1 for calculations for now, UNLESS we want calculated runs?)
|
||||
// Most calculations are "Total" points which have run_number = 1
|
||||
$indexedNotenArray[$gereadIdArrays][$sRechnung[0]][1] = $calcResult['value'];
|
||||
|
||||
// Track that this ID needs to be written to the database (Target run is 1)
|
||||
$updatedValues[$gereadIdArrays][$sRechnung[0]][1] = $calcResult['value'];
|
||||
}
|
||||
|
||||
|
||||
// Prepare the statement once
|
||||
$sql = "INSERT INTO $tableNoten (`value`, `person_id`, `note_bezeichnung_id`, `geraet_id`, `jahr`, `run_number`)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)";
|
||||
|
||||
$stmt = $mysqli->prepare($sql);
|
||||
|
||||
$indexedNullstellen = array_column($alleNoten, 'nullstellen', 'id');
|
||||
|
||||
$formatedNoten = [];
|
||||
|
||||
foreach ($updatedValues as $gereat => $notenArray) {
|
||||
foreach ($notenArray as $note => $runArray) {
|
||||
foreach ($runArray as $run => $value) {
|
||||
$stmt->bind_param("siiiii", $value, $person_id, $note, $gereat, $jahr, $run);
|
||||
$stmt->execute();
|
||||
$formatedNoten[$gereat][$note][$run] = number_format($value ,$indexedNullstellen[$note] ?? 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$formatedNoten[$gereat_id][$field_type_id][$run_number] = number_format($valueNoteUpdate ,$indexedNullstellen[$field_type_id] ?? 2);
|
||||
|
||||
$stmt->close();
|
||||
$mysqli->close();
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => "Wert aktualisiert, alle Berechnungen durchgeführt",
|
||||
"noten" => $formatedNoten
|
||||
]);
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
session_start();
|
||||
|
||||
if (empty($_SESSION['access_granted_kampfrichter']) || $_SESSION['access_granted_kampfrichter'] !== true || empty($_SESSION['passcodekampfrichter_id']) || $_SESSION['passcodekampfrichter_id'] < 1 || !isset($_SESSION['selectedFreigabeKampfrichter']) || $_SESSION['selectedFreigabeKampfrichter'] !== 'admin') {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
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;
|
||||
$fieldType = isset($_POST['field_type']) ? preg_replace('/[^a-zA-Z0-9 _-]/', '', $_POST['field_type']) : '';
|
||||
$discipline = isset($_POST['discipline']) ? preg_replace('/[^a-zA-Z0-9 _-]/', '', $_POST['discipline']) : '';
|
||||
$value = isset($_POST['value']) ? floatval($_POST['value']) : 0;
|
||||
|
||||
if ($id <= 0) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($value) || floatval($value) < 0 || !isset($discipline) || $discipline === ''|| !isset($fieldType) || $fieldType === '') {
|
||||
http_response_code(422);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($discipline === 'all') {
|
||||
$column = $fieldType;
|
||||
} else {
|
||||
$column = $fieldType . ' ' . $discipline;
|
||||
}
|
||||
|
||||
$excluded_columns = [
|
||||
'id',
|
||||
'name',
|
||||
'vorname',
|
||||
'bezahlt',
|
||||
'bezahltoverride',
|
||||
'geburtsdatum',
|
||||
'programm',
|
||||
'verein',
|
||||
'bodenmusik'
|
||||
];
|
||||
|
||||
$sql = "SHOW COLUMNS FROM `$tableTurnerinnen`";
|
||||
$result = $mysqli->query($sql);
|
||||
|
||||
$all_columns = [];
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
$all_columns[] = $row['Field'];
|
||||
}
|
||||
|
||||
$allowed_columns = array_values(
|
||||
array_diff($all_columns, $excluded_columns)
|
||||
);
|
||||
|
||||
|
||||
if (!in_array($column, $allowed_columns, true)) {
|
||||
http_response_code(422);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $mysqli->prepare("UPDATE `$tableTurnerinnen` SET `$column` = ? WHERE id = ?");
|
||||
$stmt->bind_param("di", $value, $id);
|
||||
if (!$stmt->execute()) {
|
||||
http_response_code(500);
|
||||
exit;
|
||||
}
|
||||
$stmt->close();
|
||||
$mysqli->close();
|
||||
|
||||
http_response_code(200);
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Updated successfully'
|
||||
]);
|
||||
exit;
|
||||
@@ -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;
|
||||
160
www/intern/scripts/kampfrichter/ajax/neu copy.php
Normal file
160
www/intern/scripts/kampfrichter/ajax/neu copy.php
Normal file
@@ -0,0 +1,160 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
//ini_set('display_errors', 1);
|
||||
//ini_set('display_startup_errors', 1);
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
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-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
$noten = db_select($mysqli, $tableNotenBezeichnungen, "id, berechnung, type");
|
||||
|
||||
// 1. Re-index the array so the keys match the database IDs
|
||||
$notenById = array_column($noten, null, 'id');
|
||||
|
||||
$berechnungen = [];
|
||||
foreach ($notenById as $id => $sn) {
|
||||
if ($sn['type'] === 'berechnung') {
|
||||
$berechnungen[] = $sn;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($berechnungen)) {
|
||||
echo json_encode(['success' => true, 'message' => "Keine Berechnungen ausgewählt"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . "/../scripts/string-calculator/string-calculator-functions.php";
|
||||
$notenRechner = new NotenRechner();
|
||||
|
||||
// 1. Build the direct map
|
||||
// Format: [ Changed_Note_ID => [ "CalcId|GeraetId" => [CalcId, GeraetId] ] ]
|
||||
$dependencyMap = [];
|
||||
|
||||
foreach ($berechnungen as $calc) {
|
||||
$neededIdsArray = $notenRechner->getBenoetigteIdsComplex($calc['berechnung']);
|
||||
|
||||
if (empty($neededIdsArray)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$calcId = (int)$calc['id'];
|
||||
|
||||
foreach ($neededIdsArray as $needed) {
|
||||
$nId = (int)$needed['noteId'];
|
||||
|
||||
// Keep geraetId as integer if it's a number (e.g., 3), otherwise string ('S')
|
||||
$gId = is_numeric($needed['geraetId']) ? (int)$needed['geraetId'] : $needed['geraetId'];
|
||||
|
||||
// Create a unique string key so we don't store exact duplicates
|
||||
$nodeKey = $calcId . '|' . $gId;
|
||||
|
||||
if (!isset($dependencyMap[$nId])) {
|
||||
$dependencyMap[$nId] = [];
|
||||
}
|
||||
|
||||
// Store it as the "little array" you requested: [DependentCalcId, GeraetId]
|
||||
$dependencyMap[$nId][$nodeKey] = [$calcId, $gId];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 2. Our recursive helper function (Updated for complex nodes)
|
||||
function getCompleteDependencyChain($id, $directMap, $visited = [])
|
||||
{
|
||||
// If this ID doesn't have anything depending on it, return empty
|
||||
if (!isset($directMap[$id])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$allDependencies = [];
|
||||
|
||||
foreach ($directMap[$id] as $nodeKey => $complexNode) {
|
||||
// CIRCULAR DEPENDENCY CHECK:
|
||||
// We check against the string key (e.g., "10|S") to prevent infinite loops
|
||||
if (isset($visited[$nodeKey])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 1. Mark this specific node as visited
|
||||
$visited[$nodeKey] = true;
|
||||
|
||||
// 2. Add the little array [CalcId, GeraetId] to our master list
|
||||
$allDependencies[$nodeKey] = $complexNode;
|
||||
|
||||
// 3. Recursively find everything that depends on THIS calculation ID
|
||||
// $complexNode[0] is the dependent Calc ID
|
||||
$childDependencies = getCompleteDependencyChain($complexNode[0], $directMap, $visited);
|
||||
|
||||
// 4. Merge the child results into our master list safely
|
||||
foreach ($childDependencies as $childKey => $childNode) {
|
||||
$allDependencies[$childKey] = $childNode;
|
||||
$visited[$childKey] = true; // Ensure the parent loop knows this was visited
|
||||
}
|
||||
}
|
||||
|
||||
return $allDependencies;
|
||||
}
|
||||
|
||||
|
||||
// 3. Create the final flattened map for ALL IDs
|
||||
$flatDependencyMap = [];
|
||||
|
||||
foreach (array_keys($notenById) as $id) {
|
||||
$chain = getCompleteDependencyChain($id, $dependencyMap);
|
||||
|
||||
// Only add it if dependencies exist
|
||||
if (!empty($chain)) {
|
||||
// array_values() removes the "10|S" string keys, turning it into a perfect
|
||||
// 0-indexed array for clean JSON encoding: [[10, "S"], [12, 3]]
|
||||
$flatDependencyMap[$id] = array_values($chain);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 4. Database Updates
|
||||
// Step 1: Reset all rows to NULL in a single query
|
||||
$resetSql = "UPDATE $tableNotenBezeichnungen SET `berechnung_json` = NULL";
|
||||
$mysqli->query($resetSql);
|
||||
|
||||
// Step 2: Prepare the statement
|
||||
$updateSql = "UPDATE $tableNotenBezeichnungen SET `berechnung_json` = ? WHERE id = ?";
|
||||
$stmt = $mysqli->prepare($updateSql);
|
||||
|
||||
foreach ($flatDependencyMap as $id => $completeDependencyArray) {
|
||||
if (empty($completeDependencyArray)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$jsonString = json_encode($completeDependencyArray);
|
||||
|
||||
// Bind parameters: 's' for string (JSON), 'i' for integer (ID)
|
||||
$stmt->bind_param("si", $jsonString, $id);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
|
||||
echo json_encode(['success' => true, 'message' => "Abhaengigkeiten berechnet"]);
|
||||
exit;
|
||||
201
www/intern/scripts/kampfrichter/ajax/neu.php
Normal file
201
www/intern/scripts/kampfrichter/ajax/neu.php
Normal file
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
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-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
|
||||
$person_id = isset($_POST['personId']) ? intval($_POST['personId']) : 0;
|
||||
$field_type_id = intval($_POST['fieldTypeId'] ?? 0);
|
||||
$gereat_id = intval($_POST['gereatId'] ?? 0);
|
||||
$jahr = isset($_POST['jahr']) ? intval($_POST['jahr']) : 0;
|
||||
|
||||
if (!isset($_POST['value'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'Kein Value angegeben']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$value = floatval($_POST['value']);
|
||||
|
||||
if ($person_id < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalide Personen-ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($jahr < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalides Jahr']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($gereat_id < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalide Geraet-ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$geratExistiert = db_get_var($mysqli, "SELECT 1 FROM $tableNotenBezeichnungen WHERE id = ? LIMIT 1", [$gereat_id]);
|
||||
|
||||
if (!$geratExistiert) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalide Geraet-ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($field_type_id < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalide Notentyp-ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$noteConfig = db_select($mysqli, $tableNotenBezeichnungen, "*", "id = ?", [$field_type_id]);
|
||||
|
||||
if (count($noteConfig) !== 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalide Notentyp-ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$singleNoteConfig = $noteConfig[0];
|
||||
|
||||
if ($singleNoteConfig['max_value'] !== null && $value > $singleNoteConfig['max_value']) {
|
||||
echo json_encode(['success' => false, 'message' => "Wert zu hoch (max " . $singleNoteConfig['max_value'].")"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($singleNoteConfig['min_value'] !== null && $value < $singleNoteConfig['min_value']){
|
||||
echo json_encode(['success' => false, 'message' => "Wert zu niedrig (min " . $singleNoteConfig['min_value'].")"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO $tableNoten (`value`, `person_id`, `note_bezeichnung_id`, `geraet_id`, `jahr`)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)";
|
||||
|
||||
$stmt = $mysqli->prepare($sql);
|
||||
|
||||
$stmt->bind_param("siiii", $value, $person_id, $field_type_id, $gereat_id, $jahr);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$stmt->close();
|
||||
|
||||
if ($singleNoteConfig['berechnung_json'] === null) {
|
||||
echo json_encode(['success' => true, 'message' => "Wert aktualisiert"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . "/../scripts/string-calculator/string-calculator-functions.php";
|
||||
|
||||
$updateNoten = [];
|
||||
|
||||
$notenRechner = new NotenRechner();
|
||||
|
||||
try {
|
||||
$abhaenigeRechnungen = json_decode($singleNoteConfig['berechnung_json']);
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => true, 'message' => "Wert aktualisiert, fehler bei der Berechnung der weiteren Werte"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Alle Werte werden von der Datenbank geholt und werden, wenn nicht vorhanden, durch den Standartwert ersetzt.
|
||||
|
||||
$alleNoten = db_select($mysqli, $tableNotenBezeichnungen, "id, berechnung, default_value, nullstellen");
|
||||
|
||||
$noten = db_select($mysqli, $tableNoten, "`value`, `note_bezeichnung_id`", "`person_id` = ? AND `geraet_id` = ? AND `jahr` = ?", [$person_id, $gereat_id, $jahr]);
|
||||
|
||||
$ascArrayDefaultValues = array_column($alleNoten, 'default_value', 'id');
|
||||
$ascArrayRechnungen = array_column($alleNoten, 'berechnung', 'id');
|
||||
|
||||
$existierendeNotenIds = array_column($noten, 'note_bezeichnung_id') ?? [];
|
||||
|
||||
$alleNotenIds = array_column($alleNoten, 'id') ?? [];
|
||||
|
||||
$nichtExistierendeNotenIds = array_diff($alleNotenIds, $existierendeNotenIds) ?? [];
|
||||
|
||||
$noten = array_column($noten, 'value', 'note_bezeichnung_id');
|
||||
|
||||
foreach ($nichtExistierendeNotenIds as $neni) {
|
||||
if (!isset($ascArrayDefaultValues[$neni])) { continue; }
|
||||
$noten[$neni] = $ascArrayDefaultValues[$neni];
|
||||
}
|
||||
|
||||
// We only want to save the IDs that were actually recalculated
|
||||
$idsToSave = [];
|
||||
|
||||
foreach ($abhaenigeRechnungen as $sRechnung) {
|
||||
$rechnung = $ascArrayRechnungen[$sRechnung] ?? null;
|
||||
|
||||
if ($rechnung === null) {
|
||||
echo json_encode(['success' => true, 'message' => "Wert aktualisiert, Fehler: Rechnung $sRechnung nicht gefunden"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$calcResult = $notenRechner->berechneString($rechnung, $noten);
|
||||
if ($calcResult['success'] !== true) {
|
||||
echo json_encode(['success' => true, 'message' => "Wert aktualisiert, Rechenfehler: " . ($calcResult['value'] ?? '')]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Update the local array so the NEXT calculation in the loop can use this new value
|
||||
$noten[$sRechnung] = $calcResult['value'];
|
||||
|
||||
// Track that this ID needs to be written to the database
|
||||
$idsToSave[] = $sRechnung;
|
||||
}
|
||||
|
||||
// Prepare the statement once
|
||||
$sql = "INSERT INTO $tableNoten (`value`, `person_id`, `note_bezeichnung_id`, `geraet_id`, `jahr`)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)";
|
||||
|
||||
$stmt = $mysqli->prepare($sql);
|
||||
|
||||
foreach ($idsToSave as $notenId) {
|
||||
$currentValue = $noten[$notenId]; // Get the calculated value from our array
|
||||
|
||||
// i = integer, s = string (use 's' for decimals/floats to prevent rounding issues in PHP)
|
||||
$stmt->bind_param("siiii", $currentValue, $person_id, $notenId, $gereat_id, $jahr);
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$mysqli->close();
|
||||
|
||||
// 1. Combine the ID the user sent with the IDs we recalculated
|
||||
$changedIds = array_merge([$field_type_id], $idsToSave);
|
||||
|
||||
// 2. Filter the $noten array to only include these keys
|
||||
// array_flip turns [10, 20] into [10 => 0, 20 => 1] so we can intersect by keys
|
||||
$changedNoten = array_intersect_key($noten, array_flip($changedIds));
|
||||
|
||||
$indexedNullstellen = array_column($alleNoten, 'nullstellen', 'id');
|
||||
|
||||
foreach ($changedNoten as $key => $scN) {
|
||||
$changedNoten[$key] = number_format($scN ,$indexedNullstellen[$key] ?? 2);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => "Wert aktualisiert, alle Berechnungen durchgeführt",
|
||||
"noten" => $changedNoten
|
||||
]);
|
||||
Reference in New Issue
Block a user