';
}
}
}
/**
* Renders service status - in admin page it returns array so it can be processed further.
* @param boolean $admin
* @return array of services
*/
public function render_status($admin = false, $heading = true)
{
global $mysqli;
//$query = $mysqli->query("SELECT id, name, description FROM services");
$query = $mysqli->query("SELECT services.id, services.name, services.description, services_groups.name as group_name FROM services LEFT JOIN services_groups ON services.group_id=services_groups.id ORDER BY services_groups.name ");
$array = array();
if ($query->num_rows) {
$timestamp = time();
while ($result = $query->fetch_assoc()) {
$id = $result['id'];
$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) {
$array[] = new Service($result['id'], $result['name'], $result['description'], $result['group_name'], $tmp->fetch_assoc()['type']);
} else {
$array[] = new Service($result['id'], $result['name'], $result['description'], $result['group_name']);
}
}
if ($heading) {
echo Service::current_status($array);
}
} else {
$array[] = new Service(0, _("No services"), -1);
}
if (!$admin) {
//echo '