Anträge annehmen und Benutzer zu Mitglied machen
This commit is contained in:
parent
1137a794aa
commit
84c8e5b846
5 changed files with 164 additions and 4 deletions
|
|
@ -84,6 +84,8 @@ if (!tableExists($pdo, 'membership_applications')) {
|
|||
`unterschrift_2` varchar(255) DEFAULT NULL,
|
||||
`created_at` timestamp NULL DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
`accepted_at` timestamp NULL DEFAULT NULL,
|
||||
`accepted_by` bigint(20) unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;');
|
||||
$out("Tabelle 'membership_applications' angelegt");
|
||||
|
|
@ -91,6 +93,19 @@ if (!tableExists($pdo, 'membership_applications')) {
|
|||
$out("Tabelle 'membership_applications' existiert bereits (übersprungen)");
|
||||
}
|
||||
|
||||
// Spalten für die Annahme von Anträgen ergänzen
|
||||
foreach ([
|
||||
['accepted_at', 'ALTER TABLE `membership_applications` ADD COLUMN `accepted_at` timestamp NULL DEFAULT NULL AFTER `updated_at`'],
|
||||
['accepted_by', 'ALTER TABLE `membership_applications` ADD COLUMN `accepted_by` bigint(20) unsigned NULL DEFAULT NULL AFTER `accepted_at`'],
|
||||
] as [$column, $sql]) {
|
||||
if (!columnExists($pdo, 'membership_applications', $column)) {
|
||||
$pdo->exec($sql);
|
||||
$out("Spalte 'membership_applications.$column' angelegt");
|
||||
} else {
|
||||
$out("Spalte 'membership_applications.$column' existiert bereits");
|
||||
}
|
||||
}
|
||||
|
||||
// Unbenutzte Tabellen entfernen
|
||||
foreach (['migrations', 'failed_jobs', 'galleries', 'gallery_items', 'password_resets'] as $table) {
|
||||
if (tableExists($pdo, $table)) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ namespace App\Controllers;
|
|||
use App\Core\Auth;
|
||||
use App\Models\MembershipApplication;
|
||||
use App\Models\Page;
|
||||
use App\Models\User;
|
||||
|
||||
class AdminController
|
||||
{
|
||||
|
|
@ -64,7 +65,92 @@ class AdminController
|
|||
exit('Antrag nicht gefunden.');
|
||||
}
|
||||
|
||||
view('admin.application', ['application' => $application]);
|
||||
view('admin.application', [
|
||||
'application' => $application,
|
||||
'acceptedBy' => $application->accepted_by ? User::find((int) $application->accepted_by) : null,
|
||||
]);
|
||||
}
|
||||
|
||||
public function acceptApplication(string $id): void
|
||||
{
|
||||
$application = MembershipApplication::find((int) $id);
|
||||
|
||||
if ($application === null) {
|
||||
flash_set('error', 'Der Antrag wurde nicht gefunden.');
|
||||
redirect('/admin/antraege');
|
||||
}
|
||||
|
||||
if (!empty($application->accepted_at)) {
|
||||
flash_set('status', 'Der Antrag wurde bereits angenommen.');
|
||||
redirect('/admin/antraege/' . $id);
|
||||
}
|
||||
|
||||
$user = $application->user_id ? User::find((int) $application->user_id) : null;
|
||||
|
||||
if ($user === null && !empty($application->email)) {
|
||||
$user = User::byEmail((string) $application->email);
|
||||
}
|
||||
|
||||
if ($user === null) {
|
||||
flash_set('error', 'Zu diesem Antrag wurde kein Benutzerkonto gefunden. Bitte zuerst ein Konto mit der angegebenen E-Mail-Adresse anlegen.');
|
||||
redirect('/admin/antraege/' . $id);
|
||||
}
|
||||
|
||||
$roleChanged = false;
|
||||
|
||||
if ($user->role === 'GUEST') {
|
||||
$user->role = 'MEMBER';
|
||||
$user->updated_at = now();
|
||||
$user->save();
|
||||
$roleChanged = true;
|
||||
}
|
||||
|
||||
$application->user_id = (int) $user->id;
|
||||
$application->accepted_at = now();
|
||||
$application->accepted_by = Auth::id();
|
||||
$application->updated_at = now();
|
||||
$application->save();
|
||||
|
||||
app_log('info', 'Mitgliedsantrag angenommen', [
|
||||
'application_id' => (int) $id,
|
||||
'user_id' => (int) $user->id,
|
||||
'role' => $user->role,
|
||||
]);
|
||||
|
||||
flash_set('status', $roleChanged
|
||||
? 'Antrag angenommen. Der Benutzer ist jetzt Mitglied.'
|
||||
: 'Antrag angenommen. Der Benutzer hatte bereits eine Mitglieds- oder höhere Rolle.');
|
||||
|
||||
redirect('/admin/antraege/' . $id);
|
||||
}
|
||||
|
||||
public function deleteApplication(string $id): void
|
||||
{
|
||||
$application = MembershipApplication::find((int) $id);
|
||||
|
||||
if ($application === null) {
|
||||
flash_set('error', 'Der Antrag wurde nicht gefunden.');
|
||||
redirect('/admin/antraege');
|
||||
}
|
||||
|
||||
$dir = storage_path('img_storage/mitgliedsantrag');
|
||||
|
||||
foreach (['unterschrift_1', 'unterschrift_2'] as $field) {
|
||||
$file = basename((string) $application->$field);
|
||||
|
||||
if ($file !== '' && is_file($dir . '/' . $file)) {
|
||||
@unlink($dir . '/' . $file);
|
||||
}
|
||||
}
|
||||
|
||||
$application->delete();
|
||||
|
||||
app_log('info', 'Mitgliedsantrag gelöscht', [
|
||||
'application_id' => (int) $id,
|
||||
]);
|
||||
|
||||
flash_set('status', 'Der Antrag wurde gelöscht.');
|
||||
redirect('/admin/antraege');
|
||||
}
|
||||
|
||||
public function editHome(): void
|
||||
|
|
|
|||
|
|
@ -40,6 +40,8 @@ $router->get('/admin/upload_mitgliedsantrag', [AdminController::class, 'uploadMi
|
|||
$router->post('/admin/store_mitgliedsantrag', [AdminController::class, 'storeMitgliedsantrag'], 'ADMIN');
|
||||
$router->get('/admin/antraege', [AdminController::class, 'applications'], 'ADMIN');
|
||||
$router->get('/admin/antraege/{id}', [AdminController::class, 'application'], 'ADMIN');
|
||||
$router->post('/admin/antraege/{id}/accept', [AdminController::class, 'acceptApplication'], 'ADMIN');
|
||||
$router->post('/admin/antraege/{id}/delete', [AdminController::class, 'deleteApplication'], 'ADMIN');
|
||||
$router->get('/admin/edit_home', [AdminController::class, 'editHome'], 'ADMIN');
|
||||
$router->get('/admin/edit_activities', [AdminController::class, 'editActivities'], 'ADMIN');
|
||||
$router->post('/admin/store_home', [AdminController::class, 'storeHome'], 'ADMIN');
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
<?php $count = count($applications); ?>
|
||||
<?php
|
||||
$count = count($applications);
|
||||
$flashStatus = flash_pull('status');
|
||||
$flashError = flash_pull('error');
|
||||
?>
|
||||
|
||||
<div class="container text-light mt-5">
|
||||
<div class="row justify-content-center">
|
||||
|
|
@ -10,6 +14,14 @@
|
|||
|
||||
<div class="card text-dark">
|
||||
<div class="card-body">
|
||||
<?php if ($flashStatus !== null): ?>
|
||||
<div class="alert alert-success" role="alert"><?= e($flashStatus) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($flashError !== null): ?>
|
||||
<div class="alert alert-danger" role="alert"><?= e($flashError) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<p class="text-muted mb-3">
|
||||
<?= $count === 1 ? '1 eingereichter Antrag' : $count . ' eingereichte Anträge' ?>
|
||||
</p>
|
||||
|
|
@ -22,13 +34,14 @@
|
|||
<th scope="col">Name</th>
|
||||
<th scope="col">E-Mail</th>
|
||||
<th scope="col">Telefon</th>
|
||||
<th scope="col">Status</th>
|
||||
<th scope="col" class="text-right">Aktion</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php if ($applications === []): ?>
|
||||
<tr>
|
||||
<td colspan="5" class="text-muted">Es sind noch keine Anträge eingegangen.</td>
|
||||
<td colspan="6" class="text-muted">Es sind noch keine Anträge eingegangen.</td>
|
||||
</tr>
|
||||
<?php else: ?>
|
||||
<?php foreach ($applications as $application): ?>
|
||||
|
|
@ -39,10 +52,33 @@
|
|||
<td><?= e(trim($application->vorname . ' ' . $application->nachname)) ?></td>
|
||||
<td><?= e($application->email) ?></td>
|
||||
<td><?= e($application->telefon) ?></td>
|
||||
<td class="text-right">
|
||||
<td class="text-nowrap">
|
||||
<?php if (!empty($application->accepted_at)): ?>
|
||||
<span class="badge badge-success badge-pill">Angenommen</span>
|
||||
<?php else: ?>
|
||||
<span class="badge badge-warning badge-pill">Offen</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td class="text-right text-nowrap">
|
||||
<a href="/admin/antraege/<?= e($application->id) ?>" class="btn btn-sm btn-primary">
|
||||
Ansehen
|
||||
</a>
|
||||
<?php if (empty($application->accepted_at)): ?>
|
||||
<form action="/admin/antraege/<?= e($application->id) ?>/accept"
|
||||
method="POST"
|
||||
style="display:inline;"
|
||||
onsubmit="return confirm('Diesen Antrag annehmen und den Benutzer zum Mitglied machen?');">
|
||||
<?= csrf_field() ?>
|
||||
<button type="submit" class="btn btn-sm btn-success">Annehmen</button>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
<form action="/admin/antraege/<?= e($application->id) ?>/delete"
|
||||
method="POST"
|
||||
style="display:inline;"
|
||||
onsubmit="return confirm('Diesen Antrag wirklich löschen? Die Unterschriften werden ebenfalls entfernt.');">
|
||||
<?= csrf_field() ?>
|
||||
<button type="submit" class="btn btn-sm btn-outline-danger">Löschen</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
|
|
|
|||
|
|
@ -69,9 +69,30 @@ MIGRATIONS = [
|
|||
`unterschrift_2` varchar(255) DEFAULT NULL,
|
||||
`created_at` timestamp NULL DEFAULT NULL,
|
||||
`updated_at` timestamp NULL DEFAULT NULL,
|
||||
`accepted_at` timestamp NULL DEFAULT NULL,
|
||||
`accepted_by` bigint(20) unsigned DEFAULT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci''',
|
||||
|
||||
# Annahme-Felder für bestehende Installationen ergänzen (idempotent)
|
||||
'''SET @has_accepted_at := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'membership_applications' AND COLUMN_NAME = 'accepted_at');
|
||||
SET @sql := IF(@has_accepted_at = 0,
|
||||
'ALTER TABLE `membership_applications` ADD COLUMN `accepted_at` timestamp NULL DEFAULT NULL AFTER `updated_at`',
|
||||
'DO 0');
|
||||
PREPARE mig_stmt FROM @sql;
|
||||
EXECUTE mig_stmt;
|
||||
DEALLOCATE PREPARE mig_stmt''',
|
||||
|
||||
'''SET @has_accepted_by := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'membership_applications' AND COLUMN_NAME = 'accepted_by');
|
||||
SET @sql := IF(@has_accepted_by = 0,
|
||||
'ALTER TABLE `membership_applications` ADD COLUMN `accepted_by` bigint(20) unsigned NULL DEFAULT NULL AFTER `accepted_at`',
|
||||
'DO 0');
|
||||
PREPARE mig_stmt FROM @sql;
|
||||
EXECUTE mig_stmt;
|
||||
DEALLOCATE PREPARE mig_stmt''',
|
||||
|
||||
# tours.user_id -> tours.tour_guide_id umbenennen (idempotent)
|
||||
'''SET @has_user := (SELECT COUNT(*) FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'tours' AND COLUMN_NAME = 'user_id');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue