<?php

$sql_query = 'INSERT INTO `' . $config["table_prefix"] . 'calc_template`';

$sql_query .= <<<'EOT'
 (`id`, `name`, `calculate_tpl`, `params`, `type`, `tpl_name`, `javascript_tpl`, `tpl_category`, `calc_types`, `calc_num`) VALUES
(110, 'Текст: Обрезать текст', '$source = explode(\'.\', \'{$source}\');\r\nif (count($source) > 1) {\r\n    $result = sql_fetch_assoc(sql_select_field(FIELDS_TABLE, \'table_id\', \'id=\'. mb_strcut($source[\'1\'], 1) ));\r\n    $row = sql_fetch_assoc(data_select_field($result[\'table_id\'], $source[\'1\'], \'id=\'. ($line[$source[\'0\']] ? $line[$source[\'0\']] : -1) ));\r\n\r\n    $line[\'{$result}\'] = mb_substr($row[$source[\'1\']], 0, \'{$count}\');\r\n} else {\r\n    $line[\'{$result}\'] = mb_substr($line[\'{$source}\'], 0, \'{$count}\');\r\n}',	'{\r\n     \"title\": \"Текст: Объединение текста\",\r\n     \"help\": \"text_concatenation\",\r\n     \"parameters\": {\r\n         \"source\": {\r\n             \"type\": \"LinkField\",\r\n             \"name\": \"source\",\r\n             \"description\": \"Поле-источник\",\r\n             \"type_field\": [1,2,3,4,5,7,11],\r\n             \"get_link_fields\": [1,3,4],\r\n             \"help\": \"source_field\"\r\n         },\r\n         \"result\": {\r\n             \"type\": \"Field\",\r\n             \"name\": \"result\",\r\n             \"description\": \"Поле-получатель\",\r\n             \"type_field\": [3],\r\n             \"help\": \"receiver_field\"\r\n         },\r\n         \"count\": {\r\n            \"type\": \"String\",\r\n            \"name\": \"count\",\r\n            \"description\": \"Количество символов\",\r\n            \"help\": \"\"\r\n        }\r\n     },\r\n    \"events\": [\r\n        {\r\n            \"type\": 1,\r\n            \"field\": \"\"\r\n        }\r\n    ]\r\n}', '', 'crop_text.tpl', '',	1,	'[1]',	7);
EOT;

run_query($sql_query);
