2022-02-09 15:59:20 +00:00
|
|
|
<?php
|
|
|
|
$app = require '../../../app/inc.php';
|
|
|
|
|
|
|
|
$model = $app->model('Teamtable');
|
|
|
|
|
|
|
|
if (!isset($_GET['item']))
|
|
|
|
{
|
2022-02-14 01:52:59 +00:00
|
|
|
$app->session->flash('Kunne ikke slette lag: ID ikke definert som GET parameter', 'danger');
|
2022-02-09 15:59:20 +00:00
|
|
|
$app->redirect('index.php');
|
|
|
|
}
|
|
|
|
$id = $_GET['item'];
|
|
|
|
|
|
|
|
// ID must be numeric
|
|
|
|
if (!is_numeric($id))
|
|
|
|
{
|
2022-02-14 01:52:59 +00:00
|
|
|
$app->session->flash('Kunne ikke slette lag: ID må være tall', 'danger');
|
2022-02-09 15:59:20 +00:00
|
|
|
$app->redirect('index.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if ID is in teamtable
|
|
|
|
$currentTeam = $model->getTeamByID($id);
|
|
|
|
if (!$currentTeam)
|
|
|
|
{
|
2022-02-14 01:52:59 +00:00
|
|
|
$app->session->flash("Kunne ikke slette lag: ID $id finnes ikke", "danger");
|
2022-02-09 15:59:20 +00:00
|
|
|
$app->redirect('index.php');
|
|
|
|
}
|
|
|
|
|
2022-02-15 11:26:15 +00:00
|
|
|
$sameAsTemplate = $model->isEqualEmptyTemplate($currentTeam);
|
|
|
|
|
2022-02-14 01:52:59 +00:00
|
|
|
// Show confirmation page
|
2022-02-15 11:26:15 +00:00
|
|
|
if (isset($_GET['confirmation']) && $_GET['confirmation'] == 'true' && !$sameAsTemplate)
|
2022-02-14 01:52:59 +00:00
|
|
|
{
|
|
|
|
$app->view('template/header', ['title' => 'Bekreft sletting']);
|
|
|
|
$app->view('pages/teamtable/edit/delete', ['currentTeam' => $currentTeam]);
|
|
|
|
$app->view('template/footer');
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2022-02-09 15:59:20 +00:00
|
|
|
$model->deleteTeamByID($id);
|
|
|
|
|
2022-02-15 11:26:15 +00:00
|
|
|
if ($sameAsTemplate) {
|
|
|
|
$app->session->flash("Slettet lagmal", "success");
|
|
|
|
} else {
|
|
|
|
$app->session->flash("Slettet lag: {$currentTeam['LagNavn']}", "success");
|
|
|
|
}
|
2022-02-09 15:59:20 +00:00
|
|
|
|
|
|
|
$app->redirect('index.php');
|