Exemple #1
0
function get_event_actions_stat_hints($eventid)
{
    $actions = new CTable(' - ');
    $sql = 'SELECT COUNT(a.alertid) as cnt ' . ' FROM alerts a ' . ' WHERE a.eventid=' . $eventid . ' AND a.alerttype in (' . ALERT_TYPE_MESSAGE . ',' . ALERT_TYPE_COMMAND . ')';
    $alerts = DBfetch(DBselect($sql));
    if (isset($alerts['cnt']) && $alerts['cnt'] > 0) {
        $sql = 'SELECT COUNT(a.alertid) as sent ' . ' FROM alerts a ' . ' WHERE a.eventid=' . $eventid . ' AND a.alerttype in (' . ALERT_TYPE_MESSAGE . ',' . ALERT_TYPE_COMMAND . ')' . ' AND a.status=' . ALERT_STATUS_SENT;
        $alerts = DBfetch(DBselect($sql));
        $alert_cnt = new CSpan($alerts['sent'], 'green');
        if ($alerts['sent']) {
            $hint = get_actions_hint_by_eventid($eventid, ALERT_STATUS_SENT);
            $alert_cnt->SetHint($hint);
        }
        $tdl = new CCol($alerts['sent'] ? $alert_cnt : SPACE);
        $tdl->addOption('width', '10');
        $sql = 'SELECT COUNT(a.alertid) as inprogress ' . ' FROM alerts a ' . ' WHERE a.eventid=' . $eventid . ' AND a.alerttype in (' . ALERT_TYPE_MESSAGE . ',' . ALERT_TYPE_COMMAND . ')' . ' AND a.status=' . ALERT_STATUS_NOT_SENT;
        $alerts = DBfetch(DBselect($sql));
        $alert_cnt = new CSpan($alerts['inprogress'], 'orange');
        if ($alerts['inprogress']) {
            $hint = get_actions_hint_by_eventid($eventid, ALERT_STATUS_NOT_SENT);
            $alert_cnt->setHint($hint);
        }
        $tdc = new CCol($alerts['inprogress'] ? $alert_cnt : SPACE);
        $tdc->addOption('width', '10');
        $sql = 'SELECT COUNT(a.alertid) as failed ' . ' FROM alerts a ' . ' WHERE a.eventid=' . $eventid . ' AND a.alerttype in (' . ALERT_TYPE_MESSAGE . ',' . ALERT_TYPE_COMMAND . ')' . ' AND a.status=' . ALERT_STATUS_FAILED;
        $alerts = DBfetch(DBselect($sql));
        $alert_cnt = new CSpan($alerts['failed'], 'red');
        if ($alerts['failed']) {
            $hint = get_actions_hint_by_eventid($eventid, ALERT_STATUS_FAILED);
            $alert_cnt->setHint($hint);
        }
        $tdr = new CCol($alerts['failed'] ? $alert_cnt : SPACE);
        $tdr->addOption('width', '10');
        $actions->addRow(array($tdl, $tdc, $tdr));
    }
    return $actions;
}
function getEventActionsStatHints($eventIds)
{
    if (empty($eventIds)) {
        return array();
    }
    $actions = array();
    $alerts = DBselect('SELECT a.eventid,a.status,COUNT(a.alertid) AS cnt' . ' FROM alerts a' . ' WHERE a.alerttype IN (' . ALERT_TYPE_MESSAGE . ',' . ALERT_TYPE_COMMAND . ')' . ' AND ' . dbConditionInt('a.eventid', $eventIds) . ' GROUP BY eventid,status');
    while ($alert = DBfetch($alerts)) {
        if ($alert['cnt'] > 0) {
            if ($alert['status'] == ALERT_STATUS_SENT) {
                $color = 'green';
            } elseif ($alert['status'] == ALERT_STATUS_NOT_SENT) {
                $color = 'orange';
            } else {
                $color = 'red';
            }
            $hint = new CSpan($alert['cnt'], $color);
            $hint->setHint(get_actions_hint_by_eventid($alert['eventid'], $alert['status']));
            $actions[$alert['eventid']][$alert['status']] = $hint;
        }
    }
    foreach ($actions as $eventId => $action) {
        $actions[$eventId] = new CDiv(null, 'event-action-cont');
        $actions[$eventId]->addItem(array(new CDiv(isset($action[ALERT_STATUS_SENT]) ? $action[ALERT_STATUS_SENT] : SPACE), new CDiv(isset($action[ALERT_STATUS_NOT_SENT]) ? $action[ALERT_STATUS_NOT_SENT] : SPACE), new CDiv(isset($action[ALERT_STATUS_FAILED]) ? $action[ALERT_STATUS_FAILED] : SPACE)));
    }
    return $actions;
}