First version, for githup; UNSTABLE, DO NOT USE!
This commit is contained in:
@@ -0,0 +1,233 @@
|
||||
<?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);
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
|
||||
|
||||
if (empty($_SESSION['access_granted_wk_leitung']) || $_SESSION['access_granted_wk_leitung'] !== true || empty($_SESSION['passcodewk_leitung_id']) || intval($_SESSION['passcodewk_leitung_id']) < 0 ) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
$type = 'wkl';
|
||||
|
||||
$dbconnection = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($dbconnection['success'] !== true){
|
||||
echo 'Critical DB Error.';
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
$allGeraete = db_select($mysqli, $tableGeraete, "id, name, start_index", "", [], "start_index ASC");
|
||||
$allAbt = db_select($mysqli, $tableAbt, "name, id", "", [], "name ASC");
|
||||
|
||||
$maxTurnerinnenGruppe = 8;
|
||||
|
||||
// $allGeraete[] = ['name' => 'null', 'id' => 'null'];
|
||||
// $allAbt[] = ['name' => 'null', 'id' => 'null'];
|
||||
|
||||
/*$stmt = $mysqli->prepare("
|
||||
SELECT
|
||||
t.id,
|
||||
t.programm,
|
||||
t.verein,
|
||||
GROUP_CONCAT(ta.id SEPARATOR ', ') AS abt_table_id
|
||||
FROM $tableTurnerinnen t
|
||||
LEFT JOIN $tableTurnerinnenAbt ta ON ta.turnerin_id = t.id
|
||||
GROUP BY t.id, t.programm, t.verein
|
||||
ORDER BY t.id DESC
|
||||
");
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
|
||||
$result = $stmt->get_result();
|
||||
$allTurnerinnen = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
$stmt->close();
|
||||
|
||||
print_r($allTurnerinnen);*/
|
||||
|
||||
|
||||
$allTurnerinnen = db_select($mysqli, $tableTurnerinnen, "id, programm, verein, name" , "", [], "programm ASC");
|
||||
|
||||
$grouped = [];
|
||||
|
||||
foreach ($allTurnerinnen as $t) {
|
||||
$sanitasedprogramm = str_replace(['-kader'], '', strtolower($t['programm']));
|
||||
$grouped[$sanitasedprogramm][$t['verein']][] = $t;
|
||||
}
|
||||
|
||||
function getMinKey(array $array): string|int {
|
||||
return array_search(min($array), $array, true);
|
||||
}
|
||||
|
||||
function arrayRiegeneiteilung($allturnerinnen, $maxTurnerinnenGruppe, $allGeraete) {
|
||||
$indabt = 1;
|
||||
$arrayAutoRiegeneinteilung = [];
|
||||
foreach ($allturnerinnen as $prog => $vereine) {
|
||||
// ABTEILUNG BERECHNEN
|
||||
$countturterinnenprog = 0;
|
||||
foreach ($vereine as $verein => $turnerinnen) {
|
||||
foreach ($turnerinnen as $ind => $turnerin) {
|
||||
$countturterinnenprog++;
|
||||
$abt = intdiv($countturterinnenprog, $maxTurnerinnenGruppe * count($allGeraete)) + $indabt;
|
||||
$allturnerinnen[$prog][$verein][$ind]['abt'] = $abt;
|
||||
$arrayAbt[$abt][$verein][] = $turnerin;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$indabt += intdiv($countturterinnenprog - 1, $maxTurnerinnenGruppe * count($allGeraete)) + 1;
|
||||
}
|
||||
|
||||
foreach ($arrayAbt as $abt => $vereine) {
|
||||
|
||||
// AUSGLEICHEN DER GRUPPEN
|
||||
$arrayAbt = [];
|
||||
$arrayGruppen = [];
|
||||
foreach ($allGeraete as $geraet) {
|
||||
$arrayGruppen[$geraet['id']] = 0;
|
||||
}
|
||||
|
||||
$turnerinnenCount = 0;
|
||||
|
||||
foreach ($vereine as $verein => $turnerinnen) {
|
||||
$turnerinnenCount += count($turnerinnen);
|
||||
}
|
||||
|
||||
foreach ($vereine as $verein => $turnerinnen) {
|
||||
|
||||
if (count($turnerinnen) > $maxTurnerinnenGruppe || count($turnerinnen) > $turnerinnenCount / count($allGeraete)) {
|
||||
|
||||
if (count($turnerinnen) > $turnerinnenCount / count($allGeraete)) {
|
||||
$maxTurnerinnenGruppeTemp = ceil($turnerinnenCount / count($allGeraete));
|
||||
} else {
|
||||
$maxTurnerinnenGruppeTemp = $maxTurnerinnenGruppe;
|
||||
}
|
||||
// AUFTEILEN IN MEHRERE GRUPPEN
|
||||
$chunks = array_chunk($turnerinnen, $maxTurnerinnenGruppeTemp);
|
||||
foreach ($chunks as $chunk) {
|
||||
|
||||
$minKey = getMinKey($arrayGruppen);
|
||||
|
||||
$arrayGruppen[$minKey] += count($chunk);
|
||||
|
||||
foreach ($chunk as $ind =>$turnerin) {
|
||||
$arrayAutoRiegeneinteilung[$abt][$minKey][] = $turnerin;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
$minKey = getMinKey($arrayGruppen);
|
||||
|
||||
$arrayGruppen[$minKey] += count($turnerinnen);
|
||||
|
||||
foreach ($turnerinnen as $ind =>$turnerin) {
|
||||
$arrayAutoRiegeneinteilung[$abt][$minKey][] = $turnerin;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
foreach ($arrayAutoRiegeneinteilung as $indAbt => $abt) {
|
||||
foreach ($abt as $indGeraet => $geraet) {
|
||||
foreach ($geraet as $indTurnerin => $turnerin) {
|
||||
$arrayAutoRiegeneinteilung[$indAbt][$indGeraet][$indTurnerin]['turnerin_index'] = $indTurnerin + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return $arrayAutoRiegeneinteilung;
|
||||
}
|
||||
|
||||
$arrayAutoRiegeneinteilung = arrayRiegeneiteilung($grouped, $maxTurnerinnenGruppe, $allGeraete);
|
||||
|
||||
|
||||
|
||||
$stmt = $mysqli->prepare("DELETE FROM $tableTurnerinnenAbt");
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
$stmt = $mysqli->prepare("DELETE FROM $tableAbt");
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
|
||||
foreach ($arrayAutoRiegeneinteilung as $indAbt => $abt) {
|
||||
|
||||
$stmt = $mysqli->prepare("INSERT INTO $tableAbt (name) VALUES (?)");
|
||||
$stmt->bind_param("s", $indAbt);
|
||||
$stmt->execute();
|
||||
$idAbt = $stmt->insert_id;
|
||||
$stmt->close();
|
||||
|
||||
foreach ($abt as $indGeraet => $geraet) {
|
||||
foreach ($geraet as $indTurnerin => $turnerin) {
|
||||
$stmt = $mysqli->prepare("INSERT INTO $tableTurnerinnenAbt (turnerin_id, abteilung_id, geraet_id, turnerin_index) VALUES (?, ?, ?, ?)");
|
||||
$stmt->bind_param("ssss", $turnerin['id'], $idAbt, $indGeraet, $turnerin['turnerin_index']);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return http_response_code(201);
|
||||
|
||||
|
||||
|
||||
|
||||
/*foreach ($grouped as $ind => $g) {
|
||||
echo $ind;
|
||||
foreach ($g as $verein) {
|
||||
foreach ($verein as $turnerin) {
|
||||
echo '<div class="riegeneinteilung_turnerin_row" data-turnerin_id="' . $turnerin['id'] . '">';
|
||||
echo '<div class="riegeneinteilung_turnerin_info">';
|
||||
echo '<span class="riegeneinteilung_turnerin_name">' . htmlspecialchars($turnerin['name']) . '</span>';
|
||||
echo '<span class="riegeneinteilung_turnerin_verein">(' . htmlspecialchars($turnerin['verein']) . ')</span>';
|
||||
echo '<span class="riegeneinteilung_turnerin_verein">(' . htmlspecialchars($turnerin['abt']) . ')</span>';
|
||||
echo '<span class="riegeneinteilung_turnerin_verein">(' . htmlspecialchars($turnerin['geraet_id']) . ')</span>';
|
||||
echo '</div>';
|
||||
|
||||
echo '</div></div>';
|
||||
}
|
||||
}
|
||||
echo '<br><br>';
|
||||
}
|
||||
|
||||
foreach ($arrayAutoRiegeneinteilung as $ind => $abt) {
|
||||
|
||||
echo '<br>ABT:' . $ind;
|
||||
foreach ($abt as $g) {
|
||||
echo '<br>GERÄT';
|
||||
foreach ($g as $turnerin) {
|
||||
echo '<div class="riegeneinteilung_turnerin_row" data-turnerin_id="' . $turnerin['id'] . '">';
|
||||
echo '<div class="riegeneinteilung_turnerin_info">';
|
||||
echo '<span class="riegeneinteilung_turnerin_name">' . htmlspecialchars($turnerin['name']) . '</span>';
|
||||
echo '<span class="riegeneinteilung_turnerin_verein">(' . htmlspecialchars($turnerin['verein']) . ')</span>';
|
||||
echo '<span class="riegeneinteilung_turnerin_verein">(' . htmlspecialchars($turnerin['turnerin_index']) . ')</span>';
|
||||
echo '<span class="riegeneinteilung_turnerin_verein">(' . htmlspecialchars($turnerin['programm']) . ')</span>';
|
||||
echo '</div>';
|
||||
|
||||
echo '</div></div>';
|
||||
}
|
||||
}
|
||||
echo '<br><br>';
|
||||
}
|
||||
|
||||
print_r($arrayAutoRiegeneinteilung);*/
|
||||
@@ -0,0 +1,66 @@
|
||||
<?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);
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
|
||||
|
||||
if (empty($_SESSION['access_granted_wk_leitung']) || $_SESSION['access_granted_wk_leitung'] !== true || empty($_SESSION['passcodewk_leitung_id']) || intval($_SESSION['passcodewk_leitung_id']) < 0 ) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate input
|
||||
if (!isset($_POST['anz_abt']) || !ctype_digit($_POST['anz_abt'])) {
|
||||
http_response_code(406);
|
||||
exit;
|
||||
}
|
||||
|
||||
$anz_abt = (int) $_POST['anz_abt'];
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
$type = 'wkl';
|
||||
|
||||
$dbconnection = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($dbconnection['success'] !== true){
|
||||
echo 'Critical DB Error.';
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
// Fetch existing Abteilungen
|
||||
$abts = db_select($mysqli, $tableAbt, '*');
|
||||
|
||||
// Delete excess Abteilungen
|
||||
foreach ($abts as $dbabt) {
|
||||
if ((int)$dbabt['name'] > $anz_abt) {
|
||||
db_delete($mysqli, $tableAbt, ['name' => $dbabt['name']]);
|
||||
}
|
||||
}
|
||||
|
||||
// Build lookup of existing names
|
||||
$existing = array_map('intval', array_column($abts, 'name'));
|
||||
|
||||
// Insert missing Abteilungen
|
||||
$stmt = $mysqli->prepare("INSERT INTO $tableAbt (name) VALUES (?)");
|
||||
|
||||
for ($i = 1; $i <= $anz_abt; $i++) {
|
||||
if (!in_array($i, $existing, true)) {
|
||||
$stmt->bind_param('i', $i);
|
||||
$stmt->execute();
|
||||
}
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
|
||||
http_response_code(201);
|
||||
@@ -0,0 +1,74 @@
|
||||
<?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);
|
||||
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
|
||||
|
||||
if (empty($_SESSION['access_granted_wk_leitung']) || $_SESSION['access_granted_wk_leitung'] !== true || empty($_SESSION['passcodewk_leitung_id']) || intval($_SESSION['passcodewk_leitung_id']) < 0 ) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validate input
|
||||
if (!isset($_POST['abt']) || !ctype_digit($_POST['abt'])) {
|
||||
http_response_code(406);
|
||||
exit;
|
||||
}
|
||||
|
||||
$abtInput = (int) $_POST['abt'];
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
$type = 'wkl';
|
||||
|
||||
$dbconnection = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($dbconnection['success'] !== true){
|
||||
echo 'Critical DB Error.';
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-functions.php';
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
// Fetch existing Abteilungen ordered by name
|
||||
$abts = db_select($mysqli, $tableAbt, '*', '', [], 'name ASC');
|
||||
|
||||
$deleteId = null;
|
||||
$deleteIndex = null;
|
||||
|
||||
foreach ($abts as $ind => $abt) {
|
||||
if ((int)$abt['name'] === (int)$abtInput) {
|
||||
$deleteId = (int)$abt['id'];
|
||||
$deleteIndex = $ind;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($deleteId === null) {
|
||||
http_response_code(406);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Delete selected row
|
||||
db_delete($mysqli, $tableAbt, ['id' => $deleteId]);
|
||||
|
||||
// Reindex subsequent rows
|
||||
for ($i = $deleteIndex + 1; $i < count($abts); $i++) {
|
||||
db_update(
|
||||
$mysqli,
|
||||
$tableAbt,
|
||||
['name' => (int)$abts[$i]['name'] - 1],
|
||||
['id' => (int)$abts[$i]['id']]
|
||||
);
|
||||
}
|
||||
|
||||
http_response_code(201);
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
|
||||
|
||||
if (empty($_SESSION['access_granted_wk_leitung']) || $_SESSION['access_granted_wk_leitung'] !== true || empty($_SESSION['passcodewk_leitung_id']) || intval($_SESSION['passcodewk_leitung_id']) < 0 ) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
$type = 'wkl';
|
||||
|
||||
|
||||
$dbconnection = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($dbconnection['success'] !== true){
|
||||
echo 'Critical DB Error.';
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (!$input || !isset($input['new'])) {
|
||||
http_response_code(400);
|
||||
exit;
|
||||
}
|
||||
|
||||
$mysqli->begin_transaction();
|
||||
|
||||
try {
|
||||
$stmt = $mysqli->prepare("
|
||||
UPDATE $tableTurnerinnenAbt
|
||||
SET turnerin_index = ?
|
||||
WHERE turnerin_id = ?
|
||||
");
|
||||
|
||||
foreach (['new', 'old'] as $bucket) {
|
||||
if (empty($input[$bucket])) continue;
|
||||
|
||||
foreach ($input[$bucket] as $row) {
|
||||
$stmt->bind_param("ii", $row['order_index'], $row['id']);
|
||||
$stmt->execute();
|
||||
}
|
||||
}
|
||||
|
||||
$mysqli->commit();
|
||||
http_response_code(200);
|
||||
|
||||
} catch (Throwable $e) {
|
||||
$mysqli->rollback();
|
||||
http_response_code(500);
|
||||
}
|
||||
74
www/intern/scripts/riegeneinteilung/ajax_update_turnerin.php
Normal file
74
www/intern/scripts/riegeneinteilung/ajax_update_turnerin.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
if (session_status() !== PHP_SESSION_ACTIVE) session_start();
|
||||
|
||||
if (empty($_SESSION['access_granted_wk_leitung']) || $_SESSION['access_granted_wk_leitung'] !== true || empty($_SESSION['passcodewk_leitung_id']) || intval($_SESSION['passcodewk_leitung_id']) < 0 ) {
|
||||
http_response_code(403);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!isset($baseDir)) {
|
||||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||||
}
|
||||
|
||||
$type = 'wkl';
|
||||
|
||||
$dbconnection = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||||
|
||||
if ($dbconnection['success'] !== true){
|
||||
echo 'Critical DB Error.';
|
||||
exit;
|
||||
}
|
||||
|
||||
require $baseDir . '/../scripts/db/db-tables.php';
|
||||
|
||||
$turnerinId = (int)$_POST['turnerin_id'];
|
||||
$abteilung = $_POST['abteilung'];
|
||||
$geraet = $_POST['geraet'];
|
||||
|
||||
// Default to NULL if frontend sends "null"
|
||||
$abtId = null;
|
||||
$geraetId = null;
|
||||
|
||||
// Resolve Abteilung ID
|
||||
if ($abteilung !== 'null') {
|
||||
$stmt = $mysqli->prepare("SELECT id FROM $tableAbt WHERE name = ?");
|
||||
$stmt->bind_param("s", $abteilung);
|
||||
$stmt->execute();
|
||||
if ($row = $stmt->get_result()->fetch_assoc()) {
|
||||
$abtId = (int)$row['id'];
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
// Resolve Gerät ID
|
||||
if ($geraet !== 'null') {
|
||||
$stmt = $mysqli->prepare("SELECT id FROM $tableGeraete WHERE name = ?");
|
||||
$stmt->bind_param("s", $geraet);
|
||||
$stmt->execute();
|
||||
if ($row = $stmt->get_result()->fetch_assoc()) {
|
||||
$geraetId = (int)$row['id'];
|
||||
}
|
||||
$stmt->close();
|
||||
}
|
||||
|
||||
// Upsert into turnerinnen_abt (turnerin_id is UNIQUE)
|
||||
$stmt = $mysqli->prepare("
|
||||
INSERT INTO $tableTurnerinnenAbt (turnerin_id, abteilung_id, geraet_id)
|
||||
VALUES (?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE
|
||||
abteilung_id = VALUES(abteilung_id),
|
||||
geraet_id = VALUES(geraet_id)
|
||||
");
|
||||
$stmt->bind_param("iii", $turnerinId, $abtId, $geraetId);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
// Return JSON
|
||||
http_response_code(200);
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'turnerin_id' => $turnerinId,
|
||||
'abteilung_id' => $abtId,
|
||||
'geraet_id' => $geraetId
|
||||
]);
|
||||
Reference in New Issue
Block a user