|
15 | 15 | $array = $constellation->render_status(true, false); |
16 | 16 | echo json_encode($array); |
17 | 17 | }else{ |
18 | | - $query = $mysqli->prepare("SELECT name FROM services WHERE id=?"); |
19 | | - $query->bind_param("i", $_GET['id']); |
20 | | - $query->execute(); |
21 | | - $result = $query->get_result()->fetch_assoc(); |
| 18 | + // get id of service, check if service exists |
| 19 | + $queryId = $mysqli->prepare("SELECT id from services where id = ?;"); |
| 20 | + $queryId->bind_param("i", $_GET['id']); |
| 21 | + $queryId->execute(); |
| 22 | + $result = $queryId->get_result()->fetch_assoc(); |
22 | 23 | if (!count($result)) |
23 | 24 | { |
24 | 25 | die(json_encode(["error" => _("Service does not exist!")])); |
25 | 26 | } |
26 | | - |
27 | | - $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"); |
28 | | - |
29 | | - $sql->bind_param("iii", $id, $timestamp, $timestamp); |
30 | | - $sql->execute(); |
31 | | - $tmp = $sql->get_result(); |
32 | | - if ($tmp->num_rows) |
33 | | - { |
34 | | - $service = new Service($_GET['id'], $result['name'], $tmp->fetch_assoc()['type']); |
35 | | - } |
36 | | - else{ |
37 | | - $service = new Service($_GET['id'], $result['name']); |
| 27 | + // get name, description and status.type (status of service) by id |
| 28 | + $query = $mysqli->prepare("select services.id, name, description, status.type from services inner join status on status.id = services.id where services.id = ?;"); |
| 29 | + $query->bind_param("i", $_GET['id']); |
| 30 | + $query->execute(); |
| 31 | + $result = $query->get_result()->fetch_assoc(); |
| 32 | + // if type is a number then return it, else just return the service name/desc |
| 33 | + if (is_numeric($result["type"])) { |
| 34 | + $service = new Service($_GET["id"], $result["name"], $result["description"], '', $result["type"]); |
| 35 | + } else { |
| 36 | + $service = new Service($_GET["id"], $result["name"], $result["description"]); |
38 | 37 | } |
39 | 38 |
|
40 | 39 | echo json_encode($service); |
|
0 commit comments