<?php
$sql_query = 'UPDATE ' . $config['table_prefix'] . 'calc_template SET ';
$sql_query .= <<<'EOT'
calculate_tpl = 'if ($event[\'type\'] === \'delete\') {\r\n    $deleteCond = \" AND id <> $ID\";\r\n}\r\n$filter = sql_select_array(FILTERS_TABLE, \'id={$filter}\');\r\n$result = data_select_field($table_id, \'{$cond_field}\',\r\n    \'status = 0 AND {$cond_table.link_field_id} = \' . $line[\'{$cond_table.link_field_id}\'][\'raw\'] . $deleteCond .\r\n    ($filter[\'value\'] ? \' AND (\' . $filter[\'value\'] . \')\' : \'\') . \' ORDER BY id {if $record == \"last\"}DESC{/if} LIMIT 1\');\r\n$row = sql_fetch_assoc($result);\r\n{if $add_value == \'yes\'}\r\nif ($line[\'{$cond_table.link_field_id}\'][\'{$cond_table.field}\'] != \'\') {\r\n    $line[\'{$cond_table.link_field_id}\'][\'{$cond_table.field}\'] .= \"{$add_delim}\" . $row[\'{$cond_field}\'];\r\n} else {\r\n    $line[\'{$cond_table.link_field_id}\'][\'{$cond_table.field}\'] = $row[\'{$cond_field}\'];\r\n}\r\n{else}\r\n$line[\'{$cond_table.link_field_id}\'][\'{$cond_table.field}\'] = $row[\'{$cond_field}\'];\r\n{/if}' WHERE id = 43
EOT;
run_query($sql_query);
$sql_query = 'UPDATE ' . $config['table_prefix'] . 'calc_template SET ';
$sql_query .= <<<'EOT'
calculate_tpl = '$result = data_select_field({$sub_table.subTable}, \'{$sub_table.subField}\',\r\n    \'status = 0 AND {$sub_table.link_field_id} = \' . $ID . \' ORDER BY id {if $sub_record == \"last\"}DESC{/if} LIMIT 1\');\r\n$row = sql_fetch_assoc($result);\r\n{if $add_value == \'yes\'}\r\nif ($line[\'{$res_field}\'] != \'\') {\r\n    $line[\'{$res_field}\'] .= \"{$add_delim}\" . $row[\'{$sub_table.subField}\'];\r\n} else {\r\n    $line[\'{$res_field}\'] = $row[\'{$sub_table.subField}\'];\r\n}\r\n{else}\r\n$line[\'{$res_field}\'] = $row[\'{$sub_table.subField}\'];\r\n{/if}' WHERE id = 43
EOT;
run_query($sql_query);