commit 79fa358cb2254c0bdbbf9bfdcdd51ff363272e0a
parent b9dcb06772b3aa8c3e1af289b02eb29413671ab1
Author: William Lindholm <william_lindholm@outlook.com>
Date: Wed, 27 Sep 2023 21:53:44 +0000
Added ability to create cardlayout from tables.
Diffstat:
7 files changed, 90 insertions(+), 6 deletions(-)
diff --git a/db/dbhelper.php b/db/dbhelper.php
@@ -37,6 +37,22 @@
}
}
+ function getTableCount($table) {
+ $db = dbconnection::getInstance();
+ $pdo = $db->getPdo();
+
+ try {
+ $query = "SELECT COUNT(*) FROM $table";
+ $stmt = $pdo->prepare($query);
+ $stmt->execute();
+
+ return (int) $stmt->fetchColumn();
+ } catch (PDOException $e) {
+ echo "Error: " . $e->getMessage();
+ return 0;
+ }
+ }
+
function RefreshTables() {
$location = $_SERVER['PHP_SELF'];
if (!empty($_SERVER['QUERY_STRING'])) {
diff --git a/index.php b/index.php
@@ -19,7 +19,12 @@
$pageContent .= $attributeModalBuilder->build();
$pageContent .= $attributeModalBuilder->generateOpenButton("Set specialty");
+ $pageContent .= "<hr>";
+
$pageContent .= "<h3>GroupLeaders</h3>" . tableFactory::createTable("GroupLeaders");
+
+ $pageContent .= "<hr>";
+
$pageContent .= "<h3>Managers</h3>" . tableFactory::createTable("Managers");
$agentModalBuilder = (new ModalBuilder())
diff --git a/operation.php b/operation.php
@@ -35,6 +35,8 @@
$addAgentModalBuilder->handleData();
$pageContent .= $addAgentModalBuilder->build();
$pageContent .= $addAgentModalBuilder->generateOpenButton("Add agent");
+
+ $pageContent .= "<hr>";
$queryGroupLeader = "SELECT GroupLeader FROM Operation
WHERE OperationName = '{$operationName}'
diff --git a/terrain.php b/terrain.php
@@ -5,14 +5,14 @@
$pageContent = '';
- $pageContent .= "<h3>Terrain</h3>" . tableFactory::createTable("Terrain");
+ $pageContent .= tableFactory::createCardTable("Terrain");
$modalBuilder = (new ModalBuilder())
->setModalId('insertModal')
->setTableName("Terrain")
->setInsertHandler($handlerFactory->createHandler('Terrain'))
- ->addColumn("TerrainCode")
- ->addColumn("TerrainName");
+ ->addHiddenColumn("TerrainCode", getTableCount('Terrain') + 1)
+ ->addColumn("TerrainName");
$modalBuilder->handleData();
diff --git a/utils/logs.txt b/utils/logs.txt
@@ -593,3 +593,22 @@
AND StartDate = '2021-03-23'
AND IncidentName = 'Theft'
AND IncidentNumber = 110
+2023-09-27 21:21:33 - Inserting into: OperatesIn
+2023-09-27 21:21:39 - Updating records in: Operation
+2023-09-27 21:21:39 - UPDATE Operation SET GroupLeader = 'D56' WHERE OperationName = 'Operation Thunder'
+ AND StartDate = '2023-01-01'
+ AND IncidentName = 'Sabotage'
+ AND IncidentNumber = 103
+2023-09-27 21:26:55 - Inserting into: OperatesIn
+2023-09-27 21:27:02 - Inserting into: OperatesIn
+2023-09-27 21:27:05 - Inserting into: OperatesIn
+2023-09-27 21:27:09 - Inserting into: OperatesIn
+2023-09-27 21:27:15 - Inserting into: OperatesIn
+2023-09-27 21:27:19 - Inserting into: OperatesIn
+2023-09-27 21:27:48 - Updating records in: Operation
+2023-09-27 21:39:17 - Inserting into: Terrain
+2023-09-27 21:39:47 - Inserting into: Terrain
+2023-09-27 21:41:43 - Inserting into: OperatesIn
+2023-09-27 21:41:49 - Updating records in: Operation
+2023-09-27 21:47:42 - Inserting into: OperatesIn
+2023-09-27 21:49:22 - Inserting into: Terrain
diff --git a/utils/tableFactory.php b/utils/tableFactory.php
@@ -128,5 +128,50 @@
return '';
}
}
+
+ /**
+ * Generate a card layout instead of a table layout.
+ * Only suitable for smaller datatables.
+ */
+ public static function createCardTable($tableName) {
+ $db = dbconnection::getInstance();
+ $pdo = $db->getPdo();
+
+ $output = "<div class='card-columns'>";
+
+ try {
+ $headers = [];
+ $firstRow = true;
+ foreach($pdo->query('SELECT * FROM ' . $tableName . ';') AS $row) {
+ if($firstRow) {
+ foreach($row as $key => $value) {
+ if(!is_numeric($key)) {
+ $headers[] = $key;
+ }
+ }
+ $firstRow = false;
+ }
+
+ $output .= "<div class='card'>";
+ $output .= "<div class='card-header'>$tableName</div>";
+ $output .= "<div class='card-body'>";
+
+ for($i = 0; $i < count($headers); $i++) {
+ if(isset($row[$headers[$i]]) && !is_numeric($headers[$i])) {
+ $output .= "<p class='card-text'>" . $headers[$i] . ": " . $row[$headers[$i]] . "</p>";
+ }
+ }
+
+ $output .= "</div>";
+ $output .= "</div>";
+ }
+ $output .= "</div>";
+
+ return $output;
+ } catch (PDOException $e) {
+ echo "Error: " . $e->getMessage();
+ return '';
+ }
+ }
}
?>
\ No newline at end of file
diff --git a/utils/updateHandler.php b/utils/updateHandler.php
@@ -39,9 +39,6 @@
$setClause = implode(', ', $setClause);
$sql = "UPDATE {$this->tableName} SET {$setClause} WHERE {$this->condition}";
-
- logg($sql);
-
$stmt = $this->pdo->prepare($sql);
if (!$stmt->execute()) {