<?php
#-----------------------------------------------------#
#          ********* ROTORCMS *********               #
#              Made by  :  VANTUZ                     #
#               E-mail  :  visavi.net@mail.ru         #
#                 Site  :  http://pizdec.ru           #
#             WAP-Site  :  http://visavi.net          #
#                  ICQ  :  36-44-66                   #
#  Вы не имеете право вносить изменения в код скрипта #
#        для его дальнейшего распространения          #
#-----------------------------------------------------#
if (!defined('BASEDIR')) {
	header('Location:../index.php');
	exit;
} 

$check = DB::run() -> queryFetch("SHOW COLUMNS FROM `users` LIKE 'users_javascript';");
if (empty($check)) {
	DB::run() -> query("ALTER TABLE `users` CHANGE `users_bbpanel` `users_javascript` tinyint(1) unsigned NOT NULL DEFAULT '0';");
} 

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('wishes'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('wishes', '1'));
} 


DB::run() -> query("DELETE FROM `setting` WHERE `setting_name`=? LIMIT 1;", array('gzipout'));
DB::run() -> query("DELETE FROM `setting` WHERE `setting_name`=? LIMIT 1;", array('generics'));
DB::run() -> query("DELETE FROM `setting` WHERE `setting_name`=? LIMIT 1;", array('ras'));
DB::run() -> query("DELETE FROM `setting` WHERE `setting_name`=? LIMIT 1;", array('cookies'));
DB::run() -> query("UPDATE `setting` SET `setting_name`=? WHERE `setting_name`=?;", array('cache', 'nocache'));
DB::run() -> query("UPDATE `setting` SET `setting_name`=? WHERE `setting_name`=?;", array('timezone', 'timeclocks'));

// ------------------------------- 3.0.0 ---------------------------//


DB::run() -> query("DELETE FROM `setting` WHERE `setting_name`=? LIMIT 1;", array('editmailpoint'));
	
DB::run() -> exec("
CREATE TABLE IF NOT EXISTS `changemail` (
	`change_id` int(11) unsigned NOT NULL auto_increment,
	`change_user` varchar(20) NOT NULL,
	`change_mail` varchar(50) NOT NULL,
	`change_key` varchar(25) NOT NULL,
	`change_time` int(11) unsigned NOT NULL,
	PRIMARY KEY  (`change_id`)
	) ENGINE=MyISAM DEFAULT CHARSET=utf8;
");

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('errorlog'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('errorlog', '1'));
} 

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('session'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('session', '1'));
} 


// ------------------------------- 2.5.0 ---------------------------//
DB::run()->exec("
	CREATE TABLE IF NOT EXISTS `transfers` (
	`trans_id` int(11) unsigned NOT NULL auto_increment,
	`trans_user` varchar(20) NOT NULL,
	`trans_login` varchar(20) NOT NULL,
	`trans_text` text NOT NULL default '',
	`trans_summ` int(11) unsigned NOT NULL default '0',
	`trans_time` int(11) unsigned NOT NULL default '0',
	PRIMARY KEY (`trans_id`),
	KEY `trans_user` (`trans_user`),
	KEY `trans_login` (`trans_login`),
	KEY `trans_time` (`trans_time`)
	) ENGINE=MyISAM DEFAULT CHARSET=utf8;
");

DB::run() -> query("ALTER TABLE `photo` MODIFY `photo_link` varchar(30) NOT NULL;");

$check = DB::run() -> queryFetch("SHOW COLUMNS FROM `news` LIKE 'news_image';");
if (empty($check)) {
	DB::run() -> query("ALTER TABLE `news` ADD `news_image` varchar(30) NOT NULL default '' AFTER `news_author`;");
} 

$check = DB::run() -> queryFetch("SHOW COLUMNS FROM `forums` LIKE 'forums_closed';");
if (empty($check)) {
	DB::run() -> query("ALTER TABLE `forums` ADD `forums_closed` tinyint(1) unsigned NOT NULL default '0' AFTER `forums_last_time`;");
} 


// ------------------------------- 2.4.0 ---------------------------//
$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('performance'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('performance', '0'));
} 

DB::run() -> query("UPDATE `users` SET `users_avatar` = replace(`users_avatar`, 'gallery/avatars/', 'upload/avatars/');");


$check = DB::run() -> queryFetch("SHOW COLUMNS FROM `users` LIKE 'users_skype';");
if (empty($check)) {
	DB::run() -> query("ALTER TABLE `users` ADD `users_skype` varchar(32) NOT NULL default '' AFTER `users_icq`;");
} 

DB::run() -> exec("
	CREATE TABLE IF NOT EXISTS `login` (
	`login_id` int(11) unsigned NOT NULL auto_increment,
	`login_user` varchar(20) NOT NULL,
	`login_ip` varchar(15) NOT NULL,
	`login_brow` varchar(25) NOT NULL,
	`login_time` int(11) unsigned NOT NULL,
	`login_type` tinyint(1) unsigned NOT NULL default '0',
	PRIMARY KEY  (`login_id`),
	KEY `login_user` (`login_user`),
	KEY `login_time` (`login_time`)
	) ENGINE=MyISAM DEFAULT CHARSET=utf8;
");

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('editstatus'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('editstatus', '0'));
} 

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('editstatuspoint'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('editstatuspoint', '1000'));
} 

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('editstatusmoney'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('editstatusmoney', '10000'));
} 

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('screenupsize'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('screenupsize', '5000'));
} 
// ------------------------------- 2.3.0 ---------------------------//
DB::run() -> exec("
	CREATE TABLE IF NOT EXISTS `bookmarks` (
	`book_id` int(11) unsigned NOT NULL auto_increment,
	`book_user` varchar(20) NOT NULL,
	`book_topic` mediumint(8) unsigned NOT NULL,
	`book_forum` smallint(4) unsigned NOT NULL,
	`book_posts` mediumint(8) unsigned NOT NULL,
	PRIMARY KEY (`book_id`),
	KEY `book_user` (`book_user`),
	KEY `book_forum` (`book_forum`),
	KEY `book_topic` (`book_topic`)
	) ENGINE=MyISAM DEFAULT CHARSET=utf8;
");

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('fileupfoto'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('fileupfoto', '5000'));
} 

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('addofferspoint'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('addofferspoint', '50'));
} 

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('showrathistpoint'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('showrathistpoint', '150'));
} 

DB::run() -> query("DELETE FROM `b2` USING `ban` `b1` JOIN `ban` `b2` ON (`b1`.`ban_id` < `b2`.`ban_id` AND `b1`.`ban_ip` = `b2`.`ban_ip`);");
DB::run() -> query("ALTER TABLE `ban` MODIFY `ban_ip` varchar(15) NOT NULL;");

$queryindex = DB::run() -> queryFetch("SHOW INDEX FROM `ban` WHERE `Key_name`='ban_ip';");
if (empty($queryindex)) {
	DB::run() -> query("ALTER TABLE `ban` ADD UNIQUE `ban_ip` (`ban_ip`);");
} 
// ------------------------------- 2.2.0 ---------------------------//
DB::run() -> query("ALTER TABLE `downs` MODIFY `downs_screen` varchar(55) NOT NULL default '';");

$check = DB::run() -> queryFetch("SHOW COLUMNS FROM `visit` LIKE 'visit_allcount';");
if (!empty($check)) {
	DB::run() -> query("ALTER TABLE `visit` DROP COLUMN `visit_allcount`;");
} 

$check = DB::run() -> queryFetch("SHOW COLUMNS FROM `visit` LIKE 'visit_alltime';");
if (!empty($check)) {
	DB::run() -> query("ALTER TABLE `visit` DROP COLUMN `visit_alltime`;");
} 
// ------------------------------- 2.1.0 ---------------------------//
$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('downupload'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('downupload', '1'));
} 

DB::run() -> query("UPDATE `users` SET `users_gender`=? WHERE `users_gender`=?;", array('0', ''));
DB::run() -> query("UPDATE `users` SET `users_gender`=? WHERE `users_gender`=?;", array('1', 'М'));
DB::run() -> query("UPDATE `users` SET `users_gender`=? WHERE `users_gender`=?;", array('2', 'Ж'));

DB::run() -> query("ALTER TABLE `users` MODIFY `users_gender` tinyint(1) unsigned NOT NULL default '0';");

DB::run() -> exec("
	CREATE TABLE IF NOT EXISTS `note` (
	`note_id` int(11) unsigned NOT NULL auto_increment,
	`note_user` varchar(20) NOT NULL,
	`note_text` text NOT NULL default '',
	`note_time` int(11) unsigned NOT NULL default '0',
	PRIMARY KEY (`note_id`),
	UNIQUE KEY `note_user` (`note_user`)
	) ENGINE=MyISAM DEFAULT CHARSET=utf8;
");

$check = DB::run() -> queryFetch("SHOW COLUMNS FROM `note` LIKE 'note_edit';");
if (empty($check)) {
	DB::run() -> query("ALTER TABLE `note` ADD `note_edit` varchar(20) NOT NULL AFTER `note_text`;");
} 

$check = DB::run() -> queryFetch("SHOW COLUMNS FROM `users` LIKE 'users_note';");
if (!empty($check)) {
	DB::run() -> query("INSERT IGNORE INTO `note` (`note_user`, `note_text`, `note_time`) SELECT `users_login`, `users_note`, ? FROM `users` WHERE `users_note`!=?;", array(SITETIME, ''));
	DB::run() -> query("ALTER TABLE `users` DROP COLUMN `users_note`;");
} 

DB::run() -> query("ALTER TABLE `rating` MODIFY `rating_vote` tinyint(1) unsigned NOT NULL default '0';");

$check = DB::run() -> queryFetch("SHOW COLUMNS FROM `rating` LIKE 'rating_text';");
if (empty($check)) {
	DB::run() -> query("ALTER TABLE `rating` ADD `rating_text` varchar(255) NOT NULL default '' AFTER `rating_login`;");
} 

DB::run() -> query("ALTER TABLE `rating` MODIFY `rating_text` text NOT NULL;");

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('privatprotect'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('privatprotect', '50'));
} 

DB::run() -> query("DELETE FROM `t2` USING `counter24` `t1` JOIN `counter24` `t2` ON (`t1`.`count_id` < `t2`.`count_id` AND `t1`.`count_hour` = `t2`.`count_hour`);");
DB::run() -> query("DELETE FROM `t2` USING `counter31` `t1` JOIN `counter31` `t2` ON (`t1`.`count_id` < `t2`.`count_id` AND `t1`.`count_days` = `t2`.`count_days`);");

$queryindex = DB::run() -> queryFetch("SHOW INDEX FROM `counter24` WHERE `Key_name`='count_hour';");
if (empty($queryindex)) {
	DB::run() -> query("ALTER TABLE `counter24` ADD UNIQUE `count_hour` (`count_hour`);");
} 

$queryindex = DB::run() -> queryFetch("SHOW INDEX FROM `counter31` WHERE `Key_name`='count_days';");
if (empty($queryindex)) {
	DB::run() -> query("ALTER TABLE `counter31` ADD UNIQUE `count_days` (`count_days`);");
} 
// ------------------------------- 2.0.0 ---------------------------//
$check = DB::run() -> queryFetch("SHOW COLUMNS FROM `users` LIKE 'users_newchat';");
if (empty($check)) {
	DB::run() -> query("ALTER TABLE `users` ADD `users_newchat` int(11) unsigned NOT NULL default '0' AFTER `users_person`;");
} 

DB::run() -> exec("
	CREATE TABLE IF NOT EXISTS `banhist` (
	`ban_id` int(11) unsigned NOT NULL auto_increment,
	`ban_user` varchar(20) NOT NULL,
	`ban_send` varchar(20) NOT NULL,
	`ban_type` tinyint(1) unsigned NOT NULL default '0',
	`ban_reason` text NOT NULL default '',
	`ban_term` int(11) unsigned NOT NULL default '0',
	`ban_time` int(11) unsigned NOT NULL default '0',
	PRIMARY KEY (`ban_id`),
	KEY `ban_user` (`ban_user`),
	KEY `ban_time` (`ban_time`)
	) ENGINE=MyISAM DEFAULT CHARSET=utf8;
");

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('statusdef'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('statusdef', 'Дух'));
} 

DB::run() -> query("ALTER TABLE `forums` MODIFY `forums_title` varchar(50) NOT NULL;");
DB::run() -> query("ALTER TABLE `forums` MODIFY `forums_last_themes` varchar(50) NOT NULL default '';");
DB::run() -> query("ALTER TABLE `topics` MODIFY `topics_title` varchar(50) NOT NULL;");
DB::run() -> query("ALTER TABLE `posts` MODIFY `posts_ip` varchar(15) NOT NULL;");
DB::run() -> query("ALTER TABLE `online` MODIFY `online_ip` varchar(15) NOT NULL;");
DB::run() -> query("ALTER TABLE `visit` MODIFY `visit_self` varchar(100) NOT NULL default '';");
DB::run() -> query("ALTER TABLE `visit` MODIFY `visit_ip` varchar(15) NOT NULL default '';");

$check = DB::run() -> queryFetch("SHOW COLUMNS FROM `forums` LIKE 'forums_desc';");
if (empty($check)) {
	DB::run() -> query("ALTER TABLE `forums` ADD `forums_desc` varchar(100) NOT NULL default '' AFTER `forums_title`;");
} 

$check = DB::run() -> querySingle("SELECT `setting_name` FROM `setting` WHERE `setting_name`=?;", array('doslimit'));
if (empty($check)) {
	DB::run() -> query("INSERT INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('doslimit', '0'));
} 
// ------------------------------- 1.7.0 ---------------------------//
DB::run() -> query("UPDATE `users` SET `users_avatar`=? WHERE `users_avatar`=?;", array('', 'images/avatars/noavatar.gif'));

$queryindex = DB::run() -> queryFetch("SHOW INDEX FROM `posts` WHERE `Key_name`='posts_forums_id';");
if (empty($queryindex)) {
	DB::run() -> query("ALTER TABLE `posts` ADD INDEX `posts_forums_id` (`posts_forums_id`);");
} 

DB::run() -> exec("
	CREATE TABLE IF NOT EXISTS `offers` (
	`offers_id` smallint(4) unsigned NOT NULL auto_increment,
	`offers_type` tinyint(1) unsigned NOT NULL default '0',
	`offers_title` varchar(50) NOT NULL,
	`offers_text` text NOT NULL,
	`offers_user` varchar(20) NOT NULL,
	`offers_votes` mediumint(8) unsigned NOT NULL default '0',
	`offers_time` int(11) unsigned NOT NULL default '0',
	`offers_status` tinyint(1) unsigned NOT NULL default '0',
	`offers_comments` mediumint(8) unsigned NOT NULL default '0',
	`offers_closed` tinyint(1) unsigned NOT NULL default '0',
	`offers_text_reply` text NOT NULL default '',
	`offers_user_reply` varchar(20) NOT NULL default '',
	`offers_time_reply` int(11) unsigned NOT NULL default '0',
	PRIMARY KEY (`offers_id`),
	KEY `offers_votes` (`offers_votes`),
	KEY `offers_time` (`offers_time`)
	) ENGINE=MyISAM DEFAULT CHARSET=utf8;
");

DB::run() -> exec("
	CREATE TABLE IF NOT EXISTS `ratedoffers` (
	`rated_id` int(11) unsigned NOT NULL auto_increment,
	`rated_offers` smallint(4) unsigned NOT NULL,
	`rated_user` varchar(20) NOT NULL,
	`rated_time` int(11) unsigned NOT NULL,
	PRIMARY KEY (`rated_id`),
	KEY `rated_user` (`rated_user`)
	) ENGINE=MyISAM DEFAULT CHARSET=utf8;
");

DB::run() -> exec("
	CREATE TABLE IF NOT EXISTS `commoffers` (
	`comm_id` int(11) unsigned NOT NULL auto_increment,
	`comm_offers` smallint(4) unsigned NOT NULL,
	`comm_text` text NOT NULL,
	`comm_user` varchar(20) NOT NULL,
	`comm_time` int(11) unsigned NOT NULL default '0',
	`comm_ip` varchar(20) NOT NULL,
	`comm_brow` varchar(25) NOT NULL,
	PRIMARY KEY (`comm_id`),
	KEY `comm_offers` (`comm_offers`),
	KEY `comm_time` (`comm_time`)
	) ENGINE=MyISAM DEFAULT CHARSET=utf8;
");

$version = substr(strstr(basename(__FILE__), '_'), 1, -4);

DB::run() -> query("REPLACE INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('rotorlicense', 0));
DB::run() -> query("REPLACE INTO `setting` (`setting_name`, `setting_value`) VALUES (?, ?);", array('rotorversion', $version));
save_setting();

echo '<div class="note"><b>RotorCMS автоматически обновлен до версии ' . $version . '</b></div><br />';

?>