<?php
/*
* @package LabCMS
* @copyright (c) 2006 Alexander Levin aka Loki (loki_angel@mail.ru)
* @support http://labcms.ru
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*/
$success=true;

Db::i()->query(
	"CREATE TABLE IF NOT EXISTS ?_rating_votes (
	`module_id` int(11) NOT NULL,
	`item_id` int(11) NOT NULL,
	`key` char(10) NOT NULL default '',
	`type` tinyint(4) NOT NULL default '1',
	`user_id` int(11) NOT NULL default '0',
	`voter_id` int(11) NOT NULL,
	`vote` tinyint(4) NOT NULL default '0',
	`value` int(11) NOT NULL default '0',
	`putdate` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
	PRIMARY KEY  (`module_id`,`item_id`,`key`,`voter_id`)
	) ENGINE=MyISAM DEFAULT CHARSET=utf8;"
);

Db::i()->query(
	"INSERT IGNORE INTO ?_config (`type`, `key`, `value`)
	VALUES('config', 'user_rating_k1', '0.2'),
	('config', 'user_rating_k2', '0.4'),
	('config', 'user_rating_k3', '0.6'),
	('config', 'user_rating_k4', '0.8'),
	('config', 'user_rating_k5', '1')"
);

Db::i()->query("ALTER TABLE  ?_users ADD  `rating` INT NOT NULL DEFAULT  '0'");

if (Db::i()->selectCell("SELECT module_id FROM ?_modules WHERE module='forum'")) {
	Db::i()->query(
		"ALTER TABLE  ?_forum_posts ADD  `total_votes` INT NOT NULL DEFAULT  '0',
		ADD  `vote_result` INT NOT NULL DEFAULT  '0',
		ADD  `rating` INT NOT NULL DEFAULT  '0'"
	);
	Db::i()->query(
		"ALTER TABLE  ?_forum_hposts ADD  `total_votes` INT NOT NULL DEFAULT  '0',
		ADD  `vote_result` INT NOT NULL DEFAULT  '0',
		ADD  `rating` INT NOT NULL DEFAULT  '0'"
	);
}