<?php
// Добавляем минимальное количество цифр и заменяем формат хранения автонумерации
$result = run_query("SELECT id, table_id, type_value, default_value FROM " . $config['table_prefix'] . "fields WHERE type_field=1");
while ($field = sql_fetch_assoc($result)) {
    $ta = explode("\r\n", $field['type_value']);
    $tb = explode("/", $ta[0]);
    $ta[0] .= "|" . ($tb[1] + 1);
    $field['type_value'] = implode("\r\n", $ta);
    if ($field['default_value'] == "{autonumber}") {
        $field['type_value'] .= "\r\n{autonumber}";
        $result2 = run_query("SELECT max(f" . $field['id'] . ") as max_value FROM " . $config['table_prefix'] . "data" . $field['table_id']);
        $max_row = sql_fetch_assoc($result2);
        $field['default_value'] = $max_row['max_value'] + 1;
    }
    run_query("UPDATE " . $config['table_prefix'] . "fields SET type_value='" . $field['type_value'] . "', default_value='" . $field['default_value'] . "' WHERE id=" . $field['id']);
}
run_query("UPDATE " . $config['table_prefix'] . "fields SET default_value='' WHERE type_field=10");
?>