update Export Feature
All checks were successful
Deploy Workshop-Wahlen (DEV / PROD) / deploy (push) Successful in 13s

This commit is contained in:
ProgrammGamer
2026-02-25 18:15:11 +01:00
parent 64c4297e8d
commit 876223400e

View File

@@ -59,20 +59,34 @@ function kc_teilnehmer_page() {
$output = fopen('php://output', 'w'); $output = fopen('php://output', 'w');
$delimiter = ';'; $delimiter = ';';
fputcsv($output, ['Vorname','Nachname','Wahl','Phase'], $delimiter); fputcsv($output, ['Vorname','Nachname','Wahl','Phase','Wunsch 1','Wunsch 2','Wunsch 3'], $delimiter);
foreach ($export_rows as $tn) { foreach ($export_rows as $tn) {
$w1_id = intval($tn->wunsch1);
$w2_id = intval($tn->wunsch2);
$w3_id = intval($tn->wunsch3);
$w1_disp = $w1_id && isset($workshops_map[$w1_id]) ? $workshops_map[$w1_id] : ($w1_id ? strval($w1_id) : '');
$w2_disp = $w2_id && isset($workshops_map[$w2_id]) ? $workshops_map[$w2_id] : ($w2_id ? strval($w2_id) : '');
$w3_disp = $w3_id && isset($workshops_map[$w3_id]) ? $workshops_map[$w3_id] : ($w3_id ? strval($w3_id) : '');
$wahl_name = isset($wahl_name_map[intval($tn->wahl_id)]) ? $wahl_name_map[intval($tn->wahl_id)] : ''; $wahl_name = isset($wahl_name_map[intval($tn->wahl_id)]) ? $wahl_name_map[intval($tn->wahl_id)] : '';
$vorname = preg_replace('/<[^>]*>/', '', $tn->vorname); $vorname = preg_replace('/<[^>]*>/', '', $tn->vorname);
$nachname = preg_replace('/<[^>]*>/', '', $tn->nachname); $nachname = preg_replace('/<[^>]*>/', '', $tn->nachname);
$wahl_name_clean = preg_replace('/<[^>]*>/', '', $wahl_name); $wahl_name_clean = preg_replace('/<[^>]*>/', '', $wahl_name);
$w1_clean = preg_replace('/<[^>]*>/', '', $w1_disp);
$w2_clean = preg_replace('/<[^>]*>/', '', $w2_disp);
$w3_clean = preg_replace('/<[^>]*>/', '', $w3_disp);
fputcsv($output, [ fputcsv($output, [
$vorname, $vorname,
$nachname, $nachname,
$wahl_name_clean, $wahl_name_clean,
intval($tn->phase) intval($tn->phase),
$w1_clean,
$w2_clean,
$w3_clean
], $delimiter); ], $delimiter);
} }
@@ -288,33 +302,11 @@ function kc_teilnehmer_page() {
// Übersicht // Übersicht
// Map für Wahl-ID => Name ist bereits oben aufgebaut // Map für Wahl-ID => Name ist bereits oben aufgebaut
$selected_export_wahl = isset($_GET['wahl_id']) ? intval($_GET['wahl_id']) : 0;
$selected_export_phase = isset($_GET['phase']) ? intval($_GET['phase']) : 0;
echo '<div class="kc-admin-table-wrap">'; echo '<div class="kc-admin-table-wrap">';
echo '<h2 style="margin-top:0;">Alle Teilnehmer</h2>'; echo '<h2 style="margin-top:0;">Alle Teilnehmer</h2>';
echo '<a id="kc-export-current-view" class="kc-btn" style="float:right;margin-right:8px;margin-bottom:12px;background:#2da66a;color:#fff;" href="?page=kc_teilnehmer&export_csv=1">Teilnehmer-Export (Ansicht)</a>'; echo '<a id="kc-export-current-view" class="kc-btn" style="float:right;margin-right:8px;margin-bottom:12px;background:#2da66a;color:#fff;" href="?page=kc_teilnehmer&export_csv=1">Teilnehmer-Export (Ansicht)</a>';
echo '<a class="kc-btn" style="float:right;margin-bottom:12px;" href="?page=kc_teilnehmer&new=1">+ Neuer Teilnehmer</a>'; echo '<a class="kc-btn" style="float:right;margin-bottom:12px;" href="?page=kc_teilnehmer&new=1">+ Neuer Teilnehmer</a>';
// Manuelle Export-Auswahl (Wahl + Phase)
echo '<form method="get" id="kc-export-form" style="clear:both;margin:8px 0 12px 0;display:flex;gap:8px;align-items:center;flex-wrap:wrap;">';
echo '<input type="hidden" name="page" value="kc_teilnehmer">';
echo '<input type="hidden" name="export_csv" value="1">';
echo '<label for="kc-export-wahl" style="font-weight:600;">Export Wahl:</label>';
echo '<select id="kc-export-wahl" name="wahl_id" style="padding:6px 8px;min-width:180px;">';
echo '<option value="">Alle Wahlen</option>';
foreach($all_wahlen as $w) {
$selected = ($selected_export_wahl === intval($w->id)) ? ' selected' : '';
echo '<option value="'.intval($w->id).'"'.$selected.'>'.esc_html($w->name).'</option>';
}
echo '</select>';
echo '<label for="kc-export-phase" style="font-weight:600;">Phase:</label>';
echo '<select id="kc-export-phase" name="phase" data-current="'.intval($selected_export_phase).'" style="padding:6px 8px;min-width:140px;">';
echo '<option value="">Alle Phasen</option>';
echo '</select>';
echo '<button type="submit" class="kc-btn" style="background:#2da66a;color:#fff;">Teilnehmer-Export (Auswahl)</button>';
echo '</form>';
// Wahl-Filter-Buttons sortiert nach KC1, KC2, KC3, dann Rest // Wahl-Filter-Buttons sortiert nach KC1, KC2, KC3, dann Rest
$kc_buttons = []; $kc_buttons = [];
$rest_buttons = []; $rest_buttons = [];
@@ -409,41 +401,11 @@ function kc_teilnehmer_page() {
var status = document.getElementById("kc-wahl-filter-count"); var status = document.getElementById("kc-wahl-filter-count");
var phaseRow = document.getElementById("kc-phase-filter-row"); var phaseRow = document.getElementById("kc-phase-filter-row");
var exportBtn = document.getElementById("kc-export-current-view"); var exportBtn = document.getElementById("kc-export-current-view");
var exportWahlSelect = document.getElementById("kc-export-wahl");
var exportPhaseSelect = document.getElementById("kc-export-phase");
// Wahl-Map für Phasen // Wahl-Map für Phasen
var wahlMap = '.json_encode($wahl_map, JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP).'; var wahlMap = '.json_encode($wahl_map, JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP).';
var currentWahl = ""; var currentWahl = "";
var currentPhase = ""; var currentPhase = "";
function renderExportPhaseOptions(wahlId) {
if (!exportPhaseSelect) return;
var wanted = exportPhaseSelect.getAttribute("data-current") || exportPhaseSelect.value || "";
exportPhaseSelect.innerHTML = "";
var allOpt = document.createElement("option");
allOpt.value = "";
allOpt.text = "Alle Phasen";
exportPhaseSelect.appendChild(allOpt);
if (wahlId && wahlMap[wahlId]) {
var maxPh = wahlMap[wahlId].phases || 1;
for (var i = 1; i <= maxPh; i++) {
var o = document.createElement("option");
o.value = String(i);
o.text = String(i);
exportPhaseSelect.appendChild(o);
}
}
if (wanted && exportPhaseSelect.querySelector("option[value=\"" + wanted + "\"]")) {
exportPhaseSelect.value = wanted;
} else {
exportPhaseSelect.value = "";
}
exportPhaseSelect.setAttribute("data-current", "");
}
function updateExportButton() { function updateExportButton() {
if (!exportBtn) return; if (!exportBtn) return;
var href = "?page=kc_teilnehmer&export_csv=1"; var href = "?page=kc_teilnehmer&export_csv=1";
@@ -529,13 +491,6 @@ function kc_teilnehmer_page() {
renderPhaseButtons(""); renderPhaseButtons("");
applyFilter("", ""); applyFilter("", "");
updateExportButton(); updateExportButton();
if (exportWahlSelect) {
renderExportPhaseOptions(exportWahlSelect.value);
exportWahlSelect.addEventListener("change", function() {
renderExportPhaseOptions(this.value);
});
}
})(); })();
</script>'; </script>';
echo '</div>'; echo '</div>';