<?php if (!$this->compact): ?>
    <div class="controls">
        <?= $this->tabs ?>
    </div>
<?php endif ?>
<div class="content">
    <div class="boxview" data-base-target="_next">

<?php
if (count($servicegroups) === 0) {
    echo mt('monitoring', 'No service groups matching the filter');
}
?>
<?php foreach($servicegroups as $servicegroup): ?>
        <div class="box servicegroup">
            <h2>
                <a href="<?= $this->href(
                    'monitoring/list/services',
                    array('servicegroup' => $servicegroup->servicegroup)
                ); ?>">
                    <?= $servicegroup->servicegroup; ?>
                </a>
            </h2>
            <div class="box contents">
                <table>
                    <thead>
                        <tr>
                            <th><?= $this->translate('Hosts'); ?></th>
                            <th><?= $this->translate('Services'); ?></th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>
<?php if ($servicegroup->hosts_down_handled || $servicegroup->hosts_down_unhandled): ?>
                                <!-- Hosts DOWN -->
                                <div class="box entry state_down <?= $servicegroup->hosts_down_unhandled ? '' : 'handled'; ?>">
<?php if ($servicegroup->hosts_down_unhandled): ?>
                                    <a href="<?= $this->href(
                                        'monitoring/list/hosts',
                                        array(
                                            'host_state'        => 1,
                                            'host_unhandled'    => 1,
                                            'servicegroup'      => $servicegroup->servicegroup
                                        )
                                    ); ?>" title="<?= $this->translate('Hosts DOWN Unhandled') ?>">
                                        <?= $servicegroup->hosts_down_unhandled; ?> <?= $this->translate('DOWN', 'icinga.state') ?>
                                    </a>
<?php endif ?>
<?php if ($servicegroup->hosts_down_handled): ?>
                                    <a href="<?= $this->href(
                                        'monitoring/list/hosts',
                                        array(
                                            'host_state'    => 1,
                                            'host_handled'  => 1,
                                            'servicegroup'  => $servicegroup->servicegroup
                                        )
                                    ); ?>" title="<?= $this->translate('Hosts DOWN Handled') ?>">
                                        <?= $servicegroup->hosts_down_handled . ' ' . ($servicegroup->hosts_down_unhandled ? $this->translate('Acknowledged') : 'DOWN'); ?>
                                    </a>
<?php endif ?>
                                </div>
                                <!-- End of Hosts DOWN -->
<?php endif ?>
<?php if ($servicegroup->hosts_unreachable_handled || $servicegroup->hosts_unreachable_unhandled): ?>
                                <!-- Hosts UNREACHABLE -->
                                <div class="box entry state_unreachable <?= $servicegroup->hosts_unreachable_unhandled ? '' : 'handled'; ?>">
<?php if ($servicegroup->hosts_unreachable_unhandled): ?>
                                    <a href="<?= $this->href(
                                        'monitoring/list/hosts',
                                        array(
                                            'host_state'        => 2,
                                            'host_unhandled'    => 1,
                                            'servicegroup'      => $servicegroup->servicegroup
                                        )
                                    ); ?>" title="<?= $this->translate('Hosts UNREACHABLE Unhandled') ?>">
                                        <?= $servicegroup->hosts_unreachable_unhandled; ?> <?= $this->translate('UNREACHABLE', 'icinga.state') ?>
                                    </a>
<?php endif ?>
<?php if ($servicegroup->hosts_unreachable_handled): ?>
                                    <a href="<?= $this->href(
                                        'monitoring/list/hosts',
                                        array(
                                            'host_state'    => 2,
                                            'host_handled'  => 1,
                                            'servicegroup'  => $servicegroup->servicegroup
                                        )
                                    ); ?>" title="<?= $this->translate('Hosts UNREACHABLE Handled') ?>">
                                        <?= $servicegroup->hosts_unreachable_handled . ' ' . ($servicegroup->hosts_unreachable_unhandled ? $this->translate('Acknowledged') : 'UNREACHABLE'); ?>
                                    </a>
<?php endif ?>
                                </div>
                                <!-- End of Hosts UNREACHABLE -->
<?php endif ?>
<?php if ($servicegroup->hosts_up): ?>
                                <!-- Hosts UP -->
                                <div class="box entry state_up">
                                    <a href="<?= $this->href(
                                        'monitoring/list/hosts',
                                        array(
                                            'host_state'    => 0,
                                            'servicegroup'  => $servicegroup->servicegroup
                                        )
                                    ); ?>" title="<?= $this->translate('Hosts UP') ?>">
                                        <?= $servicegroup->hosts_up; ?> <?= $this->translate('UP', 'icinga.state') ?>
                                    </a>
                                </div>
                                <!-- End of Hosts UP -->
<?php endif ?>
<?php if ($servicegroup->hosts_pending): ?>
                                <!-- Hosts PENDING -->
                                <div class="box entry state_pending">
                                    <a href="<?= $this->href(
                                        'monitoring/list/hosts',
                                        array(
                                            'host_state'    => 99,
                                            'servicegroup'  => $servicegroup->servicegroup
                                        )
                                    ); ?>" title="<?= $this->translate('Hosts PENDING') ?>">
                                        <?= $servicegroup->hosts_pending; ?> <?= $this->translate('PENDING', 'icinga.state') ?>
                                    </a>
                                </div>
                                <!-- End of Hosts PENDING -->
<?php endif ?>
                            </td>
                            <td>
<?php if ($servicegroup->services_critical_handled || $servicegroup->services_critical_unhandled): ?>
                                <!-- Services CRITICAL -->
                                <div class="box entry state_critical <?= $servicegroup->services_critical_unhandled ? '' : 'handled'; ?>">
<?php if ($servicegroup->services_critical_unhandled): ?>
                                    <a href="<?= $this->href(
                                        'monitoring/list/services',
                                        array(
                                            'service_state'         => 2,
                                            'service_acknowledged'  => 0,
                                            'service_in_downtime'   => 0,
                                            'host_problem'          => 0,
                                            'servicegroup'          => $servicegroup->servicegroup,
                                            'sort'                  => 'service_severity'
                                        )
                                    ); ?>" title="<?= $this->translate('Services CRITICAL Unhandled') ?>">
                                        <?= $servicegroup->services_critical_unhandled; ?> <?= $this->translate('CRITICAL', 'icinga.state') ?>
                                    </a>
<?php endif ?>
<?php if ($servicegroup->services_critical_handled): ?>
                                    <a href="<?= $this->href(
                                        'monitoring/list/services',
                                        array(
                                            'service_state'     => 2,
                                            'service_handled'   => 1,
                                            'servicegroup'      => $servicegroup->servicegroup,
                                            'sort'              => 'service_severity'
                                        )
                                    ); ?>" title="<?= $this->translate('Services CRITICAL Handled') ?>">
                                        <?= $servicegroup->services_critical_handled . ' ' . ($servicegroup->services_critical_unhandled ? $this->translate('Acknowledged') : 'CRITICAL'); ?>
                                    </a>
<?php endif ?>
                                </div>
                                <!-- End of Services CRITICAL -->
<?php endif ?>
<?php if ($servicegroup->services_warning_handled || $servicegroup->services_warning_unhandled): ?>
                                <!-- Services WARNING -->
                                <div class="box entry state_warning <?= $servicegroup->services_warning_unhandled ? '' : 'handled'; ?>">
<?php if ($servicegroup->services_warning_unhandled): ?>
                                    <a href="<?= $this->href(
                                        'monitoring/list/services',
                                        array(
                                            'service_state'         => 1,
                                            'service_acknowledged'  => 0,
                                            'service_in_downtime'   => 0,
                                            'host_problem'          => 0,
                                            'servicegroup'          => $servicegroup->servicegroup,
                                            'sort'                  => 'service_severity'
                                        )
                                    ); ?>" title="<?= $this->translate('Services WARNING Unhandled') ?>">
                                        <?= $servicegroup->services_warning_unhandled; ?> <?= $this->translate('WARNING', 'icinga.state') ?>
                                    </a>
<?php endif ?>
<?php if ($servicegroup->services_warning_handled): ?>
                                    <a href="<?= $this->href(
                                        'monitoring/list/services',
                                        array(
                                            'service_state'     => 1,
                                            'service_handled'   => 1,
                                            'servicegroup'      => $servicegroup->servicegroup,
                                            'sort'              => 'service_severity'
                                        )
                                    ); ?>" title="<?= $this->translate('Services WARNING Handled') ?>">
                                        <?= $servicegroup->services_warning_handled . ' ' . ($servicegroup->services_warning_unhandled ? $this->translate('Acknowledged') : 'WARNING'); ?>
                                    </a>
<?php endif ?>
                                </div>
                                <!-- End of Services WARNING -->
<?php endif ?>
<?php if ($servicegroup->services_unknown_handled || $servicegroup->services_unknown_unhandled): ?>
                                <!-- Services UNKNOWN -->
                                <div class="box entry state_unknown <?= $servicegroup->services_unknown_unhandled ? '' : 'handled'; ?>">
<?php if ($servicegroup->services_unknown_unhandled): ?>
                                    <a href="<?= $this->href(
                                        'monitoring/list/services',
                                        array(
                                            'service_state'         => 3,
                                            'service_acknowledged'  => 0,
                                            'service_in_downtime'   => 0,
                                            'host_problem'          => 0,
                                            'servicegroup'          => $servicegroup->servicegroup,
                                            'sort'                  => 'service_severity'
                                        )
                                    ); ?>" title="<?= $this->translate('Services UNKNOWN Unhandled') ?>">
                                        <?= $servicegroup->services_unknown_unhandled; ?> <?= $this->translate('UNKNOWN', 'icinga.state') ?>
                                    </a>
<?php endif ?>
<?php if ($servicegroup->services_unknown_handled): ?>
                                    <a href="<?= $this->href(
                                        'monitoring/list/services',
                                        array(
                                            'service_state'     => 3,
                                            'service_handled'   => 1,
                                            'servicegroup'      => $servicegroup->servicegroup,
                                            'sort'              => 'service_severity'
                                        )
                                    ); ?>" title="<?= $this->translate('Services UNKNOWN Handled') ?>">
                                        <?= $servicegroup->services_unknown_handled . ' ' . ($servicegroup->services_unknown_unhandled ? $this->translate('Acknowledged') : 'UNKNOWN'); ?>
                                    </a>
<?php endif ?>
                                </div>
                                <!-- End of Services UNKNOWN -->
<?php endif ?>
<?php if ($servicegroup->services_ok): ?>
                                <!-- Services OK -->
                                <div class="box entry state_ok">
                                    <a href="<?= $this->href(
                                        'monitoring/list/services',
                                        array(
                                            'service_state' => 0,
                                            'servicegroup'  => $servicegroup->servicegroup,
                                            'sort'          => 'service_severity'
                                        )
                                    ); ?>" title="<?= $this->translate('Services OK') ?>">
                                        <?= $servicegroup->services_ok; ?> <?= $this->translate('OK', 'icinga.state') ?>
                                    </a>
                                </div>
                                <!-- End of Services OK -->
<?php endif ?>
<?php if ($servicegroup->services_pending): ?>
                                <!-- Services PENDING -->
                                <div class="box entry state_pending">
                                    <a href="<?= $this->href(
                                        'monitoring/list/services',
                                        array(
                                            'service_state' => 99,
                                            'servicegroup'  => $servicegroup->servicegroup,
                                            'sort'          => 'service_severity'
                                        )
                                    ); ?>" title="<?= $this->translate('Services PENDING') ?>">
                                        <?= $servicegroup->services_pending; ?> <?= $this->translate('PENDING', 'icinga.state') ?>
                                    </a>
                                </div>
                                <!-- End of Services PENDING -->
<?php endif ?>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
<?php endforeach; ?>
    </div>
</div>
