88 lines
2.3 KiB
PHP
88 lines
2.3 KiB
PHP
<?php $app = require '../../../../app/inc.php';
|
|
/**
|
|
* Creates and updates team in teamtable
|
|
*/
|
|
|
|
use App\Teamtable\Team;
|
|
use App\Teamtable\TeamMapper;
|
|
|
|
$item = filter_input(INPUT_GET, 'item', FILTER_VALIDATE_INT);
|
|
|
|
$teamMapper = new TeamMapper($app->database->conn);
|
|
|
|
$team;
|
|
if ($item !== NULL)
|
|
{
|
|
$team = $teamMapper->get($item);
|
|
if (!$team)
|
|
{
|
|
// team does not exist
|
|
$app->session->flash('Kunne ikke oppdatere lag: Lag finnes ikke', 'danger');
|
|
$app->redirect('index.php');
|
|
}
|
|
}
|
|
|
|
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');
|
|
$participants = (int)filter_input(INPUT_POST, 'participants');
|
|
|
|
if (!isset($team))
|
|
{
|
|
$team = new Team();
|
|
}
|
|
try {
|
|
$team->setName($name);
|
|
$team->setCompany($company);
|
|
$team->setCardnumber($cardnumber);
|
|
$team->setLeader($leader);
|
|
$team->setPhone($phone);
|
|
$team->setParticipants($participants);
|
|
} catch(InvalidArgumentException $e) {
|
|
$app->session->flash('Kunne ikke oppdatere lag: Validerings feil: ' . $e->getMessage() , 'danger');
|
|
$app->redirect('index.php');
|
|
}
|
|
|
|
if ($item !== NULL)
|
|
{
|
|
// team exists, lets update it
|
|
$team->id = $item;
|
|
$teamMapper->update($team);
|
|
$app->session->flash('Oppdaterte lag', 'success');
|
|
$app->redirect('index.php');
|
|
}
|
|
// no team was specified, lets create one
|
|
$teamMapper->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/race/configure/teams/update', [
|
|
"team" => $team,
|
|
"title" => $title
|
|
]);
|
|
$app->view('template/footer');
|
|
die();
|
|
}
|
|
|
|
// lets create a team
|
|
$title = "Legg til lag";
|
|
$app->view('template/header', [
|
|
'title' => $title
|
|
]);
|
|
$app->view('pages/race/configure/teams/update', [
|
|
"team" => new Team,
|
|
"title" => $title
|
|
]);
|
|
$app->view('template/footer'); |