} else { jQuery('#param_0').attr('readonly', 'readonly'); } } }); }); </script> <?php if (!empty($this->data['insert'])) { if ($this->data['paramtype'] == PARAM_TYPE_COUNTS) { $param_no = in_array($this->data['function'], array('regexp', 'iregexp', 'str')) ? 1 : 0; $this->data['param'][$param_no] = '#' . $this->data['param'][$param_no]; } foreach ($this->data['param'] as &$param) { $param = quoteFunctionParam($param); } unset($param); $expression = sprintf('{%s:%s.%s(%s)}%s%s', $this->data['item_host'], $this->data['item_key'], $this->data['function'], rtrim(implode(',', $this->data['param']), ','), $this->data['operator'], $this->data['value']); ?> <script language="JavaScript" type="text/javascript"> insertText(jQuery('#<?php echo $this->data['dstfld1']; ?> ', window.opener.document), <?php echo zbx_jsvalue($expression); ?> ); close_window(); </script> <?php
$expressionData = reset($triggerExpression->expressions); // validate trigger function $triggerFunctionValidator = new CFunctionValidator(); $isValid = $triggerFunctionValidator->validate(['function' => $expressionData['function'], 'functionName' => $expressionData['functionName'], 'functionParamList' => $expressionData['functionParamList'], 'valueType' => $data['itemValueType']]); if (!$isValid) { unset($data['insert']); throw new Exception($triggerFunctionValidator->getError()); } } else { unset($data['insert']); throw new Exception($triggerExpression->error); } // quote function param if (isset($data['insert'])) { foreach ($data['params'] as $pnum => $param) { $data['params'][$pnum] = quoteFunctionParam($param); } } } else { unset($data['insert']); throw new Exception(_('Item not selected')); } } catch (Exception $e) { error($e->getMessage()); show_error_message(_('Cannot insert trigger expression')); } } elseif (hasErrorMesssages()) { show_messages(); } // render view $expressionView = new CView('configuration.triggers.expression', $data);
/** * Resolves macros in the trigger function parameters. * * @param string $function a trigger function * @param array $macros the list of macros (['{<MACRO>}' => '<value>', ...]) * @param array $types the types of macros (see getMacroPositions() for more details) * * @return string */ protected function resolveFunctionMacros($function, array $macros, array $types) { $function_parser = new CFunctionParser(); if ($function_parser->parse($function) == CParser::PARSE_SUCCESS) { $params_raw = $function_parser->getParamsRaw(); $function_chain = $params_raw['raw']; foreach (array_reverse($params_raw['parameters']) as $param_raw) { $param = $param_raw['raw']; $forced = false; switch ($param_raw['type']) { case CFunctionParser::PARAM_QUOTED: $param = CFunctionParser::unquoteParam($param); $forced = true; // break; is not missing here // break; is not missing here case CFunctionParser::PARAM_UNQUOTED: $matched_macros = $this->getMacroPositions($param, $types); foreach (array_reverse($matched_macros, true) as $pos => $macro) { $param = substr_replace($param, $macros[$macro], $pos, strlen($macro)); } $param = quoteFunctionParam($param, $forced); break; } $function_chain = substr_replace($function_chain, $param, $param_raw['pos'], strlen($param_raw['raw'])); } $function = substr_replace($function, $function_chain, $params_raw['pos'], strlen($params_raw['raw'])); } return $function; }