From 58b375161df1e18c19942e4789a4306df6038155 Mon Sep 17 00:00:00 2001
From: Steffen Mueller <steffen.mueller@sovdwaer.de>
Date: Mon, 15 Mar 2021 08:57:14 +0100
Subject: [PATCH 1/2] Big fix for status api with parameter ID

---
 api/status.php | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/api/status.php b/api/status.php
index 5ace02d..613cc7d 100644
--- a/api/status.php
+++ b/api/status.php
@@ -15,26 +15,24 @@ else{
 	  $array = $constellation->render_status(true, false);
 	  echo json_encode($array);
   }else{
-  	$query = $mysqli->prepare("SELECT name FROM services WHERE id=?");
-  	$query->bind_param("i", $_GET['id']);
-  	$query->execute();
-    $result = $query->get_result()->fetch_assoc();
+    $queryId = $mysqli->prepare("SELECT id as 'id' from services where id = ?;");
+    $queryId->bind_param("i", $_GET['id']);
+    $queryId->execute();
+    $result = $queryId->get_result()->fetch_assoc();
     if (!count($result))
     {
     	die(json_encode(["error" => _("Service does not exist!")]));
     }
 
-  	$sql = $mysqli->prepare("SELECT type FROM services_status INNER JOIN status ON services_status.status_id = status.id WHERE service_id = ? AND `time` <= ? AND (`end_time` >= ? OR `end_time`=0) ORDER BY `time` DESC LIMIT 1");
+  	$query = $mysqli->prepare("select services.id, name, description, status.type from services inner join status on status.id = services.id where services.id = ?;");
+  	$query->bind_param("i", $_GET['id']);
+  	$query->execute();
+    $result = $query->get_result()->fetch_assoc();
 
-    $sql->bind_param("iii", $id, $timestamp, $timestamp);
-    $sql->execute();
-    $tmp = $sql->get_result();
-    if ($tmp->num_rows)
-    {
-      $service = new Service($_GET['id'], $result['name'], $tmp->fetch_assoc()['type']);
-    }
-    else{
-      $service = new Service($_GET['id'], $result['name']);
+    if (is_numeric($result["type"])) {
+      $service = new Service($_GET["id"], $result["name"], $result["description"], '', $result["type"]);
+    } else {
+      $service = new Service($_GET["id"], $result["name"], $result["description"]);
     }
 
     echo json_encode($service);

From 002bb13e10e8e1c95236a6e040ec0d5eee79cb17 Mon Sep 17 00:00:00 2001
From: Steffen Mueller <steffen.mueller@sovdwaer.de>
Date: Mon, 15 Mar 2021 08:57:14 +0100
Subject: [PATCH 2/2] Fix for status api by correcting sql queries

---
 api/status.php | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/api/status.php b/api/status.php
index 613cc7d..bbbf1f4 100644
--- a/api/status.php
+++ b/api/status.php
@@ -15,7 +15,8 @@ else{
 	  $array = $constellation->render_status(true, false);
 	  echo json_encode($array);
   }else{
-    $queryId = $mysqli->prepare("SELECT id as 'id' from services where id = ?;");
+    // get id of service, check if service exists
+    $queryId = $mysqli->prepare("SELECT id from services where id = ?;");
     $queryId->bind_param("i", $_GET['id']);
     $queryId->execute();
     $result = $queryId->get_result()->fetch_assoc();
@@ -23,12 +24,12 @@ else{
     {
     	die(json_encode(["error" => _("Service does not exist!")]));
     }
-
+    // get name, description and status.type (status of service) by id
   	$query = $mysqli->prepare("select services.id, name, description, status.type from services inner join status on status.id = services.id where services.id = ?;");
   	$query->bind_param("i", $_GET['id']);
   	$query->execute();
     $result = $query->get_result()->fetch_assoc();
-
+    // if type is a number then return it, else just return the service name/desc
     if (is_numeric($result["type"])) {
       $service = new Service($_GET["id"], $result["name"], $result["description"], '', $result["type"]);
     } else {