<?php
$sql_query = 'INSERT INTO ' . $config['table_prefix'] . 'calc_template (`name`, `calculate_tpl`, `params`, `type`, `tpl_name`, `javascript_tpl`, `tpl_category`, `calc_types`, `calc_num`) VALUES ';
$sql_query .= <<<'EOT'
('Заполнить поле связи по текстовому полю',	'$field_info = sql_fetch_row(sql_select_field(FIELDS_TABLE, \'type_value\', \'id = \', substr(\'{$link_field}\', 1)))[0];\r\nlist($link_table_id, $link_field_id) = explode(\'|\', $field_info);\r\n$line[\'{$link_field}\'] = sql_fetch_row(data_select_field($link_table_id, \'id\', \"f$link_field_id = \'\", $line[\'{$source_field}\'], \"\'\"))[0];',	'{\r\n    \"title\": \"Заполнить поле связи по текстовому полю\",\r\n    \"help\": \"tpl_txt_field_to_link_field\",\r\n    \"parameters\": {\r\n        \"source_field\": {\r\n            \"type\": \"Field\",\r\n            \"type_field\": 3,\r\n            \"name\": \"source_field\",\r\n            \"help\": \"source_field\",\r\n            \"description\": \"Поле-источник\"\r\n        },\r\n        \"link_field\": {\r\n            \"type\": \"Field\",\r\n            \"type_field\": 5,\r\n            \"name\": \"link_field\",\r\n            \"help\": \"receiver_field\",\r\n            \"description\": \"Поле-получатель\"\r\n        }\r\n    },\r\n    \"events\": [\r\n        {\r\n            \"type\": 3,\r\n            \"field\": \"source_field\"\r\n        }\r\n    ]\r\n}',	'',	'fill_link_field.tpl',	'',	1,	'[1]',	20);
EOT;
run_query($sql_query);