<?php
// Исправление наименований настроек календаря
// Переименование таблицы
$result = run_query("SHOW TABLES LIKE '" . $config['table_prefix'] . "calendar_tables'");
if (sql_fetch_assoc($result)) {
    run_query("RENAME TABLE `" . $config['table_prefix'] . "calendar_tables` TO `" . $config['table_prefix'] . "calendar_events`");
}
// Добавление полей
$result = run_query("SHOW COLUMNS FROM `" . $config['table_prefix'] . "calendar_events` LIKE 'id'");
if (!sql_fetch_assoc($result)) {
    run_query("ALTER TABLE `" . $config['table_prefix'] . "calendar_events` ADD `id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST");
}
$result = run_query("SHOW COLUMNS FROM `" . $config['table_prefix'] . "calendar_events` LIKE 'num'");
if (!sql_fetch_assoc($result)) {
    run_query("ALTER TABLE `" . $config['table_prefix'] . "calendar_events` ADD `num` INT(11) NOT NULL AFTER `calendar_id`");
}
$result = run_query("SHOW COLUMNS FROM `" . $config['table_prefix'] . "calendar_events` LIKE 'name'");
if (!sql_fetch_assoc($result)) {
    run_query("ALTER TABLE `" . $config['table_prefix'] . "calendar_events` ADD `name` VARCHAR(255) NOT NULL AFTER `num`");
}
$result = run_query("SHOW COLUMNS FROM `" . $config['table_prefix'] . "calendar_fields` LIKE 'event_id'");
if (!sql_fetch_assoc($result)) {
    run_query("ALTER TABLE `" . $config['table_prefix'] . "calendar_fields` ADD `event_id` INT(11) NOT NULL AFTER `calendar_id`");
}
?>