2022-03-07 06:13:17 +00:00
|
|
|
<?php $app = require '../../../app/inc.php';
|
2022-03-07 10:11:33 +00:00
|
|
|
/**
|
|
|
|
* Creates and updates team in teamtable
|
|
|
|
*/
|
2022-02-14 01:52:59 +00:00
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
use App\Teamtable\Team;
|
2022-02-14 01:52:59 +00:00
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
$item = filter_input(INPUT_GET, 'item', FILTER_VALIDATE_INT);
|
2022-02-14 01:52:59 +00:00
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
$model = $app->model('Teamtable');
|
2022-02-14 01:52:59 +00:00
|
|
|
|
2022-03-10 08:38:39 +00:00
|
|
|
$team;
|
2022-03-07 06:13:17 +00:00
|
|
|
if ($item !== NULL)
|
2022-02-14 10:23:05 +00:00
|
|
|
{
|
2022-03-07 06:13:17 +00:00
|
|
|
$team = $model->get($item);
|
|
|
|
if (!$team)
|
2022-02-14 10:23:05 +00:00
|
|
|
{
|
2022-03-07 06:13:17 +00:00
|
|
|
// team does not exist
|
2022-03-07 10:11:33 +00:00
|
|
|
$app->session->flash('Kunne ikke oppdatere lag: Lag finnes ikke', 'danger');
|
2022-03-07 06:13:17 +00:00
|
|
|
$app->redirect('index.php');
|
2022-02-14 10:23:05 +00:00
|
|
|
}
|
|
|
|
}
|
2022-02-14 01:52:59 +00:00
|
|
|
|
2022-03-07 10:11:33 +00:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
|
|
|
{
|
|
|
|
$name = filter_input(INPUT_POST, 'name');
|
|
|
|
$company = filter_input(INPUT_POST, 'company');
|
|
|
|
$cardnumber = filter_input(INPUT_POST, 'cardnumber');
|
|
|
|
$leader = filter_input(INPUT_POST, 'leader');
|
|
|
|
$phone = filter_input(INPUT_POST, 'phone', FILTER_VALIDATE_INT);
|
|
|
|
$participants = filter_input(INPUT_POST, 'participants', FILTER_VALIDATE_INT);
|
|
|
|
$rounds = filter_input(INPUT_POST, 'rounds', FILTER_VALIDATE_INT);
|
|
|
|
|
|
|
|
$team = new Team;
|
|
|
|
try {
|
|
|
|
$team->setName($name);
|
|
|
|
$team->setCompany($company);
|
|
|
|
$team->setCardnumber($cardnumber);
|
|
|
|
$team->setLeader($leader);
|
|
|
|
$team->setPhone($phone);
|
|
|
|
$team->setParticipants($participants);
|
|
|
|
$team->setRounds($rounds);
|
2022-03-09 12:11:17 +00:00
|
|
|
} catch(InvalidArgumentException $e) {
|
|
|
|
$app->session->flash('Kunne ikke oppdatere lag: Validerings feil: ' . $e->getMessage() , 'danger');
|
2022-03-07 10:11:33 +00:00
|
|
|
$app->redirect('index.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item !== NULL)
|
|
|
|
{
|
|
|
|
// team exists, lets update it
|
|
|
|
$team->id = $item;
|
|
|
|
$model->update($team);
|
|
|
|
$app->session->flash('Oppdaterte lag', 'success');
|
|
|
|
$app->redirect('index.php');
|
|
|
|
}
|
|
|
|
// no team was specified, lets create one
|
|
|
|
$model->create($team);
|
|
|
|
$app->session->flash('Opprettet nytt lag', 'success');
|
|
|
|
$app->redirect('index.php');
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($item !== NULL)
|
|
|
|
{
|
|
|
|
// team exists
|
|
|
|
$title = "Endre lag";
|
|
|
|
$app->view('template/header', [
|
|
|
|
'title' => $title
|
|
|
|
]);
|
|
|
|
$app->view('pages/teamtable/edit/update', [
|
|
|
|
"team" => $team,
|
|
|
|
"title" => $title
|
|
|
|
]);
|
|
|
|
$app->view('template/footer');
|
|
|
|
die();
|
|
|
|
}
|
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
// lets create a team
|
2022-03-07 10:11:33 +00:00
|
|
|
$title = "Legg til lag";
|
|
|
|
$app->view('template/header', [
|
|
|
|
'title' => $title
|
|
|
|
]);
|
|
|
|
$app->view('pages/teamtable/edit/update', [
|
|
|
|
"team" => new Team,
|
|
|
|
"title" => $title
|
|
|
|
]);
|
2022-02-14 01:52:59 +00:00
|
|
|
$app->view('template/footer');
|