<?php
$sql_query = 'UPDATE ' . $config['table_prefix'] . 'calc_template SET ';
$sql_query .= <<<'EOT'
`calculate_tpl` = '$filter = sql_select_array(FILTERS_TABLE, \'id = \', get_filter_id({$filter|default:0}));\r\n$result = data_select_field(\r\n    $table_id,\r\n    \'COUNT(id) AS cnt\',\r\n    \'status = 0\' . ($event[\'type\'] === \'delete\' ? \' AND id != \' . $ID : \'\') . \r\n    \' AND {$cond_table.link_field_id} = \' . (int)$line[\'{$cond_table.link_field_id}\'][\'raw\'] . \r\n    ($filter[\'value\'] ? \' AND (\' . filter_tpl_replace($filter[\'value\']) . \')\' : \'\')\r\n);\r\n$row = sql_fetch_assoc($result);\r\n{if $operand == 1}\r\n    $filter_str = \'\';\r\n    if (isset($filter)) {\r\n        $filter_str = \'&filter=\' . $filter[\'id\'];\r\n    }\r\n    $line_link = substr(\"{$cond_table.link_field_id}\", 1);\r\n    $url = $config[\'site_url\'] . \"/fields.php?table=\" . $table_id . \"&rel_search&rel_table=\" . get_table_id({$cond_table.table}) . \"&rel_line=\" . \r\n    $line[\'{$cond_table.link_field_id}\'][\'raw\'] . \"&rel_field=\" . $line_link . $filter_str;\r\n    {if $cond_table.field_type eq 3}\r\n        $line[\'{$cond_table.link_field_id}\'][\'{$cond_table.field}\'] = \"<a href=\'\" . $url . \"\'>\" . $row[\'cnt\'] . \"</a>\";\r\n    {else} \r\n        $line[\'{$cond_table.link_field_id}\'][\'{$cond_table.field}\'] = $row[\'cnt\'];\r\n    {/if}\r\n{else}\r\n    $line[\'{$cond_table.link_field_id}\'][\'{$cond_table.field}\'] = $row[\'cnt\'];\r\n{/if}'
WHERE id = 36
EOT;
run_query($sql_query);