This repository has been archived on 2023-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
web/public/race/configure/teams/delete.php
2022-03-30 19:11:34 +00:00

38 lines
1.0 KiB
PHP

<?php $app = require '../../../../app/inc.php';
use App\Teamtable\Team;
use App\Teamtable\TeamMapper;
$item = filter_input(INPUT_GET, 'item', FILTER_VALIDATE_INT);
$confirm = filter_input(INPUT_GET, 'confirm', FILTER_VALIDATE_BOOLEAN);
$teamMapper = new TeamMapper($app->database->conn);
// item is NULL if not set
if ($item === NULL)
{
$app->session->flash('Kunne ikke slette lag: Mangler parameter.', 'danger');
$app->redirect('index.php');
}
$team = $teamMapper->get($item);
if (!$team)
{
// team does not exist
$app->session->flash('Kunne ikke slette lag: Lag eksisterer ikke', 'danger');
$app->redirect('index.php');
}
// show confirmation page
if (!$confirm)
{
$app->view('template/header', ['title' => 'Bekreft sletting']);
$app->view('pages/race/configure/teams/delete', ['team' => $team]);
$app->view('template/footer');
die();
}
// all is good, lets delete the team
$teamMapper->delete($team->id);
$app->session->flash("Slettet lag: {$team->name}", "success");
$app->redirect('index.php');