This commit is contained in:
William 2022-02-14 02:52:59 +01:00
parent 313110ca2d
commit 7192710ca0
11 changed files with 92 additions and 65 deletions

View File

@ -28,8 +28,9 @@ class Teamtable
return $sth->fetch(PDO::FETCH_ASSOC); return $sth->fetch(PDO::FETCH_ASSOC);
} }
public function updateTeam(int $id, array $params): void public function updateTeamByID(int $id, array $params): void
{ {
// todo ...
$sth = $this->dbh->prepare('UPDATE lagtabell SET WHERE LagID = ?'); $sth = $this->dbh->prepare('UPDATE lagtabell SET WHERE LagID = ?');
$sth->execute([$params]); $sth->execute([$params]);
} }

View File

@ -1,6 +1,6 @@
<h1>Logg inn</h1> <h1>Logg inn</h1>
<p>Fyll inn påloggingsinformasjonen din.</p> <p>Fyll inn påloggingsinformasjonen din.</p>
<form method="post"> <form method="post" autocomplete="off">
<label for="username">Brukernavn:</label> <label for="username">Brukernavn:</label>
<br> <br>
<input type="text" id="username" name="username"> <input type="text" id="username" name="username">

View File

@ -1,6 +1,6 @@
<h1>Simulator</h1> <h1>Simulator</h1>
<p>Skriv inn et kortnummer:</p> <p>Skriv inn et kortnummer:</p>
<form method="post"> <form method="post" autocomplete="off">
<input type="text" name="cardnumber"> <input type="text" name="cardnumber">
<br> <br>
<br> <br>

View File

@ -0,0 +1,4 @@
<h1>Bekreft sletting</h1>
<p>Er du sikker at du vil slette <?=htmlspecialchars($currentTeam['LagNavn'])?>?</p>
<span>[&nbsp;<a class="success" href="delete.php?item=<?=$currentTeam['LagID']?>">Slett</a>&nbsp;]</span>
<span>[&nbsp;<a class="danger" href="index.php">Avbryt</a>&nbsp;]</span>

View File

@ -1,4 +1,5 @@
<h1>Endre lagtabell</h1> <h1>Endre lagtabell</h1>
<span class="float-right">[&nbsp;<a class="success" href="update.php?create=true">Opprett lag</a>&nbsp;]</span>
<br> <br>
<table> <table>
<tr> <tr>
@ -27,8 +28,9 @@
echo "<td>{$row['Deltagere']}</td>"; echo "<td>{$row['Deltagere']}</td>";
echo "<td>{$row['Runder']}</td>"; echo "<td>{$row['Runder']}</td>";
echo "<td>{$row['Bestetid']}</td>"; echo "<td>{$row['Bestetid']}</td>";
echo "<td><a href='delete.php?item={$row['LagID']}'>Slett</a><a href='alter.php?item={$row['LagID']}'>Endre</a></td>"; echo "<td><span>[&nbsp;<a class='danger' href='delete.php?item={$row['LagID']}&confirmation=true'>Slett</a>&nbsp;]</span> <span>[&nbsp;<a class='info' href='update.php?item={$row['LagID']}'>Endre</a>&nbsp;]</span></td>";
echo '</tr>'; echo '</tr>';
} }
?> ?>
</table> </table>
<span class="float-right">[&nbsp;<a class="success" href="update.php?create=true">Opprett lag</a>&nbsp;]</span>

View File

@ -1,5 +1,6 @@
<h1>Endre lagdetaljer</h1> <h1>Endre lagdetaljer</h1>
<form method="post"> <p>Her kan du oppdatere informasjonen om laget</p>
<form method="post" autocomplete="off">
<label for="navn">Navn:</label> <label for="navn">Navn:</label>
<br> <br>
<input type="text" id="navn" name="navn" value="<?=$team['LagNavn']?>"> <input type="text" id="navn" name="navn" value="<?=$team['LagNavn']?>">
@ -36,5 +37,6 @@
<br> <br>
<br> <br>
<input type="submit" value="Bekreft"> <input type="submit" value="Lagre">
<span>[&nbsp;<a class="danger" href="index.php">Avbryt</a>&nbsp;]</span>
</form> </form>

View File

@ -57,7 +57,7 @@
{ {
foreach ($msgs as $msg) foreach ($msgs as $msg)
{ {
echo "<div class=\"alert {$msg["type"]}\">{$msg["message"]}</div>"; echo "<div class=\"alert {$msg["type"]}\" role=\"alert\">{$msg["message"]}</div>";
} }
} }
?> ?>

View File

@ -8,7 +8,7 @@ body {
background: #eee; background: #eee;
color: #222; color: #222;
font-size: 1rem; font-size: 1rem;
font-family: "Liberation Sans", Arial, sans-serif; font-family: Arial, sans-serif;
line-height: 1.5; line-height: 1.5;
margin: 0; margin: 0;
} }
@ -58,6 +58,7 @@ a {
#main { #main {
padding: .75rem; padding: .75rem;
flex-grow: 1; flex-grow: 1;
overflow: hidden;
} }
#main img { #main img {
display: block; display: block;
@ -69,6 +70,7 @@ a {
background: #fff; background: #fff;
padding: .75rem; padding: .75rem;
line-height: 1.75; line-height: 1.75;
min-width: max-content;
} }
#nav ul { #nav ul {
margin: 0; margin: 0;
@ -98,7 +100,7 @@ a {
.alert { .alert {
padding: .5rem; padding: .5rem;
margin-bottom: .5rem; margin-bottom: .5rem;
border: 1px solid transparent; border: .05rem solid transparent;
border-radius: .15rem; border-radius: .15rem;
} }
.alert.info { .alert.info {
@ -127,8 +129,10 @@ a {
} }
table { table {
display: block;
border-collapse: collapse; border-collapse: collapse;
width: 100%; width: 100%;
overflow: auto;
} }
table td, table th { table td, table th {
border-bottom: 0.05rem solid #aaa; border-bottom: 0.05rem solid #aaa;
@ -140,4 +144,22 @@ table tr:nth-child(even) {
table th { table th {
font-weight: bold; font-weight: bold;
text-align: left; text-align: left;
}
tbody {
display: table;
width: 100%
}
a.info {
color: blue;
}
a.success {
color: darkgreen;
}
a.danger {
color: maroon;
}
.float-right {
float: right;
} }

View File

@ -1,52 +0,0 @@
<?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

@ -5,7 +5,7 @@ $model = $app->model('Teamtable');
if (!isset($_GET['item'])) if (!isset($_GET['item']))
{ {
$app->session->flash('LagID ikke definert som GET parameter', 'danger'); $app->session->flash('Kunne ikke slette lag: ID ikke definert som GET parameter', 'danger');
$app->redirect('index.php'); $app->redirect('index.php');
} }
$id = $_GET['item']; $id = $_GET['item'];
@ -13,7 +13,7 @@ $id = $_GET['item'];
// ID must be numeric // ID must be numeric
if (!is_numeric($id)) if (!is_numeric($id))
{ {
$app->session->flash('LagID må være tall', 'danger'); $app->session->flash('Kunne ikke slette lag: ID må være tall', 'danger');
$app->redirect('index.php'); $app->redirect('index.php');
} }
@ -21,10 +21,19 @@ if (!is_numeric($id))
$currentTeam = $model->getTeamByID($id); $currentTeam = $model->getTeamByID($id);
if (!$currentTeam) if (!$currentTeam)
{ {
$app->session->flash("Kunne ikke slette lag: LagID $id finnes ikke", "danger"); $app->session->flash("Kunne ikke slette lag: ID $id finnes ikke", "danger");
$app->redirect('index.php'); $app->redirect('index.php');
} }
// Show confirmation page
if (isset($_GET['confirmation']) && $_GET['confirmation'] == 'true')
{
$app->view('template/header', ['title' => 'Bekreft sletting']);
$app->view('pages/teamtable/edit/delete', ['currentTeam' => $currentTeam]);
$app->view('template/footer');
die();
}
$model->deleteTeamByID($id); $model->deleteTeamByID($id);
$app->session->flash("Slettet lag: {$currentTeam['LagNavn']}", "success"); $app->session->flash("Slettet lag: {$currentTeam['LagNavn']}", "success");

View File

@ -0,0 +1,39 @@
<?php
$app = require '../../../app/inc.php';
$model = $app->model('Teamtable');
if (!isset($_GET['item']))
{
$app->session->flash('Kunne ikke endre lag: ID ikke definert som GET parameter', 'danger');
$app->redirect('index.php');
}
$id = $_GET['item'];
// ID must be numeric
if (!is_numeric($id))
{
$app->session->flash('Kunne ikke endre lag: ID 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: ID $id finnes ikke", "danger");
$app->redirect('index.php');
}
// todo: update team details here...
// $model->updateTeamByID(...)
// 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/update', ["team" => $currentTeam]);
$app->view('template/footer');