<?php
$sql_prefix = 'UPDATE ' . $config['table_prefix'] . 'calc_template SET ';
$sql_query_50 = <<<'EOT'
`calculate_tpl` = '$sel_table = (int)\'{$correlation[\'table\']}\';\n$sel_fields = [\n    {foreach from = $correlation[\'to_field\'] item = field_id}(int)\'{$field_id}\', {/foreach}\n];\n$sel_def_vals = [\n    {foreach from = $correlation[\'def_val\'] item = field_id}\'{$field_id}\', {/foreach}\n];\n$cur_fields = [\n    {foreach from = $correlation[\'cur_field\'] item = field_id}\'{$field_id}\', {/foreach}\n];\nif ($sel_table > 0) {\n    $ins_arr = [];\n    foreach ($sel_fields as $num => $field_id) {\n        if (!$field_id) continue;\n        $def_val = $sel_def_vals[$num];\n        if ($def_val) {\n             $ins_arr[\'f\' . $field_id] = $def_val;\n        } else {\n             if (is_array($line[\'f\' . $cur_field[$num]])) {\n                 $ins_arr[\'f\' . $field_id] = $line[\'f\' . $cur_fields[$num]][\'raw\'];\n             } else {\n                 if ($cur_fields[$num] !== \'id\') {\n                     $ins_arr[\'f\' . $field_id] = $line[\'f\' . $cur_fields[$num]];\n                 } else {\n                     $ins_arr[\'f\' . $field_id] = $line[$cur_fields[$num]];\n                 }                \n             }\n        }\n    }\n    if (count($ins_arr) > 0) {\n        if ($new_id = data_insert($sel_table, EVENTS_ENABLE, $ins_arr)) {\n{if $addit neq \'stop\'}\n{if $addit eq \'go_edit\'}\n            header(\'Location: \' . $config[\'site_root\'] . \'/view_line2.php?table=\' . $sel_table . \'&line=\' . $new_id . \'&edit_mode=on\');\n{else}\n            header(\'Location: \' . $config[\'site_root\'] . \'/view_line2.php?table=\' . $sel_table . \'&line=\' . $new_id);\n{/if}\n{/if}\n        } else {\n            $error_trace[] = true;\n        }\n    } else {\n        $error_trace[] = true;\n    }\n} else {\n    $error_trace[] = true;\n}\n'
WHERE id = 50
EOT;
$sql_query_78 = <<<'EOT'
`calculate_tpl` = '$sel_table = (int)\'{$correlation[\'table\']}\';\n$sel_fields = [\n    {foreach from = $correlation[\'to_field\'] item = field_id}(int)\'{$field_id}\', {/foreach}\n];\n$sel_def_vals = [\n    {foreach from = $correlation[\'def_val\'] item = field_id}\'{$field_id}\', {/foreach}\n];\n$cur_fields = [\n    {foreach from = $correlation[\'cur_field\'] item = field_id}\'{$field_id}\', {/foreach}\n];\nif ($sel_table > 0) {\n    $ins_arr = [];\n    foreach ($sel_fields as $num => $field_id) {\n        if (!$field_id) continue;\n        $def_val = $sel_def_vals[$num];\n        if ($def_val) {\n             $ins_arr[\'f\' . $field_id] = $def_val;\n        } else {\n             if (is_array($line[\'f\' . $cur_field[$num]])) {\n                 $ins_arr[\'f\' . $field_id] = $line[\'f\' . $cur_fields[$num]][\'raw\'];\n             } else {\n                 if ($cur_fields[$num] !== \'id\') {\n                     $ins_arr[\'f\' . $field_id] = $line[\'f\' . $cur_fields[$num]];\n                 } else {\n                     $ins_arr[\'f\' . $field_id] = $line[$cur_fields[$num]];\n                 }                \n             }\n        }\n    }\n    if (count($ins_arr) > 0) {\n        if ($new_id = data_insert($sel_table, EVENTS_ENABLE, $ins_arr)) {\n{if $addit neq \'stop\'}\n{if $addit eq \'go_edit\'}\n            header(\'Location: \' . $config[\'site_root\'] . \'/view_line2.php?table=\' . $sel_table . \'&line=\' . $new_id . \'&edit_mode=on\');\n{else}\n            header(\'Location: \' . $config[\'site_root\'] . \'/view_line2.php?table=\' . $sel_table . \'&line=\' . $new_id);\n{/if}\n{/if}\n        } else {\n            $error_trace[] = true;\n        }\n    } else {\n        $error_trace[] = true;\n    }\n} else {\n    $error_trace[] = true;\n}\n'
WHERE id = 78
EOT;
run_query($sql_prefix . $sql_query_50);
run_query($sql_prefix . $sql_query_78);