{*
 Шаблон вычисления "Создать запись в подтаблице через форму"
 id - 126
*}

foreach ($_SESSION['back_urls'] as $back_url => $url) {
    if (strpos($url, "view_line2.php?table=$table_id") && strpos($url, "&line=$ID") && !strpos($url, "edit_mode=1") && !strpos($url, "csrf")) break;
}

$add_table = get_table({$sub_table.subTable});
if (($add_table['auto_save'] ?? 0) == 1 || $config['disable_full_edit']) {
    $new_line_id = data_insert({$sub_table.subTable}, EVENTS_ENABLE, [
        'status' => $config['disable_full_edit'] ? 3 : 0,
        '{$sub_table.link_field_id}' => $ID
    ]);
{if $open_form == 1}
    header("Location: view_line2.php?table={$sub_table.subTable}&line=$new_line_id&back_url=$back_url&save_close");
    exit;
{else}
    echo "<script>window.open('view_line2.php?table={$sub_table.subTable}&line=$new_line_id')</script>";
{/if}
} else {
{if $open_form == 1}
    header("Location: view_line2.php?table={$sub_table.subTable}&line=new&{$sub_table.link_field_id}=$ID&back_url=$back_url&save_close");
    exit;
{else}
    echo "<script>window.open('view_line2.php?table={$sub_table.subTable}&line=new&{$sub_table.link_field_id}=$ID')</script>";
{/if}
}