diff --git a/includes/admin-teilnehmer.php b/includes/admin-teilnehmer.php
index 0ceae29..052ec1a 100644
--- a/includes/admin-teilnehmer.php
+++ b/includes/admin-teilnehmer.php
@@ -23,18 +23,36 @@ function kc_teilnehmer_page() {
}
}
- // CSV-Export (alle Teilnehmer oder gefiltert nach Wahl)
+ // CSV-Export (alle Teilnehmer oder gefiltert nach Wahl/Phase)
if (isset($_GET['export_csv']) && current_user_can('manage_options')) {
$export_wahl_id = isset($_GET['wahl_id']) ? intval($_GET['wahl_id']) : 0;
+ $export_phase = isset($_GET['phase']) ? intval($_GET['phase']) : 0;
$sql = "SELECT * FROM {$prefix}kc_teilnehmer";
- if ($export_wahl_id > 0) {
+ if ($export_wahl_id > 0 && $export_phase > 0) {
+ $sql .= $wpdb->prepare(" WHERE wahl_id=%d AND phase=%d", $export_wahl_id, $export_phase);
+ } elseif ($export_wahl_id > 0) {
$sql .= $wpdb->prepare(" WHERE wahl_id=%d", $export_wahl_id);
+ } elseif ($export_phase > 0) {
+ $sql .= $wpdb->prepare(" WHERE phase=%d", $export_phase);
}
$sql .= " ORDER BY wahl_id, phase, nachname, vorname";
$export_rows = $wpdb->get_results($sql);
- $filename_suffix = $export_wahl_id > 0 ? '_wahl_'.$export_wahl_id : '_alle';
+ $filename_suffix = '_alle';
+ if ($export_wahl_id > 0) {
+ $wahl_name_for_file = isset($wahl_name_map[$export_wahl_id]) ? $wahl_name_map[$export_wahl_id] : ('wahl_'.$export_wahl_id);
+ $wahl_slug = sanitize_title($wahl_name_for_file);
+ if ($wahl_slug === '') {
+ $wahl_slug = 'wahl_'.$export_wahl_id;
+ }
+ $filename_suffix = '_'.$wahl_slug;
+ if ($export_phase > 0) {
+ $filename_suffix .= '_phase_'.$export_phase;
+ }
+ } elseif ($export_phase > 0) {
+ $filename_suffix = '_phase_'.$export_phase;
+ }
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename="kc_teilnehmer'.$filename_suffix.'.csv"');
echo "\xEF\xBB\xBF";
@@ -284,11 +302,33 @@ function kc_teilnehmer_page() {
// Übersicht
// 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 '
';
echo '
Alle Teilnehmer
';
- echo '
CSV Export';
+ echo '
CSV Export (Ansicht)';
echo '
+ Neuer Teilnehmer';
+ // Manuelle Export-Auswahl (Wahl + Phase)
+ echo '
';
+
// Wahl-Filter-Buttons sortiert nach KC1, KC2, KC3, dann Rest
$kc_buttons = [];
$rest_buttons = [];
@@ -382,11 +422,50 @@ function kc_teilnehmer_page() {
var rows = Array.prototype.slice.call(document.querySelectorAll(".kc-admin-table tbody tr"));
var status = document.getElementById("kc-wahl-filter-count");
var phaseRow = document.getElementById("kc-phase-filter-row");
+ 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
var wahlMap = '.json_encode($wahl_map, JSON_HEX_TAG|JSON_HEX_APOS|JSON_HEX_QUOT|JSON_HEX_AMP).';
var currentWahl = "";
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() {
+ if (!exportBtn) return;
+ var href = "?page=kc_teilnehmer&export_csv=1";
+ if (currentWahl) href += "&wahl_id=" + encodeURIComponent(currentWahl);
+ if (currentPhase) href += "&phase=" + encodeURIComponent(currentPhase);
+ exportBtn.setAttribute("href", href);
+ }
+
function renderPhaseButtons(wahlId) {
phaseRow.innerHTML = "";
if (!wahlId || !wahlMap[wahlId]) { phaseRow.style.display = "none"; currentPhase = ""; return; }
@@ -432,6 +511,7 @@ function kc_teilnehmer_page() {
if (show) shown++;
});
if (status) status.textContent = (wahlId ? (shown+" angezeigt") : "Alle anzeigen");
+ updateExportButton();
}
function attachPhaseEvents() {
@@ -462,6 +542,14 @@ function kc_teilnehmer_page() {
if(btns.length) btns[0].classList.add("active");
renderPhaseButtons("");
applyFilter("", "");
+ updateExportButton();
+
+ if (exportWahlSelect) {
+ renderExportPhaseOptions(exportWahlSelect.value);
+ exportWahlSelect.addEventListener("change", function() {
+ renderExportPhaseOptions(this.value);
+ });
+ }
})();
';
echo '
';