<?php

$sql_query = <<<EOF
INSERT INTO {$config["table_prefix"]}calc_template (name, calculate_tpl, params, type, tpl_name, javascript_tpl) VALUES
('Математические формулы', '

\$keys = [];
\$values = [];
\$fields = explode(''&'', \$params[''flex_data'']);

foreach (\$fields as \$field => \$value) {

    \$parts = explode(''='', \$value);

    array_push(\$keys, \$parts[0]);
    array_push(\$values, \$parts[1]);
}

\$func_row = str_replace(\$keys, \$values, \$params[''func_row'']);

\$keys = [
  ''{'',
  ''}''
];

\$values = [
    ''\$line["'',
    ''"]''
];

\$func_row = str_replace(\$keys, \$values, \$func_row);

\$func = ''\$line["'' . \$params["result"] . ''"] = '' . \$func_row . '';'';

eval(\$func);

', '
{     "title": "Математические формулы",     "help": "Математические формулы",     "parameters": {         "field1": {             "type": "Field",             "name": "field1",             "description": "Выберите поле", "type_field": 1         },         "func_row": {             "type": "String",             "name": "func_row",             "description": "Поле записи функции"         },         "result": {             "type": "Field",             "name": "result",             "description": "Выберите поле записи результата", "type_field": 1}, "flex_data": {"type": "String", "name": "flex_data", "description": ""}     } }
', 'calc', 'math_functions.tpl', '');
EOF;
run_query($sql_query);