1441 lines
65 KiB
PHP
1441 lines
65 KiB
PHP
<?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 (!isset($baseDir)) {
|
||
$baseDir = $_SERVER['DOCUMENT_ROOT'];
|
||
}
|
||
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html lang="de">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<link rel="icon" type="png" href="/intern/img/icon.png">
|
||
<title>Intern - Trainer</title>
|
||
|
||
<link rel="stylesheet" href="/intern/css/trainer.css">
|
||
<link rel="stylesheet" href="/intern/css/sidebar.css">
|
||
<script src="/intern/js/jquery/jquery-3.7.1.min.js"></script>
|
||
<link href="/files/fonts/fonts.css" rel="stylesheet">
|
||
<script src="/intern/js/custom-msg-display.js"></script>
|
||
|
||
<!-- Flatpickr for modern date picking -->
|
||
<link rel="stylesheet" href="/intern/css/flatpickr/flatpickr.min.css">
|
||
<script src="/intern/js/flatpickr/flatpickr.min.js"></script>
|
||
<script src="/intern/js/flatpickr/de.min.js"></script>
|
||
<script src="/intern/js/flatpickr/fr.min.js"></script>
|
||
<script src="/intern/js/flatpickr/it.min.js"></script>
|
||
</head>
|
||
<body>
|
||
<?php
|
||
|
||
require_once $baseDir . '/../scripts/session_functions.php';
|
||
|
||
ini_wkvs_session(true);
|
||
|
||
$csrf_token = $_SESSION['csrf_token'] ?? '';
|
||
|
||
$access_granted_trainer = check_user_permission('trainer', true) ?? false;
|
||
|
||
if ( ! $access_granted_trainer ) :
|
||
|
||
$logintype = 'trainer';
|
||
|
||
require $baseDir . '/../scripts/login/login.php';
|
||
|
||
$logintype = '';
|
||
|
||
else :
|
||
|
||
require $baseDir . '/../scripts/db/db-functions.php';
|
||
require $baseDir . '/../scripts/db/db-tables.php';
|
||
|
||
|
||
|
||
$type = 'tr';
|
||
|
||
$dbconnection = require $baseDir . '/../scripts/db/db-verbindung-script.php';
|
||
|
||
if ($dbconnection['success'] !== true){
|
||
echo 'Critical DB Error.';
|
||
exit;
|
||
}
|
||
|
||
$currentPage = 'trainer';
|
||
|
||
require $baseDir . '/intern/scripts/sidebar/sidebar.php';
|
||
|
||
function createPaystatusSvg(int $type, int $dataId) : string {
|
||
switch ($type) {
|
||
case 5:
|
||
case 2:
|
||
return '<div class="bezahlstatus paymentPayed" data-id=""><span class="paymentStatus"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10"/><path d="M8 12l3 3 5-6"/></svg><span>Bezahlt</span></span></div>';
|
||
|
||
case 4:
|
||
case 1:
|
||
return '<div class="bezahlstatus paymentProcess addTurnerinToWarenkorb" data-id="' . $dataId . '" title="Zum Warenkorb hinzufügen"><span class="paymentStatus"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l3 3"/></svg><span>In Bearbeitung</span></span></div>';
|
||
|
||
case 3:
|
||
case 0:
|
||
return '<div class="bezahlstatus paymentOpen addTurnerinToWarenkorb" data-id="' . $dataId . '" title="Zum Warenkorb hinzufügen"><span class="paymentStatus"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10"/><path d="M15 9l-6 6M9 9l6 6"/></svg><span>Nicht bezahlt</span></span></div>';
|
||
case 6:
|
||
return '<div class="bezahlstatus paymentAdmin">A</div>';
|
||
}
|
||
}
|
||
|
||
$svgbezahlt = '<div class="bezahlstatus paymentPayed" data-id=""><span class="paymentStatus"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10"/><path d="M8 12l3 3 5-6"/></svg><span>Bezahlt</span></span></div>';
|
||
$svgpending = '<div class="bezahlstatus paymentProcess addTurnerinToWarenkorb" data-id="" title="Zum Warenkorb hinzufügen"><span class="paymentStatus"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10"/><path d="M12 6v6l3 3"/></svg><span>In Bearbeitung</span></span></div>';
|
||
$svgnichtbezahlt = '<div class="bezahlstatus paymentOpen addTurnerinToWarenkorb" data-id="" title="Zum Warenkorb hinzufügen"><span class="paymentStatus"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><circle cx="12" cy="12" r="10"/><path d="M15 9l-6 6M9 9l6 6"/></svg><span>Nicht bezahlt</span></span></div>';
|
||
$svg_cart = '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 24 24"><path d="M7 18c-1.104 0-1.99.896-1.99 2S5.896 22 7 22s2-.896 2-2-.896-2-2-2zm10 0c-1.104 0-1.99.896-1.99 2s.886 2 1.99 2 2-.896 2-2-.896-2-2-2zM7.01 14l.94-2h7.72c.75 0 1.41-.41 1.74-1.03l3.58-6.49A1 1 0 0019 3H5.21l-.94-2H1v2h2l3.6 7.59-1.35 2.45c-.16.28-.25.61-.25.96 0 1.11.89 2 2 2H19v-2H7.42c-.14 0-.25-.11-.25-.25l.02-.1z"/></svg>';
|
||
|
||
$current_year = date('Y');
|
||
$monat = date('n');
|
||
if ($monat > 6) $current_year++;
|
||
|
||
$dbProgramme = db_select($mysqli, $tableProgramme, 'programm', 'aktiv = ?', [1], 'programm ASC');
|
||
|
||
foreach ($dbProgramme as $prog) {
|
||
$programmes[] = $prog['programm'];
|
||
}
|
||
|
||
$userid = intval($_SESSION['user_id_trainer'] ?? 0);
|
||
$arrayfreigaben = [];
|
||
|
||
|
||
if ($userid > 0) {
|
||
$freigabe_json = db_get_var($mysqli, "SELECT freigabe FROM $tableInternUsers WHERE id = ?", [$userid]);
|
||
|
||
// Only decode if it’s a string
|
||
if (is_string($freigabe_json) && $freigabe_json !== '') {
|
||
$arrayfreigaben = json_decode($freigabe_json, true) ?: [];
|
||
|
||
$arrayfreigaben = $arrayfreigaben['freigabenTrainer'] ?? [];
|
||
}
|
||
}
|
||
|
||
if (!empty($arrayfreigaben)) {
|
||
$selectedverein = $_SESSION['selectedFreigabeTrainer'] ?? '';
|
||
|
||
if (!in_array($selectedverein, $arrayfreigaben)) {
|
||
$selectedverein = $arrayfreigaben[0];
|
||
$_SESSION['selectedFreigabeTrainer'] = $selectedverein;
|
||
}
|
||
}
|
||
|
||
require $baseDir . "/../scripts/trainer/post-handler.php";
|
||
|
||
setlocale(LC_TIME, 'de_DE.UTF-8');
|
||
|
||
$sortprio = ['ep', 'p1', 'p1 kader', 'p2', 'p2 kader'];
|
||
|
||
$displayLogo = $_SESSION['logoDisplay'] ?? true;
|
||
|
||
if ($displayLogo !== false){
|
||
require $baseDir . '/intern/scripts/wkvs/wkvs.html';
|
||
$_SESSION['logoDisplay'] = false;
|
||
}
|
||
?>
|
||
|
||
<div class="internMenuDiv">
|
||
<div class="closeInternMenuMobileDiv"></div>
|
||
<div class="innerInternMenuDiv">
|
||
|
||
<div class="header-text-conatiner"></div>
|
||
|
||
<h3 class="headingStartgebuerenTabelle">Warenkorb Startgebühren</h3>
|
||
|
||
<?php
|
||
|
||
$iduser = $_SESSION['user_id_trainer'];
|
||
|
||
$result = $mysqli->query("SELECT * FROM `$tableOrders` WHERE user_id = $iduser AND order_status = 0");
|
||
|
||
if (!$result) {
|
||
die("Query failed: " . $mysqli->error);
|
||
}
|
||
|
||
$rows = $result->fetch_all(MYSQLI_ASSOC);
|
||
|
||
|
||
$query = "SELECT * FROM `$tableBasketItems` WHERE user_id = $iduser";
|
||
$result = $mysqli->query($query);
|
||
|
||
if (!$result) {
|
||
echo json_encode(['success' => false, 'message' => 'Select failed: ' . $mysqli->error]);
|
||
exit;
|
||
}
|
||
|
||
$item_ids = [];
|
||
$entries = [];
|
||
$querytudb = '';
|
||
$totalprice = 0;
|
||
|
||
while ($row = $result->fetch_assoc()) {
|
||
$entries[] = $row;
|
||
if (!in_array($row['item_id'], $item_ids)){
|
||
$item_ids[] = $row['item_id'];
|
||
}
|
||
|
||
if ($querytudb !== '') {
|
||
$querytudb .= " OR";
|
||
}
|
||
$querytudb .= " id = " . intval($row['item_id']);
|
||
}
|
||
|
||
// Step 2: Fetch related data from $table_name_turnerinnen
|
||
$entriestable = [];
|
||
if ($querytudb !== '') {
|
||
$querytu = "SELECT `name`, `vorname`, `verein`, `programm`, id
|
||
FROM $tableTurnerinnen
|
||
WHERE $querytudb
|
||
ORDER BY name DESC";
|
||
|
||
$resulttu = $mysqli->query($querytu);
|
||
if (!$resulttu) {
|
||
echo json_encode(['success' => false, 'message' => 'Select failed: ' . $mysqli->error]);
|
||
exit;
|
||
}
|
||
|
||
$arrayprog = [];
|
||
$queryprogdb = '';
|
||
|
||
while ($row = $resulttu->fetch_assoc()) {
|
||
$entriestable[] = $row;
|
||
if (!in_array($row['programm'], $arrayprog)){
|
||
$arrayprog[] = $row['programm'];
|
||
if ($queryprogdb !== ''){
|
||
$queryprogdb .= " OR ";
|
||
}
|
||
$queryprogdb .= "programm = '" . $mysqli->real_escape_string($row['programm']) . "'";
|
||
}
|
||
}
|
||
|
||
if ($queryprogdb !== '') {
|
||
$queryprog = "SELECT *
|
||
FROM $tableProgramme
|
||
WHERE $queryprogdb
|
||
ORDER BY programm DESC";
|
||
|
||
|
||
$resultprog = $mysqli->query($queryprog);
|
||
if (!$resultprog) {
|
||
echo json_encode(['success' => false, 'message' => 'Select failed: ' . $mysqli->error]);
|
||
exit;
|
||
}
|
||
|
||
|
||
while ($row = $resultprog->fetch_assoc()) {
|
||
foreach ($entriestable as &$entry) {
|
||
if ($row['programm'] === $entry['programm']) {
|
||
$entry['startgebuer'] = $row['preis'];
|
||
$totalprice += $row['preis'];
|
||
}
|
||
}
|
||
}
|
||
unset($entry); // always unset after using & to avoid accidental reuse
|
||
|
||
}
|
||
}
|
||
$basketIsEmptyClass = ($entriestable && is_array($entriestable) && count($entriestable) > 0) ? '' : 'hidden';
|
||
$basketIsNotEmptyClass = ($entriestable && is_array($entriestable) && count($entriestable) > 0) ? 'hidden' : '';
|
||
|
||
?>
|
||
<table class="tableStartgebueren <?= $basketIsEmptyClass ?>">
|
||
<thead>
|
||
<tr class="hidden">
|
||
<th>Name</th>
|
||
<th>Gebühr</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody class="tbodyStartGebueren">
|
||
<?php
|
||
if ($entriestable && is_array($entriestable) && count($entriestable) > 0) {
|
||
foreach ($entriestable as $entry){
|
||
echo '<tr class="rowStartgebuer" data-id="'.$entry['id'].'">
|
||
<td class="cellStartgebuer"><b>' . $entry['name'] . '</b>, ' . $entry['vorname'] . ' | ' . $entry['programm'] . '</td>
|
||
<td class="cellStartgebuer" data-type="startgebuer">'.$entry['startgebuer'].' Fr.</td>
|
||
<td class="cellStartgebuer" data-type="delete" data-id="'.$entry['id'].'">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||
<polyline points="3 6 5 6 21 6"></polyline>
|
||
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
|
||
<line x1="10" y1="11" x2="10" y2="17"></line>
|
||
<line x1="14" y1="11" x2="14" y2="17"></line>
|
||
</svg>
|
||
</td>
|
||
</tr>';
|
||
}
|
||
}
|
||
echo '<tr class="rowStartgebuerTotal">
|
||
<td>Total:</td>
|
||
<td class="totalStartgebueren">'.number_format((float)$totalprice, 2, '.', '').' Fr.</td>
|
||
</tr>';
|
||
?>
|
||
</tbody>
|
||
</table>
|
||
<div>
|
||
<button id="checkoutButton" class="checkoutButton newBtn <?= $basketIsEmptyClass ?>">
|
||
<span>Daten für Rechnung eingeben</span>
|
||
<svg
|
||
xmlns="http://www.w3.org/2000/svg"
|
||
fill="none"
|
||
viewBox="0 0 74 74"
|
||
height="34"
|
||
width="34"
|
||
>
|
||
<circle stroke-width="3" stroke="black" r="35.5" cy="37" cx="37"></circle>
|
||
<path
|
||
fill="black"
|
||
d="M25 35.5C24.1716 35.5 23.5 36.1716 23.5 37C23.5 37.8284 24.1716 38.5 25 38.5V35.5ZM49.0607 38.0607C49.6464 37.4749 49.6464 36.5251 49.0607 35.9393L39.5147 26.3934C38.9289 25.8076 37.9792 25.8076 37.3934 26.3934C36.8076 26.9792 36.8076 27.9289 37.3934 28.5147L45.8787 37L37.3934 45.4853C36.8076 46.0711 36.8076 47.0208 37.3934 47.6066C37.9792 48.1924 38.9289 48.1924 39.5147 47.6066L49.0607 38.0607ZM25 38.5L48 38.5V35.5L25 35.5V38.5Z"
|
||
></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
|
||
<p id="textKeineStartgebuerenAusgewählt" class="<?= $basketIsNotEmptyClass ?>">Es wurden keine Startgebühren ausgwählt</p>
|
||
</div>
|
||
</div>
|
||
|
||
<section class="bgSection">
|
||
<div class="headerDivTrainer">
|
||
<div class="headingPanelDiv">
|
||
<h2 class="headingPanel">Trainerpanel</h2>
|
||
<h3 class="headingPanelUser"><?= ucfirst($selectedverein) ?></h3>
|
||
</div>
|
||
<div class="menuWrapper">
|
||
<div class="trainerBurgerMenuDiv">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||
<circle cx="9" cy="21" r="1"></circle>
|
||
<circle cx="20" cy="21" r="1"></circle>
|
||
<path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path>
|
||
</svg>
|
||
</div>
|
||
<?php sidebarRender('button'); ?>
|
||
</div>
|
||
<script>
|
||
const menuburger = document.querySelector('.trainerBurgerMenuDiv');
|
||
const menudiv = document.querySelector('.internMenuDiv');
|
||
//const menubg = document.querySelector('.menuBg');
|
||
const content = document.querySelector('.bgSection');
|
||
const closeMenuMobile = document.querySelector('.closeInternMenuMobileDiv');
|
||
|
||
const storageKey = "trainerInternMenuOpen";
|
||
|
||
const isOpen = localStorage.getItem(storageKey) === "true";
|
||
|
||
document.addEventListener('keydown', function (e) {
|
||
// Mac = Option, Windows/Linux = Alt
|
||
const isOptionOrAlt = e.altKey || e.metaKey;
|
||
|
||
if (e.key.toLowerCase() === 'w') {
|
||
menuburger.classList.add("menuTransition");
|
||
menudiv.classList.add("menuTransition");
|
||
content.classList.add("menuTransition");
|
||
|
||
menuburger.classList.toggle("open");
|
||
menudiv.classList.toggle("open");
|
||
content.classList.toggle("open");
|
||
|
||
const isOpenEl =
|
||
menudiv.classList.contains("open") &&
|
||
menuburger.classList.contains("open");
|
||
|
||
localStorage.setItem(storageKey, isOpenEl);
|
||
}
|
||
});
|
||
|
||
if (isOpen) {
|
||
menuburger.classList.add("open");
|
||
menudiv.classList.add("open");
|
||
content.classList.add("open");
|
||
}
|
||
|
||
menuburger.addEventListener("click", function () {
|
||
menuburger.classList.add("menuTransition");
|
||
menudiv.classList.add("menuTransition");
|
||
content.classList.add("menuTransition");
|
||
|
||
menuburger.classList.toggle("open");
|
||
menudiv.classList.toggle("open");
|
||
content.classList.toggle("open");
|
||
|
||
const isOpenEl =
|
||
menudiv.classList.contains("open") &&
|
||
menuburger.classList.contains("open");
|
||
|
||
localStorage.setItem(storageKey, isOpenEl);
|
||
});
|
||
|
||
closeMenuMobile.addEventListener("click", function () {
|
||
const isOpenEl =
|
||
menudiv.classList.contains("open") &&
|
||
menuburger.classList.contains("open");
|
||
|
||
if (isOpenEl) {
|
||
menuburger.classList.remove("open");
|
||
menudiv.classList.remove("open");
|
||
content.classList.remove("open");
|
||
|
||
localStorage.setItem(storageKey, false);
|
||
}
|
||
});
|
||
|
||
|
||
</script>
|
||
</div>
|
||
|
||
<?php
|
||
|
||
sidebarRender('modal');
|
||
|
||
if ( !empty($programmes) && is_array($programmes) ) : ?>
|
||
|
||
<div class="editContainerDiv">
|
||
|
||
<h3 class="heading_edit_turnerin"><?= isset($_POST['edit_id']) ? 'Daten aktualisieren' : 'Neue Turnerin hinzufügen' ?></h3>
|
||
|
||
<div class="editContainerDivInner">
|
||
<form action="" method="post">
|
||
<input type="hidden" name="csrf_token" value="<?= $csrf_token ?>">
|
||
|
||
<?php if ( isset($_POST['edit_id']) ) { ?>
|
||
<input type="hidden" name="edit_id" value="<?= intval($_POST['edit_id']) ?>">
|
||
<?php } ?>
|
||
|
||
<label for="nachname">Name:</label>
|
||
<input type="text" id="nachname" name="nachname" required value="<?php echo isset($_POST['nachname']) ? htmlspecialchars($_POST['nachname']) : ''; ?>">
|
||
|
||
<label for="vorname">Vorname:</label>
|
||
<input type="text" id="vorname" name="vorname" required value="<?php echo isset($_POST['vorname']) ? htmlspecialchars($_POST['vorname']) : ''; ?>">
|
||
|
||
<label for="geburtsdatum">Geburtsdatum:</label>
|
||
<input type="text" id="geburtsdatum" name="geburtsdatum" class="flatpickr-input" placeholder="Tag. Monat Jahr" required value="<?php echo isset($_POST['geburtsdatum']) ? htmlspecialchars($_POST['geburtsdatum']) : ''; ?>">
|
||
<label for="programm">Programm:</label>
|
||
<select id="programm" name="programm" required>
|
||
<option value="">Bitte wählen</option>
|
||
<?php
|
||
if ( !empty($programmes) && is_array($programmes) ) {
|
||
foreach ( $programmes as $prog ) {
|
||
// Preserve selected value on form submit
|
||
$selected = ( isset($_POST['programm']) && $_POST['programm'] === $prog ) ? 'selected' : '';
|
||
echo '<option value="' . htmlspecialchars($prog) . '" ' . $selected . '>' . htmlspecialchars($prog) . '</option>';
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
<?php if ($selectedverein !== 'admin'){?>
|
||
<label for="verein">Verein:</label>
|
||
<input type="text" id="verein" name="verein" required disabled value="<?php echo htmlspecialchars($selectedverein); ?>">
|
||
<?php } else {?>
|
||
<label for="verein">Verein:</label>
|
||
<select id="verein" name="verein" required>
|
||
<option value="" disabled selected hidden>Bitte wählen</option>
|
||
<?php
|
||
$vereine = db_select($mysqli, $tableVereine, "verein", "", [], "verein ASC");
|
||
if ( !empty($vereine) && is_array($vereine) ) {
|
||
foreach ($vereine as $index => $item ) {
|
||
// Preserve selected value on form submit
|
||
$selected_v = ( isset($_POST['verein']) && $_POST['verein'] === $item['verein'] ) ? 'selected' : '';
|
||
echo '<option value="' . htmlspecialchars($item['verein']) . '" ' . $selected_v . '>' . htmlspecialchars($item['verein']) . '</option>';
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
<?php }?>
|
||
<?php if($selectedverein === 'admin' && ($access_granted_trainer && isset($_GET['edit_id']) && is_numeric($_GET['edit_id']) && !isset($_POST['submit_turnerinnen_form']))){?>
|
||
<label for="bezahlt">Bezahlt:</label>
|
||
<select id="bezahlt" name="bezahlt" required>
|
||
<option value="" disabled <?php if($_POST['bezahlt'] ?? '' === '') echo 'selected'; ?>>Bitte wählen</option>
|
||
<option value="3" <?php if($_POST['bezahlt'] ?? '' === '3') echo 'selected'; ?>>Nein</option>
|
||
<option value="4" <?php if($_POST['bezahlt'] ?? '' === '4') echo 'selected'; ?>>In Bearbeitung</option>
|
||
<option value="5" <?php if($_POST['bezahlt'] ?? '' === '5') echo 'selected'; ?>>Ja</option>
|
||
<option value="0" <?php if (in_array($_POST['bezahlt'] ?? '', ['0', '1', '2'])) echo 'selected'; ?>>Automatisch</option>
|
||
</select>
|
||
<?php }?>
|
||
<input type="submit" name="submit_turnerinnen_form" value="<?php echo isset($_POST['edit_id']) ? 'Änderung speichern' : 'Daten speichern'; ?>">
|
||
<?php if (isset($_GET['edit_id'])) echo '<a class="emptyEditForm" href="/intern/trainer">Formular leeren</a>'; ?>
|
||
</form>
|
||
|
||
<form class="form_excel" action="" method="post" enctype="multipart/form-data">
|
||
<input type="hidden" name="csrf_token" value="<?= $csrf_token ?>">
|
||
<h4>Excel Tabelle hochladen</h4>
|
||
<a href="https://wkvs.ch/files/WKVS_Vorlage_Upload_Turnerinnen.xlsx" download>
|
||
<button type="button">Vorlage Herunterladen</button>
|
||
</a>
|
||
<input type="file" name="xlsx_file" accept=".xlsx" required>
|
||
<button type="submit">Hochladen und Importieren</button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
|
||
<?php if (isset($excelMessage) && !empty($excelMessage)) { ?>
|
||
<p><?php echo htmlspecialchars($excelMessage); ?></p>
|
||
<?php } ?>
|
||
|
||
<?php else :?>
|
||
<h3>Eingabetool noch nicht freigeschalten</h3>
|
||
<?php endif; ?>
|
||
|
||
<div class="allTurnerinenDiv"><h3 class="headingAlleTurnerinnen">Alle Turnerinnen:</h3>
|
||
|
||
<?php
|
||
|
||
//$entries = db_select($mysqli, $tableTurnerinnen, "*", "", [], "id DESC");
|
||
|
||
$sql = "
|
||
SELECT
|
||
t.*,
|
||
agg.bodenmusikId,
|
||
agg.bodenmusikFileName,
|
||
agg.bodenmusikFilePath
|
||
FROM $tableTurnerinnen t
|
||
LEFT JOIN (
|
||
SELECT
|
||
a.id AS bodenmusikId,
|
||
a.file_name AS bodenmusikFileName,
|
||
a.file_path AS bodenmusikFilePath
|
||
FROM $tableAudiofiles a
|
||
) agg ON agg.bodenmusikId = t.bodenmusik
|
||
ORDER BY t.programm ASC, t.verein ASC, t.name ASC, t.vorname ASC
|
||
";
|
||
|
||
$stmt = $mysqli->prepare($sql);
|
||
|
||
if (!$stmt->execute()) {
|
||
http_response_code(500);
|
||
exit;
|
||
}
|
||
|
||
// get result set
|
||
$result = $stmt->get_result();
|
||
|
||
// fetch all rows as associative array
|
||
$entries = $result->fetch_all(MYSQLI_ASSOC);
|
||
|
||
$stmt->close();
|
||
|
||
// Filter for non-admins
|
||
if ($selectedverein !== 'admin') {
|
||
$entries = array_filter($entries, function ($row) use ($selectedverein) {
|
||
return $row['verein'] === $selectedverein;
|
||
});
|
||
}
|
||
|
||
// Group entries by programm
|
||
$grouped = [];
|
||
foreach ($entries as $entry) {
|
||
$key = $entry['programm'];
|
||
$grouped[$key][] = $entry;
|
||
}
|
||
|
||
// Sort the grouped keys by defined priority
|
||
uksort($grouped, function ($a, $b) use ($sortprio) {
|
||
$a_index = array_search($a, $sortprio);
|
||
$b_index = array_search($b, $sortprio);
|
||
$a_index = $a_index === false ? PHP_INT_MAX : $a_index;
|
||
$b_index = $b_index === false ? PHP_INT_MAX : $b_index;
|
||
return $a_index <=> $b_index;
|
||
});
|
||
|
||
$total_count = 0;
|
||
|
||
$invalidProgrammes = false;
|
||
|
||
if (!empty($grouped)) : ?>
|
||
<form action="" method="post" id="bulk-action-form">
|
||
<input type="hidden" name="csrf_token" id="bulc_nonce" value="<?= $csrf_token ?>">
|
||
<div>
|
||
<p class="labelBulkSelect">Bulk Select:</p>
|
||
<div style="display: flex; align-items: center; gap: 10px; margin-bottom: 15px;">
|
||
<select class="bulkSelect" name="bulk_action_select" id="bulk_action_select">
|
||
<option value="" disabled selected hidden>Aktion auswählen</option>
|
||
<option value="changeProgramm">Programm ändern</option>
|
||
<?php
|
||
if ($selectedverein === 'admin') {
|
||
echo '<option value="changeEntryFee">Bezahlt Status ändern</option>';
|
||
}
|
||
?>
|
||
<option value="payEntryFee">Startgebühren bezahlen</option>
|
||
</select>
|
||
<select class="bulkSelect hidden" name="bulk_action_programm" id="bulk_action_programm">
|
||
<option value="" disabled selected hidden>Programm ändern zu...</option>
|
||
<?php
|
||
if ( !empty($programmes) && is_array($programmes) ) {
|
||
foreach ($programmes as $prog) {
|
||
echo '<option value="' . htmlspecialchars($prog) . '">' . htmlspecialchars($prog) . '</option>';
|
||
}
|
||
}
|
||
?>
|
||
</select>
|
||
<?php if ($selectedverein === 'admin'){ ?>
|
||
<select name="bulk_action_bezahlt" id="bulk_action_bezahlt" class="bulkSelect hidden">
|
||
<option value="" disabled selected hidden>Bezahlt setzen auf...</option>
|
||
<option value="5">Ja</option>
|
||
<option value="4">In Bearbeitung</option>
|
||
<option value="3">Nein</option>
|
||
<option value="0">Automatisch</option>
|
||
</select>
|
||
<?php } ?>
|
||
|
||
<input type="submit" name="apply_bulk_action" class="bulk-select-submit" value="Anwenden">
|
||
</div>
|
||
|
||
<script>
|
||
$('#bulk_action_programm').addClass("hidden");
|
||
$('.bulk-select-submit').addClass("hidden");
|
||
</script>
|
||
<!-- <input type="submit" name="apply_bulk_add_to_cart" id="" class="button" value="Ausgewählte Startgebüren bezahlen"> -->
|
||
</div>
|
||
<?php
|
||
foreach ($grouped as $programm => $entries_group) :
|
||
$count = count($entries_group);
|
||
$total_count += $count;
|
||
?>
|
||
<div class="singleProgDiv">
|
||
<h2 class="titleSingleProg"><?php echo htmlspecialchars($programm); ?></h2>
|
||
<div class="tableWraperOverflowY">
|
||
<table class="widefat striped wkvsTabelle trainer">
|
||
<thead>
|
||
<tr>
|
||
<th style="width:20px;">
|
||
<label class="checkbox">
|
||
<input type="checkbox" id="check_all_<?php echo str_replace(" ", "-", $programm); ?>">
|
||
<span class="checkbox-ui"></span>
|
||
</label>
|
||
</th>
|
||
<th>Name</th>
|
||
<th>Geburtsdatum</th>
|
||
<th>Programm</th>
|
||
<?php if ($selectedverein === 'admin') { ?> <th>Verein</th> <?php } ?>
|
||
<th>Startgebühr</th>
|
||
<th>Musik (Boden)</th>
|
||
<th>Aktionen</th>
|
||
</tr>
|
||
</thead>
|
||
<tbody>
|
||
<?php foreach ($entries_group as $row) : ?>
|
||
<tr>
|
||
<td>
|
||
<label class="checkbox">
|
||
<input type="checkbox" name="turnerin_ids[]" class="row_check_<?php echo str_replace(" ", "-", $programm); ?>" value="<?php echo intval($row['id']); ?>">
|
||
<span class="checkbox-ui"></span>
|
||
</label>
|
||
</td>
|
||
<td><b><?php echo htmlspecialchars($row['name']); ?></b>, <?php echo htmlspecialchars($row['vorname']); ?></td>
|
||
<td><?php echo htmlspecialchars(strftime('%d. %B %Y', (new DateTime($row['geburtsdatum']))->getTimestamp())); ?></td>
|
||
<td <?php if (!in_array(htmlspecialchars($row['programm']), $programmes)){
|
||
echo ' style="background-color: #f00; color: var(--ktbb_bg);" title="Ungültiges Programm"';
|
||
$invalidProgrammes = true;
|
||
} ?>
|
||
>
|
||
<?php
|
||
echo htmlspecialchars($row['programm']);
|
||
?>
|
||
</td>
|
||
<?php if ($selectedverein === 'admin') { ?> <td><?php echo htmlspecialchars($row['verein']); ?></td> <?php } ?>
|
||
<td><div class="paymentDivWraper">
|
||
<?php
|
||
// Decide which value to evaluate
|
||
$value = (intval($row['bezahltoverride']) !== 0)
|
||
? htmlspecialchars($row['bezahltoverride'])
|
||
: htmlspecialchars($row['bezahlt']);
|
||
|
||
echo createPaystatusSvg(intval($value), $row['id']);
|
||
if (intval($row['bezahltoverride']) !== 0) {
|
||
//echo '<span class="bezahltOverrideInfo">Durch Admin überschrieben</span>';
|
||
echo createPaystatusSvg(6, $row['id']);
|
||
}
|
||
?>
|
||
</div>
|
||
</td>
|
||
<td>
|
||
<?php
|
||
$hasMusic = htmlspecialchars($row['bodenmusik']) !== '0';
|
||
$musicClass = $hasMusic ? 'hasMusic' : 'noMusic';
|
||
$musicText = $hasMusic ? (isset($row['bodenmusikFileName']) ? $row['bodenmusikFileName'] : 'Musik vorhanden') : 'Musik hochladen';
|
||
?>
|
||
<div class="musicDivWraper">
|
||
<div class="musicStatus noMusic">
|
||
<div class="uploadmusic-container">
|
||
<label style="cursor: pointer; display: flex; align-items: center; gap: 8px; margin: 0;">
|
||
<?php if (!$hasMusic): ?>
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||
<path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path>
|
||
<polyline points="17 8 12 3 7 8"></polyline>
|
||
<line x1="12" y1="3" x2="12" y2="15"></line>
|
||
</svg>
|
||
|
||
<span class="label-music" <?= $hasMusic ? 'data-url="'.$row['bodenmusikFilePath'].'"' : '' ?>><?= $musicText ?></span>
|
||
<?php else: ?>
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||
<path d="M23 4v6h-6"></path>
|
||
<path d="M20.49 15a9 9 0 1 1-2.12-9.36L23 10"></path>
|
||
</svg>
|
||
<?php endif; ?>
|
||
<input type="file"
|
||
name="music_file"
|
||
accept=".mp3,.wav,.ogg"
|
||
data-id="<?= $row['id'] ?>"
|
||
data-musicid="<?= isset($row['bodenmusikId']) ? $row['bodenmusikId'] : 0 ?>"
|
||
style="display:none;"
|
||
onchange="uploadFile(this)">
|
||
</label>
|
||
</div>
|
||
|
||
</div>
|
||
<?php if ($hasMusic) { ?>
|
||
<div class="musicStatus <?= $musicClass ?>">
|
||
<span class="label-music" <?= $hasMusic ? 'data-url="'.$row['bodenmusikFilePath'].'"' : '' ?>><?= $musicText ?></span>
|
||
</div>
|
||
<?php } ?>
|
||
</div>
|
||
</td>
|
||
<td style="min-width:150px;">
|
||
<div class="editDiv" style="display: flex; align-items: center; gap: 10px;">
|
||
<?php if ((intval($row['bezahlt']) === 0 || intval($row['bezahlt']) === 1) && intval($row['bezahltoverride']) !== 5) { ?>
|
||
<button class="addTurnerinToWarenkorb" type="submit" aria-label="Zum Warenkarb hinzufügen" title="Zum Warenkarb hinzufügen" data-id="<?= $row['id'] ?>">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||
<circle cx="9" cy="21" r="1"></circle>
|
||
<circle cx="20" cy="21" r="1"></circle>
|
||
<path d="M1 1h4l2.68 13.39a2 2 0 0 0 2 1.61h9.72a2 2 0 0 0 2-1.61L23 6H6"></path>
|
||
</svg>
|
||
</button>
|
||
<?php } ?>
|
||
|
||
<a href="?edit_id=<?php echo intval($row['id']); ?>" aria-label="Bearbeiten" title="Bearbeiten">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="var(--main)" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||
<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path>
|
||
<path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path>
|
||
</svg>
|
||
</a>
|
||
|
||
<button type="button" onclick="confirmDelete(<?= $row['id'] ?>, '<?= $row['name'] ?>, <?= $row['vorname'] ?>')" aria-label="Löschen" title="Löschen">
|
||
<svg xmlns="http://www.w3.org/2000/svg" width="22" height="22" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round">
|
||
<polyline points="3 6 5 6 21 6"></polyline>
|
||
<path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path>
|
||
<line x1="10" y1="11" x2="10" y2="17"></line>
|
||
<line x1="14" y1="11" x2="14" y2="17"></line>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
</td>
|
||
</tr>
|
||
<?php endforeach; ?>
|
||
</tbody>
|
||
</table>
|
||
</div>
|
||
<?php if ($count > 1) { echo '<p>' . $count . ' Turnerinnen</p>'; } else { echo '<p>' . $count . ' Turnerin</p>';}?>
|
||
</div>
|
||
<?php
|
||
endforeach;
|
||
|
||
?>
|
||
<p><strong>Gesamtanzahl Turnerinnen: <?php echo $total_count; ?></strong></p>
|
||
</form>
|
||
<?php else : ?>
|
||
<p>Noch keine Datensätze vorhanden.</p>
|
||
<?php endif; ?>
|
||
<div class="msgDiv"></div>
|
||
<form id="global-delete-form" method="post" style="display:none;">
|
||
<input type="hidden" name="delete_id" id="global-delete-id">
|
||
<input type="hidden" name="csrf_token" value="<?= $csrf_token ?>">
|
||
</form>
|
||
</section>
|
||
<div id="musicDiv"><audio controls><source id="sorceAudioPreview" src="" type="audio/mp3"></audio></div>
|
||
<?php endif; ?>
|
||
|
||
<div id="paymentFormContainer" class="payment-modal-overlay" style="display:none;">
|
||
<div class="payment-modal-content">
|
||
<div class="payment-modal-header">
|
||
<h2>Zahldaten</h2>
|
||
<span class="closePaymentForm">×</span>
|
||
</div>
|
||
<p class="payment-modal-desc">Die folgenden Daten werden für die Verbuchung der Zahlung benötigt. <br>Die Rechnung wird bei uns gespeichert (Art 958e Abs 1 ZGB).</p>
|
||
<div class="paymentFormOverflowWrapper">
|
||
<form id="paymentForm" method="POST" action="/intern/scripts/trainer/rechnung/rechnung-pdf.php">
|
||
<div class="fullinput-row">
|
||
<div class="fullinput-group">
|
||
<label for="vorname" class="requiredInput">Vorname</label>
|
||
<input type="text" id="vorname" name="vorname" class="fullinput" required placeholder="Vorname" autocomplete="given-name">
|
||
</div>
|
||
<div class="fullinput-group">
|
||
<label for="name" class="requiredInput">Name</label>
|
||
<input type="text" id="name" name="name" class="fullinput" required placeholder="Nachname" autocomplete="family-name">
|
||
</div>
|
||
</div>
|
||
<div class="fullinput-row">
|
||
<div class="fullinput-group">
|
||
<label for="strasse" class="requiredInput">Strasse</label>
|
||
<input type="text" id="strasse" name="strasse" class="fullinput" required placeholder="Strasse">
|
||
</div>
|
||
<div class="fullinput-group" style="flex: 0 0 80px;">
|
||
<label for="hausnummer" class="requiredInput">Nr.</label>
|
||
<input type="text" id="hausnummer" name="hausnummer" class="fullinput" required placeholder="Nr.">
|
||
</div>
|
||
</div>
|
||
<div class="fullinput-row">
|
||
<div class="fullinput-group" style="flex: 0 0 100px;">
|
||
<label for="plz" class="requiredInput">PLZ</label>
|
||
<input type="text" id="plz" name="plz" class="fullinput" required placeholder="PLZ">
|
||
</div>
|
||
<div class="fullinput-group">
|
||
<label for="ort" class="requiredInput">Ort</label>
|
||
<input type="text" id="ort" name="ort" class="fullinput" required placeholder="Ort">
|
||
</div>
|
||
</div>
|
||
<?php /* <label class="checkbox payment-checkbox-label">
|
||
<input type="checkbox" id="postversand" name="postversand">
|
||
<span class="checkbox-ui"></span>
|
||
<span>Postversand der Rechnung (Aufpreis CHF 2.50)</span>
|
||
</label> */ ?>
|
||
<input type="hidden" name="order_id" value="">
|
||
<input type="hidden" name="preis" value="">
|
||
<input type="hidden" name="csrf_token" value="<?= $csrf_token ?>">
|
||
<div>
|
||
<button type="submit" class="newBtn">
|
||
<span>Rechnung erstellen</span>
|
||
<svg
|
||
xmlns="http://www.w3.org/2000/svg"
|
||
fill="none"
|
||
viewBox="0 0 74 74"
|
||
height="34"
|
||
width="34"
|
||
>
|
||
<circle stroke-width="3" stroke="black" r="35.5" cy="37" cx="37"></circle>
|
||
<path
|
||
fill="black"
|
||
d="M25 35.5C24.1716 35.5 23.5 36.1716 23.5 37C23.5 37.8284 24.1716 38.5 25 38.5V35.5ZM49.0607 38.0607C49.6464 37.4749 49.6464 36.5251 49.0607 35.9393L39.5147 26.3934C38.9289 25.8076 37.9792 25.8076 37.3934 26.3934C36.8076 26.9792 36.8076 27.9289 37.3934 28.5147L45.8787 37L37.3934 45.4853C36.8076 46.0711 36.8076 47.0208 37.3934 47.6066C37.9792 48.1924 38.9289 48.1924 39.5147 47.6066L49.0607 38.0607ZM25 38.5L48 38.5V35.5L25 35.5V38.5Z"
|
||
></path>
|
||
</svg>
|
||
</button>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<script>
|
||
|
||
const csrf_token = "<?= $csrf_token ?>";
|
||
|
||
(function () {
|
||
let lastWrite = 0;
|
||
const interval = 200;
|
||
|
||
window.addEventListener('scroll', function () {
|
||
const now = Date.now();
|
||
if (now - lastWrite >= interval) {
|
||
sessionStorage.setItem('scrollY', window.scrollY);
|
||
lastWrite = now;
|
||
}
|
||
}, { passive: true });
|
||
<?php
|
||
if (!isset($_GET['edit_id']) || intval($_GET['edit_id']) < 1) {
|
||
echo "window.addEventListener('load', function () {
|
||
const scrollY = sessionStorage.getItem('scrollY');
|
||
if (scrollY !== null) {
|
||
window.scrollTo(0, parseInt(scrollY, 10));
|
||
}
|
||
});";
|
||
} else {
|
||
echo "window.addEventListener('load', function () {
|
||
window.scrollTo(0, 0);
|
||
});";
|
||
}
|
||
?>
|
||
});
|
||
function uploadFile(input) {
|
||
const idTurnerin = input.dataset.id;
|
||
const idOldMusic = input.dataset.musicid;
|
||
const formData = new FormData();
|
||
formData.append('music_file', input.files[0]);
|
||
formData.append('turnerinId', idTurnerin);
|
||
formdata.append('csrf_token', csrf_token);
|
||
|
||
fetch('/intern/scripts/audiofiles-uploads/ajax_audiofile_upload.php', {
|
||
method: 'POST',
|
||
body: formData
|
||
})
|
||
.then(async res => {
|
||
const data = await res.json(); // ALWAYS read JSON
|
||
|
||
if (!res.ok) {
|
||
// backend sent JSON error message
|
||
throw {
|
||
status: res.status,
|
||
message: data.message || 'Upload failed'
|
||
};
|
||
}
|
||
|
||
return data;
|
||
})
|
||
.then(data => {
|
||
displayMsg(1, data.filename + ' hochgeladen');
|
||
|
||
return fetch('/intern/scripts/trainer/ajax_link_bodenmusik.php', {
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/x-www-form-urlencoded'
|
||
},
|
||
body: new URLSearchParams({
|
||
musicId: data.id,
|
||
turnerinId: idTurnerin,
|
||
oldMusicId: idOldMusic
|
||
})
|
||
});
|
||
})
|
||
.then(async res => {
|
||
const data = await res.json();
|
||
|
||
if (!res.ok) {
|
||
throw {
|
||
status: res.status,
|
||
message: data.message || 'Link failed'
|
||
};
|
||
}
|
||
|
||
window.location.reload();
|
||
})
|
||
.catch(err => {
|
||
displayMsg(0, `${err.message} (HTTP ${err.status ?? 'unknown'})`);
|
||
});
|
||
|
||
}
|
||
|
||
function confirmDelete(id, name) {
|
||
if (confirm(name + ' wirklich aus dem System entfernen?')) {
|
||
document.getElementById('global-delete-id').value = id;
|
||
document.getElementById('global-delete-form').submit();
|
||
}
|
||
}
|
||
function updatePosition($input, $div) {
|
||
const offset = $input.offset();
|
||
const height = $input.outerHeight();
|
||
const inputWidth = $input.outerWidth();
|
||
const divWidth = $div.outerWidth();
|
||
const divHeight = $div.outerHeight();
|
||
|
||
const left = offset.left + (inputWidth / 2) - (divWidth / 2);
|
||
const top = offset.top + height + 20;
|
||
|
||
const windowWidth = $(window).width();
|
||
const windowHeight = $(window).height();
|
||
const scrollTop = $(window).scrollTop();
|
||
const scrollLeft = $(window).scrollLeft();
|
||
|
||
const isInsideViewport =
|
||
left >= scrollLeft &&
|
||
top >= scrollTop &&
|
||
left + divWidth <= scrollLeft + windowWidth &&
|
||
top + divHeight <= scrollTop + windowHeight;
|
||
|
||
if (!isInsideViewport) {
|
||
$div.hide();
|
||
return;
|
||
}
|
||
|
||
$div.show().css({
|
||
left: left,
|
||
top: top
|
||
});
|
||
}
|
||
|
||
|
||
function updateMusicPreviewFileUrl(path) {
|
||
const $source = $('#sorceAudioPreview');
|
||
|
||
$source.attr('src', path);
|
||
|
||
const extension = path.split('.').pop().toLowerCase();
|
||
$source.attr('type', 'audio/' + extension);
|
||
|
||
// Reload audio element if needed
|
||
$source.closest('audio')[0].load();
|
||
}
|
||
|
||
async function urlExists(url) {
|
||
try {
|
||
const response = await fetch(url, { method: 'HEAD', mode: 'no-cors' });
|
||
return true;
|
||
} catch (error) {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
let lastInput = null;
|
||
|
||
const $musicDiv = $('#musicDiv');
|
||
$musicDiv.hide();
|
||
|
||
$('.label-music').on('click', async function () {
|
||
if (lastInput !== this) {
|
||
if (lastInput !== null && $(lastInput).hasClass('selected')) {
|
||
$(lastInput).removeClass('selected');
|
||
}
|
||
lastInput = this;
|
||
const url = $(lastInput).data("url") ?? '';
|
||
if (url === '') { return; }
|
||
const exists = await urlExists(url);
|
||
if (!exists) { return; }
|
||
$(lastInput).addClass('selected');
|
||
updateMusicPreviewFileUrl($(lastInput).data("url"));
|
||
$musicDiv.show();
|
||
updatePosition($(lastInput), $musicDiv);
|
||
} else {
|
||
if (lastInput !== null && $(lastInput).hasClass('selected')) {
|
||
$(lastInput).removeClass('selected');
|
||
}
|
||
$musicDiv.hide();
|
||
lastInput = null;
|
||
}
|
||
});
|
||
|
||
$(window).on('scroll resize', function () {
|
||
if (lastInput) {
|
||
updatePosition($(lastInput), $musicDiv);
|
||
}
|
||
});
|
||
|
||
let bulkSelectPay;
|
||
document.addEventListener('DOMContentLoaded', function () {
|
||
<?php
|
||
if (isset($invalidProgrammes) && $invalidProgrammes === true){
|
||
?>
|
||
displayMsg(2, 'Manche Turnerinnen haben nicht aktive Programme');
|
||
<?php
|
||
}
|
||
?>
|
||
<?php if (isset($_SESSION['form_message'])) echo "console.log(" . $_SESSION['form_message'] . ")"; ?>
|
||
|
||
// BULK ADD-TO-CART via the main bulk form
|
||
const bulkForm = document.getElementById('bulk-action-form');
|
||
if(bulkForm) {
|
||
bulkForm.addEventListener('submit', async function(e) {
|
||
const btn = document.activeElement;
|
||
// Only run bulk add-to-cart if that was the submitted button
|
||
if ((btn && btn.name === 'apply_bulk_add_to_cart') || bulkSelectPay === true) {
|
||
e.preventDefault();
|
||
// Gather selected IDs
|
||
const checked = Array.from(document.querySelectorAll('input[name="turnerin_ids[]"]:checked'));
|
||
if (checked.length === 0) {
|
||
alert('Bitte mindestens eine Turnerin auswählen.');
|
||
return;
|
||
}
|
||
const ids = checked.map(input => input.value);
|
||
|
||
const url = "/intern/scripts/trainer/ajax-add_entry_fees_to_basket.php";
|
||
|
||
fetch(url,{
|
||
method: 'POST',
|
||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||
body: new URLSearchParams({
|
||
csrf_token,
|
||
ids,
|
||
user: <?php echo $userid; ?>
|
||
})
|
||
})
|
||
.then(res => res.json())
|
||
.then(response => {
|
||
if (response.success) {
|
||
window.location.reload();
|
||
} else {
|
||
alert('Error: ' + response.message);
|
||
}
|
||
})
|
||
.catch(err => {
|
||
console.error('AJAX fetch error:', err);
|
||
});
|
||
}
|
||
});
|
||
}
|
||
// find all "check all" master checkboxes
|
||
document.querySelectorAll('[id^="check_all_"]').forEach(master => {
|
||
const programm = master.id.replace("check_all_", "");
|
||
const checkboxes = document.querySelectorAll(".row_check_" + programm);
|
||
|
||
// toggle all rows when master is clicked
|
||
master.addEventListener("change", function() {
|
||
checkboxes.forEach(cb => cb.checked = master.checked);
|
||
});
|
||
|
||
// update master if all rows are manually checked/unchecked
|
||
checkboxes.forEach(cb => {
|
||
cb.addEventListener("change", function() {
|
||
master.checked = [...checkboxes].every(c => c.checked);
|
||
});
|
||
});
|
||
});
|
||
});
|
||
|
||
let menuTriggerdGebueren = false;
|
||
jQuery(function($) {
|
||
const scrollY = sessionStorage.getItem("scrollY");
|
||
if (scrollY) $(window).scrollTop(scrollY);
|
||
|
||
$(window).on('beforeunload', function() {
|
||
sessionStorage.setItem("scrollY", $(window).scrollTop());
|
||
});
|
||
|
||
const user = '<?php echo strtolower($selectedverein);?>';
|
||
|
||
$('#bulk_action_select').change(function(){
|
||
let value = $(this).val();
|
||
$('.bulk-select-submit').removeClass("hidden");
|
||
|
||
if (value === 'changeProgramm'){
|
||
$('#bulk_action_programm').removeClass("hidden");
|
||
bulkSelectPay = false;
|
||
|
||
if (user === 'admin'){
|
||
$('#bulk_action_bezahlt').addClass("hidden");
|
||
}
|
||
}
|
||
|
||
if (value === 'changeEntryFee' && user === 'admin'){
|
||
$('#bulk_action_bezahlt').removeClass("hidden");
|
||
$('#bulk_action_programm').addClass("hidden");
|
||
bulkSelectPay = false;
|
||
}
|
||
|
||
if (value === 'payEntryFee'){
|
||
if (user === 'admin'){
|
||
$('#bulk_action_bezahlt').addClass("hidden");
|
||
}
|
||
$('#bulk_action_programm').addClass("hidden");
|
||
bulkSelectPay = true;
|
||
}
|
||
});
|
||
$('.addTurnerinToWarenkorb').on('click', function (e) {
|
||
e.preventDefault();
|
||
|
||
const el = $(this);
|
||
const id = el.data('id');
|
||
|
||
// Build the URL with GET parameters safely
|
||
const url = `/intern/scripts/trainer/ajax-add_entry_fees_to_basket.php`;
|
||
|
||
fetch(url,{
|
||
method: 'POST',
|
||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||
body: new URLSearchParams({
|
||
csrf_token,
|
||
ids: id
|
||
})
|
||
})
|
||
.then(res => {
|
||
// 200–299
|
||
if (res.ok) {
|
||
return res.json();
|
||
}
|
||
|
||
// Non-2xx → throw a structured error
|
||
return res.json().then(body => {
|
||
throw {
|
||
status: res.status,
|
||
message: body.message || res.statusText
|
||
};
|
||
});
|
||
})
|
||
.then(data => {
|
||
// SUCCESS PATH (200)
|
||
displayMsg(1, 'Startgebühren dem Warenkorb hinzugefügt');
|
||
|
||
const $tbody = $('.tbodyStartGebueren');
|
||
|
||
$tbody.append('<tr class="rowStartgebuer" data-id="' + id + '"><td class="cellStartgebuer"><b>' + data.arrayData[id].turnerinName + '</b>, ' + data.arrayData[id].turnerinVorname + ' | ' + data.arrayData[id].programm + '</td><td class="cellStartgebuer" data-type="startgebuer">' + data.arrayData[id].preis + ' Fr.</td><td class="cellStartgebuer" data-type="delete" data-id="' + id + '"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="var(--accent)" stroke-width="1.75" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg></td></tr>');
|
||
|
||
// Separate rows
|
||
const $totalRows = $tbody.find('tr.rowStartgebuerTotal').detach();
|
||
const rows = $tbody.find('tr:not(.rowStartgebuerTotal)').get();
|
||
|
||
// Sort remaining rows
|
||
rows.sort(function (a, b) {
|
||
const textA = $(a).find('td:first').text();
|
||
const textB = $(b).find('td:first').text();
|
||
|
||
const keyA = textA.split(', ')[1]?.toLowerCase() || '';
|
||
const keyB = textB.split(', ')[1]?.toLowerCase() || '';
|
||
|
||
return keyA.localeCompare(keyB, 'de', { sensitivity: 'base' });
|
||
});
|
||
|
||
// Re-append sorted rows
|
||
$.each(rows, function (_, row) {
|
||
$tbody.append(row);
|
||
});
|
||
|
||
// Append total row last
|
||
$tbody.append($totalRows);
|
||
|
||
let newcost = 0;
|
||
|
||
if ($('.cellStartgebuer[data-type="startgebuer"]').length > 0) {
|
||
$('.tableStartgebueren').removeClass('hidden');
|
||
$('.checkoutButton').removeClass('hidden');
|
||
$('#textKeineStartgebuerenAusgewählt').addClass('hidden');
|
||
}
|
||
|
||
$( '.cellStartgebuer[data-type="startgebuer"]' ).each(function(){
|
||
newcost += parseFloat($(this).text().replace(/\s*Fr\.?/g, ""));
|
||
});
|
||
|
||
$('.totalStartgebueren').text(newcost.toFixed(2) + " Fr.");
|
||
|
||
if (!menuTriggerdGebueren) {
|
||
menuTriggerdGebueren = true;
|
||
$('.trainerBurgerMenuDiv').addClass('open');
|
||
$('.internMenuDiv').addClass('open');
|
||
$('.bgSection').addClass('open');
|
||
$('.closeInternMenuMobileDiv').addClass('open');
|
||
|
||
localStorage.setItem(storageKey, true);
|
||
}
|
||
|
||
$('.tbodyStartGebuer').on('click', '.rowStartgebuer', function () {
|
||
const id = $(this).data('id'); // get data-id of clicked row
|
||
const name = $(this).find('td:first').text(); // first cell
|
||
|
||
console.log('Clicked row with id:', id, 'name:', name);
|
||
});
|
||
|
||
$(el).on('click', function() {
|
||
const id = el.data('id');
|
||
|
||
const url = '/intern/scripts/trainer/ajax-remove_basket_item.php';
|
||
fetch(url, {
|
||
method: 'POST',
|
||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||
body: new URLSearchParams({
|
||
id: id
|
||
})
|
||
})
|
||
.then(response => {
|
||
if (!response.ok) {
|
||
throw new Error(`HTTP ${response.status}`);
|
||
}
|
||
|
||
return response.text();
|
||
})
|
||
.then(a => {
|
||
console.log(id);
|
||
$('.rowStartgebuer[data-id="' + id + '"]').remove();
|
||
|
||
let newcost = 0;
|
||
|
||
if ($('.cellStartgebuer[data-type="startgebuer"]').length < 1) {
|
||
$('.tableStartgebueren').addClass('hidden');
|
||
$('.checkoutButton').addClass('hidden');
|
||
$('#textKeineStartgebuerenAusgewählt').removeClass('hidden');
|
||
}
|
||
|
||
$( '.cellStartgebuer[data-type="startgebuer"]' ).each(function(){
|
||
newcost += parseFloat($(this).text().replace(/\s*Fr\.?/g, ""));
|
||
});
|
||
|
||
$('.totalStartgebueren').text(newcost.toFixed(2) + " Fr.");
|
||
})
|
||
});
|
||
|
||
|
||
return;
|
||
})
|
||
.catch(error => {
|
||
// ERROR PATH ONLY
|
||
console.error('Fetch error:', error);
|
||
|
||
const msg = error?.message || 'Netzwerk- oder Serverfehler';
|
||
displayMsg(0, msg);
|
||
});
|
||
|
||
});
|
||
|
||
const $paymentFormContainer = $('#paymentFormContainer');
|
||
|
||
$('.closePaymentForm').on('click', function() {
|
||
$paymentFormContainer.hide();
|
||
});
|
||
|
||
$('#checkoutButton').on('click', function() {
|
||
const $input = $(this);
|
||
|
||
// Build the URL with GET parameters safely
|
||
const url = `/intern/scripts/trainer/ajax-neu_temp_order.php`;
|
||
|
||
fetch(url,{
|
||
method: 'POST',
|
||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||
body: new URLSearchParams({
|
||
csrf_token
|
||
})
|
||
})
|
||
.then(res => res.json())
|
||
.then(response => {
|
||
|
||
if (response.success) {
|
||
// Fetch the order_id and preis
|
||
return fetch(`/intern/scripts/trainer/ajax-fetch_temp_order.php` , {
|
||
method: 'POST',
|
||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||
body: new URLSearchParams({
|
||
csrf_token
|
||
})
|
||
})
|
||
.then(res2 => res2.json())
|
||
.then(orderData => {
|
||
if (orderData.success && orderData.result) {
|
||
$('#paymentForm input[name="order_id"]').val(orderData.result.order_id);
|
||
$('#paymentForm input[name="preis"]').val(orderData.result.preis);
|
||
$paymentFormContainer.show();
|
||
} else {
|
||
throw new Error('Could not fetch temp order details');
|
||
}
|
||
});
|
||
} else {
|
||
// Flash red on error
|
||
console.error(response.message || 'Unknown error');
|
||
}
|
||
})
|
||
.catch(err => {
|
||
console.error('AJAX fetch error:', err);
|
||
});
|
||
});
|
||
|
||
$('#paymentForm').on('submit', function(e) {
|
||
e.preventDefault();
|
||
|
||
const $form = $(this);
|
||
const $submitBtn = $form.find('button[type="submit"]');
|
||
const originalText = $submitBtn.text();
|
||
|
||
$submitBtn.text('Bitte warten...').prop('disabled', true);
|
||
|
||
const formData = new FormData(this);
|
||
|
||
fetch($form.attr('action'), {
|
||
method: 'POST',
|
||
body: formData
|
||
})
|
||
.then(res => {
|
||
if (!res.ok) {
|
||
throw new Error(`HTTP Error: ${res.status}`);
|
||
}
|
||
// Check if it's a PDF
|
||
const contentType = res.headers.get('content-type');
|
||
if (contentType && contentType.includes('application/pdf')) {
|
||
// Get filename from Content-Disposition if possible
|
||
let filename = 'Rechnung.pdf';
|
||
const disposition = res.headers.get('content-disposition');
|
||
if (disposition && disposition.indexOf('attachment') !== -1) {
|
||
const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
|
||
const matches = filenameRegex.exec(disposition);
|
||
if (matches != null && matches[1]) {
|
||
filename = matches[1].replace(/['"]/g, '');
|
||
}
|
||
}
|
||
|
||
return res.blob().then(blob => ({blob, filename}));
|
||
} else {
|
||
return res.json().then(data => {
|
||
throw new Error(data.message || 'Error generating invoice');
|
||
});
|
||
}
|
||
})
|
||
.then(({blob, filename}) => {
|
||
// Create a link to download the PDF
|
||
const url = window.URL.createObjectURL(blob);
|
||
const a = document.createElement('a');
|
||
a.style.display = 'none';
|
||
a.href = url;
|
||
a.download = filename;
|
||
document.body.appendChild(a);
|
||
a.click();
|
||
window.URL.revokeObjectURL(url);
|
||
|
||
// Clean up and reload
|
||
$paymentFormContainer.hide();
|
||
displayMsg(1, 'Rechnung erfolgreich erstellt!');
|
||
|
||
setTimeout(() => {
|
||
window.location.reload();
|
||
}, 1500);
|
||
})
|
||
.catch(err => {
|
||
console.error(err);
|
||
alert('Fehler: ' + err.message);
|
||
$submitBtn.text(originalText).prop('disabled', false);
|
||
});
|
||
});
|
||
$(document).on('click', '.cellStartgebuer[data-type="delete"]', function () {
|
||
|
||
const el = $(this);
|
||
|
||
const id = el.data('id');
|
||
|
||
const url = '/intern/scripts/trainer/ajax-remove_basket_item.php';
|
||
fetch(url, {
|
||
method: 'POST',
|
||
headers: {'Content-Type': 'application/x-www-form-urlencoded'},
|
||
body: new URLSearchParams({
|
||
id: id,
|
||
csrf_token
|
||
})
|
||
})
|
||
.then(response => {
|
||
if (!response.ok) {
|
||
throw new Error(`HTTP ${response.status}`);
|
||
}
|
||
|
||
return response.text();
|
||
})
|
||
.then(a => {
|
||
console.log(id);
|
||
$('.rowStartgebuer[data-id="' + id + '"]').remove();
|
||
|
||
let newcost = 0;
|
||
|
||
if ($('.cellStartgebuer[data-type="startgebuer"]').length < 1) {
|
||
$('.tableStartgebueren').addClass('hidden');
|
||
$('.checkoutButton').addClass('hidden');
|
||
$('#textKeineStartgebuerenAusgewählt').removeClass('hidden');
|
||
}
|
||
|
||
$( '.cellStartgebuer[data-type="startgebuer"]' ).each(function(){
|
||
newcost += parseFloat($(this).text().replace(/\s*Fr\.?/g, ""));
|
||
});
|
||
|
||
$('.totalStartgebueren').text(newcost.toFixed(2) + " Fr.");
|
||
})
|
||
|
||
});
|
||
});
|
||
</script>
|
||
|
||
<script>
|
||
flatpickr("#geburtsdatum", {
|
||
locale: "de",
|
||
dateFormat: "Y-m-d",
|
||
altInput: true,
|
||
altFormat: "d. F Y",
|
||
allowInput: true,
|
||
disableMobile: "true",
|
||
|
||
minDate: "1920-01-01",
|
||
maxDate: "today"
|
||
});
|
||
</script>
|
||
|
||
<?php
|
||
if (isset($_SESSION['form_message']) && $_SESSION['form_message'] !== '' && isset($_SESSION['form_message_type']) && (intval($_SESSION['form_message_type']) === 0 || intval($_SESSION['form_message_type']) === 1)) {
|
||
echo '<script>displayMsg('.intval($_SESSION['form_message_type']).', "'.$_SESSION['form_message'].'");</script>';
|
||
unset($_SESSION['form_message']);
|
||
unset($_SESSION['form_message_type']);
|
||
}
|
||
?>
|