Пример #1
0
function get_act_operations_form($action = null)
{
    $tblOper = new CTableInfo(S_NO_OPERATIONS_DEFINED);
    $tblOper->addOption('style', 'background-color: #CCC;');
    if (isset($_REQUEST['actionid']) && empty($action)) {
        $action = get_action_by_actionid($_REQUEST['actionid']);
    }
    $operations = get_request('operations', array());
    if (isset($_REQUEST['actionid']) && !isset($_REQUEST['form_refresh'])) {
        $eventsource = $action['eventsource'];
        $evaltype = $action['evaltype'];
        $esc_period = $action['esc_period'];
        /* prepate operations */
        $db_operations = DBselect('SELECT * ' . ' FROM operations' . ' WHERE actionid=' . $_REQUEST['actionid'] . ' ORDER BY esc_step_from,operationtype,object,operationid');
        while ($operation_data = DBfetch($db_operations)) {
            $operation_data = array('operationtype' => $operation_data['operationtype'], 'operationid' => $operation_data['operationid'], 'object' => $operation_data['object'], 'objectid' => $operation_data['objectid'], 'shortdata' => $operation_data['shortdata'], 'longdata' => $operation_data['longdata'], 'esc_period' => $operation_data['esc_period'], 'esc_step_from' => $operation_data['esc_step_from'], 'esc_step_to' => $operation_data['esc_step_to'], 'default_msg' => $operation_data['default_msg'], 'evaltype' => $operation_data['evaltype']);
            $operation_data['opconditions'] = array();
            $sql = 'SELECT * FROM opconditions WHERE operationid=' . $operation_data['operationid'];
            $db_opconds = DBselect($sql);
            while ($db_opcond = DBfetch($db_opconds)) {
                $operation_data['opconditions'][] = $db_opcond;
            }
            if (str_in_array($operation_data, $operations)) {
                continue;
            }
            array_push($operations, $operation_data);
        }
        unset($db_operations, $operation_data);
    } else {
        $eventsource = get_request('eventsource');
        $evaltype = get_request('evaltype');
        $esc_period = get_request('esc_period');
    }
    $esc_step_from = array();
    foreach ($operations as $key => $operation) {
        $esc_step_from[$key] = $operation['esc_step_from'];
    }
    array_multisort($esc_step_from, SORT_ASC, $operations);
    $tblOper->SetHeader(array(new CCheckBox('all_operations', null, 'CheckAll("' . S_ACTION . '","all_operations","g_operationid");'), isset($_REQUEST['escalation']) ? S_STEPS : null, S_DETAILS, isset($_REQUEST['escalation']) ? S_PERIOD . ' (' . S_SEC_SMALL . ')' : null, isset($_REQUEST['escalation']) ? S_DELAY : null, S_ACTION));
    $allowed_operations = get_operations_by_eventsource($eventsource);
    zbx_rksort($operations);
    $delay = count_operations_delay($operations, $esc_period);
    foreach ($operations as $id => $val) {
        if (!str_in_array($val['operationtype'], $allowed_operations)) {
            continue;
        }
        if (!isset($val['default_msg'])) {
            $val['default_msg'] = 0;
        }
        if (!isset($val['opconditions'])) {
            $val['opconditions'] = array();
        }
        $oper_details = new CSpan(get_operation_desc(SHORT_DESCRITION, $val));
        $oper_details->SetHint(nl2br(get_operation_desc(LONG_DESCRITION, $val)));
        $esc_steps_txt = null;
        $esc_period_txt = null;
        $esc_delay_txt = null;
        if ($val['esc_step_from'] < 1) {
            $val['esc_step_from'] = 1;
        }
        if (isset($_REQUEST['escalation'])) {
            $esc_steps_txt = $val['esc_step_from'] . ' - ' . $val['esc_step_to'];
            $esc_period_txt = $val['esc_period'] ? $val['esc_period'] : S_DEFAULT;
            $esc_delay_txt = $delay[$val['esc_step_from']] ? convert_units($delay[$val['esc_step_from']], 'uptime') : S_AT_MOMENT;
        }
        $tblOper->addRow(array(new CCheckBox("g_operationid[]", 'no', null, $id), $esc_steps_txt, $oper_details, $esc_period_txt, $esc_delay_txt, new CButton('edit_operationid[' . $id . ']', S_EDIT)));
        $tblOper->addItem(new CVar('operations[' . $id . '][operationtype]', $val['operationtype']));
        $tblOper->addItem(new CVar('operations[' . $id . '][object]', $val['object']));
        $tblOper->addItem(new CVar('operations[' . $id . '][objectid]', $val['objectid']));
        $tblOper->addItem(new CVar('operations[' . $id . '][shortdata]', $val['shortdata']));
        $tblOper->addItem(new CVar('operations[' . $id . '][longdata]', $val['longdata']));
        $tblOper->addItem(new CVar('operations[' . $id . '][esc_period]', $val['esc_period']));
        $tblOper->addItem(new CVar('operations[' . $id . '][esc_step_from]', $val['esc_step_from']));
        $tblOper->addItem(new CVar('operations[' . $id . '][esc_step_to]', $val['esc_step_to']));
        $tblOper->addItem(new CVar('operations[' . $id . '][default_msg]', $val['default_msg']));
        $tblOper->addItem(new CVar('operations[' . $id . '][evaltype]', $val['evaltype']));
        foreach ($val['opconditions'] as $opcondid => $opcond) {
            foreach ($opcond as $field => $value) {
                $tblOper->addItem(new CVar('operations[' . $id . '][opconditions][' . $opcondid . '][' . $field . ']', $value));
            }
        }
    }
    unset($operations);
    $tblOperFooter = new CTableInfo(null);
    $oper_buttons = array();
    if (!isset($_REQUEST['new_operation'])) {
        $oper_buttons[] = new CButton('new_operation', S_NEW);
    }
    if ($tblOper->ItemsCount() > 0) {
        $oper_buttons[] = new CButton('del_operation', S_DELETE_SELECTED);
    }
    $td = new CCol($oper_buttons);
    $td->addOption('colspan', isset($_REQUEST['escalation']) ? 6 : 3);
    $td->addOption('style', 'text-align: right;');
    $tblOperFooter->SetFooter($td);
    // end of condition list preparation
    return array($tblOper, $tblOperFooter);
}
Пример #2
0
$conditionTable->addRow(array($conditionTypeComboBox, $conditionOperatorsComboBox, $condition));
$conditionTable->addRow(array(new CSubmit('add_condition', _('Add'), null, 'link_menu'), SPACE, SPACE));
$conditionFormList->addRow(_('New condition'), new CDiv($conditionTable, 'objectgroup inlineblock border_dotted ui-corner-all'));
/*
 * Operation tab
 */
$operationFormList = new CFormList('operationlist');
if ($this->data['eventsource'] == EVENT_SOURCE_TRIGGERS || $this->data['eventsource'] == EVENT_SOURCE_INTERNAL) {
    $operationFormList->addRow(_('Default operation step duration'), array(new CNumericBox('esc_period', $this->data['action']['esc_period'], 6, 'no'), ' (' . _('minimum 60 seconds') . ')'));
}
// create operation table
$operationsTable = new CTable(_('No operations defined.'), 'formElementTable');
$operationsTable->attr('style', 'min-width: 600px;');
if ($this->data['action']['eventsource'] == EVENT_SOURCE_TRIGGERS || $this->data['eventsource'] == EVENT_SOURCE_INTERNAL) {
    $operationsTable->setHeader(array(_('Steps'), _('Details'), _('Start in'), _('Duration (sec)'), _('Action')));
    $delay = count_operations_delay($this->data['action']['operations'], $this->data['action']['esc_period']);
} else {
    $operationsTable->setHeader(array(_('Details'), _('Action')));
}
foreach ($this->data['action']['operations'] as $operationid => $operation) {
    if (!str_in_array($operation['operationtype'], $this->data['allowedOperations'])) {
        continue;
    }
    if (!isset($operation['opconditions'])) {
        $operation['opconditions'] = array();
    }
    if (!isset($operation['mediatypeid'])) {
        $operation['mediatypeid'] = 0;
    }
    $details = new CSpan(get_operation_descr(SHORT_DESCRIPTION, $operation));
    $details->setHint(get_operation_descr(LONG_DESCRIPTION, $operation));
Пример #3
0
     $eventsource = get_request('eventsource');
     $evaltype = get_request('evaltype');
     $esc_period = get_request('esc_period');
 }
 $esc_step_from = array();
 $objects_tmp = array();
 $objectids_tmp = array();
 foreach ($operations as $key => $operation) {
     $esc_step_from[$key] = $operation['esc_step_from'];
     $objects_tmp[$key] = $operation['object'];
     $objectids_tmp[$key] = $operation['objectid'];
 }
 array_multisort($esc_step_from, SORT_ASC, SORT_NUMERIC, $objects_tmp, SORT_DESC, $objectids_tmp, SORT_ASC, $operations);
 $tblOper->setHeader(array(new CCheckBox('all_operations', null, 'checkAll("' . S_ACTION . '","all_operations","g_operationid");'), isset($_REQUEST['escalation']) ? S_STEPS : null, S_DETAILS, isset($_REQUEST['escalation']) ? S_PERIOD . ' (' . S_SEC_SMALL . ')' : null, isset($_REQUEST['escalation']) ? S_DELAY : null, S_ACTION));
 $allowed_operations = get_operations_by_eventsource($eventsource);
 $delay = count_operations_delay($operations, $esc_period);
 foreach ($operations as $id => $condition) {
     if (!str_in_array($condition['operationtype'], $allowed_operations)) {
         continue;
     }
     if (!isset($condition['default_msg'])) {
         $condition['default_msg'] = 0;
     }
     if (!isset($condition['opconditions'])) {
         $condition['opconditions'] = array();
     }
     if (!isset($condition['mediatypeid'])) {
         $condition['mediatypeid'] = 0;
     }
     $oper_details = new CSpan(get_operation_desc(SHORT_DESCRITION, $condition));
     $oper_details->setHint(nl2br(get_operation_desc(LONG_DESCRITION, $condition)));