<?php
$sql_query = 'UPDATE ' . $config['table_prefix'] . 'calc_template SET ';
$sql_query .= <<<'EOT'
calculate_tpl = "{if $field == $field1}
$line['{$value}'] = 0;
{else}
if ($line['{$field}'] == '0000-00-00 00:00:00' || $line['{$field1}'] == '0000-00-00 00:00:00'){
    $line['{$value}'] = 0;
} else {
{if $case_type == 2}
    $datetime1 = strtotime({if $field == 'currentDate'}date('Y-m-d H:i:s'){else}$line['{$field}']{/if});
    $datetime2 = strtotime({if $field1 == 'currentDate'}date('Y-m-d H:i:s'){else}$line['{$field1}']{/if});
    $interval = $datetime2 - $datetime1;
{if $case_measure == 1}
    $total = $interval;
{elseif $case_measure == 2}
    $total = $interval / 60;
{elseif $case_measure == 3}
    $total = $interval / 3600;
{elseif $case_measure == 4}
    $total = $interval / (3600 * 24);
{elseif $case_measure == 5}
    $total = $interval / (3600 * 24 * 7);
{elseif $case_measure == 6}
    $total = $interval / (3600 * 24 * 30);
{elseif $case_measure == 7}
    $total = $interval / (3600 * 24 * 365.25);
{/if}
    $line['{$value}'] = round($total, {$decimal_places|default:0}, PHP_ROUND_HALF_DOWN);
{else}
    $datetime1 = date_create({if $field == 'currentDate'}date('Y-m-d H:i:s'){else}$line['{$field}']{/if});
    $datetime2 = date_create({if $field == 'currentDate'}date('Y-m-d H:i:s'){else}$line['{$field1}']{/if});
    $interval = date_diff($datetime1, $datetime2);
    $date = $interval->format('%a д. %H ч. %I м.');
    $result = str_replace('0 д.,', '', $date);
    $result = str_replace('0 м.,', '', $result);
    $result = str_replace('0 ч.,', '', $result);
    $line['{$value}'] = $result;
{/if}
}
{/if}" WHERE id = 84
EOT;
run_query($sql_query);