Semi-stable version with old variable names
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user