<?php
$sql_query = 'UPDATE ' . $config['table_prefix'] . 'calc_template SET ';
$sql_query .= <<<'EOT'
`params` = '{\r\n    \"title\": \"Создать запись в подтаблице через форму\",\r\n    \"help\": \"create_subrecord_by_form\",\r\n    \"parameters\": {\r\n        \"sub_table\": {\r\n            \"type\": \"SubField\",\r\n            \"name\": \"sub_table\",\r\n            \"description\": \"Подтаблица\",\r\n            \"sub_description\": \"\",\r\n            \"help\": \"tpl_sub_table\",\r\n            \"field_help\": \"tpl_sub_field\"\r\n        },\r\n        \"open_form\": {\r\n            \"type\": \"List\",\r\n            \"name\": \"open_form\",\r\n            \"values\":{\"1\":\"в текущем окне\",\"2\":\"в новом окне\"},\r\n            \"description\": \"Открыть форму\",\r\n            \"help\": \"tpl_open_form\"\r\n        },\r\n        \"res_field\": {\r\n            \"type\": \"Field\",\r\n            \"name\": \"res_field\",\r\n            \"description\": \"\",\r\n            \"help\": \"\"\r\n        }\r\n    }\r\n}',
`calculate_tpl` = '{if $open_form == 1}\r\nforeach ($_SESSION[\'back_urls\'] as $back_url => $url) {\r\n    if (strpos($url, \"view_line2.php?table=$table_id\") && strpos($url, \"&line=$ID\")) break;\r\n}\r\nheader(\"Location: view_line2.php?table={$sub_table.subTable}&line=new&{$sub_table.link_field_id}=$ID&back_url=$back_url\");\r\n{else}\r\necho \"<script>window.open(\'view_line2.php?table={$sub_table.subTable}&line=new&{$sub_table.link_field_id}=$ID\')</script>\";\r\n{/if}',
`javascript_tpl` = '{if $open_form == 2}\r\nwindow.open(\'view_line2.php?table={$sub_table.subTable}&line=new&{$sub_table.link_field_id}=\' + line_id); return false;;\r\n{/if}'
WHERE `id` = 126;
EOT;
run_query($sql_query);