TODO commit

This commit is contained in:
William 2022-02-09 16:59:20 +01:00
parent e3e429e2ad
commit 5d5a998c35
5 changed files with 149 additions and 1 deletions

View File

@ -14,4 +14,28 @@ class Teamtable
$sth = $this->dbh->query('SELECT * FROM lagtabell');
return $sth->fetchAll(PDO::FETCH_ASSOC);
}
public function deleteTeamByID(int $LagID): void
{
$sth = $this->dbh->prepare('DELETE FROM lagtabell WHERE LagID = ?');
$sth->execute([$LagID]);
}
public function getTeamByID(int $LagID) # Mixed, array if exists, false if not
{
$sth = $this->dbh->prepare('SELECT * FROM lagtabell WHERE LagID = ?');
$sth->execute([$LagID]);
return $sth->fetch(PDO::FETCH_ASSOC);
}
public function updateTeam(int $id, array $params): void
{
$sth = $this->dbh->prepare('UPDATE lagtabell SET WHERE LagID = ?');
$sth->execute([$params]);
}
public function addTeam(int $id, array $params): void
{
// todo ...
}
}

View File

@ -0,0 +1,40 @@
<h1>Endre lagdetaljer</h1>
<form method="post">
<label for="navn">Navn:</label>
<br>
<input type="text" id="navn" name="navn" value="<?=$team['LagNavn']?>">
<br>
<label for="bedrift">Bedrift:</label>
<br>
<input type="text" id="bedrift" name="bedrift" value="<?=$team['Bedrift']?>">
<br>
<label for="kortnummer">Kortnummer:</label>
<br>
<input type="text" id="kortnummer" name="kortnummer" value="<?=$team['Kortnummer']?>">
<br>
<label for="leder">Leder:</label>
<br>
<input type="text" id="leder" name="leder" value="<?=$team['Lagleder']?>">
<br>
<label for="telefon">Telefon:</label>
<br>
<input type="text" id="telefon" name="telefon" value="<?=$team['Telefon']?>">
<br>
<label for="deltagere">Deltagere:</label>
<br>
<input type="text" id="deltagere" name="deltagere" value="<?=$team['Deltagere']?>">
<br>
<label for="runder">Runder:</label>
<br>
<input type="text" id="runder" name="runder" value="<?=$team['Runder']?>">
<br>
<br>
<input type="submit" value="Bekreft">
</form>

View File

@ -27,7 +27,7 @@
echo "<td>{$row['Deltagere']}</td>";
echo "<td>{$row['Runder']}</td>";
echo "<td>{$row['Bestetid']}</td>";
echo "<td><a href='delete.php?item={$row['LagID']}'>Slett</td>";
echo "<td><a href='delete.php?item={$row['LagID']}'>Slett</a><a href='alter.php?item={$row['LagID']}'>Endre</a></td>";
echo '</tr>';
}
?>

View File

@ -0,0 +1,52 @@
<?php
$app = require '../../../app/inc.php';
$model = $app->model('Teamtable');
if (!isset($_GET['item']))
{
$app->session->flash('LagID ikke definert som GET parameter', 'danger');
$app->redirect('index.php');
}
$id = $_GET['item'];
// ID must be numeric
if (!is_numeric($id))
{
$app->session->flash('LagID må være tall', 'danger');
$app->redirect('index.php');
}
// Check if ID is in teamtable
$currentTeam = $model->getTeamByID($id);
if (!$currentTeam)
{
$app->session->flash("Kunne ikke endre lag: LagID \"$id\" finnes ikke", "danger");
$app->redirect('index.php');
}
// Change team
if ($_SERVER['REQUEST_METHOD'] === 'POST')
{
$model->updateTeam(
$id, [
$_POST['navn'],
$_POST['bedrift'],
$_POST['kortnummer'],
$_POST['leder'],
$_POST['telefon'],
$_POST['deltagere'],
$_POST['runder'],
],
);
}
// Escape all values
foreach ($currentTeam as $key => $value)
{
$currentTeam[$key] = htmlspecialchars($currentTeam[$key]);
}
$app->view('template/header', ['title' => 'Endre lagdetaljer']);
$app->view('pages/teamtable/edit/alter', ["team" => $currentTeam]);
$app->view('template/footer');

View File

@ -0,0 +1,32 @@
<?php
$app = require '../../../app/inc.php';
$model = $app->model('Teamtable');
if (!isset($_GET['item']))
{
$app->session->flash('LagID ikke definert som GET parameter', 'danger');
$app->redirect('index.php');
}
$id = $_GET['item'];
// ID must be numeric
if (!is_numeric($id))
{
$app->session->flash('LagID må være tall', 'danger');
$app->redirect('index.php');
}
// Check if ID is in teamtable
$currentTeam = $model->getTeamByID($id);
if (!$currentTeam)
{
$app->session->flash("Kunne ikke slette lag: LagID \"$id\" finnes ikke", "danger");
$app->redirect('index.php');
}
$model->deleteTeamByID($id);
$app->session->flash("Slettet lag: {$currentTeam['LagNavn']}", "success");
$app->redirect('index.php');