function get_act_new_cond_form($action = null) { $tblCond = new CTable('', 'nowrap'); if (isset($_REQUEST['actionid']) && empty($action)) { $action = get_action_by_actionid($_REQUEST['actionid']); } if (isset($_REQUEST['actionid']) && !isset($_REQUEST['form_refresh'])) { $eventsource = $action['eventsource']; $evaltype = $action['evaltype']; } else { $evaltype = get_request('evaltype'); $eventsource = get_request('eventsource'); } $allowed_conditions = get_conditions_by_eventsource($eventsource); /* init new_condition variable */ $new_condition = get_request('new_condition', array()); if (!is_array($new_condition)) { $new_condition = array(); } if (!isset($new_condition['type'])) { $new_condition['type'] = CONDITION_TYPE_TRIGGER_NAME; } if (!isset($new_condition['operator'])) { $new_condition['operator'] = CONDITION_OPERATOR_LIKE; } if (!isset($new_condition['value'])) { $new_condition['value'] = ''; } if (!str_in_array($new_condition['type'], $allowed_conditions)) { $new_condition['type'] = $allowed_conditions[0]; } // NEW CONDITION $rowCondition = array(); // add condition type $cmbCondType = new CComboBox('new_condition[type]', $new_condition['type'], 'submit()'); foreach ($allowed_conditions as $cond) { $cmbCondType->addItem($cond, condition_type2str($cond)); } array_push($rowCondition, $cmbCondType); // add condition operation $cmbCondOp = new CComboBox('new_condition[operator]'); foreach (get_operators_by_conditiontype($new_condition['type']) as $op) { $cmbCondOp->addItem($op, condition_operator2str($op)); } array_push($rowCondition, $cmbCondOp); // add condition value switch ($new_condition['type']) { case CONDITION_TYPE_HOST_GROUP: $tblCond->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('group', '', 20, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . S_ACTION . "&dstfld1=new_condition%5Bvalue%5D&dstfld2=group&srctbl=host_group" . "&srcfld1=groupid&srcfld2=name',450,450);", 'T')); break; case CONDITION_TYPE_HOST_TEMPLATE: $tblCond->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('host', '', 20, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . S_ACTION . "&dstfld1=new_condition%5Bvalue%5D&dstfld2=host&srctbl=host_templates" . "&srcfld1=hostid&srcfld2=host',450,450);", 'T')); break; case CONDITION_TYPE_HOST: $tblCond->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('host', '', 20, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . S_ACTION . "&dstfld1=new_condition%5Bvalue%5D&dstfld2=host&srctbl=hosts" . "&srcfld1=hostid&srcfld2=host',450,450);", 'T')); break; case CONDITION_TYPE_TRIGGER: $tblCond->addItem(new CVar('new_condition[value]', '0')); $rowCondition[] = array(new CTextBox('trigger', '', 20, 'yes'), new CButton('btn1', S_SELECT, "return PopUp('popup.php?dstfrm=" . S_ACTION . "&dstfld1=new_condition%5Bvalue%5D&dstfld2=trigger&srctbl=triggers" . "&srcfld1=triggerid&srcfld2=description');", 'T')); break; case CONDITION_TYPE_TRIGGER_NAME: $rowCondition[] = new CTextBox('new_condition[value]', "", 40); break; case CONDITION_TYPE_TRIGGER_VALUE: $cmbCondVal = new CComboBox('new_condition[value]'); foreach (array(TRIGGER_VALUE_FALSE, TRIGGER_VALUE_TRUE) as $tr_val) { $cmbCondVal->addItem($tr_val, trigger_value2str($tr_val)); } $rowCondition[] = $cmbCondVal; break; case CONDITION_TYPE_TIME_PERIOD: $rowCondition[] = new CTextBox('new_condition[value]', "1-7,00:00-23:59", 40); break; case CONDITION_TYPE_TRIGGER_SEVERITY: $cmbCondVal = new CComboBox('new_condition[value]'); foreach (array(TRIGGER_SEVERITY_INFORMATION, TRIGGER_SEVERITY_WARNING, TRIGGER_SEVERITY_AVERAGE, TRIGGER_SEVERITY_HIGH, TRIGGER_SEVERITY_DISASTER) as $id) { $cmbCondVal->addItem($id, get_severity_description($id)); } $rowCondition[] = $cmbCondVal; break; case CONDITION_TYPE_MAINTENANCE: $rowCondition[] = new CCol(S_MAINTENANCE_SMALL); break; case CONDITION_TYPE_DHOST_IP: $rowCondition[] = new CTextBox('new_condition[value]', '192.168.0.1-127,192.168.2.1', 50); break; case CONDITION_TYPE_DSERVICE_TYPE: $cmbCondVal = new CComboBox('new_condition[value]'); foreach (array(SVC_SSH, SVC_LDAP, SVC_SMTP, SVC_FTP, SVC_HTTP, SVC_POP, SVC_NNTP, SVC_IMAP, SVC_TCP, SVC_AGENT, SVC_SNMPv1, SVC_SNMPv2, SVC_ICMPPING) as $svc) { $cmbCondVal->addItem($svc, discovery_check_type2str($svc)); } $rowCondition[] = $cmbCondVal; break; case CONDITION_TYPE_DSERVICE_PORT: $rowCondition[] = new CTextBox('new_condition[value]', '0-1023,1024-49151', 40); break; case CONDITION_TYPE_DSTATUS: $cmbCondVal = new CComboBox('new_condition[value]'); foreach (array(DOBJECT_STATUS_UP, DOBJECT_STATUS_DOWN, DOBJECT_STATUS_DISCOVER, DOBJECT_STATUS_LOST) as $stat) { $cmbCondVal->addItem($stat, discovery_object_status2str($stat)); } $rowCondition[] = $cmbCondVal; break; case CONDITION_TYPE_DUPTIME: $rowCondition[] = new CNumericBox('new_condition[value]', '600', 15); break; case CONDITION_TYPE_DVALUE: $rowCondition[] = new CTextBox('new_condition[value]', "", 40); break; case CONDITION_TYPE_APPLICATION: $rowCondition[] = new CTextBox('new_condition[value]', "", 40); break; } $tblCond->addRow($rowCondition); $tblConditions = new CTableInfo(); $tblConditions->addRow($tblCond); $td = new CCol(array(new CButton('add_condition', S_ADD), new CButton('cancel_new_condition', S_CANCEL))); $td->addOption('colspan', '3'); $td->addOption('style', 'text-align: right;'); $tblConditions->SetFooter($td); unset($grouped_conditions, $cond_el, $cond_buttons); // end of NEW CONDITION return $tblConditions; }
$data['action']['def_longdata'] = get_request('def_longdata', ACTION_DEFAULT_MSG_DISCOVERY); } elseif ($data['eventsource'] == EVENT_SOURCE_AUTO_REGISTRATION) { $data['action']['def_shortdata'] = get_request('def_shortdata', ACTION_DEFAULT_SUBJ_AUTOREG); $data['action']['def_longdata'] = get_request('def_longdata', ACTION_DEFAULT_MSG_AUTOREG); } else { $data['action']['def_shortdata'] = get_request('def_shortdata'); $data['action']['def_longdata'] = get_request('def_longdata'); $data['action']['r_shortdata'] = get_request('r_shortdata'); $data['action']['r_longdata'] = get_request('r_longdata'); } } } if (!$data['actionid'] && !hasRequest('form_refresh') && $data['eventsource'] == EVENT_SOURCE_TRIGGERS) { $data['action']['conditions'] = array(array('conditiontype' => CONDITION_TYPE_TRIGGER_VALUE, 'operator' => CONDITION_OPERATOR_EQUAL, 'value' => TRIGGER_VALUE_TRUE), array('conditiontype' => CONDITION_TYPE_MAINTENANCE, 'operator' => CONDITION_OPERATOR_NOT_IN, 'value' => '')); } $data['allowedConditions'] = get_conditions_by_eventsource($data['eventsource']); $data['allowedOperations'] = get_operations_by_eventsource($data['eventsource']); // sort conditions $sortFields = array(array('field' => 'conditiontype', 'order' => ZBX_SORT_DOWN), array('field' => 'operator', 'order' => ZBX_SORT_DOWN), array('field' => 'value', 'order' => ZBX_SORT_DOWN)); CArrayHelper::sort($data['action']['conditions'], $sortFields); // new condition $data['new_condition'] = array('conditiontype' => isset($data['new_condition']['conditiontype']) ? $data['new_condition']['conditiontype'] : CONDITION_TYPE_TRIGGER_NAME, 'operator' => isset($data['new_condition']['operator']) ? $data['new_condition']['operator'] : CONDITION_OPERATOR_LIKE, 'value' => isset($data['new_condition']['value']) ? $data['new_condition']['value'] : ''); if (!str_in_array($data['new_condition']['conditiontype'], $data['allowedConditions'])) { $data['new_condition']['conditiontype'] = $data['allowedConditions'][0]; } // new operation if (!empty($data['new_operation'])) { if (!is_array($data['new_operation'])) { $data['new_operation'] = array('action' => 'create', 'operationtype' => 0, 'esc_period' => 0, 'esc_step_from' => 1, 'esc_step_to' => 1, 'evaltype' => 0); } }
$tblCond->addItem(new CVar('evaltype', ACTION_EVAL_TYPE_AND_OR)); } $tblCond->addRow(array(S_CONDITIONS, $cond_el)); $left_tab->addRow(new CFormElement(S_ACTION_CONDITIONS, $tblCond, $footer)); // }}} CONDITIONS FORM // NEW CONDITION FORM {{{ if (isset($_REQUEST['new_condition'])) { $tblNewCond = new CTable(null, 'formElementTable'); if (isset($_REQUEST['actionid']) && !isset($_REQUEST['form_refresh'])) { $eventsource = $action['eventsource']; $evaltype = $action['evaltype']; } else { $evaltype = get_request('evaltype'); $eventsource = get_request('eventsource'); } $allowed_conditions = get_conditions_by_eventsource($eventsource); $new_condition = get_request('new_condition', array()); $new_condition = array('type' => isset($new_condition['type']) ? $new_condition['type'] : CONDITION_TYPE_TRIGGER_NAME, 'operator' => isset($new_condition['operator']) ? $new_condition['operator'] : CONDITION_OPERATOR_LIKE, 'value' => isset($new_condition['value']) ? $new_condition['value'] : ''); if (!str_in_array($new_condition['type'], $allowed_conditions)) { $new_condition['type'] = $allowed_conditions[0]; } $rowCondition = array(); $cmbCondType = new CComboBox('new_condition[type]', $new_condition['type'], 'submit()'); foreach ($allowed_conditions as $cond) { $cmbCondType->addItem($cond, condition_type2str($cond)); } $rowCondition[] = $cmbCondType; $cmbCondOp = new CComboBox('new_condition[operator]'); foreach (get_operators_by_conditiontype($new_condition['type']) as $op) { $cmbCondOp->addItem($op, condition_operator2str($op)); }