All checks were successful
Deploy Workshop-Wahlen (DEV / PROD) / deploy (push) Successful in 13s
141 lines
6.7 KiB
PHP
141 lines
6.7 KiB
PHP
<?php
|
||
function kc_teamer_page() {
|
||
global $wpdb;
|
||
$prefix = $wpdb->prefix;
|
||
kc_admin_tabs('kc_teamer');
|
||
|
||
// --- Teamer access password (admin only) ---
|
||
if (isset($_POST['kc_teamer_pass_save'])) {
|
||
if (empty($_POST['kc_teamer_pass_nonce']) || !wp_verify_nonce($_POST['kc_teamer_pass_nonce'], 'kc_teamer_pass_action')) {
|
||
echo '<div class="notice notice-error">Ungültiger Request (Nonce).</div>';
|
||
} else {
|
||
$pw = trim($_POST['kc_teamer_password'] ?? '');
|
||
if ($pw === '') {
|
||
delete_option('kc_teamer_password_hash');
|
||
echo '<div class="notice notice-success">Teamer-Passwort entfernt.</div>';
|
||
} else {
|
||
update_option('kc_teamer_password_hash', wp_hash_password($pw));
|
||
echo '<div class="notice notice-success">Teamer-Passwort gespeichert.</div>';
|
||
}
|
||
}
|
||
}
|
||
|
||
// Show small management box for the password
|
||
$saved = get_option('kc_teamer_password_hash', '');
|
||
echo '<div class="kc-admin-table-wrap">';
|
||
echo '<h2 style="margin-top:0;">Teamer Zugriff</h2>';
|
||
echo '<form method="post" style="max-width:480px;">';
|
||
$nonce = wp_create_nonce('kc_teamer_pass_action');
|
||
echo '<input type="hidden" name="kc_teamer_pass_nonce" value="'.esc_attr($nonce).'">';
|
||
echo '<label style="display:block;margin-bottom:6px;font-weight:700;">Neues Teamer-Passwort (leer = entfernen)</label>';
|
||
echo '<label style="display:block;margin-bottom:6px;font-weight:700;">Shortcut = [konficastle_teamer_create]</label>';
|
||
echo '<input type="password" name="kc_teamer_password" value="" style="display:block;width:100%;padding:7px;margin-bottom:8px;">';
|
||
echo '<button name="kc_teamer_pass_save" class="kc-btn">Speichern</button>';
|
||
echo '</form>';
|
||
echo '</div>';
|
||
|
||
// Teamer l<>schen
|
||
if (isset($_GET['delete_teamer'])) {
|
||
$tid = intval($_GET['delete_teamer']);
|
||
$wpdb->delete("{$prefix}kc_teamer", ['id' => $tid]);
|
||
echo '<div class="notice notice-success">Teamer gelöscht!</div>';
|
||
}
|
||
|
||
// Teamer speichern (neu/<2F>ndern)
|
||
if (isset($_POST['kc_teamer_save'])) {
|
||
$data = [
|
||
'vorname' => sanitize_text_field($_POST['vorname']),
|
||
'nachname' => sanitize_text_field($_POST['nachname'])
|
||
];
|
||
if (!empty($_POST['tid'])) {
|
||
$wpdb->update("{$prefix}kc_teamer", $data, ['id'=>intval($_POST['tid'])]);
|
||
echo '<div class="notice notice-success">Teamer aktualisiert!</div>';
|
||
} else {
|
||
// Prüfe ob Kombination aus Vorname und Nachname bereits existiert
|
||
$existing = $wpdb->get_var($wpdb->prepare(
|
||
"SELECT COUNT(*) FROM {$prefix}kc_teamer WHERE vorname = %s AND nachname = %s",
|
||
$data['vorname'],
|
||
$data['nachname']
|
||
));
|
||
|
||
if ($existing > 0) {
|
||
echo '<div class="notice notice-error">Ein Teamer mit dieser Kombination aus Vor- und Nachname existiert bereits!</div>';
|
||
} else {
|
||
$wpdb->insert("{$prefix}kc_teamer", $data);
|
||
echo '<div class="notice notice-success">Teamer angelegt!</div>';
|
||
}
|
||
}
|
||
}
|
||
|
||
// Teamer bearbeiten
|
||
if (isset($_GET['edit_teamer'])) {
|
||
$tid = intval($_GET['edit_teamer']);
|
||
$tm = $wpdb->get_row("SELECT * FROM {$prefix}kc_teamer WHERE id=$tid");
|
||
echo '<div class="kc-admin-table-wrap">';
|
||
echo '<h2>Teamer bearbeiten</h2>
|
||
<form method="post">
|
||
<input type="hidden" name="tid" value="'.intval($tm->id).'">
|
||
<input type="text" name="vorname" placeholder="Vorname" value="'.esc_attr($tm->vorname).'" required style="margin-bottom:8px;width:100%;padding:7px;">
|
||
<input type="text" name="nachname" placeholder="Nachname (optional)" value="'.esc_attr($tm->nachname).'" style="margin-bottom:8px;width:100%;padding:7px;">
|
||
<button name="kc_teamer_save" class="kc-btn">Speichern</button>
|
||
<a href="?page=kc_teamer" class="kc-btn del" style="margin-left:24px;">Abbrechen</a>
|
||
</form>';
|
||
echo '</div>';
|
||
return;
|
||
}
|
||
|
||
// Neuen Teamer anlegen
|
||
if (isset($_GET['new'])) {
|
||
echo '<div class="kc-admin-table-wrap">';
|
||
echo '<h2>Neuen Teamer anlegen</h2>
|
||
<form method="post">
|
||
<input type="text" name="vorname" placeholder="Vorname" required style="margin-bottom:8px;width:100%;padding:7px;">
|
||
<input type="text" name="nachname" placeholder="Nachname (optional)" style="margin-bottom:8px;width:100%;padding:7px;">
|
||
<button name="kc_teamer_save" class="kc-btn">Speichern</button>
|
||
<a href="?page=kc_teamer" class="kc-btn del" style="margin-left:24px;">Abbrechen</a>
|
||
</form>';
|
||
echo '</div>';
|
||
return;
|
||
}
|
||
|
||
// <20>bersicht
|
||
echo '<div class="kc-admin-table-wrap">';
|
||
echo '<h2 style="margin-top:0;">Alle Teamer</h2>';
|
||
echo '<a class="kc-btn" style="float:right;margin-bottom:12px;" href="?page=kc_teamer&new=1">+ Neuer Teamer</a>';
|
||
|
||
// Sortierung
|
||
$sort = isset($_GET['sort']) ? sanitize_text_field($_GET['sort']) : 'vorname';
|
||
$order = isset($_GET['order']) ? (($_GET['order'] === 'desc') ? 'DESC' : 'ASC') : 'ASC';
|
||
$allowed_sort = ['vorname', 'nachname', 'id'];
|
||
if (!in_array($sort, $allowed_sort)) {
|
||
$sort = 'vorname';
|
||
}
|
||
|
||
// Sortier-Links
|
||
$vorname_order = ($sort === 'vorname' && $order === 'ASC') ? 'desc' : 'asc';
|
||
$nachname_order = ($sort === 'nachname' && $order === 'ASC') ? 'desc' : 'asc';
|
||
$vorname_arrow = ($sort === 'vorname') ? ($order === 'ASC' ? ' ▲' : ' ▼') : '';
|
||
$nachname_arrow = ($sort === 'nachname') ? ($order === 'ASC' ? ' ▲' : ' ▼') : '';
|
||
|
||
echo '<table class="kc-admin-table">';
|
||
echo '<thead><tr>';
|
||
echo '<th><a href="?page=kc_teamer&sort=vorname&order='.$vorname_order.'" style="text-decoration:none;color:inherit;">Vorname'.$vorname_arrow.'</a></th>';
|
||
echo '<th><a href="?page=kc_teamer&sort=nachname&order='.$nachname_order.'" style="text-decoration:none;color:inherit;">Nachname'.$nachname_arrow.'</a></th>';
|
||
echo '<th>Aktion</th>';
|
||
echo '</tr></thead><tbody>';
|
||
|
||
$teamer = $wpdb->get_results("SELECT * FROM {$prefix}kc_teamer ORDER BY {$sort} {$order}");
|
||
foreach ($teamer as $tm) {
|
||
echo "<tr>
|
||
<td>".esc_html($tm->vorname)."</td>
|
||
<td>".esc_html($tm->nachname)."</td>
|
||
<td class='kc-actions'>
|
||
<a class='kc-btn edit' href='?page=kc_teamer&edit_teamer={$tm->id}'>Bearbeiten</a>
|
||
<a class='kc-btn del' href='?page=kc_teamer&delete_teamer={$tm->id}' onclick=\"return confirm('Wirklich loeschen?');\">Loeschen</a>
|
||
</td>
|
||
</tr>";
|
||
}
|
||
echo '</tbody></table>';
|
||
echo '</div>';
|
||
}
|
||
?>
|