<?php

	$query = "SHOW TABLES LIKE 'content'";
	$result = db_do_query($query);
	$count = db_num_rows($result);
	if (!$count) {
		$result_content = db_do_query("
			CREATE TABLE `content` (
			  `ID` int(11) NOT NULL auto_increment,
			  `path` tinytext NOT NULL,
			  `field` tinytext NOT NULL,
			  `content` text NOT NULL,
			  `user` int(11) NOT NULL default '0',
			  `status` tinyint(4) NOT NULL default '0',
			  `comment` text NOT NULL,
			  `date` datetime NOT NULL default '0000-00-00 00:00:00',
			  `schedule` datetime NOT NULL default '0000-00-00 00:00:00',
			  PRIMARY KEY (`ID`)
			)
		");
	}

	$query = "SHOW TABLES LIKE 'role'";
	$result = db_do_query($query);
	$count = db_num_rows($result);
	if (!$count) {
		$result_content = db_do_query("
			CREATE TABLE `role` (
			  `ID` tinyint(4) NOT NULL auto_increment,
			  `name` tinytext NOT NULL,
			  `active` tinyint(4) NOT NULL default '1',
			  PRIMARY KEY (`ID`)
			)
		");
		db_do_query("INSERT INTO `role` (`ID`,`name`,`active`) VALUES ('1','Editor','1')");
		db_do_query("INSERT INTO `role` (`ID`,`name`,`active`) VALUES ('2','Reviewer','1')");
		db_do_query("INSERT INTO `role` (`ID`,`name`,`active`) VALUES ('3','Administrator','1')");
	}

	$query = "SHOW TABLES LIKE 'status'";
	$result = db_do_query($query);
	$count = db_num_rows($result);
	if (!$count) {
		$result_content = db_do_query("
			CREATE TABLE `status` (
			  `ID` tinyint(4) NOT NULL auto_increment,
			  `name` tinytext NOT NULL,
			  `active` tinyint(4) NOT NULL default '1',
			  PRIMARY KEY (`ID`)
			)
		");
		db_do_query("INSERT INTO `status` (`ID`,`name`,`active`) VALUES ('1','In progress','1')");
		db_do_query("INSERT INTO `status` (`ID`,`name`,`active`) VALUES ('2','In review','1')");
		db_do_query("INSERT INTO `status` (`ID`,`name`,`active`) VALUES ('4','Published','1')");
		db_do_query("INSERT INTO `status` (`ID`,`name`,`active`) VALUES ('5','Reverted','1')");
		db_do_query("INSERT INTO `status` (`ID`,`name`,`active`) VALUES ('6','Deleted','1')");
		db_do_query("INSERT INTO `status` (`ID`,`name`,`active`) VALUES ('3','Scheduled','1')");
	}

	$query = "SHOW TABLES LIKE 'timezone'";
	$result = db_do_query($query);
	$count = db_num_rows($result);
	if (!$count) {
		$result_content = db_do_query("
			CREATE TABLE `timezone` (
			  `ID` int(11) NOT NULL auto_increment,
			  `name` tinytext NOT NULL,
			  `offset` decimal(4,2) NOT NULL default '0',
			  `active` tinyint(4) NOT NULL default '1',
			  PRIMARY KEY (`ID`)
			)
		");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('1','New York (GMT-5)','-5.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('2','Chicago (GMT -6)','-6.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('3','Denver (GMT -7)','-7.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('4','Los Angeles (GMT -8)','-8.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('5','U.S. Minor Outlying Islands (GMT -12)','-12.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('6','Samoa (GMT -11)','-11.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('7','Aleutian Islands, Hawaii (GMT -10)','-10.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('8','French Polynesia (GMT -9:30)','-9.50','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('9','Juneau (GMT -9)','-9.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('10','Venezuela (GMT -4:30)','-4.50','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('11','Puerto Rico (GMT -4)','-4.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('12','New Foundland (GMT -3:30)','-3.50','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('13','Greenland (GMT -3)','-3.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('14','Sandwich Islands (GMT -2)','-2.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('15','Portugal (GMT -1)','-1.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('16','London (GMT)','0.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('17','Paris (GMT +1)','1.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('18','Athens (GMT +2)','2.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('19','Moscow (GMT +3)','3.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('20','Tehran (GMT +3:30)','3.50','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('21','Dubai (GMT +4)','4.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('22','Kabul (GMT +4:30)','4.50','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('23','Karachi (GMT +5)','5.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('24','Delhi (GMT +5:30)','5.50','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('25','Kathmandu (GMT +5:45)','5.75','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('26','Kyrgyzstan (GMT +6)','6.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('27','Myanmar (GMT +6:30)','6.50','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('28','Bangkok (GMT +7)','7.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('29','Hong Kong (GMT +8)','8.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('30','Western Australia (GMT +8:45)','8.75','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('31','Japan (GMT +9)','9.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('32','Northern Territory (GMT +9:30)','9.50','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('33','Queensland (GMT +10)','10.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('34','Lord Howe Island (GMT +10:30)','10.50','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('35','Solomon Islands (GMT +11)','11.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('36','Norfolk Island (GMT +11.5)','11.50','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('37','New Zealand (GMT +12)','12.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('38','Chatham Islands (GMT +12:45)','12.75','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('39','Phoenix Islands (GMT +13)','13.00','1')");
		db_do_query("INSERT INTO `timezone` (`ID`,`name`,`offset`,`active`) VALUES ('40','Line Islands (GMT +14)','14.00','1')");
	}

	$query = "SHOW TABLES LIKE 'user'";
	$result = db_do_query($query);
	$count = db_num_rows($result);
	if (!$count) {
		$result_content = db_do_query("
			CREATE TABLE `user` (
			  `ID` int(11) NOT NULL auto_increment,
			  `name` tinytext NOT NULL,
			  `password` tinytext NOT NULL,
			  `email` tinytext NOT NULL,
			  `timezone` tinyint(4) NOT NULL default '0',
			  `role` tinyint(4) NOT NULL default '1',
			  `access` text NOT NULL,
			  `active` tinyint(4) NOT NULL default '1',
			  PRIMARY KEY (`ID`)
			)
		");
		db_do_query("INSERT INTO `user` (`ID`,`name`,`password`,`email`,`timezone`,`role`,`active`) VALUES ('1','admin','d41d8cd98f00b204e9800998ecf8427e','','0','3','1')");
	}

	$query = "SHOW TABLES LIKE 'user_filter'";
	$result = db_do_query($query);
	$count = db_num_rows($result);
	if (!$count) {
		$result_content = db_do_query("
			CREATE TABLE `user_filter` (
			  `ID` int(11) NOT NULL auto_increment,
			  `user_variable` tinytext NOT NULL,
			  `user` int(11) NOT NULL default '0',
			  `page` tinytext NOT NULL,
			  `name` tinytext NOT NULL,
			  `value` tinytext NOT NULL,
			  PRIMARY KEY (`ID`)
			)
		");
	}

	$query = "SHOW TABLES LIKE 'user_sort'";
	$result = db_do_query($query);
	$count = db_num_rows($result);
	if (!$count) {
		$result_content = db_do_query("
			CREATE TABLE `user_sort` (
			  `ID` int(11) NOT NULL auto_increment,
			  `user_variable` tinytext NOT NULL,
			  `user` int(11) NOT NULL default '0',
			  `page` tinytext NOT NULL,
			  `name` tinytext NOT NULL,
			  `value` tinytext NOT NULL,
			  PRIMARY KEY (`ID`)
			) 
		");
	}

	redirect($login_page);
	
?>
