From 7192710ca0034c0a7f261a3d9e2f3946b6b291d8 Mon Sep 17 00:00:00 2001 From: William Date: Mon, 14 Feb 2022 02:52:59 +0100 Subject: [PATCH] Commit --- app/model/Teamtable.php | 3 +- app/view/pages/login.php | 2 +- app/view/pages/simulator.php | 2 +- app/view/pages/teamtable/edit/delete.php | 4 ++ app/view/pages/teamtable/edit/index.php | 6 ++- .../teamtable/edit/{alter.php => update.php} | 6 ++- app/view/template/header.php | 2 +- public/static/style/main.css | 26 +++++++++- public/teamtable/edit/alter.php | 52 ------------------- public/teamtable/edit/delete.php | 15 ++++-- public/teamtable/edit/update.php | 39 ++++++++++++++ 11 files changed, 92 insertions(+), 65 deletions(-) create mode 100644 app/view/pages/teamtable/edit/delete.php rename app/view/pages/teamtable/edit/{alter.php => update.php} (82%) delete mode 100644 public/teamtable/edit/alter.php create mode 100644 public/teamtable/edit/update.php diff --git a/app/model/Teamtable.php b/app/model/Teamtable.php index 5a43f05..7e11af4 100644 --- a/app/model/Teamtable.php +++ b/app/model/Teamtable.php @@ -28,8 +28,9 @@ class Teamtable 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->execute([$params]); } diff --git a/app/view/pages/login.php b/app/view/pages/login.php index 9a7f1ea..42a994a 100644 --- a/app/view/pages/login.php +++ b/app/view/pages/login.php @@ -1,6 +1,6 @@

Logg inn

Fyll inn påloggingsinformasjonen din.

-
+
diff --git a/app/view/pages/simulator.php b/app/view/pages/simulator.php index 29f41bf..573ca4f 100644 --- a/app/view/pages/simulator.php +++ b/app/view/pages/simulator.php @@ -1,6 +1,6 @@

Simulator

Skriv inn et kortnummer:

- +

diff --git a/app/view/pages/teamtable/edit/delete.php b/app/view/pages/teamtable/edit/delete.php new file mode 100644 index 0000000..e932d0a --- /dev/null +++ b/app/view/pages/teamtable/edit/delete.php @@ -0,0 +1,4 @@ +

Bekreft sletting

+

Er du sikker på at du vil slette ?

+Slett ] +Avbryt ] \ No newline at end of file diff --git a/app/view/pages/teamtable/edit/index.php b/app/view/pages/teamtable/edit/index.php index 18554d8..ee176c5 100644 --- a/app/view/pages/teamtable/edit/index.php +++ b/app/view/pages/teamtable/edit/index.php @@ -1,4 +1,5 @@

Endre lagtabell

+Opprett lag ]
@@ -27,8 +28,9 @@ echo ""; echo ""; echo ""; - echo ""; + echo ""; echo ''; } ?> -
{$row['Deltagere']}{$row['Runder']}{$row['Bestetid']}SlettEndreSlett ] Endre ]
\ No newline at end of file + +Opprett lag ] \ No newline at end of file diff --git a/app/view/pages/teamtable/edit/alter.php b/app/view/pages/teamtable/edit/update.php similarity index 82% rename from app/view/pages/teamtable/edit/alter.php rename to app/view/pages/teamtable/edit/update.php index 11b4c8c..3ac8b58 100644 --- a/app/view/pages/teamtable/edit/alter.php +++ b/app/view/pages/teamtable/edit/update.php @@ -1,5 +1,6 @@

Endre lagdetaljer

- +

Her kan du oppdatere informasjonen om laget

+
@@ -36,5 +37,6 @@

- + + Avbryt ]
\ No newline at end of file diff --git a/app/view/template/header.php b/app/view/template/header.php index 5afee16..3c92fd0 100644 --- a/app/view/template/header.php +++ b/app/view/template/header.php @@ -57,7 +57,7 @@ { foreach ($msgs as $msg) { - echo "
{$msg["message"]}
"; + echo "
{$msg["message"]}
"; } } ?> \ No newline at end of file diff --git a/public/static/style/main.css b/public/static/style/main.css index 4298eec..1bd8a18 100644 --- a/public/static/style/main.css +++ b/public/static/style/main.css @@ -8,7 +8,7 @@ body { background: #eee; color: #222; font-size: 1rem; - font-family: "Liberation Sans", Arial, sans-serif; + font-family: Arial, sans-serif; line-height: 1.5; margin: 0; } @@ -58,6 +58,7 @@ a { #main { padding: .75rem; flex-grow: 1; + overflow: hidden; } #main img { display: block; @@ -69,6 +70,7 @@ a { background: #fff; padding: .75rem; line-height: 1.75; + min-width: max-content; } #nav ul { margin: 0; @@ -98,7 +100,7 @@ a { .alert { padding: .5rem; margin-bottom: .5rem; - border: 1px solid transparent; + border: .05rem solid transparent; border-radius: .15rem; } .alert.info { @@ -127,8 +129,10 @@ a { } table { + display: block; border-collapse: collapse; width: 100%; + overflow: auto; } table td, table th { border-bottom: 0.05rem solid #aaa; @@ -140,4 +144,22 @@ table tr:nth-child(even) { table th { font-weight: bold; text-align: left; +} +tbody { + display: table; + width: 100% +} + +a.info { + color: blue; +} +a.success { + color: darkgreen; +} +a.danger { + color: maroon; +} + +.float-right { + float: right; } \ No newline at end of file diff --git a/public/teamtable/edit/alter.php b/public/teamtable/edit/alter.php deleted file mode 100644 index 7a3ba72..0000000 --- a/public/teamtable/edit/alter.php +++ /dev/null @@ -1,52 +0,0 @@ -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'); \ No newline at end of file diff --git a/public/teamtable/edit/delete.php b/public/teamtable/edit/delete.php index 77c1e39..4d1320b 100644 --- a/public/teamtable/edit/delete.php +++ b/public/teamtable/edit/delete.php @@ -5,7 +5,7 @@ $model = $app->model('Teamtable'); 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'); } $id = $_GET['item']; @@ -13,7 +13,7 @@ $id = $_GET['item']; // ID must be numeric 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'); } @@ -21,10 +21,19 @@ if (!is_numeric($id)) $currentTeam = $model->getTeamByID($id); 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'); } +// 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); $app->session->flash("Slettet lag: {$currentTeam['LagNavn']}", "success"); diff --git a/public/teamtable/edit/update.php b/public/teamtable/edit/update.php new file mode 100644 index 0000000..b8fa8da --- /dev/null +++ b/public/teamtable/edit/update.php @@ -0,0 +1,39 @@ +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'); \ No newline at end of file