104 lines
2.3 KiB
PHP
104 lines
2.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace App\Controllers;
|
||
|
|
|
||
|
|
use App\Core\Auth;
|
||
|
|
use App\Models\Page;
|
||
|
|
|
||
|
|
class AdminController
|
||
|
|
{
|
||
|
|
public function uploadTourplan(): void
|
||
|
|
{
|
||
|
|
view('admin.upload_tourplan');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function storeTourplan(): void
|
||
|
|
{
|
||
|
|
validate(['tourplan' => 'required|mimes:pdf']);
|
||
|
|
|
||
|
|
$dir = storage_path('img_storage/pdf');
|
||
|
|
if (!is_dir($dir)) {
|
||
|
|
mkdir($dir, 0777, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
move_uploaded_file($_FILES['tourplan']['tmp_name'], $dir . '/Tourenplan.pdf');
|
||
|
|
|
||
|
|
redirect('/');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function uploadMitgliedsantrag(): void
|
||
|
|
{
|
||
|
|
view('admin.upload_mitgliedsantrag');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function storeMitgliedsantrag(): void
|
||
|
|
{
|
||
|
|
validate(['mitgliedsantrag' => 'required|mimes:pdf']);
|
||
|
|
|
||
|
|
$dir = public_path('img/pdf');
|
||
|
|
if (!is_dir($dir)) {
|
||
|
|
mkdir($dir, 0777, true);
|
||
|
|
}
|
||
|
|
|
||
|
|
move_uploaded_file($_FILES['mitgliedsantrag']['tmp_name'], $dir . '/Mitgliedsantrag.pdf');
|
||
|
|
|
||
|
|
redirect('/');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function editHome(): void
|
||
|
|
{
|
||
|
|
$page = Page::byName('home');
|
||
|
|
|
||
|
|
view('admin.edit_home', ['content' => $page->content ?? '']);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function storeHome(): void
|
||
|
|
{
|
||
|
|
validate(['pagecontent' => 'required']);
|
||
|
|
|
||
|
|
$page = Page::byName('home');
|
||
|
|
|
||
|
|
if ($page !== null) {
|
||
|
|
$page->content = (string) input('pagecontent');
|
||
|
|
$page->updated_at = now();
|
||
|
|
$page->save();
|
||
|
|
}
|
||
|
|
|
||
|
|
redirect('/');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function editActivities(): void
|
||
|
|
{
|
||
|
|
$page = Page::byName('activities');
|
||
|
|
$content = str_replace('<br/><br/>', "\n\n", $page->content ?? '');
|
||
|
|
|
||
|
|
view('admin.edit_activities', ['content' => $content]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function storeActivities(): void
|
||
|
|
{
|
||
|
|
validate(['pagecontent' => 'required']);
|
||
|
|
|
||
|
|
$page = Page::byName('activities');
|
||
|
|
|
||
|
|
if ($page !== null) {
|
||
|
|
$page->content = str_replace("\n\n", '<br/><br/>', (string) input('pagecontent'));
|
||
|
|
$page->updated_at = now();
|
||
|
|
$page->save();
|
||
|
|
}
|
||
|
|
|
||
|
|
redirect('/activities');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function deleteGuests(): void
|
||
|
|
{
|
||
|
|
if (Auth::user()->isAdmin()) {
|
||
|
|
db()->execute("DELETE FROM `users` WHERE role = 'GUEST'");
|
||
|
|
}
|
||
|
|
|
||
|
|
redirect('/');
|
||
|
|
}
|
||
|
|
}
|