From d37805a7980bd86828c205128399fe080d7157ce Mon Sep 17 00:00:00 2001 From: Torsten Schulz Date: Fri, 29 Dec 2023 08:37:14 +0100 Subject: [PATCH] fixed from error --- include/projectsmanagement.php | 25 +++++++++++++++---------- templates/projectsmanagement.html | 12 +++++++++++- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/include/projectsmanagement.php b/include/projectsmanagement.php index 567fedc..1cc87cb 100644 --- a/include/projectsmanagement.php +++ b/include/projectsmanagement.php @@ -55,13 +55,13 @@ class Projectsmanagement extends Renderer { WHERE caption = "Fortlaufende Projekte"', $newName); mysqli_query($this->dbConnection, $query); $id = mysqli_insert_id($this->dbConnection); - $query = 'SELECT id, short_title FROM project p ORDER BY short_title'; + $query = 'SELECT id, short_title, project_type_id FROM project p ORDER BY short_title'; $dbResult = mysqli_query($this->dbConnection, $query); $list = []; while ($row = mysqli_fetch_assoc($dbResult)) { - $list[] = ['id' => $row['id'], 'title' => $row['short_title'] ]; + $list[] = ['id' => $row['id'], 'title' => $row['short_title'], 'project_type_id' => $row['project_type_id'] ]; } - echo json_encode(['list' => $list, 'id' => $id]); + echo json_encode(['list' => $list, 'id' => $id, 'types' => $this->getProjectTypes()]); } protected function setDescription(): void { @@ -90,15 +90,10 @@ class Projectsmanagement extends Renderer { } protected function generateContent(): void { - $typesQuery = 'SELECT * FROM project_type ORDER BY id'; - $typesResult = mysqli_query($this->dbConnection, $typesQuery); - $types = []; - while ($row = mysqli_fetch_assoc($typesResult)) { - $types[$row['id'] ] = $row['caption']; - } + $types = $this->getProjectTypes(); $query = 'SELECT * FROM project ORDER BY short_title'; $result = mysqli_query($this->dbConnection, $query); - $overviewHtml = ''; + $overviewHtml = '
ProjektProjekttyp
'; while ($row = mysqli_fetch_assoc($result)) { $overviewHtml .= ''; $overviewHtml .= '
ProjektProjekttyp
' . $row['short_title'] . '
'; $this->content['projects'] = $overviewHtml; } + + protected function getProjectTypes(): array { + $typesQuery = 'SELECT * FROM project_type ORDER BY id'; + $typesResult = mysqli_query($this->dbConnection, $typesQuery); + $types = []; + while ($row = mysqli_fetch_assoc($typesResult)) { + $types[$row['id'] ] = $row['caption']; + } + return $types; + } } diff --git a/templates/projectsmanagement.html b/templates/projectsmanagement.html index d4852c3..68bcc98 100644 --- a/templates/projectsmanagement.html +++ b/templates/projectsmanagement.html @@ -19,6 +19,7 @@ $(document).ready(function() { return; } $("#shorttitle > option:not(:first-child)").remove(); + $("#projectoverview > tbody > tr").remove(); response.list.forEach(function(item) { let newItem = $(""); newItem.attr("id", item.id); @@ -26,7 +27,16 @@ $(document).ready(function() { if (item.id == response.id) { newItem.attr("selected", "selected"); } - $("#shorttitle").append(newItem); + let newRow = $('' + item.title + ''); + let selectElement = $(''); + for (let typeId in response.types) { + if (response.types.hasOwnProperty(typeId)) { + let option = $(''); + selectElement.append(option); + } + } + newRow.append('' + selectElement.prop('outerHTML') + ''); + $("#projectoverview tbody").append(newRow); }); }).fail(function(response) { alert(response);