function image_tag($size, $route, $upcoming_stops) { if ($route == 'boston_all' || $route == 'cambridge_all') { // these don't have maps // should save this info somewhere else instead of hard coding here return ''; } $base = $route; if (count($upcoming_stops) > 0) { $base .= '-'; foreach ($upcoming_stops as $nextStop) { $base .= strtolower(num2letter($nextStop)); } } return '<img src="images/' . $size . '/' . $base . '.gif" width="' . $size . '" height="' . $size . '" id="mapimage" alt="Map" />'; }
/** * Extract the numeric IDs used in the given formula and generate a set of letter aliases for them. * Aliases will be generated in the order they appear in the formula. * * Example: * var_dump(CFormulaHelper::getFormulaIds('1 or (2 and 3) or 2')); * * // array(1 => 'A', 2 => 'B', 3 => 'C') * * @param string $formula a formula with numeric IDs * * @return array */ public static function getFormulaIds($formula) { $matches = array(); preg_match_all('/\\d+/', $formula, $matches); $ids = array_keys(array_flip($matches[0])); $i = 0; $formulaIds = array(); foreach ($ids as $id) { $formulaIds[$id] = num2letter($i); $i++; } return $formulaIds; }
/** * Builds expression html tree * * @param array $expressionTree output of getExpressionTree() function * @param array $next parameter only for recursive call; should be empty array * @param int $letterNum parameter only for recursive call; should be 0 * @param int $level parameter only for recursive call * @param string $operand parameter only for recursive call * * @return bool returns true if element is found, false - otherwise */ function buildExpressionHtmlTree(array $expressionTree, array &$next, &$letterNum, $level = 0, $operand = null) { $treeList = array(); $outline = ''; end($expressionTree); $lastKey = key($expressionTree); foreach ($expressionTree as $key => $element) { switch ($element['type']) { case 'operand': $next[$level] = $key != $lastKey; $expr = expressionLevelDraw($next, $level); $expr[] = SPACE; $expr[] = italic($element['operand'] == '&' ? _('AND') : _('OR')); $levelDetails = array('list' => $expr, 'id' => $element['id'], 'expression' => array('value' => $element['expression'])); $levelErrors = expressionHighLevelErrors($element['expression']); if (count($levelErrors) > 0) { $levelDetails['expression']['levelErrors'] = $levelErrors; } $treeList[] = $levelDetails; list($subOutline, $subTreeList) = buildExpressionHtmlTree($element['elements'], $next, $letterNum, $level + 1, $element['operand']); $treeList = array_merge($treeList, $subTreeList); $outline .= $level == 0 ? $subOutline : '(' . $subOutline . ')'; if ($operand !== null && $next[$level]) { $outline .= ' ' . $operand . ' '; } break; case 'expression': $next[$level] = $key != $lastKey; $letter = num2letter($letterNum++); $outline .= $letter; if ($operand !== null && $next[$level]) { $outline .= ' ' . $operand . ' '; } if (defined('NO_LINK_IN_TESTING')) { $url = new CSpan($element['expression']); } else { $expressionId = 'expr_' . $element['id']; $url = new CSpan($element['expression'], 'link'); $url->setAttribute('id', $expressionId); $url->setAttribute('onclick', 'javascript: copy_expression("' . $expressionId . '");'); } $expr = expressionLevelDraw($next, $level); $expr[] = SPACE; $expr[] = bold($letter); $expr[] = SPACE; $expr[] = $url; $levelDetails = array('list' => $expr, 'id' => $element['id'], 'expression' => array('value' => $element['expression'])); $levelErrors = expressionHighLevelErrors($element['expression']); if (count($levelErrors) > 0) { $levelDetails['expression']['levelErrors'] = $levelErrors; } $treeList[] = $levelDetails; break; } } return array($outline, $treeList); }
$operationConditionsTable->setHeader(array(_('Label'), _('Name'), _('Action'))); $i = 0; foreach ($this->data['new_operation']['opconditions'] as $opcondition) { if (!isset($opcondition['conditiontype'])) { $opcondition['conditiontype'] = 0; } if (!isset($opcondition['operator'])) { $opcondition['operator'] = 0; } if (!isset($opcondition['value'])) { $opcondition['value'] = 0; } if (!str_in_array($opcondition['conditiontype'], $allowed_opconditions)) { continue; } $label = num2letter($i); $operationConditionsTable->addRow(array('(' . $label . ')', get_condition_desc($opcondition['conditiontype'], $opcondition['operator'], $opcondition['value']), array(new CButton('remove', _('Remove'), 'javascript: removeOperationCondition(' . $i . ');', 'link_menu'), new CVar('new_operation[opconditions][' . $i . '][conditiontype]', $opcondition['conditiontype']), new CVar('new_operation[opconditions][' . $i . '][operator]', $opcondition['operator']), new CVar('new_operation[opconditions][' . $i . '][value]', $opcondition['value']))), null, 'opconditions_' . $i); $grouped_opconditions[$opcondition['conditiontype']][] = $label; $i++; } if ($operationConditionsTable->itemsCount() > 1) { switch ($this->data['new_operation']['evaltype']) { case ACTION_EVAL_TYPE_AND: $group_op = $glog_op = _('and'); break; case ACTION_EVAL_TYPE_OR: $group_op = $glog_op = _('or'); break; default: $group_op = _('or'); $glog_op = _('and');
$delayFlexTable->addRow([(new CButton('interval_add', _('Add')))->addClass(ZBX_STYLE_BTN_LINK)->addClass('element-table-add')]); $itemFormList->addRow(_('Custom intervals'), (new CDiv($delayFlexTable))->addClass(ZBX_STYLE_TABLE_FORMS_SEPARATOR)->setAttribute('style', 'min-width: ' . ZBX_TEXTAREA_STANDARD_WIDTH . 'px;'), 'row_flex_intervals')->addRow(_('Keep lost resources period (in days)'), (new CTextBox('lifetime', $this->data['lifetime'], false, 64))->setWidth(ZBX_TEXTAREA_SMALL_WIDTH))->addRow(_('Allowed hosts'), (new CTextBox('trapper_hosts', $this->data['trapper_hosts']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH), 'row_trapper_hosts')->addRow(_('Description'), (new CTextArea('description', $this->data['description']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)); // status $enabledCheckBox = (new CCheckBox('status', ITEM_STATUS_ACTIVE))->setChecked($this->data['status'] == ITEM_STATUS_ACTIVE); $itemFormList->addRow(_('Enabled'), $enabledCheckBox); /* * Condition tab */ $conditionFormList = new CFormList(); // type of calculation $conditionFormList->addRow(_('Type of calculation'), [new CComboBox('evaltype', $this->data['evaltype'], null, [CONDITION_EVAL_TYPE_AND_OR => _('And/Or'), CONDITION_EVAL_TYPE_AND => _('And'), CONDITION_EVAL_TYPE_OR => _('Or'), CONDITION_EVAL_TYPE_EXPRESSION => _('Custom expression')]), (new CDiv())->addClass(ZBX_STYLE_FORM_INPUT_MARGIN), (new CSpan(''))->setId('expression'), (new CTextBox('formula', $this->data['formula']))->setWidth(ZBX_TEXTAREA_STANDARD_WIDTH)->setId('formula')->setAttribute('placeholder', 'A or (B and C) …')], 'conditionRow'); // macros $conditionTable = (new CTable())->setId('conditions')->setAttribute('style', 'width: 100%;')->setHeader([_('Label'), _('Macro'), '', _('Regular expression'), _('Action')]); $conditions = $this->data['conditions']; if (!$conditions) { $conditions = [['macro' => '', 'value' => '', 'formulaid' => num2letter(0)]]; } else { $conditions = CConditionHelper::sortConditionsByFormulaId($conditions); } // fields foreach ($conditions as $i => $condition) { // formula id $formulaId = [new CSpan($condition['formulaid']), new CVar('conditions[' . $i . '][formulaid]', $condition['formulaid'])]; // macro $macro = (new CTextBox('conditions[' . $i . '][macro]', $condition['macro'], false, 64))->setWidth(ZBX_TEXTAREA_MACRO_WIDTH)->addClass(ZBX_STYLE_UPPERCASE)->addClass('macro')->setAttribute('placeholder', '{#MACRO}')->setAttribute('data-formulaid', $condition['formulaid']); // value $value = (new CTextBox('conditions[' . $i . '][value]', $condition['value'], false, 255))->setWidth(ZBX_TEXTAREA_MACRO_VALUE_WIDTH)->setAttribute('placeholder', _('regular expression')); // delete button $deleteButtonCell = [(new CButton('conditions_' . $i . '_remove', _('Remove')))->addClass(ZBX_STYLE_BTN_LINK)->addClass('element-table-remove')]; $row = [$formulaId, $macro, new CSpan(_('matches')), $value, (new CCol($deleteButtonCell))->addClass(ZBX_STYLE_NOWRAP)]; $conditionTable->addRow($row, 'form_row');
$conditionFormList = new CFormList('conditionlist'); // type of calculation $formula = new CTextBox('formula', $this->data['formula'], ZBX_TEXTBOX_STANDARD_SIZE); $formula->attr('id', 'formula'); $formula->attr('placeholder', 'A or (B and C) …'); if ($this->data['evaltype'] != CONDITION_EVAL_TYPE_EXPRESSION) { $formula->addClass('hidden'); } $conditionFormList->addRow(_('Type of calculation'), array(new CComboBox('evaltype', $this->data['evaltype'], null, array(CONDITION_EVAL_TYPE_AND_OR => _('And/Or'), CONDITION_EVAL_TYPE_AND => _('And'), CONDITION_EVAL_TYPE_OR => _('Or'), CONDITION_EVAL_TYPE_EXPRESSION => _('Custom expression'))), new CSpan('', $this->data['evaltype'] == CONDITION_EVAL_TYPE_EXPRESSION ? 'hidden' : '', 'expression'), $formula), count($this->data['conditions']) < 2, 'conditionRow'); // macros $conditionTable = new CTable('', 'formElementTable'); $conditionTable->attr('id', 'conditions'); $conditionTable->addRow(array(_('Label'), _('Macro'), SPACE, _('Regular expression'), SPACE)); $conditions = $this->data['conditions']; if (!$conditions) { $conditions = array(array('macro' => '', 'value' => '', 'formulaid' => num2letter(0))); } else { $conditions = CConditionHelper::sortConditionsByFormulaId($conditions); } // fields foreach ($conditions as $i => $condition) { // formula id $formulaId = array(new CSpan($condition['formulaid']), new CVar('conditions[' . $i . '][formulaid]', $condition['formulaid'])); // macro $macro = new CTextBox('conditions[' . $i . '][macro]', $condition['macro'], 30, false, 64); $macro->addClass('macro'); $macro->setAttribute('placeholder', '{#MACRO}'); $macro->setAttribute('data-formulaid', $condition['formulaid']); // value $value = new CTextBox('conditions[' . $i . '][value]', $condition['value'], 40, false, 255); $value->setAttribute('placeholder', _('regular expression'));
/** * Builds expression html tree * * @param array $expressionTree output of getExpressionTree() function * @param array $next parameter only for recursive call; should be empty array * @param int $letterNum parameter only for recursive call; should be 0 * @param int $level parameter only for recursive call * @param string $operator parameter only for recursive call * * @return array array containing the trigger expression formula as the first element and an array describing the * expression tree as the second */ function buildExpressionHtmlTree(array $expressionTree, array &$next, &$letterNum, $level = 0, $operator = null) { $treeList = []; $outline = ''; end($expressionTree); $lastKey = key($expressionTree); foreach ($expressionTree as $key => $element) { switch ($element['type']) { case 'operator': $next[$level] = $key != $lastKey; $expr = expressionLevelDraw($next, $level); $expr[] = SPACE; $expr[] = $element['operator'] === 'and' ? _('And') : _('Or'); $levelDetails = ['list' => $expr, 'id' => $element['id'], 'expression' => ['value' => $element['expression']]]; $levelErrors = expressionHighLevelErrors($element['expression']); if (count($levelErrors) > 0) { $levelDetails['expression']['levelErrors'] = $levelErrors; } $treeList[] = $levelDetails; list($subOutline, $subTreeList) = buildExpressionHtmlTree($element['elements'], $next, $letterNum, $level + 1, $element['operator']); $treeList = array_merge($treeList, $subTreeList); $outline .= $level == 0 ? $subOutline : '(' . $subOutline . ')'; if ($operator !== null && $next[$level]) { $outline .= ' ' . $operator . ' '; } break; case 'expression': $next[$level] = $key != $lastKey; $letter = num2letter($letterNum++); $outline .= $letter; if ($operator !== null && $next[$level]) { $outline .= ' ' . $operator . ' '; } if (defined('NO_LINK_IN_TESTING')) { $url = $element['expression']; } else { $expressionId = 'expr_' . $element['id']; $url = (new CSpan($element['expression']))->addClass(ZBX_STYLE_LINK_ACTION)->setId($expressionId)->onClick('javascript: copy_expression("' . $expressionId . '");'); } $expr = expressionLevelDraw($next, $level); $expr[] = SPACE; $expr[] = bold($letter); $expr[] = SPACE; $expr[] = $url; $levelDetails = ['list' => $expr, 'id' => $element['id'], 'expression' => ['value' => $element['expression']]]; $levelErrors = expressionHighLevelErrors($element['expression']); if (count($levelErrors) > 0) { $levelDetails['expression']['levelErrors'] = $levelErrors; } $treeList[] = $levelDetails; break; } } return [$outline, $treeList]; }