mirror of
				https://github.com/ShaYmez/FreeSTAR-Status-Engine.git
				synced 2025-10-31 03:50:20 -04:00 
			
		
		
		
	Merge pull request #148 from Steffen-MLR/master
Fix for status api by correcting sql queries
This commit is contained in:
		
						commit
						c9bcbc241b
					
				| @ -15,26 +15,25 @@ 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(); | ||||
|     // 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(); | ||||
|     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"); | ||||
| 
 | ||||
|     $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']); | ||||
|     // 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 { | ||||
|       $service = new Service($_GET["id"], $result["name"], $result["description"]); | ||||
|     } | ||||
| 
 | ||||
|     echo json_encode($service); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user