From 10f2e69c437b96f25b5ddc4d193e64638666464a Mon Sep 17 00:00:00 2001 From: William Date: Mon, 28 Feb 2022 05:51:22 +0100 Subject: [PATCH] Commit --- app/core/User.php | 1 - app/model/Teamtable.php | 12 ++++----- app/view/pages/teamtable/edit/index.php | 35 ++++++++++++++----------- app/view/pages/teamtable/index.php | 31 +++++++++++----------- public/teamtable/edit/index.php | 4 ++- public/teamtable/edit/update.php | 2 +- public/teamtable/index.php | 4 ++- 7 files changed, 49 insertions(+), 40 deletions(-) diff --git a/app/core/User.php b/app/core/User.php index 9d7e801..e56f9ed 100644 --- a/app/core/User.php +++ b/app/core/User.php @@ -65,7 +65,6 @@ class User if ($this->authenticate($username, $password)) { $this->session->set(self::SESSION_KEY, [ - 'loggedIn' => TRUE, 'username' => $username, 'password' => $password ]); diff --git a/app/model/Teamtable.php b/app/model/Teamtable.php index 3781b99..4ec70eb 100644 --- a/app/model/Teamtable.php +++ b/app/model/Teamtable.php @@ -2,9 +2,7 @@ class Teamtable { - public PDO $dbh; - - public array $emptyTeamTemplate = [ + public array $template = [ 'LagNavn' => 'NN', 'Bedrift' => 'NN', 'Kortnummer' => 'NN', @@ -14,6 +12,8 @@ class Teamtable 'Runder' => 0 ]; + public PDO $dbh; + public function __construct(Database $database) { $this->dbh = $database->conn; @@ -61,7 +61,7 @@ class Teamtable $sth = $this->dbh->prepare( 'INSERT INTO lagtabell (LagNavn, Bedrift, Kortnummer, Lagleder, Telefon, Deltagere, Runder) VALUES (?, ?, ?, ?, ?, ?, ?)' ); - $template = $this->emptyTeamTemplate; + $template = $this->template; $sth->execute([ $template['LagNavn'], $template['Bedrift'], @@ -77,7 +77,7 @@ class Teamtable // Check if team is empty by comparing it to the template public function isEqualEmptyTemplate(array $team): bool { - $template = $this->emptyTeamTemplate; + $template = $this->template; foreach ($template as $key => $value) { if ((string)$team[$key] !== (string)$template[$key]) { return FALSE; @@ -105,7 +105,7 @@ class Teamtable $sth = $this->dbh->prepare( "INSERT INTO `lagtabell` (`LagNavn`, `Bedrift`, `Kortnummer`, `Lagleder`, `Telefon`, `Deltagere`, `Runder`) VALUES (?, ?, ?, ?, ?, ?, ?)" ); - $template = $this->emptyTeamTemplate; + $template = $this->template; $sth->execute([ $template['LagNavn'], $template['Bedrift'], diff --git a/app/view/pages/teamtable/edit/index.php b/app/view/pages/teamtable/edit/index.php index 9a0f789..ea33dd5 100644 --- a/app/view/pages/teamtable/edit/index.php +++ b/app/view/pages/teamtable/edit/index.php @@ -15,24 +15,29 @@ Handling $value) + $i = 1; + foreach ($teams as $team) { + $i++; + // Remember to escape your values! + foreach ($team as $key => $value) { - $row[$key] = htmlspecialchars($row[$key]); + $team[$key] = htmlspecialchars($team[$key]); } + echo ''; - echo "{$iterator}"; - echo "{$row['LagNavn']}"; - echo "{$row['Bedrift']}"; - echo "{$row['Kortnummer']}"; - echo "{$row['Lagleder']}"; - echo "{$row['Telefon']}"; - echo "{$row['Deltagere']}"; - echo "{$row['Runder']}"; - echo "{$row['Bestetid']}"; - echo "Slett ] Endre ]"; + echo "{$i}"; + echo "{$team['LagNavn']}"; + echo "{$team['Bedrift']}"; + echo "{$team['Kortnummer']}"; + echo "{$team['Lagleder']}"; + echo "{$team['Telefon']}"; + echo "{$team['Deltagere']}"; + echo "{$team['Runder']}"; + echo "{$team['Bestetid']}"; + echo ""; + echo "Slett ]"; + echo "Endre ]"; + echo ""; echo ''; } ?> diff --git a/app/view/pages/teamtable/index.php b/app/view/pages/teamtable/index.php index d723a48..3275d7f 100644 --- a/app/view/pages/teamtable/index.php +++ b/app/view/pages/teamtable/index.php @@ -13,24 +13,25 @@ Bestetid $value) + $i = 1; + foreach ($teams as $team) { + $i++; + // Remember to escape your values! + foreach ($team as $key => $value) { - $row[$key] = htmlspecialchars($row[$key]); + $team[$key] = htmlspecialchars($team[$key]); } + echo ''; - echo "{$iterator}"; - echo "{$row['LagNavn']}"; - echo "{$row['Bedrift']}"; - echo "{$row['Kortnummer']}"; - echo "{$row['Lagleder']}"; - echo "{$row['Telefon']}"; - echo "{$row['Deltagere']}"; - echo "{$row['Runder']}"; - echo "{$row['Bestetid']}"; + echo "{$i}"; + echo "{$team['LagNavn']}"; + echo "{$team['Bedrift']}"; + echo "{$team['Kortnummer']}"; + echo "{$team['Lagleder']}"; + echo "{$team['Telefon']}"; + echo "{$team['Deltagere']}"; + echo "{$team['Runder']}"; + echo "{$team['Bestetid']}"; echo ''; } ?> diff --git a/public/teamtable/edit/index.php b/public/teamtable/edit/index.php index 8c1334d..34d4aa5 100644 --- a/public/teamtable/edit/index.php +++ b/public/teamtable/edit/index.php @@ -3,6 +3,8 @@ $app = require '../../../app/inc.php'; $model = $app->model('Teamtable'); +$teams = $model->getTable(); + $app->view('template/header', ['title' => 'Endre lagtabell']); -$app->view('pages/teamtable/edit/index', ["teams" => $model->getTable()]); +$app->view('pages/teamtable/edit/index', ["teams" => $teams]); $app->view('template/footer'); \ No newline at end of file diff --git a/public/teamtable/edit/update.php b/public/teamtable/edit/update.php index d26b210..7819f55 100644 --- a/public/teamtable/edit/update.php +++ b/public/teamtable/edit/update.php @@ -54,7 +54,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') //====Validate Input====// $validationError = FALSE; - $template = $model->emptyTeamTemplate; + $template = $model->template; // LagNavn if (!strlen($LagNavn)) { diff --git a/public/teamtable/index.php b/public/teamtable/index.php index 3de46a9..3767acc 100644 --- a/public/teamtable/index.php +++ b/public/teamtable/index.php @@ -3,6 +3,8 @@ $app = require '../../app/inc.php'; $model = $app->model('Teamtable'); +$teams = $model->getTable(); + $app->view('template/header', ['title' => 'Lagtabell']); -$app->view('pages/teamtable/index', ["teams" => $model->getTable()]); +$app->view('pages/teamtable/index', ["teams" => $teams]); $app->view('template/footer'); \ No newline at end of file