Semi-stable version with old variable names
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
require_once $baseDir . '/../scripts/session_functions.php';
|
||||
|
||||
ini_wkvs_session();
|
||||
|
||||
check_user_permission('wk_leitung');
|
||||
check_user_permission('kampfrichter');
|
||||
|
||||
require_once $baseDir . '/../scripts/delete_request_type_functions.php';
|
||||
|
||||
parse_input_to_delete();
|
||||
|
||||
verify_delete_csrf($_DELETE);
|
||||
|
||||
$programm_id = (int) ($_DELETE['programmId'] ?? 0);
|
||||
|
||||
if ($programm_id <= 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'message' => 'Keine valide Programm-ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
|
||||
$type = 'wkl';
|
||||
|
||||
$dbconnection = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($dbconnection['success'] !== true){
|
||||
echo 'Critical DB Error.';
|
||||
exit;
|
||||
}
|
||||
|
||||
$programm_name = db_get_var($mysqli, "SELECT `programm` FROM $tableProgramme WHERE id = ? LIMIT 1", [$programm_id]) ?: null;
|
||||
|
||||
if ($programm_name === null) {
|
||||
echo json_encode(['success' => true, 'message' => 'Dieses Programm existiert nicht.']);
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
$personen = db_select($mysqli, $tableTeilnehmende, "id", '`programm` = ?', [$programm_name]);
|
||||
|
||||
if (count($personen) < 1) {
|
||||
echo json_encode(['success' => true, 'message' => 'Es existieren keine Personen mit diesem Programm.']);
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
$personen_id_array = array_column($personen, 'id');
|
||||
|
||||
$parram_array = array_fill(0, count($personen_id_array), "?");
|
||||
$parram_string = implode(', ', $parram_array);
|
||||
|
||||
$year = date('n') > 6 ? intval(date('Y')) + 1 : intval(date('Y'));
|
||||
|
||||
$value_array = array_merge($personen_id_array, [$year]);
|
||||
|
||||
$stmt = $mysqli->prepare("DELETE FROM $tableNoten WHERE `person_id` IN ($parram_string) AND `jahr` = ?");
|
||||
|
||||
$types_string = str_repeat("i", count($personen_id_array)) . "i";
|
||||
$stmt->bind_param($types_string, ...$value_array);
|
||||
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
$stmt = $mysqli->prepare("DELETE FROM $tableNotenChanges WHERE `person_id` IN ($parram_string) AND `jahr` = ?");
|
||||
|
||||
$stmt->bind_param($types_string, ...$value_array);
|
||||
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
echo json_encode(['success' => true, 'message' => 'Noten gelöscht']);
|
||||
http_response_code(200);
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
require_once $baseDir . '/../scripts/session_functions.php';
|
||||
|
||||
ini_wkvs_session();
|
||||
|
||||
check_user_permission('kampfrichter');
|
||||
|
||||
verify_csrf();
|
||||
|
||||
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';
|
||||
|
||||
$abt_id = intval($_POST['abteilungId'] ?? 1);
|
||||
|
||||
// Determine current year
|
||||
$current_year = date('Y');
|
||||
$monat = date('n');
|
||||
if ($monat > 6) $current_year++;
|
||||
|
||||
// Prepare SQL statement
|
||||
$stmt = $mysqli->prepare("
|
||||
SELECT
|
||||
t.id AS person_id
|
||||
FROM $tableTeilnehmendeAbt tab
|
||||
INNER JOIN $tableTeilnehmende t ON tab.turnerin_id = t.id
|
||||
INNER JOIN $tableAbt ab ON ab.id = tab.abteilung_id
|
||||
WHERE ab.id = ?
|
||||
ORDER BY t.id ASC
|
||||
");
|
||||
|
||||
$stmt->bind_param('i', $abt_id);
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$personen = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
$indexedPersonen = array_column($personen, null, 'person_id');
|
||||
|
||||
// Close statement
|
||||
$stmt->close();
|
||||
|
||||
// 1. Get the IDs from the first query results
|
||||
$personenIds = array_column($personen, 'person_id');
|
||||
|
||||
if (empty($personenIds)) {
|
||||
echo json_encode(["success" => false, "message" => "Keine Notenänderungen vorhanden"]);
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
$placeholders = implode(',', array_fill(0, count($personenIds), '?'));
|
||||
|
||||
$sqlNotenChanges = "DELETE FROM $tableNotenChanges WHERE person_id IN ($placeholders) AND `jahr` = ?";
|
||||
$stmtNotenChanges = $mysqli->prepare($sqlNotenChanges);
|
||||
|
||||
$paramsArray = array_merge($personenIds, [$current_year]);
|
||||
|
||||
$types = str_repeat('i', count($personenIds)) . 's';
|
||||
|
||||
$stmtNotenChanges->bind_param($types, ...$paramsArray);
|
||||
|
||||
$stmtNotenChanges->execute();
|
||||
$stmtNotenChanges->close();
|
||||
|
||||
echo json_encode(["success" => true, "message" => "Notenänderung für Abteilung " . $abt_id . " gelöscht"]);
|
||||
http_response_code(200);
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
require_once $baseDir . '/../scripts/session_functions.php';
|
||||
|
||||
ini_wkvs_session();
|
||||
|
||||
check_user_permission('kampfrichter');
|
||||
|
||||
verify_csrf();
|
||||
|
||||
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';
|
||||
|
||||
$wkName = db_get_var($mysqli, "SELECT `value` FROM $tableVar WHERE `name` = ?", ['wkName']);
|
||||
|
||||
$mysqli->close();
|
||||
|
||||
if ($wkName === null) {
|
||||
echo json_encode(["success" => false, "message" => "Keinen Wettkampfname angegeben. Setzen unter: /intern/wk-leitung/einstellungen"]);
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
$programm = trim($_POST['prog'] ?? '');
|
||||
|
||||
$current_year = date('Y');
|
||||
$monat = date('n');
|
||||
if ($monat > 6) $current_year++;
|
||||
|
||||
$dir = $baseDir . '/files/ranglisten/';
|
||||
$localPath = $dir . str_replace("/", "", str_replace(" ", "_", $wkName)) . "_Ergebnisse_" . str_replace("/", "", $programm) . "_" . $current_year . ".pdf";
|
||||
|
||||
if (!file_exists($localPath)) {
|
||||
echo json_encode(["success" => false, "message" => "Diese Rangliste existiert nicht."]);
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
unlink($localPath);
|
||||
|
||||
echo json_encode(["success" => true, "message" => "Rangliste gelöscht"]);
|
||||
http_response_code(200);
|
||||
@@ -14,13 +14,6 @@ check_user_permission('kampfrichter');
|
||||
|
||||
verify_csrf();
|
||||
|
||||
|
||||
|
||||
if (!verify_csrf()) {
|
||||
echo json_encode(['success' => false, 'message' => 'Forbidden']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate editId from POST
|
||||
if (isset($_POST['editId'])) {
|
||||
$editId = intval($_POST['editId']);
|
||||
@@ -37,8 +30,6 @@ if ($editId === false) {
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
@@ -51,21 +42,41 @@ if (!($data['success'] ?? false)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$isAdmin = (($_SESSION['selectedFreigabeKampfrichter'] ?? '') === 'admin') ? true : false;
|
||||
$is_payed = db_get_var($mysqli, "SELECT 1 FROM $tableTeilnehmende WHERE id = ? AND ((bezahltoverride = ?) OR (bezahlt = ? AND bezahltoverride != ? AND bezahltoverride != ?))", [$editId, 5, 2, 3, 4]);
|
||||
|
||||
if ($is_payed != '1') {
|
||||
echo json_encode(['success'=> false, 'message'=> 'Startgebühr nicht bezahlt']);
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
$isAdmin = (($_SESSION['selectedFreigabeIdKampfrichter'] ?? '') === 'A') ? true : false;
|
||||
|
||||
$disciplines = db_select($mysqli, $tableGeraete, 'id', '', [], 'start_index ASC');
|
||||
|
||||
$disciplines = array_column($disciplines, "id");
|
||||
|
||||
if (!$isAdmin) {
|
||||
$requested_discipline = trim($_POST['geraet'] ?? '');
|
||||
|
||||
$discipline = intval($_POST['geraet']) ?? 0;
|
||||
$all_disciplines = false;
|
||||
|
||||
if (!in_array($discipline, $disciplines)) {
|
||||
if ($isAdmin && $requested_discipline === 'A') {
|
||||
$all_disciplines = true;
|
||||
} else {
|
||||
$requested_discipline = (int) $requested_discipline;
|
||||
|
||||
if (!in_array($requested_discipline, $disciplines)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Falsche Geräte ID']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$discipline = $requested_discipline;
|
||||
}
|
||||
|
||||
if ($all_disciplines) {
|
||||
$stmt = $mysqli->prepare("SELECT t.`name`, t.`vorname`, t.`programm`, p.id as programm_id FROM $tableTeilnehmende t LEFT JOIN $tableProgramme p ON p.programm = t.programm WHERE t.id = ?");
|
||||
} else {
|
||||
|
||||
$disciplines = [$discipline];
|
||||
|
||||
|
||||
@@ -78,7 +89,7 @@ if (!$isAdmin) {
|
||||
agg.abteilung,
|
||||
agg.geraeteIndex,
|
||||
agg.startIndex
|
||||
FROM $tableTurnerinnen t
|
||||
FROM $tableTeilnehmende t
|
||||
LEFT JOIN $tableProgramme p ON p.programm = t.programm
|
||||
LEFT JOIN (
|
||||
SELECT
|
||||
@@ -86,7 +97,7 @@ if (!$isAdmin) {
|
||||
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
|
||||
FROM $tableTeilnehmendeAbt ta
|
||||
INNER JOIN $tableAbt a
|
||||
ON a.id = ta.abteilung_id
|
||||
LEFT JOIN $tableGeraete g
|
||||
@@ -96,10 +107,7 @@ if (!$isAdmin) {
|
||||
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();
|
||||
@@ -118,7 +126,7 @@ $now = new DateTime();
|
||||
|
||||
$jahr = ($now->format('n') > 6) ? $now->modify('+1 year')->format('Y') : $now->format('Y');
|
||||
|
||||
if ($isAdmin) {
|
||||
if ($all_disciplines) {
|
||||
$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);
|
||||
@@ -177,7 +185,7 @@ foreach ($disciplines as $d) {
|
||||
// Determine number of runs for this program
|
||||
$anzRunsConfig = !empty($snC['anzahl_laeufe_json']) ? json_decode($snC['anzahl_laeufe_json'], true) : [];
|
||||
|
||||
$runs = $anzRunsConfig[$d][$programm_id] ?? $anzRunsConfig['default'] ?? 1;
|
||||
$runs = $anzRunsConfig[$d][$programm_id] ?? $anzRunsConfig[$d]["all"] ?? $anzRunsConfig['default'] ?? 1;
|
||||
|
||||
if (isset($displayNoten) && array_key_exists($snC['id'], $displayNoten)) {
|
||||
$displayNoten[$snC['id']] = $runs;
|
||||
@@ -199,10 +207,9 @@ if (isset($displayNoten)) {
|
||||
|
||||
$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']]);
|
||||
if (!$all_disciplines) {
|
||||
|
||||
|
||||
$stmt = $mysqli->prepare("
|
||||
SELECT
|
||||
t.name,
|
||||
@@ -212,14 +219,14 @@ if (!$isAdmin) {
|
||||
agg.abteilung,
|
||||
agg.geraeteIndex,
|
||||
agg.startIndex
|
||||
FROM $tableTurnerinnen t
|
||||
FROM $tableTeilnehmende 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
|
||||
FROM $tableTeilnehmendeAbt ta
|
||||
INNER JOIN $tableAbt a
|
||||
ON a.id = ta.abteilung_id
|
||||
LEFT JOIN $tableGeraete g
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
<?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);*/
|
||||
use TCPDF;
|
||||
|
||||
// Start session if not already started
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
@@ -20,13 +14,6 @@ check_user_permission('kampfrichter');
|
||||
|
||||
verify_csrf();
|
||||
|
||||
|
||||
// Validate POST input
|
||||
if (!isset($_POST['abteilung'])) {
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
@@ -34,296 +21,472 @@ if (!isset($baseDir)) {
|
||||
$type = 'kr';
|
||||
$data = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($data['success'] === false){
|
||||
if ($data['success'] === false) {
|
||||
header('Content-Type: application/json');
|
||||
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']);
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
|
||||
$disciplines = db_select($mysqli, $tableGeraete, '*', '', [], 'start_index ASC');
|
||||
$wkName = db_get_var($mysqli, "SELECT `value` FROM $tableVar WHERE `name` = ?", ['wkName']);
|
||||
|
||||
$wkName = ($wkName === null) ? 'Keinen Wettkampfname angegeben. Setzen unter: /intern/wk-leitung/einstellungen' : $wkName;
|
||||
|
||||
$normalFontSize = 11;
|
||||
$marginSide = 10;
|
||||
$marginTop = 10;
|
||||
$minMarginBottomTable = 20;
|
||||
$format = 'A4';
|
||||
$orientation = 'L';
|
||||
|
||||
// Load TCPDF
|
||||
require $baseDir . '/wp-content/uploads/TCPDF-main/tcpdf.php';
|
||||
$abt = intval($_POST['abteilungId'] ?? 1);
|
||||
|
||||
$current_year = (date('n') > 6) ? date('Y') + 1 : date('Y');
|
||||
$now = trim($_POST['date'] ?? date('Y-m-d H:i:s'));
|
||||
|
||||
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);
|
||||
}
|
||||
$geraete = db_select($mysqli, $tableGeraete, "*", '', [], "start_index ASC");
|
||||
|
||||
// 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');
|
||||
}
|
||||
}
|
||||
$IndexedGeraete = array_column($geraete, 'name', 'id');
|
||||
|
||||
$pdf = new MYPDF('L', 'mm', 'A4', true, 'UTF-8', false);
|
||||
//$pdf->AddFont('outfit-bold', '', 'outfitb.php');
|
||||
$notenBezeichnungen = db_select($mysqli, $tableNotenBezeichnungen, "`name`, `id`, `nullstellen`, `anzahl_laeufe_json`", '', [], "");
|
||||
|
||||
$IndexedNotenBezeichnungen = array_column($notenBezeichnungen, 'name', 'id');
|
||||
|
||||
$pdf->current_year = $current_year;
|
||||
$pdf->abteilung = $abteilung;
|
||||
$IndexedNotenNullstellen = array_column($notenBezeichnungen, 'nullstellen', 'id');
|
||||
|
||||
$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);
|
||||
$IndexedNotenJsonGeraete = array_column($notenBezeichnungen, 'anzahl_laeufe_json', 'id');
|
||||
|
||||
$startindex = 0;
|
||||
$programme = db_select($mysqli, $tableProgramme, "`programm`, `id`", '', [], "");
|
||||
|
||||
foreach ($disciplines as $singledisciplin){
|
||||
|
||||
$startindex ++;
|
||||
$indexedProgramme = array_column($programme, 'id', 'programm');
|
||||
|
||||
$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'];
|
||||
}
|
||||
}
|
||||
// Determine current year
|
||||
$current_year = date('Y');
|
||||
$monat = date('n');
|
||||
if ($monat > 6) $current_year++;
|
||||
|
||||
foreach ($disciplines as $shiftstartindex => $subdisciplin){
|
||||
// Prepare SQL statement
|
||||
$stmt = $mysqli->prepare("
|
||||
SELECT
|
||||
t.id AS person_id,
|
||||
t.name,
|
||||
t.vorname,
|
||||
t.programm,
|
||||
t.verein,
|
||||
ab.id AS abteilung_id,
|
||||
tab.geraet_id AS start_geraet_id,
|
||||
tab.turnerin_index
|
||||
FROM $tableTeilnehmendeAbt tab
|
||||
INNER JOIN $tableTeilnehmende t ON tab.turnerin_id = t.id
|
||||
INNER JOIN $tableAbt ab ON ab.id = tab.abteilung_id
|
||||
WHERE ab.id = ?
|
||||
ORDER BY t.id ASC
|
||||
");
|
||||
|
||||
$pdf->AddPage();
|
||||
$stmt->bind_param('i', $abt);
|
||||
$stmt->execute();
|
||||
|
||||
$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('', '');
|
||||
$result = $stmt->get_result();
|
||||
$personen = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
$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');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$indexedPersonen = array_column($personen, null, 'person_id');
|
||||
|
||||
// Close statement
|
||||
$stmt->close();
|
||||
|
||||
$pdf->Output("Protokoll_Kutu-Tage_beider_Basel_{$current_year}_Abt_{$abteilung}.pdf", 'D');
|
||||
// 1. Get the IDs from the first query results
|
||||
$personenIds = array_column($personen, 'person_id');
|
||||
|
||||
if (!empty($personenIds)) {
|
||||
$placeholders = implode(',', array_fill(0, count($personenIds), '?'));
|
||||
|
||||
$sqlNotenChanges = "SELECT * FROM $tableNotenChanges WHERE person_id IN ($placeholders) AND `jahr` = ?";
|
||||
$stmtNotenChanges = $mysqli->prepare($sqlNotenChanges);
|
||||
|
||||
$paramsArray = array_merge($personenIds, [$current_year]);
|
||||
|
||||
$types = str_repeat('i', count($personenIds)) . 's';
|
||||
|
||||
$stmtNotenChanges->bind_param($types, ...$paramsArray);
|
||||
|
||||
$stmtNotenChanges->execute();
|
||||
$notenChangesResult = $stmtNotenChanges->get_result();
|
||||
$notenChangesEntries = $notenChangesResult->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
$stmtNotenChanges->close();
|
||||
} else {
|
||||
$notenChangesEntries = [];
|
||||
}
|
||||
|
||||
$kampfrichterIds = array_column($notenChangesEntries, 'edited_by');
|
||||
|
||||
if (!empty($kampfrichterIds)) {
|
||||
$placeholders = implode(',', array_fill(0, count($kampfrichterIds), '?'));
|
||||
|
||||
$sqlKampfrichter = "SELECT `id` AS `id_kampfrichter`, `name_person` AS `name_kampfrichter` FROM $tableInternUsers WHERE id IN ($placeholders)";
|
||||
$stmtKampfrichter = $mysqli->prepare($sqlKampfrichter);
|
||||
|
||||
$types = str_repeat('i', count($kampfrichterIds));
|
||||
|
||||
$stmtKampfrichter->bind_param($types, ...$kampfrichterIds);
|
||||
|
||||
$stmtKampfrichter->execute();
|
||||
$kampfrichterResult = $stmtKampfrichter->get_result();
|
||||
$kampfrichter = $kampfrichterResult->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
$indexedKampfrichter = array_column($kampfrichter, 'name_kampfrichter', 'id_kampfrichter');
|
||||
|
||||
$stmtKampfrichter->close();
|
||||
} else {
|
||||
$indexedKampfrichter = [];
|
||||
}
|
||||
|
||||
$entriesArray = [];
|
||||
|
||||
|
||||
|
||||
foreach ($notenChangesEntries as $snce) {
|
||||
|
||||
$programmId = $indexedProgramme[$indexedPersonen[$snce['person_id']]['programm']] ?? 0;
|
||||
|
||||
$runs = json_decode($IndexedNotenJsonGeraete[$snce['note_bezeichnung_id']], true) ?? [];
|
||||
|
||||
$countRuns = (int) $runs[$snce['geraet_id']][$programmId] ?? (int) $runs['default'] ?? 1;
|
||||
|
||||
$notenTextRaw = $IndexedNotenBezeichnungen[$snce['note_bezeichnung_id']] ?? 'Unbekannter Notenname';
|
||||
|
||||
$notenText = ($countRuns > 1) ? $notenTextRaw . ' (R' . ($snce['run_number'] ?? 1 ). ')' : $notenTextRaw;
|
||||
|
||||
$nullstellen = (int) $IndexedNotenNullstellen[$snce['note_bezeichnung_id']] ?? 2;
|
||||
$value = ($snce['old_value'] !== null) ? number_format((float) $snce['old_value'], $nullstellen) . ' ' . json_decode('"\u2192"') . ' ' . number_format((float) $snce['new_value'], $nullstellen) : number_format((float) $snce['new_value'], $nullstellen);
|
||||
|
||||
$entriesArray[$snce['geraet_id']][$indexedPersonen[$snce['person_id']]['start_geraet_id']][] = [
|
||||
'name' => ($indexedPersonen[$snce['person_id']]['name'] ?? 'Unbekannter Nachname') . ', ' . ($indexedPersonen[$snce['person_id']]['vorname'] ?? 'Unbekannter Vorname'),
|
||||
'programm' => $indexedPersonen[$snce['person_id']]['programm'] ?? 'Unbekanntes Programm',
|
||||
'verein' => $indexedPersonen[$snce['person_id']]['verein'] ?? 'Unbekannter Verein',
|
||||
'note' => $notenText,
|
||||
'value' => $value,
|
||||
'kampfrichter' => $indexedKampfrichter[$snce['edited_by']] ?? 'Unbekannter Kampfrichter',
|
||||
'timestamp' => new DateTime($snce['timestamp'])->format('d.m.Y H:i:s') ?? '---'
|
||||
];
|
||||
}
|
||||
|
||||
// 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 ProtokollPDF extends TCPDF
|
||||
{
|
||||
public $current_year;
|
||||
public $subAbt;
|
||||
public $abt;
|
||||
public $columns;
|
||||
public $discipline;
|
||||
public $wkName;
|
||||
public $marginSide;
|
||||
public $marginTop;
|
||||
public $pdfHeight;
|
||||
public $pdfWidth;
|
||||
public $headerType;
|
||||
public $now;
|
||||
// Page header
|
||||
|
||||
public $headerBottomY = 0;
|
||||
|
||||
|
||||
public function Header()
|
||||
{
|
||||
$this->SetFillColor(255, 255, 255);
|
||||
|
||||
$this->Rect(0, 0, $this->pdfWidth, $this->pdfHeight, 'F');
|
||||
|
||||
$arrayTitles = [];
|
||||
$image_file = $_SERVER['DOCUMENT_ROOT'] . '/intern/img/logo-normal.png';
|
||||
$this->SetY($this->marginTop);
|
||||
$this->SetX(($this->marginSide ?? 10));
|
||||
$this->SetFont('freesans', '', 20);
|
||||
|
||||
if ($this->headerType === 'bigHeader') {
|
||||
|
||||
$this->Cell(0, 0, 'Protokoll ' . $this->wkName . ' ' . $this->current_year, 0, 1, 'L', 0, '', 0, false, 'T', 'M');
|
||||
$preimageX = $this->GetX();
|
||||
$preimageY = $this->GetY();
|
||||
$this->Image($image_file, $this->pdfWidth - 10 - $this->marginSide, $this->marginTop, '', 10, 'png', '', 'T');
|
||||
|
||||
$this->SetY($preimageY + 5);
|
||||
$this->SetX($this->marginSide ?? 10); // Force back to left margin
|
||||
$this->SetFont('freesans', '', 11);
|
||||
$this->Cell(0, 6, 'Gereat: ' . $this->discipline, 0, 1, 'L');
|
||||
$this->Cell(0, 6, 'Abteilung: ' . $this->abt, 0, 1, 'L');
|
||||
$this->Cell(0, 6, 'Gruppe: ' . $this->subAbt, 0, 1, 'L');
|
||||
|
||||
$this->Ln(5);
|
||||
|
||||
} else {
|
||||
|
||||
$this->Cell(10, 0, 'Protokoll ' . $this->wkName . ' ' . $this->current_year, 0, 1, 'L', 0, '', 0, false, 'T', 'M');
|
||||
$this->SetFont('freesans', '', 11);
|
||||
$info = "Gerät: {$this->discipline} | Abt: {$this->abt} | Gruppe: {$this->subAbt}";
|
||||
$this->Cell(10, 6, $info, 0, 1, 'L'); // Align all info to the right while title is on the left
|
||||
|
||||
$this->Image($image_file, $this->pdfWidth - 10 - $this->marginSide, $this->marginTop, '', 10, 'png', '', 'T');
|
||||
|
||||
$this->Ln(18);
|
||||
}
|
||||
|
||||
$columns = $this->columns;
|
||||
$startY = $this->GetY();
|
||||
$this->SetFont('', 'B');
|
||||
|
||||
$this->SetX($this->marginSide ?? 10);
|
||||
|
||||
foreach ($columns as $col) {
|
||||
|
||||
$title = $col['header'];
|
||||
|
||||
if (($col['rotate'] ?? false)) {
|
||||
$x = $this->GetX();
|
||||
$y = $this->GetY() + 7;
|
||||
|
||||
$this->StartTransform();
|
||||
$this->Rotate(45, $x, $y);
|
||||
|
||||
$lineY = $startY + 7;
|
||||
if (($col['id'] ?? '') === 'gesamt') {
|
||||
$this->SetLineWidth(0.6);
|
||||
} else {
|
||||
$this->SetLineWidth(0.2);
|
||||
}
|
||||
|
||||
$this->Line($x, $lineY, $x + ($col['width_header'] ?? 0), $lineY);
|
||||
$this->SetLineWidth(0.2);
|
||||
|
||||
$this->Cell($col['width_header'] ?? 0, 7, $title ?? '', 0, 0, 'C');
|
||||
$this->StopTransform();
|
||||
$this->SetX($x + ($col['max_width'] ?? 0));
|
||||
} else {
|
||||
$this->Cell($col['max_width'] ?? 0, 7, $title ?? '', 0, 0, $col['align'] ?? 'L');
|
||||
}
|
||||
}
|
||||
|
||||
$this->Ln();
|
||||
$this->headerBottomY = $this->GetY();
|
||||
}
|
||||
|
||||
|
||||
// Page footer
|
||||
public function Footer()
|
||||
{
|
||||
$this->SetLineWidth(0.6);
|
||||
$this->Line($this->marginSide ?? 10, $this->headerBottomY, $this->pdfWidth - ($this->marginSide ?? 10), $this->headerBottomY);
|
||||
|
||||
$this->SetLineWidth(0.2);
|
||||
|
||||
$this->SetY(0);
|
||||
$this->SetX(0);
|
||||
|
||||
$this->SetFillColor(255, 255, 255); // white
|
||||
|
||||
$this->Cell(($this->marginSide ?? 10), $this->pdfHeight, '', 0, 0, 'L', true);
|
||||
|
||||
$this->SetY(0);
|
||||
$this->SetX($this->pdfWidth - ($this->marginSide ?? 10));
|
||||
|
||||
$this->Cell(($this->marginSide ?? 10), $this->pdfHeight, '', 0, 0, 'L', true);
|
||||
|
||||
$this->SetY(-15);
|
||||
$this->SetFont('freesans', 'I', 8);
|
||||
|
||||
// 1. Page Number - Centered
|
||||
$this->Cell(0, 10, 'Seite ' . $this->getAliasNumPage() . ' von ' . $this->getAliasNbPages(), 0, false, 'C');
|
||||
|
||||
// 2. Timestamp - Force to Left
|
||||
$this->SetX($this->getMargins()['left']); // Reset to left margin
|
||||
$this->Cell(0, 10, 'Zeitstempel: ' . $this->now, 0, false, 'L');
|
||||
|
||||
// 3. Host - Force to Right (Cell with width 0 and align 'R' handles this)
|
||||
$this->SetX($this->getMargins()['left']); // Reset again so 'R' alignment works from the start
|
||||
$this->Cell(0, 10, $_SERVER['HTTP_HOST'], 0, 0, 'R', false, 'https://'.$_SERVER['HTTP_HOST']);
|
||||
}
|
||||
}
|
||||
|
||||
$pdf = new ProtokollPDF($orientation, 'mm', $format, true, 'UTF-8', false);
|
||||
|
||||
$pdfHeight = $pdf->getPageHeight();
|
||||
$pdfWidth = $pdf->getPageWidth();
|
||||
|
||||
$pdf->current_year = $current_year;
|
||||
$pdf->wkName = $wkName;
|
||||
$pdf->abt = $abt;
|
||||
$pdf->marginSide = $marginSide;
|
||||
$pdf->marginTop = $marginTop;
|
||||
$pdf->pdfHeight = $pdfHeight;
|
||||
$pdf->pdfWidth = $pdfWidth;
|
||||
$pdf->now = $now;
|
||||
|
||||
$pdf->SetCreator(PDF_CREATOR);
|
||||
$pdf->SetAuthor($wkName);
|
||||
$pdf->SetTitle($wkName . "_Protokoll_" . $abt . "_" . $current_year . ".pdf");
|
||||
|
||||
$pdf->SetAutoPageBreak(FALSE);
|
||||
|
||||
|
||||
$pdf->SetFont('freesans', '', 11);
|
||||
|
||||
// Define columns dynamically
|
||||
$columns = [
|
||||
['id' => 'name', 'header' => 'Name Person', 'align' => 'L', 'flex' => true, 'type' => 'field', 'field' => 'name'],
|
||||
['id' => 'programm', 'header' => 'Programm', 'align' => 'L', 'flex' => true, 'type' => 'field', 'field' => 'programm'],
|
||||
['id' => 'verein', 'header' => 'Verein', 'align' => 'L', 'flex' => true, 'type' => 'field', 'field' => 'verein'],
|
||||
['id' => 'note', 'header' => 'Note', 'align' => 'C', 'flex' => false, 'type' => 'field', 'field' => 'note'],
|
||||
['id' => 'value', 'header' => 'Wert', 'align' => 'C', 'flex' => false, 'type' => 'field', 'field' => 'value'],
|
||||
['id' => 'kr', 'header' => 'Kampfrichter/in', 'align' => 'C', 'flex' => true, 'type' => 'field', 'field' => 'kampfrichter'],
|
||||
['id' => 'timestamp', 'header' => 'Zeitstempel', 'align' => 'C', 'flex' => false, 'type' => 'field', 'field' => 'timestamp'],
|
||||
];
|
||||
|
||||
|
||||
$padding = 4;
|
||||
|
||||
unset($col);
|
||||
|
||||
// 1. Calculate initial max widths based on headers
|
||||
foreach ($columns as &$col) {
|
||||
$col['width_header'] = $pdf->GetStringWidth($col['header']) + ($padding * 2);
|
||||
if ($col['type'] !== 'note') {
|
||||
$col['max_width'] = $col['width_header'];
|
||||
} else {
|
||||
$col['max_width'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($entriesArray as $geratId => $singleGeraet) {
|
||||
|
||||
$pdf->discipline = $IndexedGeraete[$geratId] ?? 'Unbekanntes Gerät';
|
||||
|
||||
foreach ($singleGeraet as $geratIdStart => $singleStartGeraet) {
|
||||
|
||||
$pdf->subAbt = $geratIdStart;
|
||||
|
||||
$tcolumns = $columns;
|
||||
|
||||
foreach ($singleStartGeraet as $se) {
|
||||
foreach ($tcolumns as &$col) {
|
||||
$text = '';
|
||||
if (isset($se[$col['field']])) {
|
||||
$text = $se[$col['field']];
|
||||
}
|
||||
$width = $pdf->GetStringWidth($text) + ($padding * 2);
|
||||
if ($width > $col['max_width']) {
|
||||
$col['max_width'] = $width;
|
||||
}
|
||||
}
|
||||
unset($col);
|
||||
}
|
||||
|
||||
// 4. Distribute Flexible Widths
|
||||
$tablew = $pdfWidth - (2 * $marginSide); // total table width (A4 landscape in mm minus margins)
|
||||
$fixedWidth = 0;
|
||||
$flexCols = [];
|
||||
|
||||
foreach ($tcolumns as $col) {
|
||||
if ($col['flex'] ?? false) {
|
||||
$flexCols[] = $col['id'];
|
||||
$fixedWidth += $col['max_width'];
|
||||
} else {
|
||||
$fixedWidth += $col['max_width'];
|
||||
}
|
||||
}
|
||||
|
||||
$effTableWidth = $tablew - $fixedWidth;
|
||||
|
||||
if (!empty($flexCols) && $effTableWidth > 0) {
|
||||
$flexTotalInitial = 0;
|
||||
foreach ($tcolumns as $col) {
|
||||
if ($col['flex'] ?? false) $flexTotalInitial += $col['max_width'];
|
||||
}
|
||||
|
||||
foreach ($tcolumns as &$col) {
|
||||
if ($col['flex'] ?? false) {
|
||||
$col['max_width'] += ($col['max_width'] / $flexTotalInitial) * $effTableWidth;
|
||||
}
|
||||
}
|
||||
unset($col);
|
||||
}
|
||||
|
||||
$pdf->columns = $tcolumns;
|
||||
|
||||
$pdf->headerType = 'bigHeader';
|
||||
$pdf->AddPage();
|
||||
$pdf->headerType = '';
|
||||
|
||||
// After AddPage(), the header has been drawn
|
||||
$margin_top = $pdf->headerBottomY;
|
||||
|
||||
// Now adjust your margins if needed
|
||||
$pdf->SetMargins($marginSide, $margin_top, $marginSide); // +5 mm padding below header
|
||||
$pdf->SetY($margin_top); // Move cursor below header manually
|
||||
|
||||
$pdf->SetFont('', '');
|
||||
$rIndex = 0;
|
||||
|
||||
foreach ($singleStartGeraet as $r) {
|
||||
|
||||
$pdf->SetTextColor(0, 0, 0);
|
||||
|
||||
if ($rIndex % 2 == 0) {
|
||||
$pdf->SetFillColor(255, 255, 255);
|
||||
} else {
|
||||
$pdf->SetFillColor(240, 240, 240);
|
||||
}
|
||||
|
||||
$rowHeight = 10;
|
||||
|
||||
foreach ($tcolumns as $col) {
|
||||
|
||||
if ($pdf->getY() + $rowHeight > $pdfHeight - $minMarginBottomTable) {
|
||||
$pdf->addPage();
|
||||
$margin_top = $pdf->headerBottomY;
|
||||
$pdf->setY($margin_top);
|
||||
}
|
||||
|
||||
$customFontSize = (isset($col['font_size']) && $col['font_size'] != 0);
|
||||
|
||||
if ($customFontSize) {
|
||||
$pdf->SetFont('', '', $col['font_size']);
|
||||
}
|
||||
|
||||
$startX = $pdf->GetX();
|
||||
$startY = $pdf->GetY();
|
||||
|
||||
$text = strip_tags($r[$col['field']]);
|
||||
|
||||
if ($col['type'] === 'field') {
|
||||
$pdf->MultiCell($col['max_width'], $rowHeight, $text, 'B', $col['align'], true, 0, $startX, $startY, true, 0, false, true, $rowHeight, 'M');
|
||||
}
|
||||
|
||||
if ($customFontSize) {
|
||||
$pdf->SetFont('', '', $normalFontSize);
|
||||
}
|
||||
}
|
||||
|
||||
$pdf->SetY($startY + $rowHeight); // Move Y manually instead of Ln() to account for rowHeight
|
||||
$rIndex++;
|
||||
}
|
||||
$textanzEintaege = (count($singleStartGeraet) > 1) ? 'Einträge': 'Eintrag';
|
||||
|
||||
$pdf->SetFont('', '', 7);
|
||||
|
||||
$pdf->Cell(20, 6, count($singleStartGeraet).' '.$textanzEintaege, 0, 0, 'L');
|
||||
|
||||
$pdf->SetFont('', '', $normalFontSize);
|
||||
}
|
||||
}
|
||||
|
||||
$pdf->Output($wkName . "_Protokoll_" . $abt . "_" . $current_year . ".pdf", 'I');
|
||||
exit;
|
||||
@@ -14,13 +14,6 @@ check_user_permission('kampfrichter');
|
||||
|
||||
verify_csrf();
|
||||
|
||||
// Validate POST input
|
||||
/*
|
||||
if (!isset($_POST['prog']) && !isset($_POST['type'])) {
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}*/
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
@@ -28,7 +21,8 @@ if (!isset($baseDir)) {
|
||||
$type = 'kr';
|
||||
$data = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($data['success'] === false){
|
||||
if ($data['success'] === false) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(['success' => false, 'message' => $data['message']]);
|
||||
exit;
|
||||
}
|
||||
@@ -36,9 +30,28 @@ if ($data['success'] === false){
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
|
||||
$wkName = db_get_var($mysqli, "SELECT `value` FROM $tableVar WHERE `name` = ?", ['wkName']);
|
||||
|
||||
$wkName = ($wkName === null) ? 'Keinen Wettkampfname angegeben. Setzen unter: /intern/wk-leitung/einstellungen' : $wkName;
|
||||
|
||||
$normalFontSize = 11;
|
||||
$marginSide = 10;
|
||||
$marginTop = 10;
|
||||
$minMarginBottomTable = 20;
|
||||
$format = 'A4';
|
||||
$orientation = 'L';
|
||||
|
||||
$programm = trim($_POST['prog'] ?? 'P6A');
|
||||
$buttontype = trim($_POST['type'] ?? 'downloadRangliste');
|
||||
|
||||
$allowedOperations = ['downloadRangliste', 'updateServerRangliste'];
|
||||
|
||||
if (!in_array($buttontype, $allowedOperations)) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(["success" => false, "message" => "Invalide Operation"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$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");
|
||||
@@ -64,26 +77,40 @@ if ($monat > 6) $current_year++;
|
||||
|
||||
// Prepare SQL statement
|
||||
$stmt = $mysqli->prepare("
|
||||
SELECT * FROM $tableTurnerinnen
|
||||
SELECT * FROM $tableTeilnehmende
|
||||
WHERE LOWER(programm) = LOWER(?)
|
||||
AND (bezahlt = ? OR bezahltoverride = ?)
|
||||
AND ((bezahlt = ? OR bezahltoverride = ?) AND bezahltoverride != ?)
|
||||
ORDER BY rang ASC
|
||||
");
|
||||
$bezahlt1 = '2';
|
||||
$bezahlt2 = '5';
|
||||
$stmt->bind_param('sss', $programm, $bezahlt1, $bezahlt2);
|
||||
$bezahlt3 = '3';
|
||||
$stmt->bind_param('ssss', $programm, $bezahlt1, $bezahlt2, $bezahlt3);
|
||||
$stmt->execute();
|
||||
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$personen = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
|
||||
// Close statement
|
||||
$stmt->close();
|
||||
|
||||
$programmId = db_get_var($mysqli, "SELECT `id` FROM $tableProgramme WHERE LOWER(`programm`) = LOWER(?)", [$programm]);
|
||||
$cache = require $baseDir . '/../scripts/cache/noten-config-calculating-cache.php';
|
||||
$ascArrayAnzahlLaeufeJSON = $cache['anzahl_laeufe_json'];
|
||||
|
||||
// 1. Get the IDs from the first query results
|
||||
$turnerinnenIds = array_column($personen, 'id');
|
||||
|
||||
$rangNote = intval(db_get_var($mysqli, "SELECT `value` FROM $tableVar WHERE `name` = ?", ['rangNote']));
|
||||
|
||||
if ($rangNote === 0) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(["success" => false, "message" => "Keine Note für Rangvergabe ausgewählt"]);
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!empty($turnerinnenIds)) {
|
||||
// 2. Create a string of placeholders: ?,?,?
|
||||
$placeholders = implode(',', array_fill(0, count($turnerinnenIds), '?'));
|
||||
@@ -115,26 +142,34 @@ if (!empty($turnerinnenIds)) {
|
||||
$notenEntries = [];
|
||||
}
|
||||
|
||||
$rangNote = intval(db_get_var($mysqli, "SELECT `value` FROM $tableVar WHERE `name` = ?", ['rangNote']));
|
||||
|
||||
var_dump($rangNote);
|
||||
$indexedNotenEntries = [];
|
||||
foreach ($notenEntries as $sn) {
|
||||
if (!isset($indexedNotenEntries[$sn['person_id']][$sn['note_bezeichnung_id']][$sn['geraet_id']])) {
|
||||
$indexedNotenEntries[$sn['person_id']][$sn['note_bezeichnung_id']][$sn['geraet_id']] = [];
|
||||
}
|
||||
$indexedNotenEntries[$sn['person_id']][$sn['note_bezeichnung_id']][$sn['geraet_id']][$sn['run_number']] = $sn['value'];
|
||||
}
|
||||
|
||||
$orderBestRang = db_get_var($mysqli, "SELECT `value` FROM $tableVar WHERE `name` = ?", ['orderBestRang']);
|
||||
|
||||
$okValuesOrderBestRang = ["ASC", "DESC"];
|
||||
|
||||
if (!in_array($orderBestRang, $okValuesOrderBestRang)) {
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(["success" => false, "message" => "Invalide Sortierung der Ränge"]);
|
||||
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]);
|
||||
$alleNoten = db_select($mysqli, $tableNotenBezeichnungen, "id, default_value, nullstellen, pro_geraet, geraete_json, zeige_auf_rangliste, groesse_auf_rangliste, name", "zeige_auf_rangliste = ? OR id = ?", ['1', $rangNote]);
|
||||
|
||||
$displayedNoten = [];
|
||||
|
||||
foreach ($alleNoten as $sN) {
|
||||
$alleNotenIndexed = array_column($alleNoten, null, 'id');
|
||||
|
||||
foreach ($alleNotenIndexed as $key => $sN) {
|
||||
if (intval($sN['zeige_auf_rangliste']) === 1) {
|
||||
$displayedNoten[$sN['id']] = $sN;
|
||||
$displayedNoten[$key] = $sN;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,31 +182,38 @@ foreach ($ascArrayGeraeteJSON as $key => $saagj) {
|
||||
|
||||
// 1. Initialize the structure for every person
|
||||
$indexedNotenArray = [];
|
||||
$sortArray = [];
|
||||
|
||||
$notenGeraeteArray = array_merge($geraete, array(array("id" => 0)));
|
||||
|
||||
foreach ($personen as $sp) {
|
||||
$pId = $sp['id'];
|
||||
foreach ($geraete as $g) {
|
||||
$indexedNotenArray[$pId][$g['id']] = [];
|
||||
}
|
||||
$indexedNotenArray[$pId][0] = []; // Total/Overall device per person
|
||||
}
|
||||
foreach ($displayedNoten as $an) {
|
||||
$nId = $an['id'];
|
||||
$isProGeraet = (intval($an['pro_geraet']) === 1);
|
||||
$allowedGeraete = $ascArrayGeraeteJSON[$nId] ?? [];
|
||||
|
||||
// 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'];
|
||||
foreach ($notenGeraeteArray as $g) {
|
||||
$gId = $g['id'];
|
||||
|
||||
if ($isProGeraet) {
|
||||
if ($gId === 0) continue;
|
||||
} else {
|
||||
if (!in_array($gId, $allowedGeraete)) continue;
|
||||
}
|
||||
|
||||
$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 ===
|
||||
$indexedNotenArray[$pId][$gId][$nId] = $indexedNotenEntries[$pId][$nId][$gId] ?? [$an['default_value']];
|
||||
}
|
||||
|
||||
if (intval($nId) === $rangNote) {
|
||||
$val = $indexedNotenArray[$pId][0][$nId] ?? [$an['default_value']];
|
||||
$sortArray[$pId] = is_array($val) ? end($val) : $val; // fallback to the last run for sorting if needed, or total should just be one run
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$wkWebpageDomain = db_get_var($mysqli, "SELECT `value` FROM $tableVar WHERE `name` = ?", ['linkWebseite']);
|
||||
|
||||
// Load TCPDF
|
||||
require $baseDir . '/../composer/vendor/autoload.php';
|
||||
|
||||
@@ -181,227 +223,318 @@ if (file_exists($fontfile)) {
|
||||
$fontname = TCPDF_FONTS::addTTFfont($fontfile, 'TrueTypeUnicode', '', 32);
|
||||
}
|
||||
|
||||
class MYPDF extends TCPDF
|
||||
class RanglistePDF extends TCPDF
|
||||
{
|
||||
public $current_year;
|
||||
public $programm;
|
||||
public $upperprogramm;
|
||||
public $columns;
|
||||
public $disciplines;
|
||||
public $wkName;
|
||||
public $marginSide;
|
||||
public $marginTop;
|
||||
public $pdfHeight;
|
||||
public $pdfWidth;
|
||||
public $wkWebpageDomain;
|
||||
// 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');
|
||||
$this->SetFillColor(255, 255, 255);
|
||||
|
||||
$this->Rect(0, 0, $this->pdfWidth, $this->pdfHeight, 'F');
|
||||
|
||||
$arrayTitles = [];
|
||||
$image_file = $_SERVER['DOCUMENT_ROOT'] . '/intern/img/logo-normal.png';
|
||||
$this->SetY($this->marginTop);
|
||||
$this->SetX(($this->marginSide ?? 10));
|
||||
$this->SetFont('freesans', '', 20);
|
||||
$this->Cell(0, 0, 'Rangliste ' . $this->wkName . ' ' . $this->current_year, 0, 1, 'L', 0, '', 0, false, 'T', '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->Image($image_file, $this->pdfWidth - 10 - $this->marginSide, $this->marginTop, '', 10, 'png', '', 'T');
|
||||
|
||||
$this->SetX($preimageX);
|
||||
$this->SetY($preimageY);
|
||||
$this->SetY($preimageY);
|
||||
$this->SetX($this->marginSide ?? 10); // Force back to left margin
|
||||
$this->SetFont('freesans', '', 11);
|
||||
$this->Cell(0, 10, 'Programm: ' . $this->upperprogramm, 0, 1, 'L');
|
||||
|
||||
$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);
|
||||
$this->SetFont('', 'B');
|
||||
|
||||
// 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'];
|
||||
$this->SetX($this->marginSide ?? 10);
|
||||
|
||||
$x = $this->GetX();
|
||||
$y = $this->GetY() + 7;
|
||||
foreach ($columns as $col) {
|
||||
$isDuplicate = in_array($col['header'], $arrayTitles);
|
||||
|
||||
// Start transformation for rotation
|
||||
$this->StartTransform();
|
||||
$title = $isDuplicate ? '' : $col['header'];
|
||||
|
||||
// Rotate around top-left of cell
|
||||
$this->Rotate(45, $x, $y);
|
||||
if (!$isDuplicate) {
|
||||
$arrayTitles[] = $col['header'];
|
||||
}
|
||||
|
||||
// Draw a line **above the first data row**
|
||||
$lineY = $startY + 7; // adjust 7 depending on cell height
|
||||
$this->Line($x, $lineY, $x + $ws, $lineY);
|
||||
if (($col['rotate'] ?? false) && !$isDuplicate) {
|
||||
$x = $this->GetX();
|
||||
$y = $this->GetY() + 7;
|
||||
|
||||
// Print the rotated header text
|
||||
$this->Cell($w, 7, ucfirst($d), 0, 0, 'L');
|
||||
$this->StartTransform();
|
||||
$this->Rotate(45, $x, $y);
|
||||
|
||||
$this->StopTransform();
|
||||
$lineY = $startY + 7;
|
||||
if (($col['id'] ?? '') === 'gesamt') {
|
||||
$this->SetLineWidth(0.6);
|
||||
} else {
|
||||
$this->SetLineWidth(0.2);
|
||||
}
|
||||
|
||||
$this->Line($x, $lineY, $x + ($col['width_header'] ?? 0), $lineY);
|
||||
$this->SetLineWidth(0.2);
|
||||
|
||||
$this->SetX($x + $w);
|
||||
$this->Cell($col['width_header'] ?? 0, 7, $title ?? '', 0, 0, 'C');
|
||||
$this->StopTransform();
|
||||
$this->SetX($x + ($col['max_width'] ?? 0));
|
||||
} else {
|
||||
$this->Cell($col['max_width'] ?? 0, 7, $title ?? '', 0, 0, $col['align'] ?? 'L');
|
||||
}
|
||||
}
|
||||
|
||||
$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->Line($this->marginSide ?? 10, $this->headerBottomY, $this->pdfWidth - ($this->marginSide ?? 10), $this->headerBottomY);
|
||||
|
||||
$this->SetLineWidth(0.2);
|
||||
|
||||
$this->SetY(0);
|
||||
$this->SetX(5);
|
||||
$this->SetX(0);
|
||||
|
||||
$this->SetFillColor(255, 255, 255); // white
|
||||
|
||||
$this->Cell(5, 190, '', 0, 0, 'L', true);
|
||||
$this->Cell(($this->marginSide ?? 10), $this->pdfHeight, '', 0, 0, 'L', true);
|
||||
|
||||
$this->SetY(0);
|
||||
$this->SetX(297 - 10);
|
||||
$this->SetX($this->pdfWidth - ($this->marginSide ?? 10));
|
||||
|
||||
$this->Cell(5, 190, '', 0, 0, 'L', true);
|
||||
$this->Cell(($this->marginSide ?? 10), $this->pdfHeight, '', 0, 0, 'L', true);
|
||||
|
||||
$this->SetY(-15);
|
||||
$this->SetFont('freesans', '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, ($this->wkWebpageDomain ?? $_SERVER['HTTP_HOST']), 0, 0, 'R', false, 'https://' . ($this->wkWebpageDomain ?? $_SERVER['HTTP_HOST']), 0, false, 'T', 'M');
|
||||
}
|
||||
}
|
||||
|
||||
$pdf = new MYPDF('L', 'mm', 'A4', true, 'UTF-8', false);
|
||||
$pdf = new RanglistePDF($orientation, 'mm', $format, true, 'UTF-8', false);
|
||||
|
||||
$pdfHeight = $pdf->getPageHeight();
|
||||
$pdfWidth = $pdf->getPageWidth();
|
||||
|
||||
$pdf->current_year = $current_year;
|
||||
$pdf->wkName = $wkName;
|
||||
$pdf->wkWebpageDomain = $wkWebpageDomain;
|
||||
$pdf->programm = $programm;
|
||||
$pdf->upperprogramm = $upperprogramm;
|
||||
$pdf->marginSide = $marginSide;
|
||||
$pdf->marginTop = $marginTop;
|
||||
$pdf->pdfHeight = $pdfHeight;
|
||||
$pdf->pdfWidth = $pdfWidth;
|
||||
|
||||
$pdf->SetCreator(PDF_CREATOR);
|
||||
$pdf->SetAuthor('WKVS-FH');
|
||||
$pdf->SetTitle("KTBB_Ergebnisse_" . $programm . "_" . $current_year . ".pdf");
|
||||
$pdf->SetAuthor($wkName);
|
||||
$pdf->SetTitle($wkName . "_Ergebnisse_" . $programm . "_" . $current_year . ".pdf");
|
||||
|
||||
$pdf->SetAutoPageBreak(TRUE, 10);
|
||||
$pdf->SetFont('helvetica', '', 11);
|
||||
$pdf->SetAutoPageBreak(FALSE);
|
||||
|
||||
|
||||
// Define columns (including discipline sub-columns)
|
||||
$pdf->SetFont('freesans', '', 11);
|
||||
|
||||
// Define columns dynamically
|
||||
$columns = [
|
||||
'rang' => [ 0 => ['header' => 'Rang']],
|
||||
'name' => [ 0 => ['header' => 'Name']],
|
||||
'vorname' => [ 0 => ['header' => 'Vorname']],
|
||||
'geburtsdatum' => [ 0 => ['header' => 'Jg.']],
|
||||
'verein' => [ 0 => ['header' => 'Verein']],
|
||||
['id' => 'rang', 'header' => 'Rang', 'align' => 'C', 'flex' => false, 'type' => 'rank'],
|
||||
['id' => 'name', 'header' => 'Name', 'align' => 'L', 'flex' => true, 'type' => 'field', 'field' => 'name'],
|
||||
['id' => 'vorname', 'header' => 'Vorname', 'align' => 'L', 'flex' => true, 'type' => 'field', 'field' => 'vorname'],
|
||||
['id' => 'geburtsdatum', 'header' => 'Jg.', 'align' => 'C', 'flex' => false, 'type' => 'year', 'field' => 'geburtsdatum'],
|
||||
['id' => 'verein', 'header' => 'Verein', 'align' => 'L', 'flex' => true, 'type' => 'field', 'field' => '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];
|
||||
// Add notes dynamically per device
|
||||
foreach ($geraete as $g) {
|
||||
foreach ($displayedNoten as $noteDef) {
|
||||
$neni = $noteDef['id'];
|
||||
$isProGeraet = (intval($noteDef['pro_geraet']) === 1);
|
||||
$allowedGeraete = $ascArrayGeraeteJSON[$neni] ?? [];
|
||||
|
||||
if ($isProGeraet || in_array($g['id'], $allowedGeraete)) {
|
||||
$columns[] = [
|
||||
'id' => 'note_' . $g['id'] . '_' . $neni,
|
||||
'header' => $g['name'],
|
||||
'align' => 'C',
|
||||
'flex' => false,
|
||||
'rotate' => true,
|
||||
'type' => 'note',
|
||||
'geraet_id' => $g['id'],
|
||||
'note_bezeichnung_id' => $neni,
|
||||
'nullstellen' => $noteDef['nullstellen'] ?? 2,
|
||||
'font_size' => intval($noteDef['groesse_auf_rangliste']) ?? 0
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
// Add Gesamt (Total) column
|
||||
$columns[] = [
|
||||
'id' => 'gesamt',
|
||||
'header' => $alleNotenIndexed[$rangNote]['name'] ?? 'Total',
|
||||
'align' => 'C',
|
||||
'flex' => false,
|
||||
'rotate' => true,
|
||||
'type' => 'note',
|
||||
'geraet_id' => 0,
|
||||
'note_bezeichnung_id' => $rangNote,
|
||||
'nullstellen' => $alleNotenIndexed[$rangNote]['nullstellen'] ?? 2,
|
||||
'font_size' => intval($alleNotenIndexed[$rangNote]['groesse_auf_rangliste']) ?? 0
|
||||
];
|
||||
|
||||
|
||||
|
||||
$padding = 4;
|
||||
|
||||
unset($col);
|
||||
|
||||
// 1. Calculate initial max widths based on headers
|
||||
foreach ($columns as &$col) {
|
||||
$col['width_header'] = $pdf->GetStringWidth($col['header']) + ($padding * 2);
|
||||
if ($col['type'] !== 'note') {
|
||||
$col['max_width'] = $col['width_header'];
|
||||
} else {
|
||||
$col['max_width'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Fill missing defaults and finalize the sortArray
|
||||
// 2. Fill missing defaults and update max widths based on data
|
||||
foreach ($personen as $sp) {
|
||||
$pId = $sp['id'];
|
||||
|
||||
// We check all possible devices (including 0)
|
||||
foreach ($indexedNotenArray[$pId] as $sG => $currentNoten) {
|
||||
|
||||
foreach ($alleNoten as $noteDef) {
|
||||
foreach ($displayedNoten 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;
|
||||
if (isset($currentNoten[$neni])) {
|
||||
$runs = $currentNoten[$neni];
|
||||
if (is_array($runs)) {
|
||||
$runsConfig = $ascArrayAnzahlLaeufeJSON[$neni] ?? [];
|
||||
$runsCount = $runsConfig[$sG][$programmId] ?? $runsConfig[$sG]['all'] ?? $runsConfig["default"] ?? 1;
|
||||
$defaultValue = $ascArrayDefaultValues[$neni] ?? 0;
|
||||
|
||||
for ($r = 1; $r <= $runsCount - 1; $r++) {
|
||||
if (!isset($runs[$r])) {
|
||||
$runs[$r] = $defaultValue;
|
||||
}
|
||||
}
|
||||
$indexedNotenArray[$pId][$sG][$neni] = $runs;
|
||||
|
||||
ksort($runs);
|
||||
$maxLenStr = "";
|
||||
foreach ($runs as $rVal) {
|
||||
$str = number_format((float)$rVal, $noteDef['nullstellen']);
|
||||
// Approximate max width by string length, GetStringWidth will do the real check later
|
||||
if (strlen($str) > strlen($maxLenStr)) {
|
||||
$maxLenStr = $str;
|
||||
}
|
||||
}
|
||||
$val = $maxLenStr;
|
||||
} else {
|
||||
$val = number_format((float)$runs, $noteDef['nullstellen']);
|
||||
}
|
||||
} else {
|
||||
if (!in_array($sG, $allowedGeraete)) 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;
|
||||
}
|
||||
|
||||
$defaultValue = $ascArrayDefaultValues[$neni] ?? 0;
|
||||
|
||||
$runsConfig = $ascArrayAnzahlLaeufeJSON[$neni] ?? [];
|
||||
$runsCount = $runsConfig[$sG][$programmId] ?? $runsConfig[$sG]['all'] ?? $runsConfig["default"] ?? 1;
|
||||
|
||||
$valArray = [];
|
||||
$maxLenStr = "";
|
||||
for ($r = 1; $r <= $runsCount - 1; $r++) {
|
||||
$valArray[$r] = $defaultValue;
|
||||
$str = number_format((float)$defaultValue, $noteDef['nullstellen']);
|
||||
if (strlen($str) > strlen($maxLenStr)) {
|
||||
$maxLenStr = $str;
|
||||
}
|
||||
}
|
||||
|
||||
$val = $maxLenStr;
|
||||
$indexedNotenArray[$pId][$sG][$neni] = $valArray;
|
||||
|
||||
if ($neni === $rangNote && $sG === 0) {
|
||||
$sortArray[$pId] = $defaultValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Assign default value
|
||||
$defaultValue = $ascArrayDefaultValues[$neni] ?? 0;
|
||||
|
||||
$string = nuber_format($defaultValue, $noteDef['nullstellen']);
|
||||
// Update column width if this note is displayed
|
||||
foreach ($columns as &$col) {
|
||||
if ($col['type'] === 'note' && $col['geraet_id'] == $sG && $col['note_bezeichnung_id'] == $neni) {
|
||||
|
||||
$indexedNotenArray[$pId][$sG][$neni] = $string;
|
||||
$customFontSize = (isset($col['font_size']) && $col['font_size'] != 0);
|
||||
|
||||
$width = $pdf->GetStringWidth($string) + 4;
|
||||
$cpadding = $padding;
|
||||
|
||||
if ($w > $columns[$noteDef['name']][$sG]['max_width']) {
|
||||
$columns[$noteDef['name']][$sG] = $w;
|
||||
}
|
||||
if ($customFontSize) {
|
||||
$pdf->SetFont('', '', $col['font_size']);
|
||||
$cpadding = ($col['font_size'] / $normalFontSize) * $padding;
|
||||
}
|
||||
|
||||
// If this missing note was our ranking note, add default to sortArray
|
||||
if ($neni === $rangNote && $sG === 0) {
|
||||
$sortArray[$pId] = $defaultValue;
|
||||
$width = $pdf->GetStringWidth($val) + ($cpadding * 2);
|
||||
if ($width > $col['max_width']) {
|
||||
$col['max_width'] = $width;
|
||||
}
|
||||
|
||||
if ($customFontSize) {
|
||||
$pdf->SetFont('', '', $normalFontSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($col);
|
||||
}
|
||||
}
|
||||
|
||||
// Also update widths for static fields
|
||||
foreach ($columns as &$col) {
|
||||
if ($col['type'] === 'field' || $col['type'] === 'year' || $col['type'] === 'rank') {
|
||||
$text = '';
|
||||
if ($col['type'] === 'rank') {
|
||||
$text = '999'; // Placeholder for rank width
|
||||
} elseif ($col['type'] === 'year') {
|
||||
$text = '0000';
|
||||
} elseif (isset($sp[$col['field']])) {
|
||||
$text = $sp[$col['field']];
|
||||
}
|
||||
$width = $pdf->GetStringWidth($text) + ($padding * 2);
|
||||
if ($width > $col['max_width']) {
|
||||
$col['max_width'] = $width;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($col);
|
||||
}
|
||||
|
||||
function calculateRanks(array $scoreArray, $direction = 'DESC') {
|
||||
@@ -431,66 +564,40 @@ function calculateRanks(array $scoreArray, $direction = 'DESC') {
|
||||
return $ranks;
|
||||
}
|
||||
|
||||
// 4. Calculate Ranks
|
||||
// FIXED: Passing $orderBestRang (the string "ASC"/"DESC") instead of the array
|
||||
|
||||
// 3. Finalize Ranks
|
||||
$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
|
||||
// 4. Distribute Flexible Widths
|
||||
$tablew = $pdfWidth - (2 * $marginSide); // total table width (A4 landscape in mm minus margins)
|
||||
$fixedWidth = 0;
|
||||
$flexCols = [];
|
||||
|
||||
/*
|
||||
// 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'];
|
||||
foreach ($columns as $col) {
|
||||
if ($col['flex'] ?? false) {
|
||||
$flexCols[] = $col['id'];
|
||||
$fixedWidth += $col['max_width'];
|
||||
} else {
|
||||
$fixedWidth += $col['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;
|
||||
}
|
||||
|
||||
if (!empty($flexCols) && $effTableWidth > 0) {
|
||||
$flexTotalInitial = 0;
|
||||
foreach ($columns as $col) {
|
||||
if ($col['flex'] ?? false) $flexTotalInitial += $col['max_width'];
|
||||
}
|
||||
|
||||
foreach ($columns as &$col) {
|
||||
if ($col['flex'] ?? false) {
|
||||
$col['max_width'] += ($col['max_width'] / $flexTotalInitial) * $effTableWidth;
|
||||
}
|
||||
}
|
||||
unset($col);
|
||||
}
|
||||
*/
|
||||
|
||||
$pdf->columns = $columns;
|
||||
$pdf->disciplines = $disciplines;
|
||||
@@ -501,14 +608,19 @@ $pdf->AddPage();
|
||||
$margin_top = $pdf->headerBottomY;
|
||||
|
||||
// Now adjust your margins if needed
|
||||
$pdf->SetMargins(10, $margin_top, 10); // +5 mm padding below header
|
||||
$pdf->SetMargins($marginSide, $margin_top, $marginSide); // +5 mm padding below header
|
||||
$pdf->SetY($margin_top); // Move cursor below header manually
|
||||
|
||||
|
||||
$mbs = false;
|
||||
$mbl = false;
|
||||
$pdf->SetFont('', '');
|
||||
$index = 0;
|
||||
$rIndex = 0;
|
||||
|
||||
usort($personen, function($a, $b) use ($ranks) {
|
||||
$rankA = $ranks[$a['id']];
|
||||
$rankB = $ranks[$b['id']];
|
||||
|
||||
return $rankA <=> $rankB;
|
||||
});
|
||||
|
||||
foreach ($personen as $r) {
|
||||
|
||||
$pdf->SetTextColor(0, 0, 0);
|
||||
@@ -519,81 +631,118 @@ foreach ($personen as $r) {
|
||||
$pdf->SetFillColor(255, 235, 128);
|
||||
} elseif($rang == 2) {
|
||||
$pdf->SetFillColor(224, 224, 224);
|
||||
} elseif($$rang == 3) {
|
||||
} elseif($rang == 3) {
|
||||
$pdf->SetFillColor(230, 191, 153);
|
||||
} elseif ($index % 2 == 0) {
|
||||
} elseif ($rIndex % 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);
|
||||
// Determine row height based on max runs
|
||||
$maxRuns = 1;
|
||||
foreach ($columns as $col) {
|
||||
if ($col['type'] === 'note') {
|
||||
$runs = $indexedNotenArray[$r['id']][$col['geraet_id']][$col['note_bezeichnung_id']] ?? [];
|
||||
if (is_array($runs) && count($runs) > $maxRuns) {
|
||||
$maxRuns = count($runs);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$gesamt = isset($r["gesamtpunktzahl"]) ? number_format((float)$r["gesamtpunktzahl"], 3) : '';
|
||||
// Base height is 8, add extra height for additional runs. Let's say 4mm per additional line.
|
||||
// But to keep it centered properly, we will use MultiCell with valign='M' (Middle).
|
||||
$rowHeight = max(8, $maxRuns * 5 + 3); // 5mm per line
|
||||
|
||||
$pdf->SetFont('', 'B');
|
||||
$pdf->Cell($columns['gesamt'][0]['max_width'], 8, $gesamt, 'B', 0, 'C', true);
|
||||
$pdf->SetFont('', '');
|
||||
if ($pdf->getY() + $rowHeight >= $pdfHeight - $minMarginBottomTable) {
|
||||
$pdf->addPage();
|
||||
$pdf->setX($marginSide);
|
||||
}
|
||||
|
||||
$x = $pdf->GetX() - $columns['gesamt'][0]['max_width'];
|
||||
$y = $pdf->GetY();
|
||||
foreach ($columns as $col) {
|
||||
|
||||
$pdf->SetLineWidth(0.6);
|
||||
$pdf->Line($x, $y, $x, $y + 7.7);
|
||||
$customFontSize = (isset($col['font_size']) && $col['font_size'] != 0);
|
||||
|
||||
$pdf->SetLineWidth(0.2);
|
||||
$pdf->Ln();
|
||||
if ($customFontSize) {
|
||||
$pdf->SetFont('', '', $col['font_size']);
|
||||
}
|
||||
|
||||
$index++;
|
||||
$startX = $pdf->GetX();
|
||||
$startY = $pdf->GetY();
|
||||
|
||||
if ($col['id'] === 'rang') {
|
||||
$pdf->SetFont('', 'B');
|
||||
$pdf->MultiCell($col['max_width'], $rowHeight, $rang, 'B', 'C', true, 0, $startX, $startY, true, 0, false, true, $rowHeight, 'M');
|
||||
$pdf->SetFont('', '');
|
||||
} elseif ($col['type'] === 'field') {
|
||||
$pdf->MultiCell($col['max_width'], $rowHeight, $r[$col['field']], 'B', $col['align'], true, 0, $startX, $startY, true, 0, false, true, $rowHeight, 'M');
|
||||
} elseif ($col['type'] === 'year') {
|
||||
$pdf->MultiCell($col['max_width'], $rowHeight, (new DateTime($r[$col['field']]))->format("Y"), 'B', $col['align'], true, 0, $startX, $startY, true, 0, false, true, $rowHeight, 'M');
|
||||
} elseif ($col['type'] === 'note') {
|
||||
$runs = $indexedNotenArray[$r['id']][$col['geraet_id']][$col['note_bezeichnung_id']] ?? [];
|
||||
if (!is_array($runs)) {
|
||||
$runs = [$runs];
|
||||
} else {
|
||||
ksort($runs);
|
||||
}
|
||||
|
||||
$numRuns = max(count($runs), 1);
|
||||
$lineHeight = $rowHeight / $numRuns;
|
||||
|
||||
$pdf->SetXY($startX, $startY);
|
||||
$pdf->Cell($col['max_width'], $rowHeight, '', 0, 0, '', true);
|
||||
|
||||
$runIndex = 0;
|
||||
foreach (array_values($runs) as $rnVal) {
|
||||
$formatted = number_format((float)$rnVal, $col['nullstellen'] ?? 0);
|
||||
$currentY = $startY + ($runIndex * $lineHeight);
|
||||
|
||||
$pdf->SetXY($startX, $currentY);
|
||||
|
||||
$pdf->Cell($col['max_width'], $lineHeight, $formatted, 0, 0, $col['align'], false);
|
||||
$runIndex++;
|
||||
}
|
||||
|
||||
// Draw the bottom border for the entire row height
|
||||
$pdf->Line($startX, $startY + $rowHeight, $startX + $col['max_width'], $startY + $rowHeight);
|
||||
|
||||
// Reset pointer for the next column
|
||||
$pdf->SetXY($startX + $col['max_width'], $startY);
|
||||
|
||||
if ($col['id'] === 'gesamt') {
|
||||
// Draw the heavy separator line on the left side of the "Gesamt" column
|
||||
$pdf->SetLineWidth(0.6);
|
||||
$pdf->Line($startX, $startY, $startX, $startY + $rowHeight);
|
||||
$pdf->SetLineWidth(0.2);
|
||||
}
|
||||
}
|
||||
|
||||
if ($customFontSize) {
|
||||
$pdf->SetFont('', '', $normalFontSize);
|
||||
}
|
||||
}
|
||||
|
||||
$pdf->SetY($startY + $rowHeight); // Move Y manually instead of Ln() to account for rowHeight
|
||||
$rIndex++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$pdf->SetFont('', '', 7);
|
||||
$textanzturnerinnen = (count($entries) > 1) ? 'Turnerinnen': 'Turnerin';
|
||||
$pdf->Cell(20, 6, count($entries).' '.$textanzturnerinnen, 0, 0, 'L');
|
||||
$textanzturnerinnen = (count($personen) > 1) ? 'Turnerinnen': 'Turnerin';
|
||||
$pdf->Cell(20, 6, count($personen).' '.$textanzturnerinnen, 0, 0, 'L');
|
||||
|
||||
if ($buttontype === 'export_programm' || $buttontype === 'export_programm_bm') {
|
||||
$pdf->Output("KTBB_Ergebnisse_" . $programm . "_" . $current_year . ".pdf", 'D');
|
||||
if ($buttontype === 'downloadRangliste') {
|
||||
$pdf->Output($wkName . "_Ergebnisse_" . $programm . "_" . $current_year . ".pdf", 'I');
|
||||
exit;
|
||||
} elseif ($buttontype === 'upload_programm') {
|
||||
$dir = $baseDir . '/wp-content/ergebnisse/';
|
||||
} elseif ($buttontype === 'updateServerRangliste') {
|
||||
$dir = $baseDir . '/files/ranglisten/';
|
||||
if (!file_exists($dir)) mkdir($dir, 0755, true);
|
||||
$localPath = $dir . "KTBB_Ergebnisse_" . $programm . "_" . $current_year . ".pdf";
|
||||
$localPath = $dir . str_replace("/", "", str_replace(" ", "_", $wkName)) . "_Ergebnisse_" . str_replace("/", "", $programm) . "_" . $current_year . ".pdf";
|
||||
if (file_exists($localPath)) unlink($localPath);
|
||||
$pdf->Output($localPath, 'F');
|
||||
$_SESSION['form_message'] = '<div class="success">PDF wurde hochgeladen</div>';
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode(["success" => true, "message" => "PDF wurde aktualisiert"]);
|
||||
exit;
|
||||
}
|
||||
@@ -24,34 +24,54 @@ if ($data['success'] === false){
|
||||
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']) : '';
|
||||
$personId = intval($_POST['personId'] ?? 0);
|
||||
$gereatId = intval($_POST['geraetId'] ?? 0);
|
||||
|
||||
if ($discipline !== 'boden') {
|
||||
echo json_encode(['success' => false, 'message' => 'Invalid discipline']);
|
||||
if ($gereatId < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Kein Gerät angegeben']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($id <= 0) {
|
||||
if ($personId < 1) {
|
||||
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;
|
||||
}
|
||||
$sqlQuery = "SELECT
|
||||
paf.`audiofile_id`,
|
||||
af.`file_path`,
|
||||
af.`file_name`,
|
||||
tu.`name`,
|
||||
tu.`vorname`
|
||||
FROM $tableTeilnehmendeAudiofiles paf
|
||||
INNER JOIN $tableAudiofiles af
|
||||
ON paf.`audiofile_id` = af.`id`
|
||||
LEFT JOIN $tableTeilnehmende tu
|
||||
ON paf.`person_id` = tu.`id`
|
||||
WHERE paf.`person_id` = ?
|
||||
AND paf.`geraet_id` = ?
|
||||
";
|
||||
|
||||
if ($row['bodenmusik'] === "0" || $row['filePath'] == null) {
|
||||
$stmt = $mysqli->prepare($sqlQuery);
|
||||
|
||||
$stmt->bind_param('ii', $personId, $gereatId);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->get_result();
|
||||
|
||||
$rows = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
if (count($rows) !== 1 || !isset($rows[0]['file_path']) || $rows[0]['file_path'] === null) {
|
||||
echo json_encode(['success' => false, 'message' => 'Keine Musik']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$folder = realpath($baseDir . '/displays/json');
|
||||
$row = $rows[0];
|
||||
|
||||
$folder = realpath($baseDir . '/externe-geraete/json');
|
||||
if ($folder === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
@@ -60,11 +80,11 @@ if ($folder === false) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$filename = 'audio.json';
|
||||
$filename = 'audio-id-'. $gereatId .'.json';
|
||||
$filepath = $folder . '/' . $filename;
|
||||
|
||||
if (!is_writable($folder)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Folder not writable: ']);
|
||||
echo json_encode(['success' => false, 'message' => 'Folder not writable.']);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -74,22 +94,23 @@ if (!is_file($filepath)){
|
||||
}
|
||||
|
||||
|
||||
$jsonString = file_get_contents($filepath);
|
||||
$json = [
|
||||
"audio_path" => $row['file_path'],
|
||||
"audio_name" => $row['file_name'],
|
||||
"start" => true,
|
||||
"person" => [
|
||||
"name" => $row['name'],
|
||||
"vorname" => $row['vorname']
|
||||
]
|
||||
];
|
||||
|
||||
// decode JSON, fallback to empty array if invalid
|
||||
$oldjson = json_decode($jsonString, true) ?? [];
|
||||
|
||||
|
||||
$oldjson["musik"] = $row['filePath'];
|
||||
$oldjson["start"] = true;
|
||||
|
||||
$jsonData = json_encode($oldjson);
|
||||
$jsonData = json_encode($json);
|
||||
|
||||
// Write file
|
||||
if (file_put_contents($filepath, $jsonData) === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Failed to write JSON file: ' . $filepath
|
||||
'message' => 'Failed to write JSON file'
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
@@ -99,7 +120,6 @@ if (file_put_contents($filepath, $jsonData) === false) {
|
||||
// ---------- Return JSON ----------
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'JSON updated successfully for '.$discipline,
|
||||
'disable_musik_button' => true
|
||||
'message' => 'Audio JSON updated successfully'
|
||||
]);
|
||||
exit;
|
||||
@@ -13,9 +13,14 @@ check_user_permission('kampfrichter');
|
||||
|
||||
verify_csrf();
|
||||
|
||||
$discipline = 'boden';
|
||||
$gereatId = intval($_POST['geraetId'] ?? 0);
|
||||
|
||||
$folder = realpath($baseDir . '/displays/json');
|
||||
if ($gereatId < 1) {
|
||||
echo json_encode(['success' => false, 'message' => 'Kein Gerät angegeben']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$folder = realpath($baseDir . '/externe-geraete/json');
|
||||
if ($folder === false) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
@@ -24,7 +29,7 @@ if ($folder === false) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$filename = 'audio.json';
|
||||
$filename = 'audio-id-'. $gereatId .'.json';
|
||||
$filepath = $folder . '/' . $filename;
|
||||
|
||||
if (!is_writable($folder)) {
|
||||
@@ -36,14 +41,11 @@ if (!is_file($filepath)){
|
||||
file_put_contents($filepath, []);
|
||||
}
|
||||
|
||||
$jsonString = file_get_contents($filepath);
|
||||
$json = [
|
||||
"start" => false
|
||||
];
|
||||
|
||||
// decode JSON, fallback to empty array if invalid
|
||||
$oldjson = json_decode($jsonString, true) ?? [];
|
||||
|
||||
$oldjson["start"] = false;
|
||||
|
||||
$jsonData = json_encode($oldjson);
|
||||
$jsonData = json_encode($json);
|
||||
|
||||
// Write file
|
||||
if (file_put_contents($filepath, $jsonData) === false) {
|
||||
|
||||
@@ -1,111 +0,0 @@
|
||||
<?php
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
require_once $baseDir . '/../scripts/session_functions.php';
|
||||
|
||||
ini_wkvs_session();
|
||||
|
||||
check_user_permission('kampfrichter');
|
||||
|
||||
verify_csrf();
|
||||
|
||||
$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;
|
||||
}
|
||||
?>
|
||||
@@ -24,7 +24,6 @@ if ($data['success'] === false){
|
||||
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);
|
||||
@@ -84,6 +83,8 @@ if ($singleNoteConfig['min_value'] !== null && $valueNoteUpdate < $singleNoteCon
|
||||
exit;
|
||||
}
|
||||
|
||||
$oldNote = db_get_var($mysqli, "SELECT `value` FROM $tableNoten WHERE `person_id` = ? AND `note_bezeichnung_id` = ? AND `geraet_id` = ? AND `jahr` = ? AND `run_number` = ?", [$person_id, $field_type_id, $gereat_id, $jahr, $run_number]);
|
||||
|
||||
$sql = "INSERT INTO $tableNoten (`value`, `person_id`, `note_bezeichnung_id`, `geraet_id`, `jahr`, `run_number`)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)";
|
||||
@@ -96,6 +97,19 @@ $stmt->execute();
|
||||
|
||||
$stmt->close();
|
||||
|
||||
$userId = (int) $_SESSION['user_id_kampfrichter'];
|
||||
|
||||
$sql = "INSERT INTO $tableNotenChanges (`new_value`, `old_value`, `person_id`, `note_bezeichnung_id`, `geraet_id`, `jahr`, `run_number`, `edited_by`)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
|
||||
$stmt = $mysqli->prepare($sql);
|
||||
|
||||
$stmt->bind_param("ssiiiiii", $valueNoteUpdate, $oldNote, $person_id, $field_type_id, $gereat_id, $jahr, $run_number, $userId);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$stmt->close();
|
||||
|
||||
if ($singleNoteConfig['berechnung_json'] === null) {
|
||||
echo json_encode(['success' => true, 'message' => "Wert aktualisiert"]);
|
||||
exit;
|
||||
@@ -116,23 +130,21 @@ try {
|
||||
|
||||
$geraete = db_select($mysqli, $tableGeraete, "id");
|
||||
|
||||
$programmName = db_get_var($mysqli, "SELECT `programm` FROM $tableTurnerinnen WHERE `id` = ?", [$person_id]);
|
||||
$programmName = db_get_var($mysqli, "SELECT `programm` FROM $tableTeilnehmende WHERE `id` = ?", [$person_id]);
|
||||
|
||||
$programmId = db_get_var($mysqli, "SELECT `id` FROM $tableProgramme WHERE `programm` = ?", [$programmName]);
|
||||
|
||||
// Alle Werte werden von der Datenbank geholt und werden, wenn nicht vorhanden, durch den Standartwert ersetzt.
|
||||
// We load the configuration native cached array
|
||||
$cache = require $baseDir . '/../scripts/cache/noten-config-calculating-cache.php';
|
||||
|
||||
$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` = ? AND `value` IS NOT NULL", [$person_id, $jahr]);
|
||||
|
||||
$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;
|
||||
$ascArrayDefaultValues = $cache['default_values'];
|
||||
$ascArrayProGeraet = $cache['pro_geraet'];
|
||||
$ascArrayGeraeteJSON = $cache['geraete_json'];
|
||||
$ascArrayAnzahlLaeufeJSON = $cache['anzahl_laeufe_json'];
|
||||
$ascArrayRechnungen = $cache['rechnungen'];
|
||||
$indexedNullstellen = $cache['nullstellen'];
|
||||
|
||||
$mRunFunctions = [];
|
||||
|
||||
@@ -143,20 +155,11 @@ foreach ($abhaenigeRechnungen as $saRechnung) {
|
||||
|
||||
if ($mRunCalc) {
|
||||
$mRunFunctions[] = $saRechnung[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$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']] = [];
|
||||
}
|
||||
@@ -164,76 +167,61 @@ foreach ($geraete as $g) {
|
||||
$indexedNotenArray[0] = [];
|
||||
|
||||
foreach ($noten as $sn) {
|
||||
$indexedNotenArray[$sn['geraet_id']][$sn['note_bezeichnung_id']][$sn['run_number']] = $sn['value'];
|
||||
$indexedNotenArray[$sn['geraet_id']][$sn['note_bezeichnung_id']][$sn['run_number']] = ["value" => $sn['value'], "type" => "note"];
|
||||
}
|
||||
|
||||
$alleNotenIds = array_column($alleNoten, 'id') ?? [];
|
||||
$requiredNoteIds = [];
|
||||
$requiredNoteIds[$field_type_id] = true;
|
||||
|
||||
foreach ($abhaenigeRechnungen as $saRechnung) {
|
||||
// Only load dependencies for the specifically connected calculations
|
||||
$sRechnungStr = $ascArrayRechnungen[$saRechnung[0]] ?? '';
|
||||
if ($sRechnungStr !== '') {
|
||||
$ids = $notenRechner->getBenoetigteIdsComplex($sRechnungStr);
|
||||
foreach ($ids as $idConfig) {
|
||||
$requiredNoteIds[(int)$idConfig['noteId']] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
$alleNotenIds = array_keys($requiredNoteIds);
|
||||
|
||||
if (count($mRunFunctions) > 0) {
|
||||
foreach ($indexedNotenArray as $sG => $siNA) {
|
||||
|
||||
foreach ($alleNotenIds as $neni) { // Use $neni as the ID
|
||||
|
||||
// 1. Skip if no default value is defined
|
||||
if (!isset($ascArrayDefaultValues[$neni])) {
|
||||
continue;
|
||||
}
|
||||
foreach ($alleNotenIds as $neni) {
|
||||
if (!isset($ascArrayDefaultValues[$neni])) continue;
|
||||
|
||||
// 2. Logic Check: Is this note assigned to this device?
|
||||
$isProGeraet = (int)($ascArrayProGeraet[$neni] ?? 0);
|
||||
|
||||
if ($isProGeraet === 1 && (int)$sG === 0) {
|
||||
continue;
|
||||
}
|
||||
if ($isProGeraet === 1 && (int)$sG === 0) continue;
|
||||
|
||||
if ($isProGeraet !== 1) {
|
||||
$allowedGeraete = $ascArrayGeraeteJSON[$neni] ?? [];
|
||||
if (!is_array($allowedGeraete) || !in_array($sG, $allowedGeraete)) {
|
||||
continue;
|
||||
}
|
||||
if (!is_array($allowedGeraete) || !in_array($sG, $allowedGeraete)) continue;
|
||||
}
|
||||
|
||||
$runs = $ascArrayAnzahlLaeufeJSON[$neni][$sG][$programmId] ?? $ascArrayAnzahlLaeufeJSON[$neni]["default"] ?? 1;
|
||||
$runs = $ascArrayAnzahlLaeufeJSON[$neni][$sG][$programmId] ?? $ascArrayAnzahlLaeufeJSON[$neni][$sG]['all'] ?? $ascArrayAnzahlLaeufeJSON[$neni]["default"] ?? 1;
|
||||
|
||||
for ($r = 1; $r <= $runs; $r++) {
|
||||
if (isset($indexedNotenArray[$sG][$neni][$r])) {
|
||||
continue;
|
||||
if (!isset($indexedNotenArray[$sG][$neni][$r])) {
|
||||
$indexedNotenArray[$sG][$neni][$r] = ["value" => $ascArrayDefaultValues[$neni], "type" => "default_value"];
|
||||
}
|
||||
$indexedNotenArray[$sG][$neni][$r] = $ascArrayDefaultValues[$neni];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
foreach ($indexedNotenArray as $sG => $siNA) {
|
||||
|
||||
foreach ($alleNotenIds as $neni) { // Use $neni as the ID
|
||||
|
||||
// 1. Skip if value already exists for this specific run
|
||||
if (isset($indexedNotenArray[$sG][$neni][$run_number])) {
|
||||
continue;
|
||||
}
|
||||
foreach ($alleNotenIds as $neni) {
|
||||
if (isset($indexedNotenArray[$sG][$neni][$run_number])) continue;
|
||||
if (!isset($ascArrayDefaultValues[$neni])) continue;
|
||||
|
||||
// 2. Skip if no default value is defined
|
||||
if (!isset($ascArrayDefaultValues[$neni])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 3. Logic Check: Is this note assigned to this device?
|
||||
$isProGeraet = (int)($ascArrayProGeraet[$neni] ?? 0);
|
||||
|
||||
if ($isProGeraet === 1 && (int)$sG === 0) {
|
||||
continue;
|
||||
}
|
||||
if ($isProGeraet === 1 && (int)$sG === 0) continue;
|
||||
|
||||
if ($isProGeraet !== 1) {
|
||||
$allowedGeraete = $ascArrayGeraeteJSON[$neni] ?? [];
|
||||
if (!is_array($allowedGeraete) || !in_array($sG, $allowedGeraete)) {
|
||||
continue;
|
||||
}
|
||||
if (!is_array($allowedGeraete) || !in_array($sG, $allowedGeraete)) continue;
|
||||
}
|
||||
|
||||
// 4. Assign the default value
|
||||
$indexedNotenArray[$sG][$neni][$run_number] = $ascArrayDefaultValues[$neni];
|
||||
$indexedNotenArray[$sG][$neni][$run_number] = ["value" => $ascArrayDefaultValues[$neni], "type" => "default_value"];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -244,6 +232,7 @@ $idsToSave = [];
|
||||
foreach ($abhaenigeRechnungen as $sRechnung) {
|
||||
$targetNoteId = $sRechnung[0];
|
||||
$rechnungType = $sRechnung[1];
|
||||
$targetRun = $sRechnung[2][0] ?? 'A';
|
||||
|
||||
// 1. Initial Filter
|
||||
if ($rechnungType !== "A" && intval($rechnungType) !== $gereat_id) continue;
|
||||
@@ -266,14 +255,14 @@ foreach ($abhaenigeRechnungen as $sRechnung) {
|
||||
|
||||
// 3. Calculation Logic
|
||||
$runsConfig = $ascArrayAnzahlLaeufeJSON[$targetNoteId] ?? [];
|
||||
$runs = $runsConfig[$gereat_id][$programmId] ?? $runsConfig["default"] ?? 1;
|
||||
$runs = $runsConfig[$targetGeraetKey][$programmId] ?? $runsConfig[$targetGeraetKey]["all"] ?? $runsConfig["default"] ?? 1;
|
||||
|
||||
$acrun = min($runs, $run_number);
|
||||
|
||||
if (in_array($targetNoteId, $mRunFunctions)) {
|
||||
$calcResult = $notenRechner->berechneStringComplexRun($rechnung, $indexedNotenArray, $gereat_id, $programmId, $ascArrayAnzahlLaeufeJSON);
|
||||
$calcResult = $notenRechner->berechneStringComplexRun($rechnung, $indexedNotenArray, $targetGeraetKey, $programmId, $ascArrayAnzahlLaeufeJSON);
|
||||
} else {
|
||||
$calcResult = $notenRechner->berechneStringComplex($rechnung, $indexedNotenArray, $gereat_id, $acrun);
|
||||
$calcResult = $notenRechner->berechneStringComplex($rechnung, $indexedNotenArray, $targetGeraetKey, $acrun);
|
||||
}
|
||||
|
||||
if (!($calcResult['success'] ?? false)) {
|
||||
@@ -281,10 +270,13 @@ foreach ($abhaenigeRechnungen as $sRechnung) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$acTargetRun = ($targetRun === "A") ? $acrun : intval($targetRun);
|
||||
|
||||
|
||||
// 4. Update State
|
||||
$val = $calcResult['value'];
|
||||
$indexedNotenArray[$targetGeraetKey][$targetNoteId][$acrun] = $val;
|
||||
$updatedValues[$targetGeraetKey][$targetNoteId][$acrun] = $val;
|
||||
$indexedNotenArray[$targetGeraetKey][$targetNoteId][$acTargetRun] = ["value" => $val, "type" => "berechnet"];
|
||||
$updatedValues[$targetGeraetKey][$targetNoteId][$acTargetRun] = $val;
|
||||
}
|
||||
|
||||
// Prepare the statement once
|
||||
@@ -293,11 +285,10 @@ $sql = "INSERT INTO $tableNoten (`value`, `person_id`, `note_bezeichnung_id`, `g
|
||||
ON DUPLICATE KEY UPDATE `value` = VALUES(`value`)";
|
||||
|
||||
$stmt = $mysqli->prepare($sql);
|
||||
|
||||
$indexedNullstellen = array_column($alleNoten, 'nullstellen', 'id');
|
||||
|
||||
$formatedNoten = [];
|
||||
|
||||
$mysqli->begin_transaction();
|
||||
|
||||
foreach ($updatedValues as $gereat => $notenArray) {
|
||||
foreach ($notenArray as $note => $runArray) {
|
||||
foreach ($runArray as $run => $value) {
|
||||
@@ -308,6 +299,8 @@ foreach ($updatedValues as $gereat => $notenArray) {
|
||||
}
|
||||
}
|
||||
|
||||
$mysqli->commit();
|
||||
|
||||
$formatedNoten[$gereat_id][$field_type_id][$run_number] = number_format($valueNoteUpdate ,$indexedNullstellen[$field_type_id] ?? 2);
|
||||
|
||||
$stmt->close();
|
||||
|
||||
@@ -14,10 +14,10 @@ check_user_permission('kampfrichter');
|
||||
verify_csrf();
|
||||
|
||||
// ---------- Get and sanitize input ----------
|
||||
$id = intval($_POST['personId']) ?? 0;
|
||||
$run = intval($_POST['run']) ?? 0;
|
||||
$geraetId = intval($_POST['geraetId']) ?? 0;
|
||||
$dataType = intval($_POST['dataType']) ?? 0;
|
||||
$id = intval($_POST['personId'] ?? 0);
|
||||
$initNoteRun = intval($_POST['run'] ?? 0);
|
||||
$geraetId = intval($_POST['geraetId'] ?? 0);
|
||||
$dataType = intval($_POST['dataType'] ?? 0);
|
||||
$jahr = isset($_POST['jahr']) ? preg_replace('/[^0-9]/', '', $_POST['jahr']) : '';
|
||||
$anfrageType = $_POST['type'] ?? '';
|
||||
|
||||
@@ -70,7 +70,7 @@ $geraetName = $geraetData['name'];
|
||||
|
||||
$stmt->close();
|
||||
|
||||
$folder = realpath($baseDir . '/displays/json');
|
||||
$folder = realpath($baseDir . '/externe-geraete/json');
|
||||
|
||||
if ($folder === false) {
|
||||
echo json_encode([
|
||||
@@ -80,7 +80,7 @@ if ($folder === false) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$filename = 'display_' . strtolower($geraetName) . '.json';
|
||||
$filename = 'display-id-' . $geraetId . '.json';
|
||||
$filepath = $folder . '/' . $filename;
|
||||
|
||||
if (!is_writable($folder)) {
|
||||
@@ -95,7 +95,7 @@ $oldjson = json_decode($jsonString, true) ?? [];
|
||||
|
||||
switch ($anfrageType) {
|
||||
case "neu":
|
||||
$stmt = $mysqli->prepare("SELECT * FROM `$tableTurnerinnen` WHERE id = ? LIMIT 1");
|
||||
$stmt = $mysqli->prepare("SELECT `id`, `name`, `vorname`, `programm`, `verein` FROM `$tableTeilnehmende` WHERE id = ? LIMIT 1");
|
||||
$stmt->bind_param("i", $id);
|
||||
$stmt->execute();
|
||||
|
||||
@@ -109,9 +109,6 @@ switch ($anfrageType) {
|
||||
|
||||
$row = $rows[0];
|
||||
|
||||
// safely get value, default 0 if missing
|
||||
$olduniqueid = $oldjson['uniqueid'] ?? 0;
|
||||
$uniqueid = $olduniqueid + 1;
|
||||
|
||||
$data = ["noteLinks" => '',
|
||||
"noteRechts" => '',
|
||||
@@ -120,10 +117,10 @@ switch ($anfrageType) {
|
||||
"vorname" => $row['vorname'],
|
||||
"programm" => $row['programm'],
|
||||
"verein" => $row['verein'],
|
||||
"start" => false,
|
||||
"musik" => 'nan',
|
||||
"uniqueid" => $uniqueid];
|
||||
$jsonData = json_encode($data);
|
||||
"start" => false
|
||||
];
|
||||
|
||||
$arrayData = $data;
|
||||
break;
|
||||
case "start":
|
||||
if (!array_key_exists("id", $oldjson) || intval($oldjson["id"]) !== $id || !array_key_exists("start", $oldjson)) {
|
||||
@@ -133,21 +130,68 @@ switch ($anfrageType) {
|
||||
|
||||
$oldjson["start"] = (bool) $dataType;
|
||||
|
||||
$jsonData = json_encode($oldjson);
|
||||
$arrayData = $oldjson;
|
||||
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']);
|
||||
$noteLinksId = db_get_variable($mysqli, $tableVar, ['displayIdNoteL']);
|
||||
$noteRechtsId = db_get_variable($mysqli, $tableVar, ['displayIdNoteR']);
|
||||
|
||||
$stmt = $mysqli->prepare("UPDATE $tableNoten SET `is_public` = 1, `public_value` = `value` WHERE `person_id` = ? AND `jahr` = ? AND `geraet_id` = ? AND `run_number` = ?");
|
||||
$programm_id = db_get_var($mysqli, "SELECT p.`id` FROM $tableTeilnehmende t INNER JOIN $tableProgramme p ON p.`programm` = t.`programm` WHERE t.`id` = ?", [$id]) ?? null;
|
||||
|
||||
$stmt->bind_param("ssss", $id, $jahr, $geraetId, $run);
|
||||
$display_cache = require $baseDir . '/../scripts/cache/display-dependencies.php';
|
||||
|
||||
$stmt->execute();
|
||||
$this_display_cache = $display_cache[$programm_id][$geraetId][$initNoteRun];
|
||||
|
||||
$stmt->close();
|
||||
$sql_where_values = $this_display_cache['values'];
|
||||
|
||||
$sql_where_string = $this_display_cache['SQL'];
|
||||
|
||||
$intersect_noten = $this_display_cache['intersect_noten'];
|
||||
|
||||
$rankLiveArray = [];
|
||||
|
||||
if (!empty($sql_where_values) && $sql_where_string !== '') {
|
||||
|
||||
$notenDB = db_select($mysqli, $tableNoten, '`value`, `note_bezeichnung_id`, `geraet_id`, `run_number`', "`person_id` = ? AND `jahr` = ? AND ($sql_where_string)", array_merge([$id, $jahr], $sql_where_values));
|
||||
|
||||
$indexedNotenDB = [];
|
||||
|
||||
foreach ($notenDB as $sn) {
|
||||
$indexedNotenDB[$sn['geraet_id']][$sn['note_bezeichnung_id']][$sn['run_number']] = $sn;
|
||||
}
|
||||
}
|
||||
|
||||
$mysqli->begin_transaction();
|
||||
|
||||
|
||||
try {
|
||||
$stmt = $mysqli->prepare("INSERT INTO $tableNoten (`person_id`, `note_bezeichnung_id`, `jahr`, `geraet_id`, `run_number`, `is_public`, `public_value`) VALUES (?, ?, ?, ?, ?, 1, ?) ON DUPLICATE KEY UPDATE `public_value` = VALUES(`public_value`), `is_public` = 1");
|
||||
|
||||
foreach ($intersect_noten as $s_note) {
|
||||
$n_id = $s_note['n_id'];
|
||||
$g_id = $s_note['g_id'];
|
||||
$run = $s_note['r'];
|
||||
|
||||
$value = $indexedNotenDB[$g_id][$n_id][$run]['value'] ?? $notenConfig['default_values'][$n_id] ?? 0;
|
||||
$rankLiveArray[$g_id][$run][$n_id] = number_format($value, $notenConfig['nullstellen'][$n_id] ?? 2);
|
||||
|
||||
$stmt->bind_param("iiiiid", $id, $n_id, $jahr, $g_id, $run, $value);
|
||||
|
||||
$stmt->execute();
|
||||
}
|
||||
|
||||
$mysqli->commit();
|
||||
$stmt->close();
|
||||
} catch (Exception $e) {
|
||||
$mysqli->rollback();
|
||||
echo json_encode(['success' => false, 'message' => 'DB Transaction failed Error: ' . $e->getMessage()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Create an array of IDs that actually exist
|
||||
$validIds = array_filter([$noteLinksId, $noteRechtsId]);
|
||||
|
||||
@@ -164,7 +208,7 @@ switch ($anfrageType) {
|
||||
|
||||
$stmt = $mysqli->prepare($sqlNoten);
|
||||
// Combine standard params with our dynamic ID list
|
||||
$params = array_merge([$id, $jahr, $geraetId, $run], $validIds);
|
||||
$params = array_merge([$id, $jahr, $geraetId, $initNoteRun], $validIds);
|
||||
$types = str_repeat('s', count($params));
|
||||
$stmt->bind_param($types, ...$params);
|
||||
$stmt->execute();
|
||||
@@ -173,7 +217,7 @@ switch ($anfrageType) {
|
||||
$stmt->close();
|
||||
|
||||
// 3. Fetch Config
|
||||
$sqlConfig = "SELECT `id`, `default_value`, `nullstellen`, `prefix_display`
|
||||
$sqlConfig = "SELECT `id`, `default_value`, `nullstellen`, `display_string`
|
||||
FROM $tableNotenBezeichnungen WHERE `id` IN ($placeholders)";
|
||||
|
||||
$stmt = $mysqli->prepare($sqlConfig);
|
||||
@@ -194,20 +238,34 @@ switch ($anfrageType) {
|
||||
$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, '.', '');
|
||||
|
||||
$display_schema = $conf['display_string'] ?? '${note}';
|
||||
|
||||
$formatted_note = number_format((float)$val, (int)$prec, '.', '');
|
||||
|
||||
$result = str_ireplace('${note}', $formatted_note, $display_schema);
|
||||
|
||||
if ($result === $display_schema) {
|
||||
return $formatted_note;
|
||||
}
|
||||
|
||||
return $result;
|
||||
};
|
||||
|
||||
// 5. Assign to JSON
|
||||
$oldjson["noteLinks"] = $formatNote($noteLinksId);
|
||||
$oldjson["noteRechts"] = $formatNote($noteRechtsId);
|
||||
|
||||
$jsonData = json_encode($oldjson);
|
||||
$arrayData = $oldjson;
|
||||
|
||||
break;
|
||||
default:
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
$jsonData = json_encode($arrayData);
|
||||
|
||||
// Write file
|
||||
if (file_put_contents($filepath, $jsonData) === false) {
|
||||
echo json_encode([
|
||||
@@ -217,11 +275,21 @@ if (file_put_contents($filepath, $jsonData) === false) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// ---------- Return JSON ----------
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'JSON updated successfully for ' . $geraetName,
|
||||
'data' => json_decode($jsonData, true),
|
||||
'nameGeraet' => strtolower($geraetName)
|
||||
]);
|
||||
if ($anfrageType === "result") {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'JSON updated successfully for ' . $geraetName,
|
||||
'data' => $arrayData,
|
||||
'rankLive' => $rankLiveArray,
|
||||
'nameGeraet' => strtolower($geraetName)
|
||||
]);
|
||||
} else {
|
||||
// ---------- Return JSON ----------
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'JSON updated successfully for ' . $geraetName,
|
||||
'data' => $arrayData,
|
||||
'nameGeraet' => strtolower($geraetName)
|
||||
]);
|
||||
}
|
||||
exit;
|
||||
@@ -1,201 +0,0 @@
|
||||
<?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['user_id_kampfrichter']) || $_SESSION['user_id_kampfrichter'] < 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