<?php
// Конвертируем datetime в timestamp для поддержки часовых поясов
$result = run_query("SHOW TABLES LIKE '" . $config["table_prefix"] . "%'");
while ($table = mysqli_fetch_array($result)) {
    if (substr($table[0], 0, strlen($config["table_prefix"] . "data")) == $config["table_prefix"] . "data") {
        run_query("ALTER TABLE `" . $table[0] . "` CHANGE `add_time` `add_time` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'");
    } else {
        $result2 = run_query("SHOW FIELDS FROM " . $table[0]);
        while ($field = mysqli_fetch_assoc($result2)) {
            if ($field['Type'] == "datetime") {
                run_query("ALTER TABLE `" . $table[0] . "` CHANGE `" . $field['Field'] . "` `" . $field['Field'] . "` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'");
            }
        }
    }
}
$result = run_query("SELECT * FROM " . $config["table_prefix"] . "fields WHERE type_field=2 and type_value=1");
while ($field = mysqli_fetch_array($result)) {
    run_query("ALTER TABLE " . $config["table_prefix"] . "data" . $field['table_id'] . " CHANGE `f" . $field['id'] . "` `f" . $field['id'] . "` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00'");
}

// Добавляем часовой пояс в программу
$dateTimeZone = new DateTimeZone(date_default_timezone_get());
$dateTime = new DateTime("now", $dateTimeZone);
$offset = $dateTimeZone->getOffset($dateTime) / 3600;
$time_zone = ($offset < 0) ? "$offset" : "+$offset";
run_query("INSERT INTO `" . $config["table_prefix"] . "config` (`key`, `value`) VALUES ('time_zone', '$time_zone')");

// Добавляем часовой пояс пользователя
run_query("ALTER TABLE `" . $config["table_prefix"] . "users` ADD `time_zone` VARCHAR(255) NOT NULL AFTER `lang`");
?>