<?php
$sql_query = 'UPDATE ' . $config['table_prefix'] . 'calc_template SET ';
$sql_query .= <<<'EOT'
calculate_tpl = '$sel_table = get_table_id({$correlation[\'table\']|default:0});\r\n$sel_fields = [\r\n    {foreach from = $correlation[\'to_field\'] item = field_id}get_field_id({$field_id|default:0}), {/foreach}\r\n];\r\n$sel_def_vals = [\r\n    {foreach from = $correlation[\'def_val\'] item = value}\'{$value}\', {/foreach}\r\n];\r\n$cur_fields = [\r\n    {foreach from = $correlation[\'cur_field\'] item = field_id}get_field_id({$field_id|default:0}), {/foreach}\r\n];\r\n$link_field = get_field_id({$correlation[\'link_field_id\']|default:0});\r\nif ($sel_table > 0) {\r\n    $ins_arr = [];\r\n    foreach ($sel_fields as $num => $field_id) {\r\n        if (!$field_id) continue;\r\n        $def_val = $sel_def_vals[$num];\r\n        if ($def_val && $def_val != \'null\') {\r\n             $ins_arr[\'f\' . $field_id] = $def_val;\r\n        } else {\r\n             if (is_array($line[$cur_field[$num]])) {\r\n                 $ins_arr[\'f\' . $field_id] = $line[\'f\' . $cur_fields[$num]][\'raw\'];\r\n             } else {\r\n                 $ins_arr[\'f\' . $field_id] = $line[\'f\' . $cur_fields[$num]];\r\n             }\r\n        }\r\n    }\r\n    if ($link_field) {\r\n        $ins_arr[\'f\' . $link_field] = $ID;\r\n    }\r\n    if (count($ins_arr) > 0) {\r\n        data_insert($sel_table, EVENTS_ENABLE, $ins_arr);\r\n    } else {\r\n        $error_trace[] = true;\r\n    }\r\n} else {\r\n    $error_trace[] = true;\r\n}' WHERE id = 60 OR id = 101
EOT;
run_query($sql_query);