Big fix for status api with parameter ID

This commit is contained in:
Steffen Mueller 2021-03-15 08:57:14 +01:00
parent f33bf996c6
commit 58b375161d
1 changed files with 12 additions and 14 deletions

View File

@ -15,26 +15,24 @@ else{
$array = $constellation->render_status(true, false); $array = $constellation->render_status(true, false);
echo json_encode($array); echo json_encode($array);
}else{ }else{
$query = $mysqli->prepare("SELECT name FROM services WHERE id=?"); $queryId = $mysqli->prepare("SELECT id as 'id' from services where id = ?;");
$query->bind_param("i", $_GET['id']); $queryId->bind_param("i", $_GET['id']);
$query->execute(); $queryId->execute();
$result = $query->get_result()->fetch_assoc(); $result = $queryId->get_result()->fetch_assoc();
if (!count($result)) if (!count($result))
{ {
die(json_encode(["error" => _("Service does not exist!")])); 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); if (is_numeric($result["type"])) {
$sql->execute(); $service = new Service($_GET["id"], $result["name"], $result["description"], '', $result["type"]);
$tmp = $sql->get_result(); } else {
if ($tmp->num_rows) $service = new Service($_GET["id"], $result["name"], $result["description"]);
{
$service = new Service($_GET['id'], $result['name'], $tmp->fetch_assoc()['type']);
}
else{
$service = new Service($_GET['id'], $result['name']);
} }
echo json_encode($service); echo json_encode($service);