Index: include/actions.inc.php =================================================================== --- include/actions.inc.php (revision 32601) +++ include/actions.inc.php (working copy) @@ -933,128 +933,83 @@ function get_event_actions_status($eventid) { $actionTable = new CTable(' - '); - $alerts = DBfetch(DBselect( - 'SELECT COUNT(a.alertid) AS cnt_all'. - ' FROM alerts a'. - ' WHERE a.eventid='.$eventid. - ' AND a.alerttype IN ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')' - )); + $alerts = DBfetchArray(DBselect( + 'SELECT a.status, COUNT(a.alertid) AS cnt'. + ' FROM alerts a'. + ' WHERE a.eventid='.$eventid. + ' AND a.alerttype IN ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.') GROUP BY a.status' + )); - if (isset($alerts['cnt_all']) && $alerts['cnt_all'] > 0) { - $mixed = 0; + if (zbx_empty($alerts)) { + return $actionTable; + } - // sent - $tmp = DBfetch(DBselect( - '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['sent'] = $tmp['sent']; - $mixed += $alerts['sent'] ? ALERT_STATUS_SENT : 0; + $alerts = zbx_toHash($alerts, 'status'); - // in progress - $tmp = DBfetch(DBselect( - '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['inprogress'] = $tmp['inprogress']; + if (isset($alerts[ALERT_STATUS_NOT_SENT])) { + $status = new CSpan(_('In progress'), 'orange'); + } + elseif (!isset($alerts[ALERT_STATUS_FAILED])) { + $status = new CSpan(_('Ok'), 'green'); + } + elseif (!isset($alerts[ALERT_STATUS_SENT])) { + $status = new CSpan(_('Failed'), 'red'); + } + else { + $tdl = new CCol(isset($alerts[ALERT_STATUS_SENT]) ? new CSpan($alerts[ALERT_STATUS_SENT]['cnt'], 'green') : SPACE); + $tdl->setAttribute('width', '10'); - // failed - $tmp = DBfetch(DBselect( - '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['failed'] = $tmp['failed']; - $mixed += $alerts['failed'] ? ALERT_STATUS_FAILED : 0; + $tdr = new CCol(isset($alerts[ALERT_STATUS_FAILED]) ? new CSpan($alerts[ALERT_STATUS_FAILED]['cnt'], 'red') : SPACE); + $tdr->setAttribute('width', '10'); - if ($alerts['inprogress']) { - $status = new CSpan(_('In progress'), 'orange'); - } - elseif ($mixed == ALERT_STATUS_SENT) { - $status = new CSpan(_('Ok'), 'green'); - } - elseif ($mixed == ALERT_STATUS_FAILED) { - $status = new CSpan(_('Failed'), 'red'); - } - else { - $tdl = new CCol($alerts['sent'] ? new CSpan($alerts['sent'], 'green') : SPACE); - $tdl->setAttribute('width', '10'); + $status = new CRow(array($tdl, $tdr)); + } - $tdr = new CCol($alerts['failed'] ? new CSpan($alerts['failed'], 'red') : SPACE); - $tdr->setAttribute('width', '10'); + $actionTable->addRow($status); - $status = new CRow(array($tdl, $tdr)); - } - $actionTable->addRow($status); - } return $actionTable; } function get_event_actions_stat_hints($eventid) { $actionCont = new CDiv(null, 'event-action-cont'); - $alerts = DBfetch(DBselect( - 'SELECT COUNT(a.alertid) AS cnt'. + $alerts = DBfetchArray(DBselect( + 'SELECT a.status, COUNT(a.alertid) AS cnt'. ' FROM alerts a'. ' WHERE a.eventid='.$eventid. - ' AND a.alerttype IN ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.')' + ' AND a.alerttype IN ('.ALERT_TYPE_MESSAGE.','.ALERT_TYPE_COMMAND.') GROUP BY a.status' )); - if (isset($alerts['cnt']) && $alerts['cnt'] > 0) { - // left - $alerts = DBfetch(DBselect( - '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 - )); - $alert_cnt = new CSpan($alerts['sent'], 'green'); - if ($alerts['sent']) { - $alert_cnt->setHint(get_actions_hint_by_eventid($eventid, ALERT_STATUS_SENT)); - } - $left = new CDiv($alerts['sent'] ? $alert_cnt : SPACE); + if (zbx_empty($alerts)) { + $actionCont->addItem('-'); + return $actionCont; + } - // center - $alerts = DBfetch(DBselect( - '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 - )); - $alert_cnt = new CSpan($alerts['inprogress'], 'orange'); - if ($alerts['inprogress']) { - $alert_cnt->setHint(get_actions_hint_by_eventid($eventid, ALERT_STATUS_NOT_SENT)); - } - $center = new CDiv($alerts['inprogress'] ? $alert_cnt : SPACE); + $alerts = zbx_toHash($alerts, 'status'); - // right - $alerts = DBfetch(DBselect( - '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 - )); - $alert_cnt = new CSpan($alerts['failed'], 'red'); - if ($alerts['failed']) { - $alert_cnt->setHint(get_actions_hint_by_eventid($eventid, ALERT_STATUS_FAILED)); - } - $right = new CDiv($alerts['failed'] ? $alert_cnt : SPACE); + $alerts_sent = isset($alerts[ALERT_STATUS_SENT]) ? $alerts[ALERT_STATUS_SENT]['cnt'] : 0; + $alerts_notsent = isset($alerts[ALERT_STATUS_NOT_SENT]) ? $alerts[ALERT_STATUS_NOT_SENT]['cnt'] : 0; + $alerts_failed = isset($alerts[ALERT_STATUS_FAILED]) ? $alerts[ALERT_STATUS_FAILED]['cnt'] : 0; - $actionCont->addItem(array($left, $center, $right)); - } - else { - $actionCont->addItem('-'); - } + $alert_cnt = new CSpan($alerts_sent, 'green'); + if ($alerts_sent) { + $alert_cnt->setHint(get_actions_hint_by_eventid($eventid, ALERT_STATUS_SENT)); + } + $left = new CDiv($alerts_sent ? $alert_cnt : SPACE); + + $alert_cnt = new CSpan($alerts_notsent, 'orange'); + if ($alerts_notsent) { + $alert_cnt->setHint(get_actions_hint_by_eventid($eventid, ALERT_STATUS_NOT_SENT)); + } + $center = new CDiv($alerts_notsent ? $alert_cnt : SPACE); + + $alert_cnt = new CSpan($alerts_failed, 'red'); + if ($alerts_failed) { + $alert_cnt->setHint(get_actions_hint_by_eventid($eventid, ALERT_STATUS_FAILED)); + } + $right = new CDiv($alerts_failed ? $alert_cnt : SPACE); + + $actionCont->addItem(array($left, $center, $right)); + return $actionCont; }