$stepTable = new CTable();
     $stepTable->addRow(array(_('From'), $stepFrom), 'indent_both');
     $stepTable->addRow(array(_('To'), new CCol(array($stepTo, SPACE, _('(0 - infinitely)')))), 'indent_both');
     $stepTable->addRow(array(_('Step duration'), new CCol(array(new CNumericBox('new_operation[esc_period]', $this->data['new_operation']['esc_period'], 6), SPACE, _('(minimum 60 seconds, 0 - use action default)')))), 'indent_both');
     $newOperationsTable->addRow(array(_('Step'), $stepTable));
 }
 // if multiple operation types are available, display a select
 if (count($this->data['allowedOperations']) > 1) {
     $operationTypeComboBox = new CComboBox('new_operation[operationtype]', $this->data['new_operation']['operationtype'], 'submit()');
     foreach ($this->data['allowedOperations'] as $operation) {
         $operationTypeComboBox->addItem($operation, operation_type2str($operation));
     }
     $newOperationsTable->addRow(array(_('Operation type'), $operationTypeComboBox), 'indent_both');
 } else {
     $operation = $this->data['allowedOperations'][0];
     $newOperationsTable->addRow(array(_('Operation type'), array(operation_type2str($operation), new CVar('new_operation[operationtype]', $operation))), 'indent_both');
 }
 switch ($this->data['new_operation']['operationtype']) {
     case OPERATION_TYPE_MESSAGE:
         if (!isset($this->data['new_operation']['opmessage'])) {
             $this->data['new_operation']['opmessage_usr'] = array();
             $this->data['new_operation']['opmessage'] = array('default_msg' => 1, 'mediatypeid' => 0);
             if ($this->data['eventsource'] == EVENT_SOURCE_TRIGGERS) {
                 $this->data['new_operation']['opmessage']['subject'] = ACTION_DEFAULT_SUBJ_TRIGGER;
                 $this->data['new_operation']['opmessage']['message'] = ACTION_DEFAULT_MSG_TRIGGER;
             } elseif ($this->data['eventsource'] == EVENT_SOURCE_DISCOVERY) {
                 $this->data['new_operation']['opmessage']['subject'] = ACTION_DEFAULT_SUBJ_DISCOVERY;
                 $this->data['new_operation']['opmessage']['message'] = ACTION_DEFAULT_MSG_DISCOVERY;
             } elseif ($this->data['eventsource'] == EVENT_SOURCE_AUTO_REGISTRATION) {
                 $this->data['new_operation']['opmessage']['subject'] = ACTION_DEFAULT_SUBJ_AUTOREG;
                 $this->data['new_operation']['opmessage']['message'] = ACTION_DEFAULT_MSG_AUTOREG;
Esempio n. 2
0
    }
} elseif (isset($_REQUEST['add_operation']) && isset($_REQUEST['new_operation'])) {
    $new_operation = $_REQUEST['new_operation'];
    $result = true;
    if (API::Action()->validateOperations($new_operation)) {
        $_REQUEST['operations'] = get_request('operations', array());
        $uniqOperations = array(OPERATION_TYPE_HOST_ADD => 0, OPERATION_TYPE_HOST_REMOVE => 0, OPERATION_TYPE_HOST_ENABLE => 0, OPERATION_TYPE_HOST_DISABLE => 0);
        if (isset($uniqOperations[$new_operation['operationtype']])) {
            foreach ($_REQUEST['operations'] as $operation) {
                if (isset($uniqOperations[$operation['operationtype']])) {
                    $uniqOperations[$operation['operationtype']]++;
                }
            }
            if ($uniqOperations[$new_operation['operationtype']]) {
                $result = false;
                info(_s('Operation "%s" already exists.', operation_type2str($new_operation['operationtype'])));
                show_messages();
            }
        }
        if ($result) {
            $eventsource = getRequest('eventsource', CProfile::get('web.actionconf.eventsource', EVENT_SOURCE_TRIGGERS));
            if (isset($new_operation['id'])) {
                $_REQUEST['operations'][$new_operation['id']] = $new_operation;
            } else {
                $_REQUEST['operations'][] = $new_operation;
            }
            sortOperations($eventsource, $_REQUEST['operations']);
        }
        unset($_REQUEST['new_operation']);
    }
} elseif (isset($_REQUEST['edit_operationid'])) {
Esempio n. 3
0
function get_act_new_oper_form($action = null)
{
    $tblOper = new CTableInfo();
    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'];
    } else {
        $eventsource = get_request('eventsource');
    }
    $allowed_operations = get_operations_by_eventsource($eventsource);
    /* init new_operation variable */
    $new_operation = get_request('new_operation', array());
    if (!is_array($new_operation)) {
        $new_operation = array();
        $new_operation['default_msg'] = 1;
    }
    if (!isset($new_operation['operationtype'])) {
        $new_operation['operationtype'] = OPERATION_TYPE_MESSAGE;
    }
    if (!isset($new_operation['object'])) {
        $new_operation['object'] = OPERATION_OBJECT_GROUP;
    }
    if (!isset($new_operation['objectid'])) {
        $new_operation['objectid'] = 0;
    }
    if (!isset($new_operation['shortdata'])) {
        $new_operation['shortdata'] = '{TRIGGER.NAME}: {STATUS}';
    }
    if (!isset($new_operation['longdata'])) {
        $new_operation['longdata'] = '{TRIGGER.NAME}: {STATUS}';
    }
    if (!isset($new_operation['esc_step_from'])) {
        $new_operation['esc_step_from'] = 1;
    }
    if (!isset($new_operation['esc_step_to'])) {
        $new_operation['esc_step_to'] = 1;
    }
    if (!isset($new_operation['esc_period'])) {
        $new_operation['esc_period'] = 0;
    }
    if (!isset($new_operation['evaltype'])) {
        $new_operation['evaltype'] = 0;
    }
    if (!isset($new_operation['opconditions'])) {
        $new_operation['opconditions'] = array();
    }
    if (!isset($new_operation['default_msg'])) {
        $new_operation['default_msg'] = 0;
    }
    unset($update_mode);
    $evaltype = $new_operation['evaltype'];
    if (isset($new_operation['id'])) {
        $tblOper->addItem(new CVar('new_operation[id]', $new_operation['id']));
        $update_mode = true;
    }
    $tblNewOperation = new CTable(null, 'nowrap');
    if (isset($_REQUEST['escalation'])) {
        $tblStep = new CTable(null, 'nowrap');
        $step_from = new CNumericBox('new_operation[esc_step_from]', $new_operation['esc_step_from'], 4);
        $step_from->addAction('onchange', 'javascript:' . $step_from->GetOption('onchange') . ' if(this.value == 0) this.value=1;');
        $tblStep->addRow(array(S_FROM, $step_from));
        $tblStep->addRow(array(S_TO, new CCol(array(new CNumericBox('new_operation[esc_step_to]', $new_operation['esc_step_to'], 4), ' [0-' . S_INFINITY . ']'))));
        $tblStep->addRow(array(S_PERIOD, new CCol(array(new CNumericBox('new_operation[esc_period]', $new_operation['esc_period'], 5), ' [0-' . S_DEFAULT . ']'))));
        $tblNewOperation->addRow(array(S_STEP, $tblStep));
    } else {
        $tblOper->addItem(new CVar('new_operation[esc_period]', $new_operation['esc_period']));
        $tblOper->addItem(new CVar('new_operation[esc_step_from]', $new_operation['esc_step_from']));
        $tblOper->addItem(new CVar('new_operation[esc_step_to]', $new_operation['esc_step_to']));
        $tblOper->addItem(new CVar('new_operation[evaltype]', $new_operation['evaltype']));
    }
    $cmbOpType = new CComboBox('new_operation[operationtype]', $new_operation['operationtype'], 'submit()');
    foreach ($allowed_operations as $oper) {
        $cmbOpType->addItem($oper, operation_type2str($oper));
    }
    $tblNewOperation->addRow(array(S_OPERATION_TYPE, $cmbOpType));
    switch ($new_operation['operationtype']) {
        case OPERATION_TYPE_MESSAGE:
            if ($new_operation['object'] == OPERATION_OBJECT_GROUP) {
                $object_srctbl = 'usrgrp';
                $object_srcfld1 = 'usrgrpid';
                $object_name = get_group_by_usrgrpid($new_operation['objectid']);
                $display_name = 'name';
            } else {
                $object_srctbl = 'users';
                $object_srcfld1 = 'userid';
                $object_name = get_user_by_userid($new_operation['objectid']);
                $display_name = 'alias';
            }
            $tblOper->addItem(new CVar('new_operation[objectid]', $new_operation['objectid']));
            if ($object_name) {
                $object_name = $object_name[$display_name];
            }
            $cmbObject = new CComboBox('new_operation[object]', $new_operation['object'], 'submit()');
            $cmbObject->addItem(OPERATION_OBJECT_USER, S_SINGLE_USER);
            $cmbObject->addItem(OPERATION_OBJECT_GROUP, S_USER_GROUP);
            $tblNewOperation->addRow(array(S_SEND_MESSAGE_TO, array($cmbObject, new CTextBox('object_name', $object_name, 40, 'yes'), new CButton('select_object', S_SELECT, 'return PopUp("popup.php?dstfrm=' . S_ACTION . '&dstfld1=new_operation%5Bobjectid%5D&dstfld2=object_name' . '&srctbl=' . $object_srctbl . '&srcfld1=' . $object_srcfld1 . '&srcfld2=' . $display_name . '",450,450)', 'T'))));
            $tblNewOperation->addRow(array(S_DEFAULT_MESSAGE, new CCheckBox('new_operation[default_msg]', $new_operation['default_msg'], 'javascript: submit();', 1)));
            if (!$new_operation['default_msg']) {
                $tblNewOperation->addRow(array(S_SUBJECT, new CTextBox('new_operation[shortdata]', $new_operation['shortdata'], 77)));
                $tblNewOperation->addRow(array(S_MESSAGE, new CTextArea('new_operation[longdata]', $new_operation['longdata'], 77, 7)));
            } else {
                $tblOper->addItem(new CVar('new_operation[shortdata]', $new_operation['shortdata']));
                $tblOper->addItem(new CVar('new_operation[longdata]', $new_operation['longdata']));
            }
            break;
        case OPERATION_TYPE_COMMAND:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', 0));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblNewOperation->addRow(array(S_REMOTE_COMMAND, new CTextArea('new_operation[longdata]', $new_operation['longdata'], 77, 7)));
            break;
        case OPERATION_TYPE_HOST_ADD:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', 0));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblOper->addItem(new CVar('new_operation[longdata]', ''));
            break;
        case OPERATION_TYPE_HOST_REMOVE:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', 0));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblOper->addItem(new CVar('new_operation[longdata]', ''));
            break;
        case OPERATION_TYPE_GROUP_ADD:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', $new_operation['objectid']));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblOper->addItem(new CVar('new_operation[longdata]', ''));
            if ($object_name = DBfetch(DBselect('select name FROM groups WHERE groupid=' . $new_operation['objectid']))) {
                $object_name = $object_name['name'];
            }
            $tblNewOperation->addRow(array(S_GROUP, array(new CTextBox('object_name', $object_name, 40, 'yes'), new CButton('select_object', S_SELECT, 'return PopUp("popup.php?dstfrm=' . S_ACTION . '&dstfld1=new_operation%5Bobjectid%5D&dstfld2=object_name' . '&srctbl=host_group&srcfld1=groupid&srcfld2=name' . '",450,450)', 'T'))));
            break;
        case OPERATION_TYPE_GROUP_REMOVE:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', $new_operation['objectid']));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblOper->addItem(new CVar('new_operation[longdata]', ''));
            if ($object_name = DBfetch(DBselect('select name FROM groups WHERE groupid=' . $new_operation['objectid']))) {
                $object_name = $object_name['name'];
            }
            $tblNewOperation->addRow(array(S_GROUP, array(new CTextBox('object_name', $object_name, 40, 'yes'), new CButton('select_object', S_SELECT, 'return PopUp("popup.php?dstfrm=' . S_ACTION . '&dstfld1=new_operation%5Bobjectid%5D&dstfld2=object_name' . '&srctbl=host_group&srcfld1=groupid&srcfld2=name' . '",450,450)', 'T'))));
            break;
        case OPERATION_TYPE_TEMPLATE_ADD:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', $new_operation['objectid']));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblOper->addItem(new CVar('new_operation[longdata]', ''));
            if ($object_name = DBfetch(DBselect('SELECT host FROM hosts ' . ' WHERE status=' . HOST_STATUS_TEMPLATE . ' AND hostid=' . $new_operation['objectid']))) {
                $object_name = $object_name['host'];
            }
            $tblNewOperation->addRow(array(S_TEMPLATE, array(new CTextBox('object_name', $object_name, 40, 'yes'), new CButton('select_object', S_SELECT, 'return PopUp("popup.php?dstfrm=' . S_ACTION . '&dstfld1=new_operation%5Bobjectid%5D&dstfld2=object_name' . '&srctbl=host_templates&srcfld1=hostid&srcfld2=host' . '",450,450)', 'T'))));
            break;
        case OPERATION_TYPE_TEMPLATE_REMOVE:
            $tblOper->addItem(new CVar('new_operation[object]', 0));
            $tblOper->addItem(new CVar('new_operation[objectid]', $new_operation['objectid']));
            $tblOper->addItem(new CVar('new_operation[shortdata]', ''));
            $tblOper->addItem(new CVar('new_operation[longdata]', ''));
            if ($object_name = DBfetch(DBselect('SELECT host FROM hosts ' . ' WHERE status=' . HOST_STATUS_TEMPLATE . ' AND hostid=' . $new_operation['objectid']))) {
                $object_name = $object_name['host'];
            }
            $tblNewOperation->addRow(array(S_TEMPLATE, array(new CTextBox('object_name', $object_name, 40, 'yes'), new CButton('select_object', S_SELECT, 'return PopUp("popup.php?dstfrm=' . S_ACTION . '&dstfld1=new_operation%5Bobjectid%5D&dstfld2=object_name' . '&srctbl=host_templates&srcfld1=hostid&srcfld2=host' . '",450,450)', 'T'))));
            break;
    }
    // new Operation conditions
    if (isset($_REQUEST['escalation'])) {
        $tblCond = new CTable();
        $opconditions = $new_operation['opconditions'];
        $allowed_opconditions = get_opconditions_by_eventsource($eventsource);
        // show opcondition LIST
        zbx_rksort($opconditions);
        /* group opconditions by type */
        $grouped_opconditions = array();
        $cond_el = new CTable(S_NO_CONDITIONS_DEFINED);
        $i = 0;
        foreach ($opconditions as $val) {
            if (!isset($val['conditiontype'])) {
                $val['conditiontype'] = 0;
            }
            if (!isset($val['operator'])) {
                $val['operator'] = 0;
            }
            if (!isset($val['value'])) {
                $val['value'] = 0;
            }
            if (!str_in_array($val["conditiontype"], $allowed_opconditions)) {
                continue;
            }
            $label = chr(ord('A') + $i);
            $cond_el->addRow(array('(' . $label . ')', array(new CCheckBox("g_opconditionid[]", 'no', null, $i), get_condition_desc($val["conditiontype"], $val["operator"], $val["value"]))));
            $tblCond->addItem(new CVar("new_operation[opconditions][{$i}][conditiontype]", $val["conditiontype"]));
            $tblCond->addItem(new CVar("new_operation[opconditions][{$i}][operator]", $val["operator"]));
            $tblCond->addItem(new CVar("new_operation[opconditions][{$i}][value]", $val["value"]));
            $grouped_opconditions[$val["conditiontype"]][] = $label;
            $i++;
        }
        unset($opconditions);
        $cond_buttons = array();
        if (!isset($_REQUEST['new_opcondition'])) {
            $cond_buttons[] = new CButton('new_opcondition', S_NEW);
        }
        if ($cond_el->ItemsCount() > 0) {
            if ($cond_el->ItemsCount() > 1) {
                /* prepare opcondition calcuation type selector */
                switch ($evaltype) {
                    case ACTION_EVAL_TYPE_AND:
                        $group_op = $glog_op = S_AND;
                        break;
                    case ACTION_EVAL_TYPE_OR:
                        $group_op = $glog_op = S_OR;
                        break;
                    default:
                        $group_op = S_OR;
                        $glog_op = S_AND;
                        break;
                }
                foreach ($grouped_opconditions as $id => $val) {
                    $grouped_opconditions[$id] = '(' . implode(' ' . $group_op . ' ', $val) . ')';
                }
                $grouped_opconditions = implode(' ' . $glog_op . ' ', $grouped_opconditions);
                $cmb_calc_type = new CComboBox('new_operation[evaltype]', $evaltype, 'submit()');
                $cmb_calc_type->addItem(ACTION_EVAL_TYPE_AND_OR, S_AND_OR_BIG);
                $cmb_calc_type->addItem(ACTION_EVAL_TYPE_AND, S_AND_BIG);
                $cmb_calc_type->addItem(ACTION_EVAL_TYPE_OR, S_OR_BIG);
                $tblNewOperation->addRow(array(S_TYPE_OF_CALCULATION, new CCol(array($cmb_calc_type, new CTextBox('preview', $grouped_opconditions, 60, 'yes')))));
                unset($cmb_calc_type, $group_op, $glog_op);
                /* end of calcuation type selector */
            } else {
                $tblCond->addItem(new CVar('new_operation[evaltype]', ACTION_EVAL_TYPE_AND_OR));
            }
            $cond_buttons[] = new CButton('del_opcondition', S_DELETE_SELECTED);
        } else {
            $tblCond->addItem(new CVar('new_operation[evaltype]', ACTION_EVAL_TYPE_AND_OR));
        }
        $tblCond->addRow($cond_el);
        $tblCond->addRow(new CCol($cond_buttons));
        // end of opcondition LIST
        $tblNewOperation->addRow(array(S_CONDITIONS, $tblCond));
        unset($grouped_opconditions, $cond_el, $cond_buttons, $tblCond);
    }
    $tblOper->addRow($tblNewOperation);
    $td = new CCol(array(new CButton('add_operation', isset($update_mode) ? S_SAVE : S_ADD), SPACE, new CButton('cancel_new_operation', S_CANCEL)));
    $td->addOption('colspan', '3');
    $td->addOption('style', 'text-align: right;');
    $tblOper->SetFooter($td);
    return $tblOper;
}
 }
 if ($this->data['eventsource'] == EVENT_SOURCE_TRIGGERS) {
     $stepFrom = new CNumericBox('new_operation[esc_step_from]', $this->data['new_operation']['esc_step_from'], 5);
     $stepFrom->attr('size', 6);
     $stepFrom->addAction('onchange', 'javascript:' . $stepFrom->getAttribute('onchange') . ' if (this.value == 0) this.value = 1;');
     $stepTo = new CNumericBox('new_operation[esc_step_to]', $this->data['new_operation']['esc_step_to'], 5);
     $stepTo->attr('size', 6);
     $stepTable = new CTable();
     $stepTable->addRow(array(_('From'), $stepFrom), 'indent_both');
     $stepTable->addRow(array(_('To'), new CCol(array($stepTo, SPACE, _('(0 - infinitely)')))), 'indent_both');
     $stepTable->addRow(array(_('Step duration'), new CCol(array(new CNumericBox('new_operation[esc_period]', $this->data['new_operation']['esc_period'], 6), SPACE, _('(minimum 60 seconds, 0 - use action default)')))), 'indent_both');
     $newOperationsTable->addRow(array(_('Step'), $stepTable));
 }
 $operationTypeComboBox = new CComboBox('new_operation[operationtype]', $this->data['new_operation']['operationtype'], 'submit()');
 foreach ($this->data['allowedOperations'] as $operation) {
     $operationTypeComboBox->addItem($operation, operation_type2str($operation));
 }
 $newOperationsTable->addRow(array(_('Operation type'), $operationTypeComboBox), 'indent_both');
 switch ($this->data['new_operation']['operationtype']) {
     case OPERATION_TYPE_MESSAGE:
         if (!isset($this->data['new_operation']['opmessage'])) {
             $this->data['new_operation']['opmessage_usr'] = array();
             $this->data['new_operation']['opmessage'] = array('default_msg' => 1, 'mediatypeid' => 0);
             if ($this->data['eventsource'] == EVENT_SOURCE_TRIGGERS) {
                 $this->data['new_operation']['opmessage']['subject'] = ACTION_DEFAULT_SUBJ_TRIGGER;
                 $this->data['new_operation']['opmessage']['message'] = ACTION_DEFAULT_MSG_TRIGGER;
             } elseif ($this->data['eventsource'] == EVENT_SOURCE_DISCOVERY) {
                 $this->data['new_operation']['opmessage']['subject'] = ACTION_DEFAULT_SUBJ_DISCOVERY;
                 $this->data['new_operation']['opmessage']['message'] = ACTION_DEFAULT_MSG_DISCOVERY;
             } elseif ($this->data['eventsource'] == EVENT_SOURCE_AUTO_REGISTRATION) {
                 $this->data['new_operation']['opmessage']['subject'] = ACTION_DEFAULT_SUBJ_AUTOREG;
Esempio n. 5
0
/**
 * Gathers media types, user groups, users, host groups, hosts and templates for actions and their operations, and
 * returns the HTML representation of action operation values according to action operation type.
 *
 * @param array $actions				array of actions
 * @param array $action['operations']	array of action operations
 *
 * @return array						returns an array of actions operation descriptions
 */
function getActionOperationDescriptions(array $actions)
{
    $result = [];
    $mediaTypeIds = [];
    $userIds = [];
    $usrGrpIds = [];
    $hostIds = [];
    $groupids = [];
    $templateids = [];
    foreach ($actions as $i => $action) {
        $result[$i] = [];
        foreach ($action['operations'] as $j => $operation) {
            $result[$i][$j] = [];
            switch ($operation['operationtype']) {
                case OPERATION_TYPE_MESSAGE:
                    $mediaTypeId = $operation['opmessage']['mediatypeid'];
                    if ($mediaTypeId != 0) {
                        $mediaTypeIds[$mediaTypeId] = $mediaTypeId;
                    }
                    if (isset($operation['opmessage_usr']) && $operation['opmessage_usr']) {
                        foreach ($operation['opmessage_usr'] as $users) {
                            $userIds[$users['userid']] = $users['userid'];
                        }
                    }
                    if (isset($operation['opmessage_grp']) && $operation['opmessage_grp']) {
                        foreach ($operation['opmessage_grp'] as $userGroups) {
                            $usrGrpIds[$userGroups['usrgrpid']] = $userGroups['usrgrpid'];
                        }
                    }
                    break;
                case OPERATION_TYPE_COMMAND:
                    if (isset($operation['opcommand_hst']) && $operation['opcommand_hst']) {
                        foreach ($operation['opcommand_hst'] as $host) {
                            if ($host['hostid'] != 0) {
                                $hostIds[$host['hostid']] = $host['hostid'];
                            }
                        }
                    }
                    if (isset($operation['opcommand_grp']) && $operation['opcommand_grp']) {
                        foreach ($operation['opcommand_grp'] as $hostGroup) {
                            $groupids[$hostGroup['groupid']] = true;
                        }
                    }
                    break;
                case OPERATION_TYPE_GROUP_ADD:
                case OPERATION_TYPE_GROUP_REMOVE:
                    foreach ($operation['groupids'] as $groupid) {
                        $groupids[$groupid] = true;
                    }
                    break;
                case OPERATION_TYPE_TEMPLATE_ADD:
                case OPERATION_TYPE_TEMPLATE_REMOVE:
                    foreach ($operation['templateids'] as $templateid) {
                        $templateids[$templateid] = true;
                    }
                    break;
            }
        }
    }
    $mediaTypes = [];
    $users = [];
    $userGroups = [];
    $hosts = [];
    $hostGroups = [];
    $templates = [];
    if ($mediaTypeIds) {
        $mediaTypes = API::Mediatype()->get(['output' => ['description'], 'mediatypeids' => $mediaTypeIds, 'preservekeys' => true]);
    }
    if ($userIds) {
        $fullnames = [];
        $users = API::User()->get(['output' => ['userid', 'alias', 'name', 'surname'], 'userids' => $userIds]);
        foreach ($users as $user) {
            $fullnames[$user['userid']] = getUserFullname($user);
        }
    }
    if ($usrGrpIds) {
        $userGroups = API::UserGroup()->get(['output' => ['name'], 'usrgrpids' => $usrGrpIds, 'preservekeys' => true]);
    }
    if ($hostIds) {
        $hosts = API::Host()->get(['output' => ['name'], 'hostids' => $hostIds, 'preservekeys' => true]);
    }
    if ($groupids) {
        $hostGroups = API::HostGroup()->get(['output' => ['name'], 'groupids' => array_keys($groupids), 'preservekeys' => true]);
    }
    if ($templateids) {
        $templates = API::Template()->get(['output' => ['name'], 'templateids' => array_keys($templateids), 'preservekeys' => true]);
    }
    // format the HTML ouput
    foreach ($actions as $i => $action) {
        foreach ($action['operations'] as $j => $operation) {
            switch ($operation['operationtype']) {
                case OPERATION_TYPE_MESSAGE:
                    $mediaType = _('all media');
                    $mediaTypeId = $operation['opmessage']['mediatypeid'];
                    if ($mediaTypeId != 0 && isset($mediaTypes[$mediaTypeId])) {
                        $mediaType = $mediaTypes[$mediaTypeId]['description'];
                    }
                    if (isset($operation['opmessage_usr']) && $operation['opmessage_usr']) {
                        $userNamesList = [];
                        foreach ($operation['opmessage_usr'] as $user) {
                            if (isset($fullnames[$user['userid']])) {
                                $userNamesList[] = $fullnames[$user['userid']];
                            }
                        }
                        order_result($userNamesList);
                        $result[$i][$j][] = bold(_('Send message to users') . ': ');
                        $result[$i][$j][] = [implode(', ', $userNamesList), SPACE, _('via'), SPACE, $mediaType];
                        $result[$i][$j][] = BR();
                    }
                    if (isset($operation['opmessage_grp']) && $operation['opmessage_grp']) {
                        $userGroupsList = [];
                        foreach ($operation['opmessage_grp'] as $userGroup) {
                            if (isset($userGroups[$userGroup['usrgrpid']])) {
                                $userGroupsList[] = $userGroups[$userGroup['usrgrpid']]['name'];
                            }
                        }
                        order_result($userGroupsList);
                        $result[$i][$j][] = bold(_('Send message to user groups') . ': ');
                        $result[$i][$j][] = [implode(', ', $userGroupsList), SPACE, _('via'), SPACE, $mediaType];
                        $result[$i][$j][] = BR();
                    }
                    break;
                case OPERATION_TYPE_COMMAND:
                    if (isset($operation['opcommand_hst']) && $operation['opcommand_hst']) {
                        $hostList = [];
                        foreach ($operation['opcommand_hst'] as $host) {
                            if ($host['hostid'] == 0) {
                                $result[$i][$j][] = [bold(_('Run remote commands on current host')), BR()];
                            } elseif (isset($hosts[$host['hostid']])) {
                                $hostList[] = $hosts[$host['hostid']]['name'];
                            }
                        }
                        if ($hostList) {
                            order_result($hostList);
                            $result[$i][$j][] = bold(_('Run remote commands on hosts') . ': ');
                            $result[$i][$j][] = [implode(', ', $hostList), BR()];
                        }
                    }
                    if (isset($operation['opcommand_grp']) && $operation['opcommand_grp']) {
                        $hostGroupList = [];
                        foreach ($operation['opcommand_grp'] as $hostGroup) {
                            if (isset($hostGroups[$hostGroup['groupid']])) {
                                $hostGroupList[] = $hostGroups[$hostGroup['groupid']]['name'];
                            }
                        }
                        order_result($hostGroupList);
                        $result[$i][$j][] = bold(_('Run remote commands on host groups') . ': ');
                        $result[$i][$j][] = [implode(', ', $hostGroupList), BR()];
                    }
                    break;
                case OPERATION_TYPE_HOST_ADD:
                    $result[$i][$j][] = [bold(_('Add host')), BR()];
                    break;
                case OPERATION_TYPE_HOST_REMOVE:
                    $result[$i][$j][] = [bold(_('Remove host')), BR()];
                    break;
                case OPERATION_TYPE_HOST_ENABLE:
                    $result[$i][$j][] = [bold(_('Enable host')), BR()];
                    break;
                case OPERATION_TYPE_HOST_DISABLE:
                    $result[$i][$j][] = [bold(_('Disable host')), BR()];
                    break;
                case OPERATION_TYPE_GROUP_ADD:
                case OPERATION_TYPE_GROUP_REMOVE:
                    $hostGroupList = [];
                    foreach ($operation['groupids'] as $groupid) {
                        if (array_key_exists($groupid, $hostGroups)) {
                            $hostGroupList[] = $hostGroups[$groupid]['name'];
                        }
                    }
                    order_result($hostGroupList);
                    if ($operation['operationtype'] == OPERATION_TYPE_GROUP_ADD) {
                        $result[$i][$j][] = bold(_('Add to host groups') . ': ');
                    } else {
                        $result[$i][$j][] = bold(_('Remove from host groups') . ': ');
                    }
                    $result[$i][$j][] = [implode(', ', $hostGroupList), BR()];
                    break;
                case OPERATION_TYPE_TEMPLATE_ADD:
                case OPERATION_TYPE_TEMPLATE_REMOVE:
                    $templateList = [];
                    foreach ($operation['templateids'] as $templateid) {
                        if (array_key_exists($templateid, $templates)) {
                            $templateList[] = $templates[$templateid]['name'];
                        }
                    }
                    order_result($templateList);
                    if ($operation['operationtype'] == OPERATION_TYPE_TEMPLATE_ADD) {
                        $result[$i][$j][] = bold(_('Link to templates') . ': ');
                    } else {
                        $result[$i][$j][] = bold(_('Unlink from templates') . ': ');
                    }
                    $result[$i][$j][] = [implode(', ', $templateList), BR()];
                    break;
                case OPERATION_TYPE_HOST_INVENTORY:
                    $host_inventory_modes = getHostInventoryModes();
                    $result[$i][$j][] = bold(operation_type2str(OPERATION_TYPE_HOST_INVENTORY) . ': ');
                    $result[$i][$j][] = [$host_inventory_modes[$operation['opinventory']['inventory_mode']], BR()];
                    break;
            }
        }
    }
    return $result;
}
Esempio n. 6
0
     $tblStep = new CTable();
     $step_from = new CNumericBox('new_operation[esc_step_from]', $new_operation['esc_step_from'], 4);
     $step_from->addAction('onchange', 'javascript:' . $step_from->getAttribute('onchange') . ' if(this.value == 0) this.value=1;');
     $tblStep->addRow(array(S_FROM, $step_from));
     $tblStep->addRow(array(S_TO, new CCol(array(new CNumericBox('new_operation[esc_step_to]', $new_operation['esc_step_to'], 4), ' [0-' . S_INFINITY . ']'))));
     $tblStep->addRow(array(S_PERIOD, new CCol(array(new CNumericBox('new_operation[esc_period]', $new_operation['esc_period'], 5), ' [' . S_MIN_SMALL . ' 60, 0-' . S_DEFAULT . ']'))));
     $tblNewOperation->addRow(array(S_STEP, $tblStep));
 } else {
     $tblOper->addItem(new CVar('new_operation[esc_period]', $new_operation['esc_period']));
     $tblOper->addItem(new CVar('new_operation[esc_step_from]', $new_operation['esc_step_from']));
     $tblOper->addItem(new CVar('new_operation[esc_step_to]', $new_operation['esc_step_to']));
     $tblOper->addItem(new CVar('new_operation[evaltype]', $new_operation['evaltype']));
 }
 $cmbOpType = new CComboBox('new_operation[operationtype]', $new_operation['operationtype'], 'submit()');
 foreach ($allowed_operations as $oper) {
     $cmbOpType->addItem($oper, operation_type2str($oper));
 }
 $tblNewOperation->addRow(array(S_OPERATION_TYPE, $cmbOpType));
 switch ($new_operation['operationtype']) {
     case OPERATION_TYPE_MESSAGE:
         if ($new_operation['object'] == OPERATION_OBJECT_GROUP) {
             $object_srctbl = 'usrgrp';
             $object_srcfld1 = 'usrgrpid';
             $object_name = CUserGroup::get(array('usrgrpids' => $new_operation['objectid'], 'output' => API_OUTPUT_EXTEND));
             $object_name = reset($object_name);
             $display_name = 'name';
         } else {
             $object_srctbl = 'users';
             $object_srcfld1 = 'userid';
             $object_name = CUser::get(array('userids' => $new_operation['objectid'], 'output' => API_OUTPUT_EXTEND));
             $object_name = reset($object_name);