commit e9dd2556bcc606fda3c73e6eec79e3f560f3c256
parent f77eb2a5ce79cc253cb2b3c39bce6c9bdff75fb0
Author: William Lindholm <william_lindholm@outlook.com>
Date: Wed, 27 Sep 2023 23:38:42 +0000
Added report handling.
Diffstat:
8 files changed, 184 insertions(+), 6 deletions(-)
diff --git a/db/dbhelper.php b/db/dbhelper.php
@@ -61,4 +61,32 @@
header("Location: " . $location);
exit();
}
+
+ function HandleProcedure($postData) {
+ if (isset($postData['OperationType']) && $postData['OperationType'] == 'EXECUTE') {
+
+ try {
+ $db = dbconnection::getInstance();
+ $pdo = $db->getPdo();
+
+ if (isset($postData['Function'])) {
+ $procedureName = $postData['Function'];
+
+ $dateCreated = $postData['DateCreated'];
+ $title = $postData['Title'];
+
+ $sql = "CALL {$procedureName}(:dateCreated, :title)";
+ $stmt = $pdo->prepare($sql);
+ $stmt->bindParam(':dateCreated', $dateCreated);
+ $stmt->bindParam(':title', $title);
+
+ $stmt->execute();
+ }
+ } catch(PDOException $e) {
+ echo "Error: " . $e->getMessage();
+ }
+
+ RefreshTables();
+ }
+ }
?>
\ No newline at end of file
diff --git a/incident.php b/incident.php
@@ -0,0 +1,68 @@
+<?php
+ require 'utils/imports.php';
+ dbconnection::getInstance('mysql', 'a22willi', 'root', 'Safiren1');
+ $handlerFactory = new InsertHandlerFactory();
+
+ $incidentName = urldecode($_GET['IncidentName']);
+ $incidentNumber = urldecode($_GET['IncidentNumber']);
+
+ $pageContent = '';
+
+ $queryOperations = "SELECT * FROM Operation WHERE IncidentName = '{$incidentName}' AND IncidentNumber = '{$incidentNumber}';";
+
+ $pageContent .= "<h3>Operations in $incidentName</h3>" . tableFactory::createTableWithRedirect($queryOperations, "operation.php", ["OperationName", "StartDate", "IncidentName", "IncidentNumber"]);
+
+ $operationModalBuilder = (new ModalBuilder())
+ ->setModalId('insertOperation')
+ ->setTableName("Operation")
+ ->setInsertHandler($handlerFactory->createHandler('Operation'))
+ ->addColumn("OperationName")
+ ->addColumn("StartDate")
+ ->addColumn("EndDate", true)
+ ->addColumn("SuccessRate", true)
+ ->addDropdownColumn("GroupLeader", getColumnValues("GroupLeaders", "CodeName"))
+ ->addHiddenColumn("Incident", "'{$incidentName}', '{$incidentNumber}'");
+
+ $operationModalBuilder->handleData();
+ $pageContent .= $operationModalBuilder->build();
+ $pageContent .= $operationModalBuilder->generateOpenButton("Create Operation");
+
+ $pageContent .= "<hr>";
+
+ $queryReports = "SELECT * FROM Report WHERE IncidentName = '{$incidentName}' AND IncidentNumber = {$incidentNumber}";
+
+ $pageContent .= "<h3>Reports</h3>" . tableFactory::createTableWithCallbackColumn($queryReports, 'archiveReport');
+
+ function ArchiveReport($rowdata) {
+ $dateCreated = isset($rowdata['DateCreated']) ? $rowdata['DateCreated'] : '';
+ $title = isset($rowdata['Title']) ? $rowdata['Title'] : '';
+
+ return "
+ <form action='' method='POST' class='mb-0'>
+ <input type='hidden' name='DateCreated' value='{$dateCreated}'>
+ <input type='hidden' name='Title' value='{$title}'>
+ <input type='hidden' name='OperationType' value='EXECUTE'>
+ <input type='hidden' name='Function' value='ArchiveReport'>
+ <button type='submit' class='btn btn-block btn-warning'>Archive</button>
+ </form>";
+ }
+
+ HandleProcedure($_POST);
+
+ $WriteReportModal = (new ModalBuilder())
+ ->setModalId('insertReport')
+ ->setTableName("Report")
+ ->setInsertHandler($handlerFactory->createHandler('Report'))
+ ->addColumn("Title")
+ ->addColumn("DateCreated")
+ ->addDropdownColumn("Author", getColumnValues("Agent", "CodeName"))
+ ->addColumn("Content")
+ ->addHiddenColumn("IncidentName", $incidentName)
+ ->addHiddenColumn("IncidentNumber", $incidentNumber);
+
+ $WriteReportModal->handleData();
+ $pageContent .= $WriteReportModal->build();
+ $pageContent .= $WriteReportModal->generateOpenButton("Write Report");
+
+ include 'utils/pageTemplate.php';
+?>
+\ No newline at end of file
diff --git a/incidents.php b/incidents.php
@@ -5,7 +5,9 @@
$pageContent = '';
- $pageContent .= "<h3>Incident</h3>" . tableFactory::createTable("Incident");
+ $query = "SELECT * FROM Incident;";
+
+ $pageContent .= "<h3>Incidents</h3>" . tableFactory::createTableWithRedirect($query, "incident.php", ["IncidentName", "IncidentNumber"]);
$modalBuilder = (new ModalBuilder())
->setModalId('insertModal')
diff --git a/operations.php b/operations.php
@@ -5,7 +5,9 @@
$pageContent = '';
- $pageContent .= "<h3>Operations</h3>" . tableFactory::createTableWithRedirect("Operation", "operation.php", ["OperationName", "StartDate", "IncidentName", "IncidentNumber"]);
+ $query = "SELECT * FROM Operation;";
+
+ $pageContent .= "<h3>Operations</h3>" . tableFactory::createTableWithRedirect($query, "operation.php", ["OperationName", "StartDate", "IncidentName", "IncidentNumber"]);
$modalBuilder = (new ModalBuilder())
->setModalId('insertModal')
diff --git a/reports.php b/reports.php
@@ -0,0 +1,14 @@
+<?php
+ require 'utils/imports.php';
+ dbconnection::getInstance('mysql', 'a22willi', 'root', 'Safiren1');
+
+ $pageContent = '';
+
+ $pageContent .= "<h3>Reports</h3>" . tableFactory::createCardTable("Report");
+
+ $pageContent .= "<hr>";
+
+ $pageContent .= "<h3>Archived Reports</h3>" . tableFactory::createTable("ArchivedReport");
+
+ include 'utils/pageTemplate.php';
+?>
+\ No newline at end of file
diff --git a/utils/logs.txt b/utils/logs.txt
@@ -612,3 +612,25 @@
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
+2023-09-27 22:01:25 - Updating records in: Operation
+2023-09-27 22:01:29 - Updating records in: Operation
+2023-09-27 22:01:35 - Inserting into: OperatesIn
+2023-09-27 22:10:32 - Inserting into: Operation
+2023-09-27 22:15:14 - Inserting into: Operation
+2023-09-27 22:16:20 - Inserting into: Operation
+2023-09-27 22:18:36 - Inserting into: Operation
+2023-09-27 22:19:34 - Inserting into: Operation
+2023-09-27 22:22:48 - Inserting into: Operation
+2023-09-27 22:24:35 - Updating records in: Operation
+2023-09-27 22:24:39 - Updating records in: Operation
+2023-09-27 22:24:42 - Updating records in: Operation
+2023-09-27 22:24:46 - Inserting into: OperatesIn
+2023-09-27 22:25:58 - Inserting into: Operation
+2023-09-27 22:43:19 - Array
+2023-09-27 22:43:19 - Array
+2023-09-27 22:43:54 - Array
+2023-09-27 22:43:54 - Array
+2023-09-27 23:35:33 - Inserting into: Report
+2023-09-27 23:36:01 - Inserting into: Report
+2023-09-27 23:36:30 - Inserting into: Report
+2023-09-27 23:37:26 - Inserting into: Report
diff --git a/utils/pageTemplate.php b/utils/pageTemplate.php
@@ -3,7 +3,8 @@
'index.php' => 'Agents',
'incidents.php' => 'Incidents',
'operations.php' => 'Operations',
- 'terrain.php' => 'Terrain'
+ 'terrain.php' => 'Terrain',
+ 'reports.php' => 'Reports'
];
?>
diff --git a/utils/tableFactory.php b/utils/tableFactory.php
@@ -39,7 +39,7 @@
/**
* Create table that redirects user to another address on click.
- * $tableName: The table to display.
+ * $query: The query to be displayed.
* $adress: The redirect adress. If user clicks a row, redirect to relative adress.
* $queryColumns: The columns that should be queried in the redirect.
*
@@ -47,7 +47,7 @@
* Clicking "Operation1" would result in a redirect to "./operationdetails.php/?OperationName=Operation1"
*/
//
- public static function createTableWithRedirect($tableName, $address, $queryColumns) {
+ public static function createTableWithRedirect($query, $address, $queryColumns) {
$db = dbconnection::getInstance();
$pdo = $db->getPdo();
@@ -55,7 +55,7 @@
try {
$firstRow = true;
- foreach($pdo->query('SELECT * FROM ' . $tableName . ';') AS $row) {
+ foreach($pdo->query($query) AS $row) {
if($firstRow) {
$output .= "<thead class='thead-dark'><tr>";
foreach($row as $key => $value) {
@@ -173,5 +173,44 @@
return '';
}
}
+
+ public static function createTableWithCallbackColumn($query, $function) {
+ $db = dbconnection::getInstance();
+ $pdo = $db->getPdo();
+
+ $output = "<div class='overflow-auto'><table class='table table-striped table-bordered'>";
+
+ try {
+ $firstRow = true;
+ foreach($pdo->query($query) AS $row) {
+ if($firstRow) {
+ $output .= "<thead class='thead-dark'><tr>";
+ foreach($row as $key => $value) {
+ if(!is_numeric($key)) {
+ $output .= "<th>" . $key . "</th>";
+ }
+ }
+
+ $output .= "<th>Action</th>";
+ $output .= "</tr></thead><tbody>";
+ $firstRow = false;
+ }
+ $output .= "<tr>";
+ foreach($row as $key => $value) {
+ if(!is_numeric($key)) {
+ $output .= "<td>" . $value . "</td>";
+ }
+ }
+ $output .= "<td>" . call_user_func($function, $row) . "</td>";
+ $output .= "</tr>";
+ }
+ $output .= "</tbody></table></div>";
+
+ return $output;
+ } catch (PDOException $e) {
+ echo "Error: " . $e->getMessage();
+ return '';
+ }
+ }
}
?>
\ No newline at end of file