2018-04-13 15:31:03 -04:00
< ? php
if ( ! file_exists ( " ../config.php " ))
{
header ( " Location: ../ " );
}
else {
require_once ( " ../config.php " );
require_once ( " ../classes/constellation.php " );
2018-06-07 15:42:06 -04:00
header ( 'Cache-Control: no-cache' );
header ( 'Content-type: application/json' );
2018-04-13 15:31:03 -04:00
if ( ! isset ( $_GET [ 'id' ]))
{
$array = $constellation -> render_status ( true , false );
echo json_encode ( $array );
} else {
2021-03-15 03:57:14 -04:00
// get id of service, check if service exists
$queryId = $mysqli -> prepare ( " SELECT id from services where id = ?; " );
2021-03-15 03:57:14 -04:00
$queryId -> bind_param ( " i " , $_GET [ 'id' ]);
$queryId -> execute ();
$result = $queryId -> get_result () -> fetch_assoc ();
2018-04-13 15:31:03 -04:00
if ( ! count ( $result ))
{
die ( json_encode ([ " error " => _ ( " Service does not exist! " )]));
}
2021-03-15 03:57:14 -04:00
// get name, description and status.type (status of service) by id
2021-03-15 03:57:14 -04:00
$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 ();
2021-03-15 03:57:14 -04:00
// if type is a number then return it, else just return the service name/desc
2021-03-15 03:57:14 -04:00
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 " ]);
2018-04-13 15:31:03 -04:00
}
echo json_encode ( $service );
}
}