Die Endnote wird wie folgt automatisch berrechnet: Endnote = $d['name'] ?> = 10 - EØ Note + D Note - Neutrale Abzüge
@@ -687,13 +694,27 @@ $baseDir = $_SERVER['DOCUMENT_ROOT'];
data-person-id=""
data-geraet-id="= $d['id'] ?>"
value="Turnerin anzeigen">
-
@@ -761,6 +782,14 @@ $baseDir = $_SERVER['DOCUMENT_ROOT'];
}
$stmt->close();
+
+ // Extended Disciplines, contains the 0 disc
+
+ $disciplinesExtended = array_merge(
+ [["id" => 0, "name" => "None"]],
+ $disciplines
+ );
+
foreach ($grouped as $abteilung => $entries_group) :
// ... (PDF path and H3 tag)
@@ -822,6 +851,56 @@ $baseDir = $_SERVER['DOCUMENT_ROOT'];
$entries_to_display = $entries_group;
}
+ // Table Header creator with run columns
+
+ $arrayIndexedNoten = [];
+ $arrayIndexedNotenHeader = [];
+ $uidN = 0;
+
+ foreach ($entries_group as $row) :
+ foreach ($disciplinesExtended as $discipline) :
+
+ // Check if the current user/admin is allowed to see this specific discipline
+ if ($discipline['id'] === 0 || $selecteduser === strtolower($discipline['name']) || $selecteduser === 'admin') :
+
+ // 2. Now iterate through the scoring configurations for this discipline
+ foreach ($notenConfig as $snC) {
+ $showAdmin = isAdmin() && intval($snC['zeige_in_tabelle_admin']) === 1;
+ $showPublic = !isAdmin() && intval($snC['zeige_in_tabelle']) === 1;
+
+ if (!($showAdmin || $showPublic)) { continue; }
+
+ if (intval($snC['pro_geraet']) === 1 && intval($discipline['id']) === 0) { continue; }
+
+ if (intval($snC['pro_geraet']) !== 1) {
+ $allowedGeraete = !empty($snC['geraete_json']) ? json_decode($snC['geraete_json'], true) : [];
+ if (!in_array($discipline['id'], $allowedGeraete)) { continue; }
+ }
+
+ $mobile = (intval($snC['zeige_in_tabelle_mobile']) === 1) ? "" : "notMobile";
+
+ // Logic to fetch and format the value
+ $defaultValue = $snC['default_value'] ?? 0;
+
+ $runsJSON = !empty($snC['anzahl_laeufe_json']) ? json_decode($snC['anzahl_laeufe_json'], true) : [];
+
+ $runs = $runsJSON[$discipline['id']][$indexedProgrammes[$row['programm'] ?? ''] ?? ''] ?? $runsJSON["default"] ?? 1;
+
+ for ($r = 1; $r <= $runs; $r++) :
+ $note = $notenIndexed[$row['id']][$discipline['id']][$snC['id']][$r] ?? $defaultValue;
+ $normalizedNote = number_format($note, $snC['nullstellen'] ?? 2);
+
+ $arrayIndexedNoten[intval($row['id'])][intval($discipline['id'])][intval($snC['id'])][intval($r)] = ["value" => $normalizedNote, "mobile" => $mobile];
+ $arrayIndexedNotenHeader[intval($discipline['id'])][intval($snC['id'])][intval($r)] = ["mobile" => $mobile];
+
+ $uidN++;
+ endfor;
+ }
+ endif;
+ endforeach;
+ endforeach;
+
+
$localPath = $_SERVER['DOCUMENT_ROOT'] . "/wp-content/ergebnisse/KTBB_Ergebnisse_" . $abteilung . "_" . $current_year . ".pdf";
echo '
';
if ($selecteduser === 'admin') echo '
'. strtoupper($abteilung);
@@ -835,12 +914,9 @@ $baseDir = $_SERVER['DOCUMENT_ROOT'];
echo '| '.$textheadingrang.' | ';
}
- if ($focus_view_admin == true){
+ if (!isAdmin() || $focus_view_admin == true){
echo 'RF | ';
- }
- if ($selecteduser !== 'admin'){
- echo ' | ';
- } ?>
+ }?>
Name |
Jg.'; } ?>
Verein |
@@ -848,7 +924,23 @@ $baseDir = $_SERVER['DOCUMENT_ROOT'];
Musik Boden |
$aNtypes) :
+ foreach ($aNtypes as $nType => $aRuns) :
+ $displayRunType = count($aRuns) > 1;
+ foreach ($aRuns as $run => $cArray) :
+ $displayRunString = $displayRunType ? '' . $run . '' : '';
+ $displayDisciplinesString = isset($indexedDisciplines[$dis]) ? ' ' . $indexedDisciplines[$dis] : '';
+ ?>
+ ">
+ = $indexedNotenNames[$nType] ?>= $displayRunString ?>= $displayDisciplinesString ?>
+ |
+
+
+
+ = $snC['name'] . ' ' . ucfirst($lowdiscipline) ?>
+ |
+
+
+
+
+ = $snC['name'] . ' ' . ucfirst($lowdiscipline) ?>
+ |
+
+
-
- = $snC['name'] . ' ' . ucfirst($lowdiscipline) ?>
- |
-
+
+
+ = $snC['name'] ?>
+ |
+
+
+
+
+ = $snC['name'] ?>
+ |
+
+
-
- = $snC['name'] ?>
- |
Edit |
@@ -938,7 +1072,29 @@ $baseDir = $_SERVER['DOCUMENT_ROOT'];
$notMobileNotAdmin = ($selecteduser !== 'admin') ? 'notMobile' : '';
- foreach ($disciplines as $discipline) {
+
+ foreach ($arrayIndexedNotenHeader as $dis => $aNtypes) :
+ foreach ($aNtypes as $nType => $aRuns) :
+ foreach ($aRuns as $run => $cArray) :
+ if (isset($arrayIndexedNoten[intval($row['id'])][intval($dis)][intval($nType)][intval($run)])) : ?>
+ changebleValue"
+ data-field-type-id="= $nType ?>"
+ data-geraet-id="= $dis ?>"
+ data-person-id="= $row["id"] ?>"
+ data-run="= $run ?>">
+ = $arrayIndexedNoten[intval($row['id'])][intval($dis)][intval($nType)][intval($run)]["value"] ?>
+ |
+
+ ">
+ ---
+ |
+
+
-
- = $normalizedNote ?>
- |
+ $runsJSON = !empty($snC['anzahl_laeufe_json']) ? json_decode($snC['anzahl_laeufe_json'], true) : [];
-
+
+
+ = $normalizedNote ?>
+ |
+
+
-
- = $normalizedNote ?>
- |
-
+
+
+ = $normalizedNote ?>
+ |
+
+ Gesamt: '.$total_count.' '.$mehrzahl.'';
}
- if ($selecteduser === 'admin' && $focus_view_admin == false) : ?>
-
-
-
-
-
+ ?>
Keine Kampfrichterinnen ausgewählt
@@ -1095,7 +1252,6 @@ $baseDir = $_SERVER['DOCUMENT_ROOT'];
Live Synchronsation:
-
window.FREIGABE = "";
- window.CSDR_TOKEN = "";
+ window.CSDR_TOKEN = "= $csrf_token; ?>";
window.WS_ACCESS_TOKEN = "= generateWSToken('kampfrichter') ?>";
window.AKTUELLES_JAHR = "= $current_year ?>";
diff --git a/www/intern/otlogin.php b/www/intern/otlogin.php
index 80c8ffc..89404fe 100644
--- a/www/intern/otlogin.php
+++ b/www/intern/otlogin.php
@@ -6,190 +6,317 @@ error_reporting(E_ALL);
use Dotenv\Dotenv;
-if (session_status() !== PHP_SESSION_ACTIVE) session_start();
+if (!isset($baseDir)) {
+ $baseDir = $_SERVER['DOCUMENT_ROOT'];
+}
+require_once $baseDir . '/../scripts/session_functions.php';
+
+ini_wkvs_session(true);
$oturl = $_GET['otl'] ?? '';
if (!$oturl) {
- http_response_code(403);
+ http_response_code(404);
exit;
}
-if (!isset($baseDir)) {
- $baseDir = $_SERVER['DOCUMENT_ROOT'];
-}
-
require $baseDir . '/../scripts/db/db-functions.php';
require $baseDir . '/../scripts/db/db-tables.php';
$error = '';
-function logIn() {
+class otl {
- global $baseDir;
+ private function connectToDB() {
- $iduser = intval($_POST['user_id']);
+ global $mysqli, $baseDir;
+ if (isset($mysqli)) { return $mysqli; }
- // security: user must have passed one-time-login first
- if (empty($_SESSION['set_new_password_id_user']) || empty($_SESSION['set_new_password_granted']) || $_SESSION['set_new_password_id_user'] !== $iduser || $_SESSION['set_new_password_granted'] !== true) {
- http_response_code(403);
- exit;
+ $_SESSION['access_granted_db_otl'] = true;
+
+ $type = 'otl';
+
+ // DB
+ $dbconnection = require $baseDir .'/../scripts/db/db-verbindung-script.php';
+ if ($dbconnection['success'] !== true){
+ return "DB Error";
+ }
+
+ $_SESSION['access_granted_db_otl'] = false;
+
+ return $mysqli;
}
- $type = 'otl';
-
- // DB
- $dbconnection = require $baseDir .'/../scripts/db/db-verbindung-script.php';
- if ($dbconnection['success'] !== true){
- return "DB Error";
- }
-
- require $baseDir . '/../scripts/db/db-tables.php';
-
- require $baseDir . '/../composer/vendor/autoload.php';
-
- $envFile = realpath($baseDir . '/../config/.env.pw-encryption-key');
-
- if ($envFile === false) {
- http_response_code(500);
- echo json_encode([
- 'success' => false,
- 'message' => "Environment file not found"
- ]);
- exit;
- }
-
- try {
- $envDir = dirname($envFile);
+ private function pwProcessing() {
- $dotenv = Dotenv::createImmutable($envDir, '.env.pw-encryption-key');
-
- $dotenv->load();
- } catch (Throwable $e) {
- http_response_code(500);
- echo json_encode([
- 'success' => false,
- 'message' => "Dotenv error"
- ]);
+ global $baseDir;
+
+ require $baseDir . '/../composer/vendor/autoload.php';
+
+ $envFile = realpath($baseDir . '/../config/.env.pw-encryption-key');
+
+ if ($envFile === false) {
+ http_response_code(500);
+ echo json_encode([
+ 'success' => false,
+ 'message' => "Environment file not found"
+ ]);
+ exit;
+ }
+
+ try {
+ $envDir = dirname($envFile);
+
+ $dotenv = Dotenv::createImmutable($envDir, '.env.pw-encryption-key');
+
+ $dotenv->load();
+ } catch (Throwable $e) {
+ http_response_code(500);
+ echo json_encode([
+ 'success' => false,
+ 'message' => "Dotenv error"
+ ]);
+ }
+
+
+ $password = trim($_POST['password1']);
+ $passwordRep = trim($_POST['password2']);
+ if ($password === '' || $passwordRep === '') {
+ return 'Beide Felder müssen ausgefüllt sein';
+ }
+
+ if ($password !== $passwordRep) {
+ return 'Beide Passwörter müssen identisch sein';
+ }
+
+ $hash = password_hash($password, PASSWORD_ARGON2ID);
+
+ $iv_length = openssl_cipher_iv_length('aes-256-cbc');
+ $iv = random_bytes($iv_length);
+
+ $encrypted = openssl_encrypt(
+ 'SET_BY_OTL',
+ 'aes-256-cbc',
+ $_ENV['PW_ENCRYPTION_KEY'],
+ 0,
+ $iv
+ );
+
+ $cipher_store = base64_encode($iv . $encrypted);
+
+ return ['success' => true, 'hash' => $hash, 'encpw' => $cipher_store];
}
+ public function logIn(int $id) {
- $password = trim($_POST['password1']);
- $password2 = trim($_POST['password2']);
- if ($password === '' || $password2 === '') {
- return 'Beide Felder müssen ausgefüllt sein';
+ global $baseDir;
+
+ $mysqli = $this->connectToDB();
+
+ require $baseDir . '/../scripts/db/db-tables.php';
+
+ // delete the one-time token
+ if (!isset($_SESSION['otl_dbid'])) {
+ return 'Interner Fehler';
+ }
+
+ $dbid = intval($_SESSION['otl_dbid']);
+
+ $stmt = $mysqli->prepare("DELETE FROM $tableOTL WHERE id = ?");
+ $stmt->bind_param("i", $dbid);
+
+ if (!$stmt->execute()) {
+ return "DB Error";
+ }
+
+ $stmt->close();
+
+ $sql = "SELECT freigabe FROM $tableInternUsers WHERE id = ?";
+
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_param("i", $id);
+ $stmt->execute();
+
+ $result = $stmt->get_result();
+ $row = $result->fetch_assoc();
+
+ $freigabe = $row['freigabe'];
+ $stmt->close();
+
+ $mysqli->close();
+
+ unset($_SESSION['set_new_password_id_user'], $_SESSION['set_new_password_granted'], $_SESSION['otl_dbid']);
+
+ $freigabenArray = json_decode($freigabe, true) ?? [];
+ $freigabenTypeArray = $freigabenArray['types'] ?? [];
+
+ if (count($freigabenTypeArray) > 0) {
+ $_SESSION = array();
+ session_destroy();
+ session_start();
+ }
+
+ foreach ($freigabenTypeArray as $freigabeType){
+ $_SESSION['access_granted_'.$freigabeType] = true;
+ $_SESSION['user_id_'.$freigabeType] = $id;
+ }
+
+ var_dump($_SESSION);
+
+ if (in_array('wk_leitung', $freigabenTypeArray)) {
+ header("Location: /intern/wk-leitung/logindata");
+ exit;
+ } elseif (in_array('trainer', $freigabenTypeArray)) {
+ header("Location: /intern/trainer");
+ exit;
+ } elseif (in_array('kampfrichter', $freigabenTypeArray)) {
+ header("Location: /intern/kampfrichter");
+ exit;
+ } else {
+ return 'Dieser Benutzer hat keine Berechtigungen.';
+ }
}
- if ($password !== $password2) {
- return 'Beide Passwörter müssen identisch sein';
- }
+ public function resetPW() {
- $hash = password_hash($password, PASSWORD_ARGON2ID);
+ global $baseDir;
- $iv_length = openssl_cipher_iv_length('aes-256-cbc');
- $iv = random_bytes($iv_length);
+ $iduser = intval($_POST['user_id']);
- $encrypted = openssl_encrypt(
- 'SET_BY_OTL',
- 'aes-256-cbc',
- $_ENV['PW_ENCRYPTION_KEY'],
- 0,
- $iv
- );
- $cipher_store = base64_encode($iv . $encrypted);
+ // security: user must have passed one-time-login first
+ if (empty($_SESSION['set_new_password_id_user']) || empty($_SESSION['set_new_password_granted']) || $_SESSION['set_new_password_id_user'] !== $iduser || $_SESSION['set_new_password_granted'] !== true) {
+ http_response_code(403);
+ exit;
+ }
- // update password
- $updateResult = db_update($mysqli, $tableInternUsers, ['password_hash' => $hash, 'password_cipher' => $cipher_store, 'edited_by' => 'otlogin'], ['id' => $iduser]);
- if ($updateResult === false) {
- return 'Passwork konnte nicht neu gesetzt werden';
+ require $baseDir . '/../scripts/db/db-tables.php';
+
+ $mysqli = $this->connectToDB();
+
+ $pwArray = $this->pwProcessing();
+
+ if (!isset($pwArray['success']) || !$pwArray['success']) {
+ return 'Passwort konnte nicht verarbeitet werden';
+ }
+
+ // update password
+ $updateResult = db_update($mysqli, $tableInternUsers, ['password_hash' => $pwArray['hash'] ?? '', 'password_cipher' => $pwArray['encpw'] ?? '', 'edited_by' => 'otlogin'], ['id' => $iduser]);
+ if ($updateResult === false) {
+ return 'Passwork konnte nicht neu gesetzt werden';
+ }
+
+ // delete the one-time token
+ if (!isset($_SESSION['otl_dbid'])) {
+ return 'Interner Fehler';
+ }
+
+ $dbid = intval($_SESSION['otl_dbid']);
+
+ $stmt = $mysqli->prepare("DELETE FROM $tableOTL WHERE id = ?");
+ $stmt->bind_param("i", $dbid);
+
+ if (!$stmt->execute()) {
+ return "DB Error";
+ }
+
+ $stmt->close();
+
+ $this->logIn($iduser);
}
- // delete the one-time token
- if (!isset($_SESSION['otl_dbid'])) {
- return 'Interner Fehler';
- }
+ public function createUser() {
- $dbid = intval($_SESSION['otl_dbid']);
+ global $baseDir;
- $stmt = $mysqli->prepare("DELETE FROM $tableOTL WHERE id = ?");
- $stmt->bind_param("i", $dbid);
+ $iduser = intval($_POST['user_id']);
- if (!$stmt->execute()) {
- return "DB Error";
- }
+ if (empty($_SESSION['set_new_user_id_user']) || empty($_SESSION['set_new_user_granted']) || $_SESSION['set_new_user_id_user'] !== $iduser || $_SESSION['set_new_user_granted'] !== true) {
+ http_response_code(403);
+ exit;
+ }
- $stmt->close();
+ require $baseDir . '/../scripts/db/db-tables.php';
- $sql = "SELECT freigabe FROM $tableInternUsers WHERE id = ?";
+ $mysqli = $this->connectToDB();
- $stmt = $mysqli->prepare($sql);
- $stmt->bind_param("i", $iduser);
- $stmt->execute();
+ $arrayDB = [];
- $result = $stmt->get_result();
- $row = $result->fetch_assoc();
+ if (isset($_POST['password1'], $_POST['password2'])) {
+ $pwArray = $this->pwProcessing();
- $freigabe = $row['freigabe'];
- $stmt->close();
+ if (!isset($pwArray['success']) || !$pwArray['success']) {
+ return 'Passwort konnte nicht verarbeitet werden';
+ }
- $mysqli->close();
+ $arrayDB[] = ["name" => 'password_hash', "value" => $pwArray['hash']];
+ $arrayDB[] = ["name" => 'password_cipher', "value" => $pwArray['encpw']];
+ }
- unset($_SESSION['set_new_password_id_user'], $_SESSION['set_new_password_granted'], $_SESSION['otl_dbid']);
+ if (isset($_POST['username'])) {
+ $arrayDB[] = ["name" => 'username', "value" => htmlspecialchars(trim($_POST['username']))];
+ }
- $freigabenArray = json_decode($freigabe, true) ?? [];
- $freigabenTypeArray = $freigabenArray['types'] ?? [];
+ if (isset($_POST['name_person'])) {
+ $arrayDB[] = ["name" => 'name_person', "value" => htmlspecialchars(trim($_POST['name_person']))];
+ }
- if (count($freigabenTypeArray) > 0) {
- $_SESSION = array();
- session_destroy();
- session_start();
- }
+ // --- NEW LOGIC TO UTILIZE $arrayDB ---
- foreach ($freigabenTypeArray as $freigabeType){
- $_SESSION['access_granted_'.$freigabeType] = true;
- $_SESSION['passcode'.$freigabeType.'_id'] = $iduser;
- }
+ $updateData = [
+ 'edited_by' => 'otlogin',
+ 'login_active' => 1
+ ];
- if (in_array('wk_leitung', $freigabenTypeArray)) {
- header("Location: /intern/wk-leitung/logindata");
- exit;
- } elseif (in_array('trainer', $freigabenTypeArray)) {
- header("Location: /intern/trainer");
- exit;
- } elseif (in_array('kampfrichter', $freigabenTypeArray)) {
- header("Location: /intern/kampfrichter");
- exit;
- } else {
- return 'Dieser Benutzer hat keine Berechtigungen.';
+ // Convert the $arrayDB list into a flat associative array
+ if (!empty($arrayDB)) {
+ foreach ($arrayDB as $entry) {
+ $updateData[$entry['name']] = $entry['value'];
+ }
+ }
+
+ // Execute update using the dynamically built array
+ $updateResult = db_update(
+ $mysqli,
+ $tableInternUsers,
+ $updateData,
+ ['id' => $iduser]
+ );
+
+ if ($updateResult === false) {
+ return 'Nutzer konnte nicht aktualisiert werden';
+ }
+
+ $this->logIn($iduser);
}
}
+$pwClass = New otl();
+
/* ============================================================
PASSWORD SET ON POST
============================================================ */
-if (isset($_POST['password1'], $_POST['password2'], $_POST['setpasswordbtn'], $_POST['user_id'])) { $error = logIn() ?? ''; }
+
/* ============================================================
ONE-TIME-LOGIN VALIDATION (GET)
============================================================ */
-$token = "QQa2UMbEYW8oOL7wz9DjtqECVCikSZsDuSdmzxiadEXFsKyujEUyQOW1AYMD2OqU8VXxClIRweRuWLzvBrZpPYL41e89Rs96tM7Lq1KpjA5E2mg2UfgvztheGRV";
-
require $baseDir .'/../scripts/db/db-verbindung-script-guest.php';
// fetch one-time login record
$result = db_select(
$guest,
$tableOTL,
- 'id, user_id',
+ 'id, user_id, `type`',
'url = ? AND timestamp >= NOW() - INTERVAL 24 HOUR',
[$oturl]
);
if (!$result || count($result) !== 1) {
+ echo 'forbidden';
http_response_code(403);
exit;
}
@@ -197,26 +324,56 @@ if (!$result || count($result) !== 1) {
$dbid = intval($result[0]['id']);
$iduser = intval($result[0]['user_id']);
+if (isset($_POST['password1'], $_POST['password2'], $_POST['setpasswordbtn'], $_POST['user_id']) && $result[0]['type'] === 'pwreset') { $error = $pwClass->resetPW() ?? ''; }
+elseif (isset($_POST['setpasswordbtn'], $_POST['user_id']) && $result[0]['type'] === 'create_profile') { $error = $pwClass->createUser() ?? ''; }
+
// store dbid for later deletion
$_SESSION['otl_dbid'] = $dbid;
-$tableusers = 'wp_secure_lock';
-
-// fetch user
-$userinfo = db_select($guest, $tableInternUsers, 'username', 'id = ?', [$iduser]);
-$guest->close();
-
-if (!$userinfo || count($userinfo) !== 1) {
- echo 'Ungültige Benutzerinformationen';
- exit;
+if ($result[0]['type'] === 'login') {
+ $pwClass->logIn($iduser);
}
-$username = $userinfo[0]['username'];
+if ($result[0]['type'] === 'pwreset') {
+ $userinfo = db_select($guest, $tableInternUsers, 'username', 'id = ?', [$iduser]);
+ $username = $userinfo[0]['username'];
+
+ if (!$userinfo || count($userinfo) !== 1) {
+ echo 'Ungültige Benutzerinformationen';
+ exit;
+ }
+
+ // set session token that grants password reset
+ $_SESSION['set_new_password_id_user'] = $iduser;
+ $_SESSION['set_new_password_granted'] = true;
+
+ $hasUsername = true;
+ $hasName = true;
-// set session token that grants password reset
-$_SESSION['set_new_password_id_user'] = $iduser;
-$_SESSION['set_new_password_granted'] = true;
+} elseif ($result[0]['type'] === 'create_profile') {
+ $userinfo = db_select($guest, $tableInternUsers, 'username, `password_hash`, `name_person`', 'id = ?', [$iduser]);
+
+ if (!$userinfo || count($userinfo) !== 1) {
+ echo 'Ungültige Benutzerinformationen';
+ exit;
+ }
+
+ $hasPW = $userinfo[0]['password_hash'] !== null;
+ $hasUsername = $userinfo[0]['username'] !== '';
+ $username = $userinfo[0]['username'];
+ $hasName = $userinfo[0]['name_person'] !== '';
+
+ unset($userinfo);
+
+ // set session token that grants password reset
+ $_SESSION['set_new_user_id_user'] = $iduser;
+ $_SESSION['set_new_user_granted'] = true;
+
+}
+// fetch user
+
+$guest->close();
?>
@@ -230,6 +387,7 @@ $_SESSION['set_new_password_granted'] = true;
+
@@ -244,6 +402,18 @@ $_SESSION['set_new_password_granted'] = true;