<?php
// Преобразуем buttons также к формату $line['']
// выбираем все кнопки
$result = run_query("SELECT * FROM " . $config["table_prefix"] . "buttons");
while ($row = mysqli_fetch_array($result)) {
    $button_id = $row['id'];
    $table_id = $row['table_id'];
    $calc = $row['php_code'];
    // Заменяем стандартные конструции ID
    $calc = str_replace('"id={ID}"', '"id=\'$ID\'"', $calc);
    if (strpos($calc, '{ID}')) {
        $old_format = 1;
    } else {
        $old_format = 0;
    }
    $calc = addslashes($calc);
    $name = addslashes("Button " . $button_id);
    run_query("INSERT INTO `" . $config["table_prefix"] . "calc` (`table_id`, `name`, `calculate`, `old_format`) VALUES ('$table_id', '$name', '$calc','$old_format')");
    $calc_id = mysqli_insert_id($sql_global_link);
    run_query("INSERT INTO `" . $config["table_prefix"] . "calc_cond` (`calc_id`, `type`, `param`) VALUES ('$calc_id', '24', '$button_id')");
}
run_query("ALTER TABLE `" . $config["table_prefix"] . "buttons` DROP `php_code`");
?>