update Teilnehmer Export
All checks were successful
Deploy Workshop-Wahlen (DEV / PROD) / deploy (push) Successful in 13s
All checks were successful
Deploy Workshop-Wahlen (DEV / PROD) / deploy (push) Successful in 13s
This commit is contained in:
@@ -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')) {
|
if (isset($_GET['export_csv']) && current_user_can('manage_options')) {
|
||||||
$export_wahl_id = isset($_GET['wahl_id']) ? intval($_GET['wahl_id']) : 0;
|
$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";
|
$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);
|
$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";
|
$sql .= " ORDER BY wahl_id, phase, nachname, vorname";
|
||||||
$export_rows = $wpdb->get_results($sql);
|
$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-Type: text/csv; charset=utf-8');
|
||||||
header('Content-Disposition: attachment; filename="kc_teilnehmer'.$filename_suffix.'.csv"');
|
header('Content-Disposition: attachment; filename="kc_teilnehmer'.$filename_suffix.'.csv"');
|
||||||
echo "\xEF\xBB\xBF";
|
echo "\xEF\xBB\xBF";
|
||||||
@@ -284,11 +302,33 @@ 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 class="kc-btn" style="float:right;margin-right:8px;margin-bottom:12px;background:#2da66a;color:#fff;" href="?page=kc_teilnehmer&export_csv=1">CSV Export</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">CSV 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;">CSV 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 = [];
|
||||||
@@ -382,11 +422,50 @@ function kc_teilnehmer_page() {
|
|||||||
var rows = Array.prototype.slice.call(document.querySelectorAll(".kc-admin-table tbody tr"));
|
var rows = Array.prototype.slice.call(document.querySelectorAll(".kc-admin-table tbody tr"));
|
||||||
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 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() {
|
||||||
|
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) {
|
function renderPhaseButtons(wahlId) {
|
||||||
phaseRow.innerHTML = "";
|
phaseRow.innerHTML = "";
|
||||||
if (!wahlId || !wahlMap[wahlId]) { phaseRow.style.display = "none"; currentPhase = ""; return; }
|
if (!wahlId || !wahlMap[wahlId]) { phaseRow.style.display = "none"; currentPhase = ""; return; }
|
||||||
@@ -432,6 +511,7 @@ function kc_teilnehmer_page() {
|
|||||||
if (show) shown++;
|
if (show) shown++;
|
||||||
});
|
});
|
||||||
if (status) status.textContent = (wahlId ? (shown+" angezeigt") : "Alle anzeigen");
|
if (status) status.textContent = (wahlId ? (shown+" angezeigt") : "Alle anzeigen");
|
||||||
|
updateExportButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
function attachPhaseEvents() {
|
function attachPhaseEvents() {
|
||||||
@@ -462,6 +542,14 @@ function kc_teilnehmer_page() {
|
|||||||
if(btns.length) btns[0].classList.add("active");
|
if(btns.length) btns[0].classList.add("active");
|
||||||
renderPhaseButtons("");
|
renderPhaseButtons("");
|
||||||
applyFilter("", "");
|
applyFilter("", "");
|
||||||
|
updateExportButton();
|
||||||
|
|
||||||
|
if (exportWahlSelect) {
|
||||||
|
renderExportPhaseOptions(exportWahlSelect.value);
|
||||||
|
exportWahlSelect.addEventListener("change", function() {
|
||||||
|
renderExportPhaseOptions(this.value);
|
||||||
|
});
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
</script>';
|
</script>';
|
||||||
echo '</div>';
|
echo '</div>';
|
||||||
|
|||||||
Reference in New Issue
Block a user