<?php
$z = "a";
$install = "yes";
$version = "2.6.4";
include ("config.php");

//Install functions start
function install_footer() {
return "</td></tr></td></tr></table></td></tr></table>";
}

function install_header() {
return "<link rel='stylesheet' type='text/css' href='ta3.css'><table width='743' cellspacing='0' cellpadding='0' border='0' align='center'><tr><td><table cellspacing='0' cellpadding='0' border='0'><tr><td><img src='a_images/install_banner.jpg'></td></tr><tr><td align='center'>";
}


//Install functions end

function install($pre) {
global $pre;
mysql_query("CREATE TABLE `".$pre."polls` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `type` text,
  `pname` text,
  `votes` text,
  PRIMARY KEY  (`id`),
  FULLTEXT KEY `name` (`name`,`type`,`pname`),
  FULLTEXT KEY `votes` (`votes`))");

mysql_query("CREATE TABLE `".$pre."stats` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `page` text NOT NULL,
  `referral` text NOT NULL,
  `type` text NOT NULL,
  `username` text NOT NULL,
  `ip` text NOT NULL,
  `info` text NOT NULL,
  `day` text NOT NULL,
  `tday` text NOT NULL,
  `month` text NOT NULL,
  `week` text NOT NULL,
  `year` text NOT NULL,
  PRIMARY KEY  (`id`))");

mysql_query("CREATE TABLE `".$pre."polls` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `type` text,
  `pname` text,
  `votes` text,
  PRIMARY KEY  (`id`),
  FULLTEXT KEY `name` (`name`,`type`,`pname`),
  FULLTEXT KEY `votes` (`votes`))");

mysql_query("CREATE TABLE `".$pre."af` (
  `id` int(11) NOT NULL auto_increment,
  `sitename` text,
  `siteurl` text,
  `where2` text,
  `type` text,
  `width` text,
  `height` text,
  `ss` text,
  `verified` text,
  `date` text,
  `clicks` int(11) NOT NULL default '0',
  PRIMARY KEY  (`id`),
  KEY `id` (`id`),
  FULLTEXT KEY `sitename` (`sitename`),
  FULLTEXT KEY `siteurl` (`siteurl`),
  FULLTEXT KEY `where2` (`where2`),
  FULLTEXT KEY `type` (`type`),
  FULLTEXT KEY `width` (`width`),
  FULLTEXT KEY `height` (`height`),
  FULLTEXT KEY `ss` (`ss`),
  FULLTEXT KEY `verified` (`verified`),
  FULLTEXT KEY `date` (`date`))");

mysql_query("CREATE TABLE `".$pre."ad` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `type` text,
  `grp` text,
  `coding` text,
  `dim` text,
  `user` char(3) NOT NULL default '',
  `views` varchar(11) NOT NULL default '0',
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`,`type`,`grp`,`coding`),
  FULLTEXT KEY `dim` (`dim`))");

mysql_query("CREATE TABLE `".$pre."albums` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `views` int(11) NOT NULL default '0',
  `systems` text NOT NULL,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`, `systems`))");

mysql_query("CREATE TABLE `".$pre."backup` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `hash` text NOT NULL,
  `type` text NOT NULL,
  `date` text NOT NULL,
  PRIMARY KEY  (`id`))");

mysql_query("CREATE TABLE `".$pre."blog` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `name` text NOT NULL,
  `blog` text NOT NULL,
  `username` text NOT NULL,
  `date` text NOT NULL,
  PRIMARY KEY `id` (`id`))");

mysql_query("CREATE TABLE `".$pre."boardcp` (
  `id` int(11) NOT NULL auto_increment,
  `uid` text,
  `place` text,
  `type` text,
  `level` text,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `uid` (`uid`,`place`,`type`,`level`))");

mysql_query("CREATE TABLE `".$pre."cat` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `parent` text,
  `date` text,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`),
  FULLTEXT KEY `date` (`date`))");

mysql_query("CREATE TABLE `".$pre."chat` (
  `id` int(11) NOT NULL auto_increment,
  `uid` text,
  `subject` text,
  `message` text,
  `date` text,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `username` (`uid`,`message`,`date`),
  FULLTEXT KEY `subject` (`subject`))");

mysql_query("CREATE TABLE `".$pre."smwords` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `field` text,
  `type` text,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`,`field`),
  FULLTEXT KEY `type` (`type`))");

mysql_query("CREATE TABLE `".$pre."comments` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `subject` text,
  `comment` text,
  `aid` text,
  `email` text,
  `date` text,
  `IP` text,
  `type` text,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`,`subject`,`comment`,`aid`,`email`,`date`))");

mysql_query("CREATE TABLE `".$pre."content` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `cat` text,
  `username` text,
  `date` text,
  `ver` text,
  `postpone` text,
  `stats` INT(20) NOT NULL default '0',
  `lev` text,
  `save` INT(10) NOT NULL default '0',  
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`,`cat`),
  FULLTEXT KEY `date` (`date`),
  FULLTEXT KEY `username` (`username`),
  FULLTEXT KEY `ver` (`ver`),
  FULLTEXT KEY `postpone` (`postpone`),
  FULLTEXT KEY `lev` (`lev`))");

mysql_query("CREATE TABLE `".$pre."contest` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `des` text,
  `email` text,
  `type` text,
  `rules` text,
  `priv` text,
  `posts` text,
  `username` text,
  `ip` text,
  `cid` text,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`,`des`,`email`,`type`,`rules`),
  FULLTEXT KEY `priv` (`priv`),
  FULLTEXT KEY `posts` (`posts`),
  FULLTEXT KEY `username` (`username`),
  FULLTEXT KEY `ip` (`ip`),
  FULLTEXT KEY `cid` (`cid`))");

mysql_query("CREATE TABLE `".$pre."elite` (
  `id` int(11) NOT NULL auto_increment,
  `pid` varchar(100) NOT NULL,
  `game` text NOT NULL,
  `type` varchar(30) NOT NULL,
  `date` varchar(200) NOT NULL,
  PRIMARY KEY `id` (`id`))");
  
mysql_query("CREATE TABLE `".$pre."featured` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` text NOT NULL,
  `description` text NOT NULL,
  `image` text NOT NULL,
  `url` text NOT NULL,
  `system` int(11) NOT NULL,
  `rank` int(11) NOT NULL,
  `userid` int(11) NOT NULL,
  PRIMARY KEY (`id`)
)");

mysql_query("CREATE TABLE `".$pre."fields` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `cat` text,
  `type` text,
  `des` text,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`),
  FULLTEXT KEY `cat` (`cat`),
  FULLTEXT KEY `type` (`type`),
  FULLTEXT KEY `des` (`des`))");

mysql_query("CREATE TABLE `".$pre."fielddata` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `name` text NOT NULL,
  `data` text NOT NULL,
  `id2` varchar(11) NOT NULL default '',
  `cat` text NOT NULL,
  PRIMARY KEY  (`id`))");

mysql_query("CREATE TABLE `".$pre."forums` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `des` text,
  `type` text,
  `cat` text,
  `ord` text,
  `locked` char(3) NOT NULL default '',
  `prequire` text,
  `vpost` varchar(100) NOT NULL default 'Yes',
  `vtopic` varchar(100) NOT NULL default 'Yes',
  `epost` varchar(100) NOT NULL default 'Yes',
  `dpost` varchar(100) NOT NULL default 'No',
  `rankreq` varchar(100) NOT NULL default '',
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`,`des`,`type`,`cat`),
  FULLTEXT KEY `order` (`ord`))");
  
  
  mysql_query("ALTER TABLE `".$pre."forums` ADD `prequire` TEXT NOT NULL");
mysql_query("ALTER TABLE `".$pre."forums` ADD `vpost` varchar(100) NOT NULL default 'Yes'");
mysql_query("ALTER TABLE `".$pre."forums` ADD `vtopic` varchar(100) NOT NULL default 'Yes'");
mysql_query("ALTER TABLE `".$pre."forums` ADD `epost` varchar(100) NOT NULL default 'Yes'");
mysql_query("ALTER TABLE `".$pre."forums` ADD `dpost` varchar(100) NOT NULL default 'No'");

mysql_query("CREATE TABLE `".$pre."friends` (
  `id` int(11) NOT NULL auto_increment,
  `pid` varchar(100) NOT NULL default '',
  `pid2` varchar(100) NOT NULL default '',
  `ver` char(3) NOT NULL default '',
  `date` varchar(200) NOT NULL default '',
  PRIMARY KEY `id` (`id`))");

mysql_query("CREATE TABLE `".$pre."game` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `type` text,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`,`type`))");

mysql_query("CREATE TABLE `".$pre."games` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `stats` INT(20) NOT NULL default '0',
  `username` text,
  `publisher` text,
  `developer` text,
  `genre` text,
  `release` INT(20) NOT NULL default '0',
  `esrb` text,
  `boxart` text,
  `des` text,
  `skin` varchar(11) NOT NULL default '',
  `system` text NOT NULL,
  `album` text NOT NULL,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`,`publisher`,`developer`,`genre`,`esrb`,`boxart`,`des`),
  FULLTEXT KEY `username` (`username`))");

mysql_query("CREATE TABLE `".$pre."images` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `album` varchar(11) NOT NULL default '',
  `caption` text NOT NULL,
  `type` text,
  `date` text,
  `type2` text NOT NULL,
  PRIMARY KEY  (`id`),
  FULLTEXT KEY `name` (`name`,`type`),
  FULLTEXT KEY `date` (`date`))");

mysql_query("CREATE TABLE `".$pre."ipban` (
  `id` int(11) NOT NULL auto_increment,
  `ip` text,
  `forums` text,
  `site` text,
  `cp` text,
  `date` text,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `ip` (`ip`,`forums`,`site`,`cp`,`date`))");

mysql_query("CREATE TABLE `".$pre."log` (
  `id` int(11) NOT NULL auto_increment,
  `url` text,
  `ip` text,
  `date` text,
  `username` text,
  PRIMARY KEY `id` (`id`),
  KEY `id` (`id`),
  FULLTEXT KEY `url` (`url`),
  FULLTEXT KEY `ip` (`ip`),
  FULLTEXT KEY `date` (`date`),
  FULLTEXT KEY `username` (`username`))");

mysql_query("CREATE TABLE `".$pre."mods` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `url` text,
  `installed` text,
  `version` varchar(5) NOT NULL default '',
  `readme` text NOT NULL,
  `sqla` text NOT NULL,
  `status` char(3) NOT NULL default '',
  PRIMARY KEY  (`id`),
  FULLTEXT KEY `name` (`name`,`url`,`installed`))");

mysql_query("CREATE TABLE `".$pre."newsletter` (
  `id` int(11) NOT NULL auto_increment,
  `name` text NOT NULL,
  `type` text NOT NULL,
  `content` text NOT NULL,
  `cat` varchar(11) NOT NULL default '',
  `date` text NOT NULL,
  PRIMARY KEY `id` (`id`))");

mysql_query("CREATE TABLE `".$pre."pages` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `url` text,
  `content` text,
  `online` text,
  `type` text,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`,`url`,`content`,`online`,`type`))");

mysql_query("CREATE TABLE `".$pre."permissions` (
  `id` int(11) NOT NULL auto_increment,
  `username` text,
  `ver` text,
  `games` text,
  `reviews` varchar(10) NOT NULL default 'yes',
  `previews` varchar(10) NOT NULL default 'yes',
  `news` varchar(10) NOT NULL default 'yes',
  `media` varchar(10) NOT NULL default 'yes',
  `cheats` varchar(10) NOT NULL default 'yes',
  `articles` varchar(10) NOT NULL default 'yes',
  `videos` varchar(10) NOT NULL default 'yes',
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `username` (`username`),
  FULLTEXT KEY `ver` (`ver`),
  FULLTEXT KEY `games` (`games`))");

mysql_query("CREATE TABLE `".$pre."pm` (
  `id` int(11) NOT NULL auto_increment,
  `viewed` text,
  `subject` text,
  `message` text,
  `who` text,
  `jo` text,
  `date` text,
  `box` text NOT NULL,
  PRIMARY KEY `id` (`id`),
  KEY `id` (`id`),
  FULLTEXT KEY `viewed` (`viewed`),
  FULLTEXT KEY `subject` (`subject`),
  FULLTEXT KEY `message` (`message`),
  FULLTEXT KEY `who` (`who`),
  FULLTEXT KEY `jo` (`jo`),
  FULLTEXT KEY `date` (`date`))");

mysql_query("CREATE TABLE `".$pre."points` (
  `id` int(11) NOT NULL auto_increment,
  `username` text NOT NULL,
  `item` varchar(11) NOT NULL default '',
  `points` text NOT NULL,
  `date` varchar(200) NOT NULL default '',
  PRIMARY KEY `id` (`id`))");

mysql_query("CREATE TABLE `".$pre."posts` (
  `id` int(11) NOT NULL auto_increment,
  `subject` text,
  `message` text,
  `uid` text,
  `date` text,
  `fid` text,
  `tid` text,
  `stats` INT(20) NOT NULL default '0',
  `type` text,
  `locked` text,
  `ip` text NOT NULL,
  `lpostdate` text NOT NULL,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `subject` (`subject`,`message`,`uid`,`date`,`fid`),
  FULLTEXT KEY `tid` (`tid`),
  FULLTEXT KEY `type` (`type`),
  FULLTEXT KEY `locked` (`locked`))");
  
mysql_query("CREATE TABLE IF NOT EXISTS `".$pre."plugins` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` text COLLATE utf8_unicode_ci,
  `url` text COLLATE utf8_unicode_ci,
  `installed` text COLLATE utf8_unicode_ci,
  `version` varchar(5) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `readme` text COLLATE utf8_unicode_ci NOT NULL,
  `status` char(3) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  FULLTEXT KEY `name` (`name`,`url`,`installed`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ");
  
mysql_query("CREATE TABLE `".$pre."pr` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` text COLLATE utf8_unicode_ci,
  `phone` text COLLATE utf8_unicode_ci,
  `country` text COLLATE utf8_unicode_ci,
  `logo` text COLLATE utf8_unicode_ci,
  `site` text COLLATE utf8_unicode_ci,
  `des` text COLLATE utf8_unicode_ci,
  `address` text COLLATE utf8_unicode_ci NOT NULL,
  PRIMARY KEY (`id`),
  FULLTEXT KEY `name` (`name`,`phone`,`country`,`logo`),
  FULLTEXT KEY `site` (`site`,`des`))");

mysql_query("CREATE TABLE `".$pre."profile` (
  `id` int(11) NOT NULL auto_increment,
  `username` text,
  `aim` text,
  `msn` text,
  `yahoo` text NOT NULL,
  `icq` text NOT NULL,
  `gtalk` text NOT NULL,
  `birthday` text NOT NULL,
  `website` text,
  `nickname` text,
  `location` text,
  `sig` text,
  `avatar` text,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `username` (`username`,`aim`,`msn`,`website`,`nickname`,`location`),
  FULLTEXT KEY `sig` (`sig`,`avatar`))");

mysql_query("CREATE TABLE `".$pre."ranks` (
  `id` int(11) NOT NULL auto_increment,
  `name` text NOT NULL,
  `color` text NOT NULL,
  `points` text NOT NULL,
  `date` varchar(200) NOT NULL default '',
  PRIMARY KEY `id` (`id`))");

mysql_query("CREATE TABLE `".$pre."settings` (
  `id` int(11) NOT NULL auto_increment,
  `name` text NOT NULL,
  `description` text,
  `data` text,
  `type` text,
  `parent` text,
  PRIMARY KEY `id` (`id`))");

mysql_query("CREATE TABLE `".$pre."shop` (
  `id` int(11) NOT NULL auto_increment,
  `name` text NOT NULL,
  `price` text NOT NULL,
  `instock` text NOT NULL,
  `image` text NOT NULL,
  `pid` varchar(11) NOT NULL default '',
  `date` varchar(200) NOT NULL default '',
  PRIMARY KEY `id` (`id`))");

mysql_query("CREATE TABLE `".$pre."shop2` (
  `id` int(11) NOT NULL auto_increment,
  `name` text NOT NULL,
  `price` text NOT NULL,
  `pid` varchar(11) NOT NULL default '',
  `date` varchar(200) NOT NULL default '',
  PRIMARY KEY `id` (`id`))");

mysql_query("CREATE TABLE `".$pre."systems` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `abr` text,
  `icon` text,
  `status` char(3) NOT NULL default '',
  `skin` varchar(11) NOT NULL default '',
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`),
  FULLTEXT KEY `abr` (`abr`),
  FULLTEXT KEY `icon` (`icon`))");

mysql_query("CREATE TABLE `".$pre."userlevels` (
  `id` int(11) NOT NULL auto_increment,
  `name` text,
  `level` text,
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `name` (`name`,`level`))");

mysql_query("CREATE TABLE `".$pre."userreviews` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `name` text NOT NULL,
  `games` text NOT NULL,
  `systems` text NOT NULL,
  `review` text NOT NULL,
  `overall` text NOT NULL,
  `rate` varchar(255) NOT NULL default '0|0',
  `user` text NOT NULL,
  `date` text NOT NULL,
  PRIMARY KEY  (`id`))");

mysql_query("CREATE TABLE `".$pre."users` (
  `id` int(10) NOT NULL auto_increment,
  `username` text,
  `password` text,
  `email` text,
  `level` text,
  `rank` text,
  `warn` text,
  `bansite` text,
  `banadmin` text,
  `logged` text,
  `skin` varchar(10) NOT NULL default '1',
  `skin2` text,
  `slist` char(3) NOT NULL default '',
  PRIMARY KEY `id` (`id`),
  FULLTEXT KEY `warn` (`warn`,`bansite`,`banadmin`),
  FULLTEXT KEY `username` (`username`,`password`,`email`),
  FULLTEXT KEY `logged` (`logged`),
  FULLTEXT KEY `skin` (`skin`),
  FULLTEXT KEY `skin2` (`skin2`))");
}

function install_data($pre) {
global $pre;
mysql_query("INSERT INTO `".$pre."af` VALUES (1, 'OneCMS', 'http://www.onecms.net', 'popup', 'link', '', '', '', 'yes', '1112602283', 0)");
mysql_query("INSERT INTO `".$pre."af` VALUES (2, 'Dog Fight Studios', 'http://www.dogfightstudios.com', 'popup', 'link', '', '', '', 'yes', '1112602283', 0)");
mysql_query("INSERT INTO `".$pre."af` VALUES (3, 'Insane Visions', 'http://www.insanevisions.com', 'popup', 'link', '', '', '', 'yes', '1112602283', 0)");
mysql_query("INSERT INTO `".$pre."cat` VALUES (1, 'reviews', '".time()."', '')");
mysql_query("INSERT INTO `".$pre."cat` VALUES (2, 'previews', '".time()."', '')");
mysql_query("INSERT INTO `".$pre."cat` VALUES (3, 'news', '".time()."', '')");
mysql_query("INSERT INTO `".$pre."cat` VALUES (4, 'media', '".time()."', '')");
mysql_query("INSERT INTO `".$pre."cat` VALUES (5, 'cheats', '".time()."', '')");
mysql_query("INSERT INTO `".$pre."cat` VALUES (7, 'videos', '".time()."', '')");
mysql_query("INSERT INTO `".$pre."cat` VALUES (8, 'articles', '".time()."', '')");
mysql_query("INSERT INTO `".$pre."fielddata` VALUES (null, 'Short', 'On behalf of the <a href=\"http://www.onecms.net\">OneCMS</a> staff, we hope you enjoy your copy of <a href=\"http://www.onecms.net\">OneCMS</a>. Feel free to delete this article and good luck on your new website!', 1, 'content')");
mysql_query("INSERT INTO `".$pre."fielddata` VALUES (null, 'Full', 'If you have feedback, suggestions or any questions feel free to contact us at the <a href=\"http://onecms.net/forums\">OneCMS Forums</a> or through the <a href=\"admin.php?load=support\">support page</a> in your admin panel.\r<br /><br />\nThank you!', 1, 'content')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'albums', '', 'album', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'image', '', 'image', 'If you want to use images for your posts, link directly to the image here.')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Overall', 'reviews', 'textfield', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Preview', 'previews', 'textarea', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Review', 'reviews', 'textarea', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Anticipation', 'previews', 'textfield', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Short', 'news', 'textarea', 'A short description of your story')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Short', 'previews', 'textarea', 'A short description of your story')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Short', 'reviews', 'textarea', 'A short description of your story')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Short', 'articles', 'textarea', 'A short description of your story')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Short', 'videos', 'textarea', 'A short description of your story')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'games', '', 'games', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Online', 'games', 'textfield', 'Is it online compatible?')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'systems', '', 'system', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'company', '', 'company', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Full', 'news', 'textarea', 'Full story.')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Article', 'articles', 'textarea', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'video', 'videos', 'textfield', 'link to your video file, the extension should end in .flv')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Price', 'games', 'textfield', '<br />\r\n')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Cheats', 'cheats', 'textarea', 'Here you enter in the cheats.')");
mysql_query("INSERT INTO `".$pre."forums` VALUES (1, 'General', '', 'cat', 'General', '0', '')");
mysql_query("INSERT INTO `".$pre."forums` VALUES (2, 'Off-Topic', 'Talk about anything', 'forum', 'General', '0', '', '')");
mysql_query("INSERT INTO `".$pre."game` VALUES (1, 'FPS', 'genre')");
mysql_query("INSERT INTO `".$pre."game` VALUES (2, 'Sports', 'genre')");
mysql_query("INSERT INTO `".$pre."game` VALUES (3, 'Action', 'genre')");
mysql_query("INSERT INTO `".$pre."game` VALUES (4, 'RPG', 'genre')");
mysql_query("INSERT INTO `".$pre."game` VALUES (5, 'Everyone', 'esrb')");
mysql_query("INSERT INTO `".$pre."game` VALUES (6, 'Mature', 'esrb')");
mysql_query("INSERT INTO `".$pre."game` VALUES (7, 'Teen', 'esrb')");
mysql_query("INSERT INTO `".$pre."game` VALUES (8, 'Rating Pending', 'esrb')");
mysql_query("INSERT INTO `".$pre."game` VALUES (9, 'Early Childhood', 'esrb')");
mysql_query("INSERT INTO `".$pre."game` VALUES (10, 'Adults Only', 'esrb')");
mysql_query("INSERT INTO `".$pre."ranks` VALUES (1, 'Queen', 'Pink', '1', '".time()."')");
mysql_query("INSERT INTO `".$pre."ranks` VALUES (2, 'King', 'Red', '10', '".time()."')");
mysql_query("INSERT INTO `".$pre."settings` VALUES 
(1, 'General', NULL, NULL, 'Category', NULL),
(2, 'sitename', 'The name of your OneCMS site.', 'OneCMS Demo', 'setting', 'Global'),
(3, 'online', 'Is the site online?', 'Yes', 'setting', 'Global'),
(4, 'siteurl', 'Your site URL', 'NULL', 'setting', 'Global'),
(5, 'dformat', 'Date format', 'M d - Y', 'setting', 'Global'),
(6, 'warn', 'Number of Warns allowed (before banned).', '5', 'setting', 'Global'),
(7, 'path', 'Path to images folder (no trailing slash)', NULL, 'setting', 'Global'),
(8, 'images', 'Path to images folder (no trailing slash).', NULL, 'setting', 'Global'),
(9, 'max_results', 'Amount of items to display (per page...recommended is 30).', '30', 'setting', 'Global'),
(10, 'email', 'Owners E-mail', NULL, 'setting', 'Global'),
(11, 'name', 'Owners Name', NULL, 'setting', 'Global'),
(12, 'thumbnail_width', 'Thumbnail Width', '150', 'setting', 'Global'),
(13, 'thumbnail_height', 'Thumbnail Width', '90', 'setting', 'Global'),
(14, 'ip_logger', 'Enable the IP Logger (Yes/No).', 'Yes', 'setting', 'General'),
(15, 'wysiwyg', 'Enable the WYSIWYG editor (True/False).', 'True', 'setting', 'General'),
(16, 'max_pm', 'Amount of PM''s allowed.', '50', 'setting', 'General'),
(17, 'modrewrite', 'Enable Mod Rewrite (Yes/No)?', 'Yes', 'setting', 'General'),
(18, 'avatar_width', 'Avatar Width', '100', 'setting', 'General'),
(19, 'avatar_height', 'Avatar Height', '100', 'setting', 'General'),
(20, 'referral', 'Enable user referals for registration (yes/no)?', 'yes', 'setting', 'General'),
(21, 'poll_type', 'The type of poll you would like users to see (graphic/text).', 'graphic', 'setting', 'General'),
(22, 'user_fields', 'Enable User Fields on profile pages (yes/no)?', 'yes', 'setting', 'General'),
(23, 'Global', NULL, NULL, 'Category', NULL),
(24, 'Forum', NULL, NULL, 'Category', NULL),
(25, 'visitor_post', 'Allow Visitors to post in the forums (yes/no)?', 'yes', 'setting', 'Forum'),
(26, 'visitor_topic', 'Allow Visitors to create topics (yes/no)?', 'yes', 'setting', 'Forum'),
(27, 'visitor_smiles', 'Allow Visitors to use smilies (yes/no)?', 'yes', 'setting', 'Forum'),
(28, 'visitor_cname', 'Allow Visitors to use custom name when posting (name cannot be already in use)?', 'no', 'setting', 'Forum'),
(29, 'topics_per_page', 'How many topics to display per page?', '25', 'setting', 'Forum'),
(30, 'posts_per_page', 'How many posts to display per page?', '10', 'setting', 'Forum'),
(31, 'spam_control', 'Set a Spam Control limit (in seconds, setting to 120 would equal 2 minutes)?', '5', 'setting', 'Forum'),
(32, 'hot_topic', 'The number of posts required for a topic to be \"hot\".', '5', 'setting', 'Forum'),
(33, 'Gallery', NULL, NULL, 'Category', NULL),
(34, 'Chat', NULL, NULL, 'Category', NULL),
(35, 'gallery_template', 'Template for the main gallery.php page.', '<td><a href=''{url}''><img src=''{thumb}'' border=''1''></a><br><b>{name}</b><br><center>{icon}</center></td>', 'setting', 'Gallery'),
(36, 'album_template', 'Template for the actual album landing page.', '<td><a href=''{image}'' rel=''lightbox''><img src=''{thumb}'' border=''1''></a></td>', 'setting', 'Gallery'),
(37, 'gallery_header', NULL, '<table align=''center'' width=''95%'' border=''0'' cellpadding=''3'' cellspacing=''1''><tr>', 'setting', 'Gallery'),
(38, 'gallery_footer', NULL, '</tr></table>', 'setting', 'Gallery'),
(39, 'images_per_row', 'How many images to display per row?', '3', 'setting', 'Gallery'),
(40, 'images_per_page', 'How many images to display per page in an album (only required if pagination is enabled)?', '15', 'setting', 'Gallery'),
(41, 'gallery_pagination', 'Enable pagination use in the gallery module (Yes/No)?', 'Yes', 'setting', 'Gallery'),
(42, 'gallery_html_between', 'HTML between each row', '</tr><tr>', 'setting', 'Gallery'),
(43, 'chat_messages', 'Amount of messages shown in chat room.', '10', 'setting', 'Chat'),
(44, 'chat_level1_access', 'Give Level 1 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(45, 'chat_level2_access', 'Give Level 1 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(46, 'chat_level3_access', 'Give Level 3 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(47, 'chat_level4_access', 'Give Level 3 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(48, 'chat_level5_access', 'Give Level 5 users access to chat (Yes/No)?', 'No', 'setting', 'Chat'),
(49, 'chat_level6_access', 'Give Level 6 users access to chat (Yes/No)?', 'No', 'setting', 'Chat'),
(50, 'Templates', '', '', 'category', ''),
(51, 'default_content', 'Default content list template.', 'latestcontent', 'setting', 'Templates'),
(52, 'default_games', 'Default games list template', 'list2games', 'setting', 'Templates'),
(53, 'default_company', 'Default companies list template', 'companies', 'setting', 'Templates'),
(54, 'abc_order_games', 'By Default - ABC Order for games list turned on (Yes/No)?', 'Yes', 'setting', 'Templates'),
(55, 'abc_order_companies', 'By Default - ABC Order for companies list turned on (Yes/No)?', 'No', 'setting', 'Templates'),
(56, 'captcha', 'Enable CAPTCHA (Yes/No)?', 'Yes', 'setting', 'General'),
(57, 'guest_comments', 'Allow unregistered users to comment on posts (Yes/No)?', 'No', 'setting', 'General')");

mysql_query("INSERT INTO `".$pre."systems` VALUES (1, 'Xbox', 'xbox', 'a_images/xboxicon.jpg', '', '')");
mysql_query("INSERT INTO `".$pre."systems` VALUES (2, 'PC', 'pc', 'a_images/pcicon.jpg', '', '')");
mysql_query("INSERT INTO `".$pre."systems` VALUES (3, 'PlayStation 2', 'ps2', 'a_images/ps2icon.jpg', '', '')");
mysql_query("INSERT INTO `".$pre."systems` VALUES (4, 'Gamecube', 'gc', 'a_images/gcicon.jpg', '', '')");
mysql_query("INSERT INTO `".$pre."systems` VALUES (5, 'Game Boy Advance', 'gba', 'a_images/gbaicon.png', '', '')");
mysql_query("INSERT INTO `".$pre."systems` VALUES (6, 'Nintendo DS', 'ds', 'a_images/dsicon.jpg', '', '')");
mysql_query("INSERT INTO `".$pre."systems` VALUES (7, 'PlayStation Portable', 'psp', 'a_images/pspicon.png', '', '')");
mysql_query("INSERT INTO `".$pre."systems` VALUES (8, 'Xbox 360', '360', 'a_images/360.jpg', '', '')");
mysql_query("INSERT INTO `".$pre."systems` VALUES (9, 'PlayStation 3', 'ps3', 'a_images/ps3icon.jpg', '', '')");
mysql_query("INSERT INTO `".$pre."systems` VALUES (10, 'Nintendo Wii', 'wii', 'a_images/wiiicon.jpg', '', '')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (1, 'Random Top 10', '', 'Yes', '1.0', '', 'random10.php', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (2, 'Newsletter', 'newsletter.php?load=newsletter', 'Yes', '1.0', '', '', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (3, 'PR', 'pr.php?load=pr', 'Yes', '1.0', '', '', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (4, 'Affiliates', 'affiliates.php?load=af', 'Yes', '1.0', '', '', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (5, 'File', 'files.php?load=files', 'Yes', '2.0', '', 'files', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (6, 'Page', 'admin.php?load=pages', 'Yes', '1.0', '', 'pages', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (7, 'Comments', 'comments.php?load=comments', 'Yes', '1.0', '', '', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (8, 'Smilies/Badwords', 'smwords.php?load=smwords', 'Yes', '1.0', '', '', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (9, 'Private Messaging', 'admin.php?load=pm&box=in', 'Yes', '1.0', '', 'pm.php?box=in', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (10, 'Ad', 'ads.php?load=ads', 'Yes', '', '', '', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (11, 'Gallery', 'gallery.php?load=gallery', 'Yes', '1.0', '', 'gallery', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (12, 'Contest', 'contests.php?load=contest', 'Yes', '1.0', '', 'contest', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (12, 'Polls', 'admin.php?load=polls', 'Yes', '1.0', '', 'polls', 'On')");
mysql_query("INSERT INTO `".$pre."mods` VALUES (13, 'Featured', 'featured.php', 'Yes', '1.0', '', '', 'On')");
mysql_query("INSERT INTO `".$pre."userlevels` VALUES (1, 'Super Admin', '1')");
mysql_query("INSERT INTO `".$pre."userlevels` VALUES (2, 'Member', '6')");
mysql_query("INSERT INTO `".$pre."userlevels` VALUES (3, 'Super Staff', '3')");
mysql_query("INSERT INTO `".$pre."userlevels` VALUES (4, 'Staff', '4')");
mysql_query("UPDATE ".$pre."mods SET name = 'Top 10', sqla = 'top10.php' WHERE name = 'Random Top 10'");
}

function upgrade2($pre) {
global $pre;
mysql_query("ALTER TABLE `".$pre."posts` ADD `ip` TEXT NOT NULL ,ADD `lpostdate` TEXT NOT NULL");
mysql_query("ALTER TABLE `".$pre."profile` ADD `yahoo` TEXT NOT NULL AFTER `msn`, ADD `icq` TEXT NOT NULL AFTER `yahoo` ,ADD `gtalk` TEXT NOT NULL AFTER `icq`, ADD `birthday` TEXT NOT NULL AFTER `gtalk`");
mysql_query("ALTER TABLE `".$pre."users` ADD `rank` TEXT NOT NULL AFTER `level`");
mysql_query("ALTER TABLE `".$pre."pm` ADD `box` TEXT NOT NULL");
mysql_query("UPDATE ".$pre."pm SET box = 'inbox' WHERE box = ''");
mysql_query("CREATE TABLE `".$pre."backup` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `hash` text NOT NULL,
  `type` text NOT NULL,
  `date` text NOT NULL,
  PRIMARY KEY  (`id`))");
}

function upgrade4($pre, $dbname) {
global $pre;
global $dbname;

mysql_query("RENAME TABLE `".$dbname."`.`".$pre."_comments1`  TO `".$dbname."`.`".$pre."_comments` ;");
mysql_query("RENAME TABLE `".$dbname."`.`".$pre."_comments2`  TO `".$dbname."`.`".$pre."_smwords` ;");

mysql_query("CREATE TABLE IF NOT EXISTS `".$pre."plugins` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` text COLLATE utf8_unicode_ci,
  `url` text COLLATE utf8_unicode_ci,
  `installed` text COLLATE utf8_unicode_ci,
  `version` varchar(5) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `readme` text COLLATE utf8_unicode_ci NOT NULL,
  `status` char(3) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  FULLTEXT KEY `name` (`name`,`url`,`installed`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ");

mysql_query("INSERT INTO `".$pre."cat` VALUES (7, 'videos', '".time()."', '')");
mysql_query("INSERT INTO `".$pre."cat` VALUES (8, 'articles', '".time()."', '')");

mysql_query("ALTER TABLE `".$pre."permissions` ADD `articles` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes'");
mysql_query("ALTER TABLE `".$pre."permissions` ADD `videos` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes'");  

mysql_query("ALTER TABLE `".$pre."mods` CHANGE `sql` `sqla` ");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'image', '', 'image', 'If you want to use images for your posts, link directly to the image here.')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'company', '', 'company', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Article', 'articles', 'textarea', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'video', 'videos', 'textfield', 'link to your video file, the extension should end in .flv')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Short', 'articles', 'textarea', 'A short description of your story')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Short', 'videos', 'textarea', 'A short description of your story')");

mysql_query("UPDATE ".$pre."mods SET url = 'newsletter.php?load=newsletter' WHERE url = 'admin.php?load=newsletter'");
mysql_query("UPDATE ".$pre."mods SET url = 'contest.php?load=contest' WHERE url = 'admin.php?load=contest'");
mysql_query("UPDATE ".$pre."mods SET url = 'gallery.php?load=gallery' WHERE url = 'admin.php?load=gallery'");
mysql_query("UPDATE ".$pre."mods SET url = 'ads.php?load=ads' WHERE url = 'admin.php?load=ads'");
mysql_query("UPDATE ".$pre."mods SET url = 'smwords.php?load=smwords' WHERE url = 'admin.php?load=smwords'");
mysql_query("UPDATE ".$pre."mods SET url = 'comments.php?load=comments' WHERE url = 'admin.php?load=comments2'");
mysql_query("UPDATE ".$pre."mods SET url = 'files.php?load=files' WHERE url = 'admin.php?load=files'");
mysql_query("UPDATE ".$pre."mods SET url = 'affiliates.php?load=af' WHERE url = 'admin.php?load=af'");
mysql_query("UPDATE ".$pre."mods SET url = 'pr.php?load=pr' WHERE url = 'admin.php?load=pr'");

$query = mysql_query("SELECT id,games FROM ".$pre."content");
while($row = mysql_fetch_array($query)) {
mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'games', '".$row[games]."', '".$row[id]."', 'content')");
}


$query = mysql_query("SELECT id,systems FROM ".$pre."content");
while($row = mysql_fetch_array($query)) {
mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'systems', '".$row[systems]."', '".$row[id]."', 'content')");
}

mysql_query("UPDATE ".$pre."mods SET url = 'admin.php?load=pm&box=in' WHERE url = 'admin.php?load=inbox&box=in'");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'company', '', 'company', '')");


mysql_query("INSERT INTO `".$pre."mods` VALUES (null, 'Featured', 'featured.php', 'Yes', '1.0', '', '', 'On')");

mysql_query("ALTER TABLE `".$pre."forums` ADD `rankreq` varchar(100) NOT NULL");

mysql_query("ALTER TABLE `".$pre."comments` ADD `IP` text NOT NULL");
mysql_query("ALTER TABLE `".$pre."comments` ADD `type` text NOT NULL");

mysql_query("RENAME TABLE `".$pre."settings`  TO `".$pre."settings2` ;");

mysql_query("CREATE TABLE IF NOT EXISTS `".$pre."featured` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` text NOT NULL,
  `description` text NOT NULL,
  `image` text NOT NULL,
  `url` text NOT NULL,
  `system` int(11) NOT NULL,
  `rank` int(11) NOT NULL,
  `userid` int(11) NOT NULL,
  PRIMARY KEY (`id`)
)");

mysql_query("CREATE TABLE `".$pre."settings` (
  `id` int(11) NOT NULL auto_increment,
  `name` text NOT NULL,
  `description` text,
  `data` text,
  `type` text,
  `parent` text,
  PRIMARY KEY `id` (`id`))");
  
  
$olddata = mysql_fetch_array(mysql_query("SELECT * FROM ".$pre."settings2 WHERE id ='1'"));
  
$newdata = mysql_query("INSERT INTO `".$pre."settings` VALUES 
(1, 'General', NULL, NULL, 'Category', NULL),
(2, 'sitename', 'The name of your OneCMS site.', '".$olddata[sitename]."', 'setting', 'Global'),
(3, 'online', 'Is the site online?', 'Yes', 'setting', 'Global'),
(4, 'siteurl', 'Your site URL', '".$olddata[siteurl]."', 'setting', 'Global'),
(5, 'dformat', 'Date format', 'M d - Y', 'setting', 'Global'),
(6, 'warn', 'Number of Warns allowed (before banned).', '5', 'setting', 'Global'),
(7, 'path', 'Path to images folder (no trailing slash)', '".$olddata[path]."', 'setting' 'Global'),
(8, 'images', 'Path to images folder (no trailing slash).', '".$olddata[images]."', 'setting', 'Global'),
(9, 'max_results', 'Amount of items to display (per page...recommended is 30).', '30', 'setting', 'Global'),
(10, 'email', 'Owners E-mail', NULL, 'setting', 'Global'),
(11, 'name', 'Owners Name', NULL, 'setting', 'Global'),
(12, 'thumbnail_width', 'Thumbnail Width', '150', 'setting', 'Global'),
(13, 'thumbnail_height', 'Thumbnail Width', '90', 'setting', 'Global'),
(14, 'ip_logger', 'Enable the IP Logger (Yes/No).', 'Yes', 'setting', 'General'),
(15, 'wysiwyg', 'Enable the WYSIWYG editor (True/False).', 'True', 'setting', 'General'),
(16, 'max_pm', 'Amount of PM''s allowed.', '50', 'setting', 'General'),
(17, 'modrewrite', 'Enable Mod Rewrite (Yes/No)?', 'Yes', 'setting', 'General'),
(18, 'avatar_width', 'Avatar Width', '100', 'setting', 'General'),
(19, 'avatar_height', 'Avatar Height', '100', 'setting', 'General'),
(20, 'referral', 'Enable user referals for registration (yes/no)?', 'yes', 'setting', 'General'),
(21, 'poll_type', 'The type of poll you would like users to see (graphic/text).', 'graphic', 'setting', 'General'),
(22, 'user_fields', 'Enable User Fields on profile pages (yes/no)?', 'yes', 'setting', 'General'),
(23, 'Global', NULL, NULL, 'Category', NULL),
(24, 'Forum', NULL, NULL, 'Category', NULL),
(25, 'visitor_post', 'Allow Visitors to post in the forums (yes/no)?', 'yes', 'setting', 'Forum'),
(26, 'visitor_topic', 'Allow Visitors to create topics (yes/no)?', 'yes', 'setting', 'Forum'),
(27, 'visitor_smiles', 'Allow Visitors to use smilies (yes/no)?', 'yes', 'setting', 'Forum'),
(28, 'visitor_cname', 'Allow Visitors to use custom name when posting (name cannot be already in use)?', 'no', 'setting', 'Forum'),
(29, 'topics_per_page', 'How many topics to display per page?', '25', 'setting', 'Forum'),
(30, 'posts_per_page', 'How many posts to display per page?', '10', 'setting', 'Forum'),
(31, 'spam_control', 'Set a Spam Control limit (in seconds, setting to 120 would equal 2 minutes)?', '5', 'setting', 'Forum'),
(32, 'hot_topic', 'The number of posts required for a topic to be \"hot\".', '5', 'setting', 'Forum'),
(33, 'Gallery', NULL, NULL, 'Category', NULL),
(34, 'Chat', NULL, NULL, 'Category', NULL),
(35, 'gallery_template', 'Template for the main gallery.php page.', '<td><a href=''{url}''><img src=''{thumb}'' border=''1''></a><br><b>{name}</b><br><center>{icon}</center></td>', 'setting', 'Gallery'),
(36, 'album_template', 'Template for the actual album landing page.', '<td><a href=''{image}'' rel=''lightbox''><img src=''{thumb}'' border=''1''></a></td>', 'setting', 'Gallery'),
(37, 'gallery_header', NULL, '<table align=''center'' width=''95%'' border=''0'' cellpadding=''3'' cellspacing=''1''><tr>', 'setting', 'Gallery'),
(38, 'gallery_footer', NULL, '</tr></table>', 'setting', 'Gallery'),
(39, 'images_per_row', 'How many images to display per row?', '3', 'setting', 'Gallery'),
(40, 'images_per_page', 'How many images to display per page in an album (only required if pagination is enabled)?', '15', 'setting', 'Gallery'),
(41, 'gallery_pagination', 'Enable pagination use in the gallery module (Yes/No)?', 'Yes', 'setting', 'Gallery'),
(42, 'gallery_html_between', 'HTML between each row', '</tr><tr>', 'setting', 'Gallery'),
(43, 'chat_messages', 'Amount of messages shown in chat room.', '10', 'setting', 'Chat'),
(44, 'chat_level1_access', 'Give Level 1 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(45, 'chat_level2_access', 'Give Level 1 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(46, 'chat_level3_access', 'Give Level 3 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(47, 'chat_level4_access', 'Give Level 3 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(48, 'chat_level5_access', 'Give Level 5 users access to chat (Yes/No)?', 'No', 'setting', 'Chat'),
(49, 'chat_level6_access', 'Give Level 6 users access to chat (Yes/No)?', 'No', 'setting', 'Chat'),
(50, 'Templates', '', '', 'category', ''),
(51, 'default_content', 'Default content list template.', 'latestcontent', 'setting', 'Templates'),
(52, 'default_games', 'Default games list template', 'list2games', 'setting', 'Templates'),
(53, 'default_company', 'Default companies list template', 'companies', 'setting', 'Templates'),
(54, 'abc_order_games', 'By Default - ABC Order for games list turned on (Yes/No)?', 'Yes', 'setting', 'Templates'),
(55, 'abc_order_companies', 'By Default - ABC Order for companies list turned on (Yes/No)?', 'No', 'setting', 'Templates'),
(56, 'captcha', 'Enable CAPTCHA (Yes/No)?', 'Yes', 'setting', 'General'),
(57, 'guest_comments', 'Allow unregistered users to comment on posts (Yes/No)?', 'No', 'setting', 'General')");

if ($newdata == TRUE)
{
mysql_query("DROP TABLE if exists ".$pre."settings2");
mysql_query("ALTER TABLE `".$pre."content` DROP `systems`");
mysql_query("ALTER TABLE `".$pre."content` DROP `games`");
mysql_query("ALTER TABLE`".$pre."content` ADD `save` INT NOT NULL DEFAULT'0'");
}

}

function upgrade5($pre, $dbname) {
global $pre;
global $dbname;

mysql_query("CREATE TABLE IF NOT EXISTS `".$pre."plugins` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` text COLLATE utf8_unicode_ci,
  `url` text COLLATE utf8_unicode_ci,
  `installed` text COLLATE utf8_unicode_ci,
  `version` varchar(5) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  `readme` text COLLATE utf8_unicode_ci NOT NULL,
  `status` char(3) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',
  PRIMARY KEY (`id`),
  FULLTEXT KEY `name` (`name`,`url`,`installed`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ");

mysql_query("INSERT INTO `".$pre."cat` VALUES (7, 'videos', '".time()."', '')");
mysql_query("INSERT INTO `".$pre."cat` VALUES (8, 'articles', '".time()."', '')");

mysql_query("ALTER TABLE `".$pre."permissions` ADD `articles` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes'");
mysql_query("ALTER TABLE `".$pre."permissions` ADD `videos` VARCHAR( 10 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'yes'");  

mysql_query("ALTER TABLE `".$pre."mods` CHANGE `sql` `sqla` ");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'image', '', 'image', 'If you want to use images for your posts, link directly to the image here.')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'company', '', 'company', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Article', 'articles', 'textarea', '')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'video', 'videos', 'textfield', 'link to your video file, the extension should end in .flv')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Short', 'articles', 'textarea', 'A short description of your story')");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'Short', 'videos', 'textarea', 'A short description of your story')");

mysql_query("UPDATE ".$pre."mods SET url = 'newsletter.php?load=newsletter' WHERE url = 'admin.php?load=newsletter'");
mysql_query("UPDATE ".$pre."mods SET url = 'contest.php?load=contest' WHERE url = 'admin.php?load=contest'");
mysql_query("UPDATE ".$pre."mods SET url = 'gallery.php?load=gallery' WHERE url = 'admin.php?load=gallery'");
mysql_query("UPDATE ".$pre."mods SET url = 'ads.php?load=ads' WHERE url = 'admin.php?load=ads'");
mysql_query("UPDATE ".$pre."mods SET url = 'smwords.php?load=smwords' WHERE url = 'admin.php?load=smwords'");
mysql_query("UPDATE ".$pre."mods SET url = 'comments.php?load=comments' WHERE url = 'admin.php?load=comments2'");
mysql_query("UPDATE ".$pre."mods SET url = 'files.php?load=files' WHERE url = 'admin.php?load=files'");
mysql_query("UPDATE ".$pre."mods SET url = 'affiliates.php?load=af' WHERE url = 'admin.php?load=af'");
mysql_query("UPDATE ".$pre."mods SET url = 'pr.php?load=pr' WHERE url = 'admin.php?load=pr'");

$query = mysql_query("SELECT id,games FROM ".$pre."content");
while($row = mysql_fetch_array($query)) {
mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'games', '".$row[games]."', '".$row[id]."', 'content')");
}


$query = mysql_query("SELECT id,systems FROM ".$pre."content");
while($row = mysql_fetch_array($query)) {
mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'systems', '".$row[systems]."', '".$row[id]."', 'content')");
}

mysql_query("UPDATE ".$pre."mods SET url = 'admin.php?load=pm&box=in' WHERE url = 'admin.php?load=inbox&box=in'");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'company', '', 'company', '')");


mysql_query("INSERT INTO `".$pre."mods` VALUES (null, 'Featured', 'featured.php', 'Yes', '1.0', '', '', 'On')");

mysql_query("ALTER TABLE `".$pre."forums` ADD `rankreq` varchar(100) NOT NULL");

mysql_query("ALTER TABLE `".$pre."comments` ADD `IP` text NOT NULL");
mysql_query("ALTER TABLE `".$pre."comments` ADD `type` text NOT NULL");

mysql_query("RENAME TABLE `".$pre."settings`  TO `".$pre."settings2` ;");

mysql_query("CREATE TABLE IF NOT EXISTS `".$pre."featured` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` text NOT NULL,
  `description` text NOT NULL,
  `image` text NOT NULL,
  `url` text NOT NULL,
  `system` int(11) NOT NULL,
  `rank` int(11) NOT NULL,
  `userid` int(11) NOT NULL,
  PRIMARY KEY (`id`)
)");

mysql_query("CREATE TABLE `".$pre."settings` (
  `id` int(11) NOT NULL auto_increment,
  `name` text NOT NULL,
  `description` text,
  `data` text,
  `type` text,
  `parent` text,
  PRIMARY KEY `id` (`id`))");
  
  
$olddata = mysql_fetch_array(mysql_query("SELECT * FROM ".$pre."settings2 WHERE id ='1'"));
  
$newdata = mysql_query("INSERT INTO `".$pre."settings` VALUES 
(1, 'General', NULL, NULL, 'Category', NULL),
(2, 'sitename', 'The name of your OneCMS site.', '".$olddata[sitename]."', 'setting', 'Global'),
(3, 'online', 'Is the site online?', 'Yes', 'setting', 'Global'),
(4, 'siteurl', 'Your site URL', '".$olddata[siteurl]."', 'setting', 'Global'),
(5, 'dformat', 'Date format', 'M d - Y', 'setting', 'Global'),
(6, 'warn', 'Number of Warns allowed (before banned).', '5', 'setting', 'Global'),
(7, 'path', 'Path to images folder (no trailing slash)', '".$olddata[path]."', 'setting' 'Global'),
(8, 'images', 'Path to images folder (no trailing slash).', '".$olddata[images]."', 'setting', 'Global'),
(9, 'max_results', 'Amount of items to display (per page...recommended is 30).', '30', 'setting', 'Global'),
(10, 'email', 'Owners E-mail', NULL, 'setting', 'Global'),
(11, 'name', 'Owners Name', NULL, 'setting', 'Global'),
(12, 'thumbnail_width', 'Thumbnail Width', '150', 'setting', 'Global'),
(13, 'thumbnail_height', 'Thumbnail Width', '90', 'setting', 'Global'),
(14, 'ip_logger', 'Enable the IP Logger (Yes/No).', 'Yes', 'setting', 'General'),
(15, 'wysiwyg', 'Enable the WYSIWYG editor (True/False).', 'True', 'setting', 'General'),
(16, 'max_pm', 'Amount of PM''s allowed.', '50', 'setting', 'General'),
(17, 'modrewrite', 'Enable Mod Rewrite (Yes/No)?', 'Yes', 'setting', 'General'),
(18, 'avatar_width', 'Avatar Width', '100', 'setting', 'General'),
(19, 'avatar_height', 'Avatar Height', '100', 'setting', 'General'),
(20, 'referral', 'Enable user referals for registration (yes/no)?', 'yes', 'setting', 'General'),
(21, 'poll_type', 'The type of poll you would like users to see (graphic/text).', 'graphic', 'setting', 'General'),
(22, 'user_fields', 'Enable User Fields on profile pages (yes/no)?', 'yes', 'setting', 'General'),
(23, 'Global', NULL, NULL, 'Category', NULL),
(24, 'Forum', NULL, NULL, 'Category', NULL),
(25, 'visitor_post', 'Allow Visitors to post in the forums (yes/no)?', 'yes', 'setting', 'Forum'),
(26, 'visitor_topic', 'Allow Visitors to create topics (yes/no)?', 'yes', 'setting', 'Forum'),
(27, 'visitor_smiles', 'Allow Visitors to use smilies (yes/no)?', 'yes', 'setting', 'Forum'),
(28, 'visitor_cname', 'Allow Visitors to use custom name when posting (name cannot be already in use)?', 'no', 'setting', 'Forum'),
(29, 'topics_per_page', 'How many topics to display per page?', '25', 'setting', 'Forum'),
(30, 'posts_per_page', 'How many posts to display per page?', '10', 'setting', 'Forum'),
(31, 'spam_control', 'Set a Spam Control limit (in seconds, setting to 120 would equal 2 minutes)?', '5', 'setting', 'Forum'),
(32, 'hot_topic', 'The number of posts required for a topic to be \"hot\".', '5', 'setting', 'Forum'),
(33, 'Gallery', NULL, NULL, 'Category', NULL),
(34, 'Chat', NULL, NULL, 'Category', NULL),
(35, 'gallery_template', 'Template for the main gallery.php page.', '<td><a href=''{url}''><img src=''{thumb}'' border=''1''></a><br><b>{name}</b><br><center>{icon}</center></td>', 'setting', 'Gallery'),
(36, 'album_template', 'Template for the actual album landing page.', '<td><a href=''{image}'' rel=''lightbox''><img src=''{thumb}'' border=''1''></a></td>', 'setting', 'Gallery'),
(37, 'gallery_header', NULL, '<table align=''center'' width=''95%'' border=''0'' cellpadding=''3'' cellspacing=''1''><tr>', 'setting', 'Gallery'),
(38, 'gallery_footer', NULL, '</tr></table>', 'setting', 'Gallery'),
(39, 'images_per_row', 'How many images to display per row?', '3', 'setting', 'Gallery'),
(40, 'images_per_page', 'How many images to display per page in an album (only required if pagination is enabled)?', '15', 'setting', 'Gallery'),
(41, 'gallery_pagination', 'Enable pagination use in the gallery module (Yes/No)?', 'Yes', 'setting', 'Gallery'),
(42, 'gallery_html_between', 'HTML between each row', '</tr><tr>', 'setting', 'Gallery'),
(43, 'chat_messages', 'Amount of messages shown in chat room.', '10', 'setting', 'Chat'),
(44, 'chat_level1_access', 'Give Level 1 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(45, 'chat_level2_access', 'Give Level 1 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(46, 'chat_level3_access', 'Give Level 3 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(47, 'chat_level4_access', 'Give Level 3 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(48, 'chat_level5_access', 'Give Level 5 users access to chat (Yes/No)?', 'No', 'setting', 'Chat'),
(49, 'chat_level6_access', 'Give Level 6 users access to chat (Yes/No)?', 'No', 'setting', 'Chat'),
(50, 'Templates', '', '', 'category', ''),
(51, 'default_content', 'Default content list template.', 'latestcontent', 'setting', 'Templates'),
(52, 'default_games', 'Default games list template', 'list2games', 'setting', 'Templates'),
(53, 'default_company', 'Default companies list template', 'companies', 'setting', 'Templates'),
(54, 'abc_order_games', 'By Default - ABC Order for games list turned on (Yes/No)?', 'Yes', 'setting', 'Templates'),
(55, 'abc_order_companies', 'By Default - ABC Order for companies list turned on (Yes/No)?', 'No', 'setting', 'Templates'),
(56, 'captcha', 'Enable CAPTCHA (Yes/No)?', 'Yes', 'setting', 'General'),
(57, 'guest_comments', 'Allow unregistered users to comment on posts (Yes/No)?', 'No', 'setting', 'General')");

if ($newdata == TRUE)
{
mysql_query("DROP TABLE if exists ".$pre."settings2");
mysql_query("ALTER TABLE `".$pre."content` DROP `systems`");
mysql_query("ALTER TABLE `".$pre."content` DROP `games`");
mysql_query("ALTER TABLE`".$pre."content` ADD `save` INT NOT NULL DEFAULT'0'");
}

}

function upgrade6($pre, $dbname) {
global $pre;
global $dbname;

$query = mysql_query("SELECT id,games FROM ".$pre."content");
while($row = mysql_fetch_array($query)) {
mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'games', '".$row[games]."', '".$row[id]."', 'content')");
}


$query = mysql_query("SELECT id,systems FROM ".$pre."content");
while($row = mysql_fetch_array($query)) {
mysql_query("INSERT INTO ".$pre."fielddata VALUES (null, 'systems', '".$row[systems]."', '".$row[id]."', 'content')");
}

mysql_query("UPDATE ".$pre."mods SET url = 'admin.php?load=pm&box=in' WHERE url = 'admin.php?load=inbox&box=in'");
mysql_query("INSERT INTO `".$pre."fields` VALUES (null, 'company', '', 'company', '')");


mysql_query("INSERT INTO `".$pre."mods` VALUES (null, 'Featured', 'featured.php', 'Yes', '1.0', '', '', 'On')");

mysql_query("ALTER TABLE `".$pre."forums` ADD `rankreq` varchar(100) NOT NULL");

mysql_query("ALTER TABLE `".$pre."comments` ADD `IP` text NOT NULL");
mysql_query("ALTER TABLE `".$pre."comments` ADD `type` text NOT NULL");

mysql_query("RENAME TABLE `".$pre."settings`  TO `".$pre."settings2` ;");

mysql_query("CREATE TABLE IF NOT EXISTS `".$pre."featured` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` text NOT NULL,
  `description` text NOT NULL,
  `image` text NOT NULL,
  `url` text NOT NULL,
  `system` int(11) NOT NULL,
  `rank` int(11) NOT NULL,
  `userid` int(11) NOT NULL,
  PRIMARY KEY (`id`)
)");

mysql_query("CREATE TABLE `".$pre."settings` (
  `id` int(11) NOT NULL auto_increment,
  `name` text NOT NULL,
  `description` text,
  `data` text,
  `type` text,
  `parent` text,
  PRIMARY KEY `id` (`id`))");
  
  
$olddata = mysql_fetch_array(mysql_query("SELECT * FROM ".$pre."settings2 WHERE id ='1'"));
  
$newdata = mysql_query("INSERT INTO `".$pre."settings` VALUES 
(1, 'General', NULL, NULL, 'Category', NULL),
(2, 'sitename', 'The name of your OneCMS site.', '".$olddata[sitename]."', 'setting', 'Global'),
(3, 'online', 'Is the site online?', 'Yes', 'setting', 'Global'),
(4, 'siteurl', 'Your site URL', '".$olddata[siteurl]."', 'setting', 'Global'),
(5, 'dformat', 'Date format', 'M d - Y', 'setting', 'Global'),
(6, 'warn', 'Number of Warns allowed (before banned).', '5', 'setting', 'Global'),
(7, 'path', 'Path to images folder (no trailing slash)', '".$olddata[path]."', 'setting' 'Global'),
(8, 'images', 'Path to images folder (no trailing slash).', '".$olddata[images]."', 'setting', 'Global'),
(9, 'max_results', 'Amount of items to display (per page...recommended is 30).', '30', 'setting', 'Global'),
(10, 'email', 'Owners E-mail', NULL, 'setting', 'Global'),
(11, 'name', 'Owners Name', NULL, 'setting', 'Global'),
(12, 'thumbnail_width', 'Thumbnail Width', '150', 'setting', 'Global'),
(13, 'thumbnail_height', 'Thumbnail Width', '90', 'setting', 'Global'),
(14, 'ip_logger', 'Enable the IP Logger (Yes/No).', 'Yes', 'setting', 'General'),
(15, 'wysiwyg', 'Enable the WYSIWYG editor (True/False).', 'True', 'setting', 'General'),
(16, 'max_pm', 'Amount of PM''s allowed.', '50', 'setting', 'General'),
(17, 'modrewrite', 'Enable Mod Rewrite (Yes/No)?', 'Yes', 'setting', 'General'),
(18, 'avatar_width', 'Avatar Width', '100', 'setting', 'General'),
(19, 'avatar_height', 'Avatar Height', '100', 'setting', 'General'),
(20, 'referral', 'Enable user referals for registration (yes/no)?', 'yes', 'setting', 'General'),
(21, 'poll_type', 'The type of poll you would like users to see (graphic/text).', 'graphic', 'setting', 'General'),
(22, 'user_fields', 'Enable User Fields on profile pages (yes/no)?', 'yes', 'setting', 'General'),
(23, 'Global', NULL, NULL, 'Category', NULL),
(24, 'Forum', NULL, NULL, 'Category', NULL),
(25, 'visitor_post', 'Allow Visitors to post in the forums (yes/no)?', 'yes', 'setting', 'Forum'),
(26, 'visitor_topic', 'Allow Visitors to create topics (yes/no)?', 'yes', 'setting', 'Forum'),
(27, 'visitor_smiles', 'Allow Visitors to use smilies (yes/no)?', 'yes', 'setting', 'Forum'),
(28, 'visitor_cname', 'Allow Visitors to use custom name when posting (name cannot be already in use)?', 'no', 'setting', 'Forum'),
(29, 'topics_per_page', 'How many topics to display per page?', '25', 'setting', 'Forum'),
(30, 'posts_per_page', 'How many posts to display per page?', '10', 'setting', 'Forum'),
(31, 'spam_control', 'Set a Spam Control limit (in seconds, setting to 120 would equal 2 minutes)?', '5', 'setting', 'Forum'),
(32, 'hot_topic', 'The number of posts required for a topic to be \"hot\".', '5', 'setting', 'Forum'),
(33, 'Gallery', NULL, NULL, 'Category', NULL),
(34, 'Chat', NULL, NULL, 'Category', NULL),
(35, 'gallery_template', 'Template for the main gallery.php page.', '<td><a href=''{url}''><img src=''{thumb}'' border=''1''></a><br><b>{name}</b><br><center>{icon}</center></td>', 'setting', 'Gallery'),
(36, 'album_template', 'Template for the actual album landing page.', '<td><a href=''{image}'' rel=''lightbox''><img src=''{thumb}'' border=''1''></a></td>', 'setting', 'Gallery'),
(37, 'gallery_header', NULL, '<table align=''center'' width=''95%'' border=''0'' cellpadding=''3'' cellspacing=''1''><tr>', 'setting', 'Gallery'),
(38, 'gallery_footer', NULL, '</tr></table>', 'setting', 'Gallery'),
(39, 'images_per_row', 'How many images to display per row?', '3', 'setting', 'Gallery'),
(40, 'images_per_page', 'How many images to display per page in an album (only required if pagination is enabled)?', '15', 'setting', 'Gallery'),
(41, 'gallery_pagination', 'Enable pagination use in the gallery module (Yes/No)?', 'Yes', 'setting', 'Gallery'),
(42, 'gallery_html_between', 'HTML between each row', '</tr><tr>', 'setting', 'Gallery'),
(43, 'chat_messages', 'Amount of messages shown in chat room.', '10', 'setting', 'Chat'),
(44, 'chat_level1_access', 'Give Level 1 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(45, 'chat_level2_access', 'Give Level 1 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(46, 'chat_level3_access', 'Give Level 3 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(47, 'chat_level4_access', 'Give Level 3 users access to chat (Yes/No)?', 'Yes', 'setting', 'Chat'),
(48, 'chat_level5_access', 'Give Level 5 users access to chat (Yes/No)?', 'No', 'setting', 'Chat'),
(49, 'chat_level6_access', 'Give Level 6 users access to chat (Yes/No)?', 'No', 'setting', 'Chat'),
(50, 'Templates', '', '', 'category', ''),
(51, 'default_content', 'Default content list template.', 'latestcontent', 'setting', 'Templates'),
(52, 'default_games', 'Default games list template', 'list2games', 'setting', 'Templates'),
(53, 'default_company', 'Default companies list template', 'companies', 'setting', 'Templates'),
(54, 'abc_order_games', 'By Default - ABC Order for games list turned on (Yes/No)?', 'Yes', 'setting', 'Templates'),
(55, 'abc_order_companies', 'By Default - ABC Order for companies list turned on (Yes/No)?', 'No', 'setting', 'Templates'),
(56, 'captcha', 'Enable CAPTCHA (Yes/No)?', 'Yes', 'setting', 'General'),
(57, 'guest_comments', 'Allow unregistered users to comment on posts (Yes/No)?', 'No', 'setting', 'General')");

if ($newdata == TRUE)
{
mysql_query("DROP TABLE if exists ".$pre."settings2");
mysql_query("ALTER TABLE `".$pre."content` DROP `systems`");
mysql_query("ALTER TABLE `".$pre."content` DROP `games`");
mysql_query("ALTER TABLE`".$pre."content` ADD `save` INT NOT NULL DEFAULT'0'");
}

}

function upgrade3($yep, $pre) {
global $pre;
mysql_query("CREATE TABLE `".$pre."stats` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `page` text NOT NULL,
  `referral` text NOT NULL,
  `type` text NOT NULL,
  `username` text NOT NULL,
  `ip` text NOT NULL,
  `info` text NOT NULL,
  `day` text NOT NULL,
  `tday` text NOT NULL,
  `month` text NOT NULL,
  `week` text NOT NULL,
  `year` text NOT NULL,
  PRIMARY KEY  (`id`))");

mysql_query("CREATE TABLE `".$pre."reputation` (
  `id` int(11) unsigned NOT NULL auto_increment,
  `type` text NOT NULL,
  `fromwho` text NOT NULL,
  `forwho` text NOT NULL,
  `comment` text NOT NULL,
  `url` text NOT NULL,
  `date` text NOT NULL,
  PRIMARY KEY  (`id`))");

mysql_query("UPDATE ".$pre."users SET skin = '8', skin2 = '3'");


mysql_query("ALTER TABLE `".$pre."forums` ADD `prequire` TEXT NOT NULL");
mysql_query("ALTER TABLE `".$pre."forums` ADD `vpost` varchar(100) NOT NULL default 'Yes'");
mysql_query("ALTER TABLE `".$pre."forums` ADD `vtopic` varchar(100) NOT NULL default 'Yes'");
mysql_query("ALTER TABLE `".$pre."forums` ADD `epost` varchar(100) NOT NULL default 'Yes'");
mysql_query("ALTER TABLE `".$pre."forums` ADD `dpost` varchar(100) NOT NULL default 'No'");
mysql_query("ALTER TABLE `".$pre."users` CHANGE `rank` `rank` TEXT NULL");
mysql_query("DELETE FROM ".$pre."comments1 WHERE type = 'smiley'");
mysql_query("UPDATE ".$pre."mods SET name = 'Badwords' WHERE name = 'Smilies/Badwords'");
mysql_query("ALTER TABLE `".$pre."games` CHANGE `date` `date` VARCHAR( 50 ) NULL ");
if ($yep) {
mysql_query("ALTER TABLE `".$pre."games` DROP INDEX `name` ,

ADD FULLTEXT `name` (
`name` ,
`publisher` ,
`developer` ,
`genre` ,
`esrb` ,
`boxart` ,
`des`
)");
}
mysql_query("ALTER TABLE `".$pre."games` ADD INDEX ( `date` )");

mysql_query("ALTER TABLE `".$pre."games` ADD INDEX ( `stats` )");
if ($yep) {
mysql_query("ALTER TABLE `".$pre."games` CHANGE `stats` `stats` INT( 20 ) NULL DEFAULT '0'");
mysql_query("ALTER TABLE `".$pre."games` CHANGE `date` `date` INT( 20 ) NULL DEFAULT '0'");
}

$bdir = $_SERVER['DOCUMENT_ROOT']."backup";
$filename = ".htaccess";
$content = "RewriteEngine on

Options -Indexes
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !".$domain."/admin/admin\.php [NC]
RewriteCond %{HTTP_REFERER} !^http://".$domain."/backup/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.".$domain."/backup/.*$ [NC]
RewriteRule .*\.(php|PHP|sql|SQL)$ - [F,NC]";

$handle = fopen($bdir.$filename, 'a');
fwrite($handle, $content);
fclose($handle);

if ($yep) {

	$query="SELECT * FROM ".$pre."games ORDER BY `stats` DESC";
	$result=mysql_query($query);
	while($r = mysql_fetch_array($result)) {

$var[] = "January";
$var[] = "February";
$var[] = "March";
$var[] = "April";
$var[] = "May";
$var[] = "June";
$var[] = "July";
$var[] = "Auguest";
$var[] = "September";
$var[] = "October";
$var[] = "November";
$var[] = "December";
$vap[] = "01";
$vap[] = "02";
$vap[] = "03";
$vap[] = "04";
$vap[] = "05";
$vap[] = "06";
$vap[] = "07";
$vap[] = "08";
$vap[] = "09";
$vap[] = "10";
$vap[] = "11";
$vap[] = "12";
$release = str_replace($var, $vap, $r[release]);

$tdate = explode("|", $release);
if (($tdate[0] == "") && ($tdate[1] == "")) {
mysql_query("UPDATE ".$pre."games SET release = '0' WHERE id = '".$r[id]."'");
} else {
if ($tdate[2] == "") {
$year = "2006";
} else {
$year = $tdate[2];
}
$date = date("U", mktime(0, 0, 0, $tdate[0], $tdate[1], $year));
mysql_query("UPDATE ".$pre."games SET release = '".$date."' WHERE id = '".$r[id]."'");
}
}
}
}

$modfile = "mods/userreviews.php";

if ($_GET['step'] == "") {
echo install_header();
$var = "";
$var2 = "0";
echo "<div align='left'>";

echo "MySQL Connection Status successfull?: ";
if (@mysql_select_db($dbname, mysql_connect($dbhost, $dbuser, $dbpass)) == TRUE) {
echo "<font color='blue'>YES</font>";
$var .= "Step1=true,";
$var2 = $var2 + 1;
} else {
echo "<font color='red'>NO</font>";
$var .= "Step1=false,";
}

echo "<br>PHP >= 4.0: ";
if (@phpversion() >= "4.0") {
echo "<font color='blue'>YES</font>";
$var .= "Step2=true,";
$var2 = $var2 + 1;
} else {
echo "<font color='red'>NO</font>";
$var .= "Step2=false,";
}

echo "<br>MySQL Enabled: ";
if (@function_exists("mysql_connect")) {
echo "<font color='blue'>YES</font>";
$var .= "Step3=true,";
$var2 = $var2 + 1;
} else {
echo "<font color='red'>NO</font>";
$var .= "Step3=false,";
}

echo "<br>GD Enabled: ";
if (@function_exists("imagecreatefromjpeg")) {
echo "<font color='blue'>YES</font>";
$var .= "Step4=true,";
$var2 = $var2 + 1;
} else {
echo "<font color='red'>NO</font>";
$var .= "Step4=false,";
}

echo "<br>Magic Quotes GPC: ";
if (@get_magic_quotes_gpc()) {
echo "<font color='blue'>YES</font>";
$var .= "=true,";
$var2 = $var2 + 1;
} else {
echo "<font color='red'>NO</font>";
$var .= "Step5=false,";
}

echo "<br>Chmoded backup folder: ";
if (is_writable("backup")) {
echo "<font color='blue'>YES</font>";
$var .= "Step6=true,";
$var2 = $var2 + 1;
} else {
echo "<font color='red'>NO</font>";
$var .= "Step6=false,";
}

$ex = @explode(",", $var);

echo "</div>";
//The following function controls the registration process
?>
<script>
//"Accept terms" form submission- By Dynamic Drive
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use

var checkobj

function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}

function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read/accept terms to continue to next step.")
return false
}
}
}

</script>
<form method="post" action="install.php?step=1" name="agreeform" onSubmit="return defaultagree(this)">
<textarea name='terms' readonly cols='58' rows='7'>OneCMS Terms of Use

By installing and using OneCMS you agree to the following terms.

1) You agree to the GPL License (included in installation folder).
2) You agree to not sell OneCMS in any way shape or form unless given permission by Dog Fight Studios Limited (Dog Fight Studios) to do so. If you were mislead and bought the script, please contact Dog Fight Studios, keep in mind, we cannot guarantee a refund of any kind. 
3) You may modify and re-distribute OneCMS with proper copyright notices attributed.
4) You agree not to hold Dog Fight Studios liable for any damages occured from proper or improper use of OneCMS. Use at your own risk.

If any of the above terms are broken, Dog Fight Studios reserves the right to report the offending website(s) to their host and use any other methods deemed necessary.

This agreement is subject to change at any time without notice, please consult http://onecms.net for the most up to date information regarding the OneCMS script. By continuing with the install and using OneCMS you agree to the terms outlined above. If you do not agree with this T.O.U. you must exit the installer and delete the script from your server ASAP.</textarea><br />
<input name="agreecheck" type="checkbox" onClick="agreesubmit(this)"><b>I agree to the above terms</b><br />
</form>

<script>
document.forms.agreeform.agreecheck.checked=false
</script>
<?php

if ((($var2 >= "2") && ($ex[0] == "Step1=true") && ($ex[2] == "Step3=true"))) {
echo "&nbsp;&nbsp;&nbsp;&nbsp;Proceed to the next step - <a href='install.php?step=1'><b>Step 1</b></a><br><br>";
}

if ($ex[0] == "Step1=false") {
echo "Please check the database information in config.php<br><br>";
}

if ($ex[1] == "Step2=false") {
echo "Your PHP is only version <b>".@phpversion()."</b> which is out of date. If you are running anything below 3.7.0 you may have many problems running OneCMS<br><br>";
}

if ($ex[2] == "Step3=false") {
echo "Sorry but MySQL appears to not be enabled on your server, you cannot use OneCMS without MySQL. Please ask your host to add MySQL<br><br>";
}

if ($ex[3] == "Step4=false") {
echo "GD is not enabled but dont fret, you can use OneCMS except the thumbnailer<br><br>";
}

if ($ex[4] == "Step5=false") {
echo "Magic Quotes GPC is not enabled but it is not a problem, infact it does not matter if it is on or off<br><br>";
}

if ($ex[5] == "Step6=false") {
echo "The backup folder has not been chmoded, which is not a big deal. But if you want to use the backup tool please chmod the backup folder to 0777 using your FTP.<br><br>";
}
echo install_footer();
}

if ($_GET['step'] == "upgrade5") {
mysql_select_db($dbname, mysql_connect($dbhost, $dbuser, $dbpass));
echo upgrade5($pre,$dbname);

$query = @mysql_num_rows(mysql_query("SELECT rank FROM ".$pre."users"));

if ($query > "0") {
echo install_header();
echo "Upgrade from v2.5 to ".$version." Successful?: ";
echo "<font color='blue'>YES</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Woah look at that, your already done!";
} else {
echo install_header();
echo "Upgrade Successful?: ";
echo "<font color='red'>NO</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Please make sure the database information is correct and also make sure that all the tables are in the <b>".$dbname."</b> database and try again!";
}
echo install_footer();
}

if ($_GET['step'] == "upgrade6") {
mysql_select_db($dbname, mysql_connect($dbhost, $dbuser, $dbpass));
echo upgrade6($pre,$dbname);

$query = @mysql_num_rows(mysql_query("SELECT data FROM ".$pre."settings"));

if ($query > "0") {
echo install_header();
echo "Upgrade from v2.6.1 to ".$version." Successful?: ";
echo "<font color='blue'>YES</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Woah look at that, your already done!";
} else {
echo install_header();
echo "Upgrade Successful?: ";
echo "<font color='red'>NO</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Please make sure the database information is correct and also make sure that all the tables are in the <b>".$dbname."</b> database and try again!";
echo "<br>Details: (".mysql_errno().")".mysql_error();
}
echo install_footer();
}

if ($_GET['step'] == "upgrade3") {
mysql_select_db($dbname, mysql_connect($dbhost, $dbuser, $dbpass));

echo upgrade3($pre, $dbname);
echo upgrade4($pre, $dbname);

$query = @mysql_num_rows(mysql_query("SELECT rank FROM ".$pre."users"));

if ($query > "0") {
echo install_header();
echo "Upgrade from v2.3 to ".$version." Successful?: ";
echo "<font color='blue'>YES</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Woah look at that, your already done!";
} else {
echo install_header();
echo "Upgrade Successful?: ";
echo "<font color='red'>NO</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Please make sure the database information is correct and also make sure that all the tables are in the <b>".$dbname."</b> database and try again!";
}
echo install_footer();
}

if ($_GET['step'] == "upgrade4") {
mysql_select_db($dbname, mysql_connect($dbhost, $dbuser, $dbpass));

echo upgrade4($pre, $dbname);
echo upgrade5($pre, $dbname);

$query = @mysql_num_rows(mysql_query("SELECT rank FROM ".$pre."users"));

if ($query > "0") {
echo install_header();
echo "Upgrade from v2.4 to ".$version." Successful?: ";
echo "<font color='blue'>YES</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Woah look at that, your already done!";
} else {
echo install_header();
echo "Upgrade Successful?: ";
echo "<font color='red'>NO</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Please make sure the database information is correct and also make sure that all the tables are in the <b>".$dbname."</b> database and try again!";
}
echo install_footer();
}

if ($_GET['step'] == "1") {
mysql_select_db($dbname, mysql_connect($dbhost, $dbuser, $dbpass));

if (((table($pre."ad") == TRUE) && (table($pre."content") == TRUE) && (table($pre."users") == TRUE))) {
echo install_header();
echo "Looks like you have OneCMS v2 installed on this database, you can upgrade, just click on the version of OneCMS you are upgrading from:<br><br><center><a href='install.php?step=upgrade4'>Upgrade from v2.4</a> :: <a href='install.php?step=upgrade5'>Upgrade from v2.5</a> :: <a href='install.php?step=upgrade6'>Upgrade from v2.6.1</a> </center>";
echo "<b>BACK UP YOUR DATABASE BEFORE UPGRADING</b>: OneCMS 2.6.4 makes various database changes, a back up is helpful if anything goes wrong.";
} else {
echo install_header();
echo "Looks like you don't have OneCMS v2 installed on this database, you only have the option to install:<br><br><center><b><a href='install.php?step=2'>Install</a></b></center>";
}
echo install_footer();
}

if ($_GET['step'] == "2") {
mysql_select_db($dbname, mysql_connect($dbhost, $dbuser, $dbpass));

echo install($pre);
echo install_data($pre);
echo upgrade3("yes", $pre);

$query = @mysql_num_rows(mysql_query("SELECT * FROM ".$pre."settings"));

if ($query > "0") {
echo install_header();
echo "SQL Uploaded to Database?: ";
echo "<font color='blue'>YES</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Proceed to the next step - <a href='install.php?step=3'><b>Step 3</b></a>";
} else {
echo install_header();
echo "SQL Uploaded to Database?: ";
echo "<font color='red'>NO</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Please make sure the database information is correct and then try again";
}
echo install_footer();
}

if ($_GET['step'] == "3") {
echo install_header();
mysql_select_db($dbname, mysql_connect($dbhost, $dbuser, $dbpass));

$ex = explode(".", $_SERVER['HTTP_HOST']);
if ($ex[2]) {
$sitename = $ex[1];
} else {
$sitename = $ex[0];
}
$siteurl .= "http://".$_SERVER['HTTP_HOST'];
$ex = explode("/install.php", $_SERVER['REQUEST_URI']);
if (preg_match("/step/", $_SERVER['REQUEST_URI'])) {
$ex2 = explode("/install.php?step", $_SERVER['REQUEST_URI']);
$siteurl .= $ex2[0];
}
$online = "Yes";
$dformat = "M d - Y";
$warn = "5";
$images = $siteurl."/images";
$path = $_SERVER['DOCUMENT_ROOT']."/images";
$max_results = "30";
$width = "150";
$height = "90";

echo "<form action='install.php?step=3_1' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td><center><b>Global Settings</b></center></td></tr><tr><td>Site Name</td><td><input type=\"text\" name=\"sitename\" value=\"$sitename\"></td></tr><tr><td>Site URL (no trailing slash)</td><td><input type=\"text\" name=\"siteurl\" value=\"$siteurl\"></td></tr><tr><td>Site Online?</td><td><select name='online'><option value=\"$online\" selected>-- $online --</option><option value=\"Yes\">Yes</option><option value=\"No\">No</option></select></td></tr><tr><td>Date Format</td><td><input type=\"text\" name=\"dformat\" value=\"$dformat\"></td></tr><tr><td>Number of Warns allowed (before banned)</td><td><input type=\"text\" name=\"warn\" value=\"$warn\"></td></tr><tr><td>URL to images folder (no trailing slash)</td><td><input type=\"text\" name=\"images\" value=\"$images\"></td></tr><tr><td>Path to images folder (no trailing slash)</td><td><input type=\"text\" name=\"path\" value=\"$path\"></td></tr><tr><td>Amount of items to display (per page...recommended is 30)</td><td><input type=\"text\" name=\"max_results\" value=\"$max_results\"></td></tr><tr><td>Owners E-mail</td><td><input type=\"text\" name=\"email\" value=\"$email\"></td></tr><tr><td>Owners Name</td><td><input type=\"text\" name=\"name\" value=\"$name\"></td></tr><tr><td>Thumbnail Width</td><td><input type=\"text\" name=\"width\" value=\"$width\"></td></tr><tr><td>Thumbnail Height</td><td><input type=\"text\" name=\"height\" value=\"$height\"></td></tr><tr><td><input type=\"submit\" value=\"Next Step\"></td></tr></form></table>";

echo install_footer();
}

if ($_GET['step'] == "3_1") {
mysql_select_db($dbname, mysql_connect($dbhost, $dbuser, $dbpass));


$query = mysql_query("UPDATE ".$pre."settings SET data = '".$_POST["sitename"]."' WHERE name = 'sitename'");

$query = mysql_query("UPDATE ".$pre."settings SET data = '".addslashes($_POST["siteurl"])."' WHERE, name = 'siteurl'");

$query = mysql_query("UPDATE ".$pre."settings SET data = '".$_POST["online"]."' WHERE name = 'online'");

$query = mysql_query("UPDATE ".$pre."settings SET data = '".$_POST["dformat"]."' WHERE name = 'dformat'");

$query = mysql_query("UPDATE ".$pre."settings SET data = '".$_POST["warn"]."' WHERE name = 'warn'");

$query = mysql_query("UPDATE ".$pre."settings SET data = '".addslashes($_POST["images"])."' WHERE name = 'images'");

$query = mysql_query("UPDATE ".$pre."settings SET data = '".$_POST["path"]."' WHERE name = 'path'");

$query = mysql_query("UPDATE ".$pre."settings SET data = '".$_POST["max_results"]."' WHERE name = 'max_results'"); 

$query = mysql_query("UPDATE ".$pre."settings SET data = '".$_POST["email"]."' WHERE name = 'email'");

$query = mysql_query("UPDATE ".$pre."settings SET data = '".$_POST["name"]."' WHERE name = 'name'");

$query = mysql_query("UPDATE ".$pre."settings SET data = '".$_POST["height"]."' WHERE name = 'thumbnail_height'");

$query = mysql_query("UPDATE ".$pre."settings SET data = '".$_POST["width"]."' WHERE name = 'thumbnail_width'");


if ($query == TRUE) {
echo install_header();
echo "Global Settings added successfully?: ";
echo "<font color='blue'>YES</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Proceed to the next step - <a href='install.php?step=4'><b>Step 4</b></a>";
} else {
echo install_header();
echo "Global Settings added successfully?: ";
echo "<font color='red'>NO</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Please make sure the SQL is uploaded, database information is correct and then try again";
echo "<br>Details: (".mysql_errno().")".mysql_error();
}
echo install_footer();
}

if ($_GET['step'] == "4") {
echo install_header();

echo "<form action='install.php?step=5' method='post'><table cellspacing=\"0\" cellpadding=\"3\" border=\"0\" align=\"center\"><tr><td>Username</td><td><input type=\"text\" name='name'></td></tr><tr><td>Password</td><td><input type=\"password\" name='password1'></td></tr><tr><td>E-Mail</td><td><input type=\"text\" name='email'></td></tr><tr><td>User Level</td><td><select name='level' multiple size='5'>";
	
	mysql_select_db($dbname, mysql_connect($dbhost, $dbuser, $dbpass));

	$query="SELECT * FROM ".$pre."userlevels WHERE id = '1'";
	$result=mysql_query($query);
	while($row = mysql_fetch_array($result)) {
		echo "<option value=\"$row[name]\" selected>$row[name]</option>";
	}
echo "</td></tr><tr><td><input type=\"submit\" name=\"Add\" value=\"Finish...\"></td></tr></form></table>";

echo install_footer();
}

if ($_GET['step'] == "5") {
mysql_select_db($dbname, mysql_connect($dbhost, $dbuser, $dbpass));
global $salt;

   $sql0 = mysql_query("INSERT INTO ".$pre."profile VALUES (null, '".$_POST["name"]."', '', '', '', '', '', '', '', '', '', '', '')") or die(mysql_error());

   $sql1 = mysql_query("INSERT INTO ".$pre."pm VALUES (null, '1', 'Welcome ".$_POST["name"]."!', 'Welcome to OneCMS ".$_POST["name"].". Below you can find your user information, please keep record of this.<br><br>Username - ".$_POST["name"]."<br>Password - ".$_POST["password1"]."<br><br>Thanks!', '".$_POST["name"]."', '".$_POST["name"]."', '".time()."', 'inbox')") or die(mysql_error());

   $sql2 = mysql_query("INSERT INTO ".$pre."permissions VALUES (null, '".$_POST["name"]."', 'no', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes', 'yes')") or die(mysql_error());
   
   $password222 = md5($salt.$_POST["password1"]);

   $zy = mysql_query("SELECT id FROM ".$pre."profile WHERE username = '".$_POST["name"]."'");
   $prof = mysql_fetch_row($zy);

   $uid = $prof[0];

   $sql3 = mysql_query("INSERT INTO ".$pre."boardcp VALUES (null, '".$uid."', '', '', 'admin')") or die(mysql_error());

   $sql4 = mysql_query("INSERT INTO ".$pre."users VALUES (null, '".$_POST["name"]."', '".$password222."', '".$_POST["email"]."', '".$_POST["level"]."', 'Queen', '0', 'no', 'no', '0', '8', '3', 'Yes')") or die(mysql_error());
   mysql_query("INSERT INTO `".$pre."content` VALUES (1, 'Welcome to OneCMS!', 'news', '".$_POST["name"]."', '".time()."', '0', '', 0, 'No', '0')");
if ($sql0 == TRUE && $sql1 == TRUE && $sql2 == TRUE && $sql3 == TRUE && $sql4 == TRUE) {
echo install_header();
echo "User account added successfully?: ";
echo "<font color='blue'>YES</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;You are now finished! You can now login - <a href='admin'><b>Login here</b></a><br><br>Also do not forget to delete the following file:<br>install.php<br><br>Thank you and enjoy OneCMS ".$version."!";
} else {
echo install_header();
echo "User account added successfully?: ";
echo "<font color='red'>NO</font>";
echo "&nbsp;&nbsp;&nbsp;&nbsp;Please make sure the SQL is uploaded, database information is correct and then try again";
}
echo install_footer();
}
?>