<?php
$_wp_installing = 1;
if (!file_exists('../wp-config.php')) 
    die(header("Location: ../index.php"));
require_once('../wp-config.php');
require('upgrade-functions.php');

if (isset($_GET['step']))
	$step = $_GET['step'];
else
	$step = 0;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<title>WordPress &rsaquo; Installation</title>
	<meta http-equiv="Content-Type" content="text/html; charset=<?php echo $guide_charset; ?>" />
	<style media="screen" type="text/css">
    <!--
	body {
		background-color: white;
		color: black;
		font-family: Osaka, Verdana, sans-serif;
		margin-left: 15%;
		margin-right: 15%;
	}
	#logo {
		margin: 0;
		padding: 0;
		background-image: url(../wp-images/wordpress.gif);
		background-repeat: no-repeat;
		height: 60px;
		border-bottom: 1px solid #dcdcdc;
	}
	#logo a {
		display: block;
		height: 60px;
	}
	#logo a span {
		display: none;
	}
	p, li {
		line-height: 140%;
	}
    -->
	</style>
</head>
<body>
<h1 id="logo"><a href="http://wordpress.xwd.jp/"><span>WordPress Japan</span></a></h1>
<?php
// Let's check to make sure WP isn't already installed.

$wpdb->hide_errors();
$installed = $wpdb->get_results("SELECT * FROM $tableusers");
if ($installed) die(_LANG_INST_GUIDE_INSTALLED);
$wpdb->show_errors();
switch($step) {

	case 0:
	printf(_LANG_INST_GUIDE_WELCOM, phpversion());
	break;

	case 1:
?>
<h1>Step 1</h1>
<p><?php echo _LANG_INST_STEP1_FIRST; ?></p>
<?php

$got_links = false;
$got_cats = false;
$got_row = false;
?>
<?php echo_LANG_INST_STEP1_LINKS; ?>
<?php
$result = $wpdb->list_tables();
if (!$result) {
    print "DB Error, could not list tables\n";
    print 'PostgreSQL Error: ' .pg_result_error();
    exit;
}

while ($row = pg_fetch_row($result)) {
    if ($row[0] == $tablelinks)
        $got_links = true;
    if ($row[0] == $tablelinkcategories)
        $got_cats = true;
    //print "Table: $row[0]<br />\n";
}
if (!$got_cats) {
    echo "<p>Can't find table '$tablelinkcategories', gonna create it...</p>\n";
    $sql = " CREATE TABLE $tablelinkcategories ( " .
           " cat_id SERIAL, " .
           " cat_name TEXT NOT NULL, ".
           " auto_toggle CHAR(1) NOT NULL CHECK (auto_toggle IN ('Y', 'N')) DEFAULT 'N', ".
           " show_images CHAR(1) NOT NULL CHECK (show_images IN ('Y', 'N')) DEFAULT 'Y'," .
           " show_description CHAR(1) NOT NULL CHECK (show_description IN ('Y','N')) DEFAULT 'Y',   " .
           " show_rating CHAR(1) NOT NULL CHECK (show_rating IN ('Y','N')) DEFAULT 'Y',        " .
           " show_updated CHAR(1) NOT NULL CHECK (show_updated IN ('Y','N')) DEFAULT 'Y',       " .
           " sort_order varchar(64) NOT NULL default 'name',         " .
           " sort_desc CHAR(1) NOT NULL CHECK (sort_desc IN ('Y','N')) DEFAULT 'N',           " .
           " text_before_link VARCHAR(128) NOT NULL DEFAULT '<li>',  " .
           " text_after_link  VARCHAR(128) NOT NULL DEFAULT '<br />'," .
           " text_after_all   VARCHAR(128) NOT NULL DEFAULT '</li>',  " .
           " list_limit INTEGER NOT NULL DEFAULT -1,                     " .
           " PRIMARY KEY (cat_id) ".
           ");";

    $result = pg_query($sql) or print ("Can't create the table '$tablelinkcategories' in the database.<br />" . $sql . "<br />" . pg_result_error());
    if ($result != false) {
        echo "<p>Table '$tablelinkcategories' created OK</p>\n";
        $got_cats = true;
    }
} else {
    echo "<p>Found table '$tablelinkcategories', don't need to create it...</p>\n";
        $got_cats = true;
}
if (!$got_links) {
    echo "<p>Can't find '$tablelinks', gonna create it...</p>\n";
    $sql = "CREATE TABLE $tablelinks ( " .
	" link_id SERIAL,           " .
	" link_url VARCHAR(255) NOT NULL DEFAULT '',         " .
	" link_name VARCHAR(255) NOT NULL DEFAULT '',        " .
	" link_image VARCHAR(255) NOT NULL DEFAULT '',       " .
	" link_target VARCHAR(25) NOT NULL DEFAULT '',       " .
	" link_category INTEGER NOT NULL DEFAULT 0,          " .
	" link_description VARCHAR(255) NOT NULL DEFAULT '', " .
	" link_visible CHAR(1) NOT NULL CHECK (link_visible IN ('Y','N')) DEFAULT 'Y',  " .
	" link_owner INTEGER NOT NULL DEFAULT 1,               " .
	" link_rating INTEGER NOT NULL DEFAULT 0,              " .
	" link_updated TIMESTAMP NOT NULL DEFAULT 'epoch', " .
	" link_rel VARCHAR(255) NOT NULL DEFAULT '',         " .
	" link_notes TEXT NOT NULL DEFAULT '',         " .
	" PRIMARY KEY (link_id)                              " .
	"); ";
 $result = pg_query($sql) or print ("Can't create the table '$tablelinks' in the database.<br />" . $sql . "<br />" . pg_result_error());
   $links = $wpdb->query("INSERT INTO $tablelinks VALUES (DEFAULT, 'http://wordpress.org/', 'WordPress', '', '', 1, '', 'Y', 1, 0, 'epoch', '', '');");
   $links = $wpdb->query("INSERT INTO $tablelinks VALUES (DEFAULT, 'http://photomatt.net/', 'Matt', '', '', 1, '', 'Y', 1, 0, 'epoch', '', '');");
   $links = $wpdb->query("INSERT INTO $tablelinks VALUES (DEFAULT, 'http://zed1.com/journalized/', 'Mike', '', '', 1, '', 'Y', 1, 0, 'epoch', '', '');");
   $links = $wpdb->query("INSERT INTO $tablelinks VALUES (DEFAULT, 'http://www.alexking.org/', 'Alex', '', '', 1, '', 'Y', 1, 0, 'epoch', '', '');");
   $links = $wpdb->query("INSERT INTO $tablelinks VALUES (DEFAULT, 'http://dougal.gunters.org/', 'Dougal', '', '', 1, '', 'Y', 1, 0, 'epoch', '', '');");

    if ($result != false) {
        echo "<p>Table '$tablelinks' created OK</p>\n";
        $got_links = true;
    }
} else {
    echo "<p>Found table '$tablelinks', don't need to create it...</p>\n";
        $got_links = true;
}

if ($got_links && $got_cats) {
    echo "<p>Looking for category 1...</p>\n";
    $sql = "SELECT * FROM $tablelinkcategories WHERE cat_id=1 ";
    $result = pg_query($sql) or print ("Can't query '$tablelinkcategories'.<br />" . $sql . "<br />" . pg_result_error());
    if ($result != false) {
        if ($row = pg_fetch_object($result)) {
            echo "<p>You have at least 1 category. Good!</p>\n";
            $got_row = true;
        } else {
            echo "<p>Gonna insert category 1...</p>\n";
            $sql = "INSERT INTO $tablelinkcategories (cat_id, cat_name) VALUES (DEFAULT, 'Links')";
            $result = $wpdb->query($sql) or print ("Can't query insert category.<br />" . $sql . "<br />" . pg_result_error());
            if ($result != false) {
                echo "<p>Inserted category Ok</p>\n";
                $got_row = true;
            }
        }
    }
}

if ($got_row) {
    echo "<p>All done!</p>\n";
}
?>
<p><?php echo _LANG_INST_STEP1_ALLDONE; ?></p>
<?php
	break;
	case 2:
?>
<h1>Step 2</h1>
<p><?php echo _LANG_INST_STEP2_INFO; ?></p>

<?php
# Note: if you want to start again with a clean b2 database,
#       just remove the // in this file

// $query = "DROP TABLE IF EXISTS $tableposts";
// $q = mysql_query($query) or die ("doh, can't drop the table \"$tableposts\" in the database.");

$query = "
BEGIN;
CREATE TABLE $tableposts (
  ID SERIAL,
  post_author INTEGER NOT NULL DEFAULT 0,
  post_date TIMESTAMP NOT NULL DEFAULT 'epoch',
  post_date_gmt TIMESTAMP NOT NULL DEFAULT 'epoch',
  post_content TEXT NOT NULL DEFAULT '',
  post_title TEXT NOT NULL DEFAULT '',
  post_category INTEGER NOT NULL default 0,
  post_excerpt TEXT NOT NULL DEFAULT '',
  post_lat FLOAT,
  post_lon FLOAT,
  post_status VARCHAR(7) NOT NULL CHECK (post_status IN ('publish','draft','private')) DEFAULT 'publish',
  comment_status VARCHAR(6) NOT NULL CHECK (comment_status IN ('open','closed')) DEFAULT 'open',
  ping_status VARCHAR(6) NOT NULL CHECK (ping_status IN ('open','closed')) DEFAULT 'open',
  post_password VARCHAR(20) NOT NULL DEFAULT '',
  post_name VARCHAR(200) NOT NULL DEFAULT '',
  to_ping TEXT NOT NULL DEFAULT '',
  pinged TEXT NOT NULL DEFAULT '',
  post_modified TIMESTAMP NOT NULL DEFAULT 'epoch',
  post_modified_gmt TIMESTAMP NOT NULL DEFAULT 'epoch',
  post_content_filtered TEXT NOT NULL DEFAULT '',
  PRIMARY KEY  (ID)
);
CREATE INDEX ${tableposts}_date_idx ON ".$tableposts."(post_date);
CREATE INDEX ${tableposts}_date_gmt_idx ON ".$tableposts."(post_date_gmt);
CREATE INDEX ${tableposts}_name_idx ON ".$tableposts."(post_name);
CREATE INDEX ${tableposts}_status_idx ON ".$tableposts."(post_status);
COMMIT;
";
$q = $wpdb->query($query);

?>

<p>The first table has been created! ...</p>

<?php
$now = date('Y-m-d H:i:s');
$now_gmt = gmdate('Y-m-d H:i:s');
$query = "INSERT INTO $tableposts (post_author, post_date, post_date_gmt, post_content, post_title, post_modified, post_modified_gmt) VALUES ('1', '$now', '$now_gmt', 'Welcome to WordPress ME. This is the first post. Edit or delete it, then start blogging!

<ul><li><a href=\"http://tekapo.com/wp_docs/readme1.2.ja.html\">Japanese Help</a></li><li><a href=\"http://phpbb.xwd.jp/\">Japanese Forum</a></li><li><a href=\"http://wordpress.xwd.jp/wiki/\">Japanese Documentation</a></li></ul>', 'We will rock you!', '$now', '$now_gmt')";

$q = $wpdb->query($query);
?>

<p>The test post has been inserted correctly...</p>

<?php
// $query = "DROP TABLE IF EXISTS $tablecategories";
// $q = mysql_query($query) or mysql_doh("doh, can't drop the table \"$tablecategories\" in the database.");

$query = "CREATE TABLE $tablecategories (
  cat_ID SERIAL,
  cat_name VARCHAR(55) NOT NULL UNIQUE DEFAULT '',
  PRIMARY KEY  (cat_ID)
);";
$q = $wpdb->query($query);

$query = "INSERT INTO $tablecategories (cat_ID, cat_name) VALUES (DEFAULT, 'General')";
$q = $wpdb->query($query);

$query = "UPDATE $tableposts SET post_category = 1";
$result = $wpdb->query($query);
?>

<p>Categories are up and running...</p>

<?php
// $query = "DROP TABLE IF EXISTS $tablecomments";
// $q = mysql_query($query) or mysql_doh("doh, can't drop the table \"$tablecomments\" in the database.");

$query = "
CREATE TABLE $tablecomments (
  comment_ID SERIAL,
  comment_post_ID INTEGER NOT NULL default 0 REFERENCES $tableposts (id),
  comment_author TEXT NOT NULL DEFAULT '',
  comment_author_email VARCHAR(100) NOT NULL DEFAULT '',
  comment_author_url VARCHAR(200) NOT NULL DEFAULT '',
  comment_author_ip inet,
  comment_date TIMESTAMP NOT NULL DEFAULT 'epoch',
  comment_date_gmt TIMESTAMP NOT NULL DEFAULT 'epoch',
  comment_content TEXT NOT NULL DEFAULT '',
  comment_karma INTEGER NOT NULL DEFAULT 0,
  PRIMARY KEY  (comment_ID)
);
";
$q = $wpdb->query($query);

$now = date('Y-m-d H:i:s');
$now_gmt = gmdate('Y-m-d H:i:s');
$query = "INSERT INTO $tablecomments (comment_post_ID, comment_author, comment_author_email, comment_author_url, comment_author_ip, comment_date, comment_date_gmt, comment_content) VALUES ('1', 'Mr WordPress', 'mr@wordpress.org', 'http://wordpress.org', '127.0.0.1', '$now', '$now_gmt', 'Hi, this is a comment.<br />To delete a comment, just log in, and view the posts\' comments, there you will have the option to edit or delete them.')";

$q = $wpdb->query($query);
?>

<p>Comments are groovy...</p>

<?php
$query = "
        BEGIN;
	CREATE TABLE $tablepostmeta (
	  meta_id SERIAL,
	  post_id INTEGER NOT NULL DEFAULT 0 REFERENCES $tableposts (id),
	  meta_key VARCHAR(255),
	  meta_value TEXT,
	  PRIMARY KEY (meta_id)
	);
	CREATE INDEX ${tablepostmeta}_post_id_idx ON ".$tablepostmeta."(post_id);
	CREATE INDEX ${tablepostmeta}_meta_key_idx ON ".$tablepostmeta."(meta_key);
	COMMIT;
	";

$q = $wpdb->query($query);


?>

<p>Post metadata table ready to go...</p>

<?php
// $query = "DROP TABLE IF EXISTS $tableoptions";
// $q = mysql_query($query) or mysql_doh("doh, can't drop the table \"$tableoptions\" in the database.");

$query = "
CREATE TABLE $tableoptions (
  option_id SERIAL,
  blog_id INTEGER NOT NULL DEFAULT 0,
  option_name VARCHAR(64) NOT NULL default '',
  option_can_override CHAR(1) NOT NULL CHECK (option_can_override IN ('Y','N')) DEFAULT 'Y',
  option_type INTEGER NOT NULL DEFAULT 1,
  option_value VARCHAR(255) NOT NULL DEFAULT '',
  option_width INTEGER NOT NULL DEFAULT 20,
  option_height INTEGER NOT NULL DEFAULT 8,
  option_description TEXT NOT NULL DEFAULT '',
  option_admin_level INTEGER NOT NULL DEFAULT '1',
  PRIMARY KEY (option_id, blog_id, option_name)
);
";
$q = $wpdb->query($query);

// $query = "DROP TABLE IF EXISTS $tableoptiontypes";
// $q = mysql_query($query) or mysql_doh("doh, can't drop the table \"$tableoptiontypes\" in the database.");

$query = "
CREATE TABLE $tableoptiontypes (
  optiontype_id SERIAL,
  optiontype_name VARCHAR(64) NOT NULL,
  PRIMARY KEY (optiontype_id)
)
";
$q = $wpdb->query($query);


// $query = "DROP TABLE IF EXISTS $tableoptiongroups";
// $q = mysql_query($query) or mysql_doh("doh, can't drop the table \"$tableoptiongroups\" in the database.");

$query = "
CREATE TABLE $tableoptiongroups (
  group_id SERIAL,
  group_name VARCHAR(64) NOT NULL,
  group_desc VARCHAR(255),
  group_longdesc TEXT,
  PRIMARY KEY (group_id)
)
";
$q = $wpdb->query($query);


// $query = "DROP TABLE IF EXISTS $tableoptiongroup_options";
// $q = mysql_query($query) or mysql_doh("doh, can't drop the table \"$tableoptiongroup_options\" in the database.");

$query = "
CREATE TABLE $tableoptiongroup_options (
  group_id INTEGER NOT NULL REFERENCES $tableoptiongroups,
  option_id INTEGER NOT NULL,
  seq INTEGER NOT NULL,
  PRIMARY KEY (group_id, option_id)
)
";
$q = $wpdb->query($query);


// $query = "DROP TABLE IF EXISTS $tableoptionvalues";
// $q = mysql_query($query) or mysql_doh("doh, can't drop the table \"$tableoptionvalues\" in the database.");

$query = "
BEGIN;
CREATE TABLE $tableoptionvalues (
  option_id INTEGER NOT NULL,
  optionvalue TEXT,
  optionvalue_desc VARCHAR(255),
  optionvalue_max INTEGER,
  optionvalue_min INTEGER,
  optionvalue_seq INTEGER,
  UNIQUE (option_id, optionvalue)
);
CREATE INDEX ${tableoptionvalues}_option_val_seq_idx ON ".$tableoptionvalues."(option_id, optionvalue_seq);
COMMIT;
";
$q = $wpdb->query($query);

?>

<p>Option Tables created okay.</p>

<?php

$option_data = array(
 "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES (DEFAULT, 'integer')",
 "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES (DEFAULT, 'boolean')",
 "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES (DEFAULT, 'string')",
 "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES (DEFAULT, 'date')",
 "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES (DEFAULT, 'select')",
 "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES (DEFAULT, 'range')",
 "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES (DEFAULT, 'sqlselect')",
 "INSERT INTO $tableoptiontypes (optiontype_id, optiontype_name) VALUES (DEFAULT, 'float')",
 
 //base options from b2cofig
 "INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(1, 'siteurl', 3, 'http://example.com', 'siteurl is your blog\'s URL: for example, \'http://example.com/wordpress\' (no trailing slash !)', 8, 30)",
 "INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(2, 'blogfilename', 3, 'index.php', 'blogfilename is the name of the default file for your blog', 8, 20)",
 "INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(3, 'blogname', 3, 'my weblog', 'blogname is the name of your blog', 8, 20)",
 "INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(4, 'blogdescription', 3, 'babblings!', 'blogdescription is the description of your blog', 8, 40)",
 //"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(6,'search_engine_friendly_urls', 2, '0', 'Querystring Configuration ** (don\'t change if you don\'t know what you\'re doing)', 8, 20)",
 "INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(7, 'new_users_can_blog', 2, '0', 'whether you want new users to be able to post entries once they have registered', 8, 20)",
 "INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(8, 'users_can_register', 2, '1', 'whether you want to allow users to register on your blog', 8, 20)",
 "INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(54, 'admin_email', 3, 'you@example.com', 'Your email (obvious eh?)', 8, 20)",

"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level) VALUES (93, 'blog_charset', 3, 'EUC-JP', 'Your blog&#8217;s charset (here&#8217;s a <a href=\'http://developer.apple.com/documentation/macos8/TextIntlSvcs/TextEncodingConversionManager/TEC1.5/TEC.b0.html\'>list of possible charsets</a>)', 8)",
// general blog setup
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(9 ,'start_of_week', 5, '1', 'day at the start of the week', 8, 20)",
//"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(10,'use_preview', 2, '1', 'Do you want to use the \'preview\' function', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(14,'use_htmltrans', 2, '0', 'IMPORTANT! set this to false if you are using Chinese, Japanese, Korean, or other double-bytes languages', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(15,'use_balanceTags', 2, '1', 'this could help balance your HTML code. if it gives bad results, set it to false', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(16,'use_smilies', 2, '1', 'set this to 1 to enable smiley conversion in posts (note: this makes smiley conversion in ALL posts)', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(18,'require_name_email', 2, '0', 'set this to true to require e-mail and name, or false to allow comments without e-mail/name', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(20,'comments_notify', 2, '1', 'set this to true to let every author be notified about comments on their posts', 8, 20)",
//rss/rdf feeds
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(21,'posts_per_rss', 1, '10', 'number of last posts to syndicate', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(22,'rss_language', 3, 'en', 'the language of your blog ( see this: http://backend.userland.com/stories/storyReader$16 )', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(23,'rss_encoded_html', 2, '0', 'for b2rss.php: allow encoded HTML in &lt;description> tag?', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(24,'rss_excerpt_length', 1, '50', 'length (in words) of excerpts in the RSS feed? 0=unlimited note: in b2rss.php, this will be set to 0 if you use encoded HTML', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(25,'rss_use_excerpt', 2, '1', 'use the excerpt field for rss feed.', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(29,'use_trackback', 2, '1', 'set this to 0 or 1, whether you want to allow your posts to be trackback\'able or not note: setting it to zero would also disable sending trackbacks', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(30,'use_pingback', 2, '1', 'set this to 0 or 1, whether you want to allow your posts to be pingback\'able or not note: setting it to zero would also disable sending pingbacks', 8, 20)",
//file upload
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(31,'use_fileupload', 2, '0', 'set this to false to disable file upload, or true to enable it', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(32,'fileupload_realpath', 3, '/home/your/site/wordpress/images', 'enter the real path of the directory where you\'ll upload the pictures \nif you\'re unsure about what your real path is, please ask your host\'s support staff \nnote that the  directory must be writable by the webserver (chmod 766) \nnote for windows-servers users: use forwardslashes instead of backslashes', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(33,'fileupload_url', 3, 'http://example.com/images', 'enter the URL of that directory (it\'s used to generate the links to the uploded files)', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(34,'fileupload_allowedtypes', 3, 'jpg jpeg gif png', 'accepted file types, separated by spaces. example: \'jpg gif png\'', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(35,'fileupload_maxk', 1, '96', 'by default, most servers limit the size of uploads to 2048 KB, if you want to set it to a lower value, here it is (you cannot set a higher value than your server limit)', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(36,'fileupload_minlevel', 1, '4', 'you may not want all users to upload pictures/files, so you can set a minimum level for this', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(37,'fileupload_allowedusers', 3, '', '...or you may authorize only some users. enter their logins here, separated by spaces. if you leave this variable blank, all users who have the minimum level are authorized to upload. example: \'barbara anne george\'', 8, 30)",
// email settings
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(38,'mailserver_url', 3, 'mail.example.com', 'mailserver settings', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(39,'mailserver_login', 3, 'login@example.com', 'mailserver settings', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(40,'mailserver_pass', 3, 'password', 'mailserver settings', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(41,'mailserver_port', 1, '110', 'mailserver settings', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(42,'default_category', 1, '1', 'by default posts will have this category', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(46,'use_phoneemail', 2, '0', 'some mobile phone email services will send identical subject & content on the same line if you use such a service, set use_phoneemail to true, and indicate a separator string', 8, 20)",
// original options from options page
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(48,'posts_per_page', 1, '20','How many posts/days to show on the index page.', 4, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(49,'what_to_show', 5, 'posts','Posts, days, or posts paged', 4, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(50,'archive_mode', 5, 'monthly','Which \'unit\' to use for archives.', 4, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(51,'time_difference', 6, '0', 'if you\'re not on the timezone of your server', 4, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(52,'date_format', 3, 'Y/n/j l', 'see note for format characters', 4, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(53,'time_format', 3, 'G:i', 'see note for format characters', 4, 20)",
       "SELECT setval('${tableoptions}_option_id_seq', MAX(${tableoptions}.option_id))",

//'pages' of options
"INSERT INTO $tableoptiongroups (group_id,  group_name, group_desc) VALUES(DEFAULT, 'Other Options', 'Posts per page etc. Original options page')",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(1,48,1 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(1,49,2 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(1,50,3 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(1,51,4 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(1,52,5 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(1,53,6 )",

"INSERT INTO $tableoptiongroups (group_id,  group_name, group_desc) VALUES(DEFAULT, 'General blog settings', 'Things you\'ll probably want to tweak')",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(2,9 ,1 )",
//"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(2,10,2 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(2,11,3 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(2,12,4 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(2,13,5 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(2,14,6 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(2,15,7 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(2,16,8 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(2,17,9 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(2,18,10)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(2,19,11)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(2,20,12)",

"INSERT INTO $tableoptiongroups (group_id,  group_name, group_desc) VALUES(DEFAULT, 'RSS/RDF Feeds, Track/Ping-backs', 'Settings for RSS/RDF Feeds, Track/ping-backs')",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(3,21,1 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(3,22,2 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(3,23,3 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(3,24,4 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(3,25,5 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(3,26,6 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(3,27,7 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(3,28,8 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(3,29,9 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(3,30,10)",

"INSERT INTO $tableoptiongroups (group_id,  group_name, group_desc) VALUES(DEFAULT, 'File uploads', 'Settings for file uploads')",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(4,31,1 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(4,32,2 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(4,33,3 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(4,34,4 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(4,35,5 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(4,36,6 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(4,37,7 )",

"INSERT INTO $tableoptiongroups (group_id,  group_name, group_desc) VALUES(DEFAULT, 'Blog-by-Email settings', 'Settings for blogging via email')",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(5,38,1 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(5,39,2 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(5,40,3 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(5,41,4 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(5,42,5 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(5,43,6 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(5,44,7 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(5,45,8 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(5,46,9 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(5,47,10)",

"INSERT INTO $tableoptiongroups (group_id,  group_name, group_desc) VALUES(DEFAULT, 'Base settings', 'Basic settings required to get your blog working')",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(6,1,1)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(6,2,2)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(6,3,3)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(6,4,4)",
//"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(6,6,5)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(6,7,6)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(6,8,7)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(6,54,8)",

// select data for what to show
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (49, 'days',  'days',        null,null,1)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (49, 'posts', 'posts',       null,null,2)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (49, 'paged', 'posts paged', null,null,3)",
// select data for archive mode
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (50, 'daily',     'daily',       null,null,1)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (50, 'weekly',    'weekly',      null,null,2)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (50, 'monthly',   'monthly',     null,null,3)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (50, 'postbypost','post by post',null,null,4)",
// select data for time diff
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (51, 'hours', 'hours', 23, -23, null)",
// select data for start of week
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (9, '0', 'Sunday',   null,null,1)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (9, '1', 'Monday',   null,null,2)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (9, '6', 'Saturday', null,null,3)",


// Add in a new page for POST DEFAULTS

// default_post_status  select one of publish draft private
// default_comment_status select one of open closed
// default_ping_status select one of open closed
// default_pingback_flag select one of checked unchecked
// default_post_category sql_select "SELECT cat_id AS value, cat_name AS label FROM $tablecategories order by cat_name"

"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(55,'default_post_status',    5, 'publish', 'The default state of each new post', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(56,'default_comment_status', 5, 'open', 'The default state of comments for each new post', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(57,'default_ping_status',    5, 'open', 'The default ping state for each new post', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(58,'default_pingback_flag',  5, '1', 'Whether the \'PingBack the URLs in this post\' checkbox should be checked by default', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(59,'default_post_category',  7, '1', 'The default category for each new post', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(83,'default_post_edit_rows', 1, '9', 'The number of rows in the edit post form (min 3, max 100)', 8, 5)",

"INSERT INTO $tableoptiongroups (group_id,  group_name, group_desc) VALUES(DEFAULT, 'Default post options', 'Default settings for new posts.')",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(7,55,1 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(7,56,2 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(7,57,3 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(7,58,4 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(7,59,5 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(7,83,5 )",

// select data for post_status
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (55, 'publish', 'Publish', null,null,1)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (55, 'draft',   'Draft',   null,null,2)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (55, 'private', 'Private', null,null,3)",

// select data for comment_status
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (56, 'open', 'Open',   null,null,1)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (56, 'closed', 'Closed', null,null,2)",

// select data for ping_status (aargh duplication!)
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (57, 'open', 'Open',   null,null,1)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (57, 'closed', 'Closed', null,null,2)",

// select data for pingback flag
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (58, '1', 'Checked',   null,null,1)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (58, '0', 'Unchecked', null,null,2)",

// sql select data for default
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (59, 'SELECT cat_id AS value, cat_name AS label FROM $tablecategories order by cat_name', '', null,null,1)",
);

foreach ($option_data as $query) {
    $q = $wpdb->query($query);
}
$wpdb->query("SELECT setval('${tableoptions}_option_id_seq', MAX(${tableoptions}.option_id))");

?>

<p>Option Data inserted okay.</p>


<?php
$links_option_data = array(
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(60,'links_minadminlevel',    1, '5', 'The minimum admin level to edit links', 8, 10)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(61,'links_use_adminlevels',  2, '1', 'set this to false to have all links visible and editable to everyone in the link manager', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(62,'links_rating_type',      5, 'image', 'Set this to the type of rating indication you wish to use', 8, 10)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(63,'links_rating_char',      3, '*', 'If we are set to \'char\' which char to use.', 8, 5)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(64,'links_rating_ignore_zero', 2, '1', 'What do we do with a value of zero? set this to true to output nothing, 0 to output as normal (number/image)', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(65,'links_rating_single_image',  2, '1', 'Use the same image for each rating point? (Uses links_rating_image[0])', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(66,'links_rating_image0',  3, 'wp-links/links-images/tick.png', 'Image for rating 0 (and for single image)', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(67,'links_rating_image1',  3, 'wp-links/links-images/rating-1.gif', 'Image for rating 1', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(68,'links_rating_image2',  3, 'wp-links/links-images/rating-2.gif', 'Image for rating 2', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(69,'links_rating_image3',  3, 'wp-links/links-images/rating-3.gif', 'Image for rating 3', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(70,'links_rating_image4',  3, 'wp-links/links-images/rating-4.gif', 'Image for rating 4', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(71,'links_rating_image5',  3, 'wp-links/links-images/rating-5.gif', 'Image for rating 5', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(72,'links_rating_image6',  3, 'wp-links/links-images/rating-6.gif', 'Image for rating 6', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(73,'links_rating_image7',  3, 'wp-links/links-images/rating-7.gif', 'Image for rating 7', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(74,'links_rating_image8',  3, 'wp-links/links-images/rating-8.gif', 'Image for rating 8', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(75,'links_rating_image9',  3, 'wp-links/links-images/rating-9.gif', 'Image for rating 9', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(77,'weblogs_xml_url',      3, 'http://www.weblogs.com/changes.xml', 'Which file to grab from weblogs.com', 8, 40)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(78,'weblogs_cacheminutes', 1, '60', 'cache time in minutes (if it is older than this get a new copy)', 8, 10)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(79,'links_updated_date_format',  3, 'd/m/Y h:i', 'The date format for the updated tooltip', 8, 25)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(80,'links_recently_updated_prepend',  3, '&gt;&gt;', 'The text to prepend to a recently updated link', 8, 10)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(81,'links_recently_updated_append',  3, '&lt;&lt;', 'The text to append to a recently updated link', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(82,'links_recently_updated_time',  1, '120', 'The time in minutes to consider a link recently updated', 8, 20)",

//group them together
"INSERT INTO $tableoptiongroups (group_id,  group_name, group_desc) VALUES(8, 'Link Manager Settings', 'Various settings for the link manager.')",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,60,1 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,61,2 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,62,3 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,63,4 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,64,5 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,65,6 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,66,7 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,67,8 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,68,9 )",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,69,10)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,70,11)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,71,12)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,72,13)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,73,14)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,74,15)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,75,16)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,76,17)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,77,18)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,78,19)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,79,20)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,80,21)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,81,22)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(8,82,23)",

// select data for rating_type
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (62, 'number', 'Number',    null,null,1)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (62, 'char',   'Character', null,null,2)",
"INSERT INTO $tableoptionvalues (option_id, optionvalue, optionvalue_desc, optionvalue_max, optionvalue_min, optionvalue_seq) VALUES (62, 'image',  'Image',     null,null,3)",
);

foreach ($links_option_data as $query) {
    $q = $wpdb->query($query);
}
$wpdb->query("SELECT setval('${tableoptions}_option_id_seq', MAX(${tableoptions}.option_id))");
?>

<p>Links option data inserted okay.</p>

<?php
$geo_option_data = array(
// data for geo settings
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(84,'use_geo_positions', 2, '0', 'Turns on the geo url features of WordPress', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(85,'use_default_geourl', 2, '1','enables placement of default GeoURL ICBM location even when no other specified', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(86,'default_geourl_lat ', 8, 0.0, 'The default Latitude ICBM value - <a href=\"http://www.geourl.org/resources.html\" target=\"_blank\">see here</a>', 8, 20)",
"INSERT INTO $tableoptions (option_id, option_name, option_type, option_value, option_description, option_admin_level, option_width) VALUES(87,'default_geourl_lon', 8, 0.0, 'The default Longitude ICBM value', 8, 20)",

"INSERT INTO $tableoptiongroups (group_id, group_name, group_desc) VALUES(9,'Geo Options', 'Settings which control the posting and display of Geo Options')",

"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(9,84,1)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(9,85,1)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(9,86,1)",
"INSERT INTO $tableoptiongroup_options (group_id, option_id, seq) VALUES(9,87,1)",

);

foreach ($geo_option_data as $query) {
    $q = $wpdb->query($query);
}
$wpdb->query("SELECT setval('${tableoptions}_option_id_seq', MAX(${tableoptions}.option_id))");
?>

<p>Geo option data inserted okay.</p>


<p><?php echo _LANG_INST_STEP2_LAST; ?></p>
<form action="install.php?step=3" method="post">
<input type="hidden" name="step" value="3" />
<p><?php echo _LANG_INST_STEP2_URL; ?><br />
<?php
$guessurl = str_replace('/wp-admin/install.php?step=2', '', 'http://' . $HTTP_HOST . $REQUEST_URI);
?>
  <input name="url" type="text" size="60" value="<?php echo $guessurl; ?>" />
</p>
<p>
    <input type="submit" value="Step 3..." />
</p>
</form>

<?php
	break;
	case 3:
?>
<h1>Step 3</h1>


<?php
$url = $_REQUEST['url'];
if (isset($url)) {
    $query= "UPDATE $tableoptions set option_value='$url' where option_id=1"; //siteurl
    $q = $wpdb->query($query);
}

// $query = "DROP TABLE IF EXISTS $tableusers";
// $q = mysql_query($query) or mysql_doh("doh, can't drop the table \"$tableusers\" in the database.");

$query = "
BEGIN;
CREATE TABLE $tableusers (
  ID SERIAL,
  user_login VARCHAR(20) NOT NULL DEFAULT '',
  user_pass VARCHAR(64) NOT NULL DEFAULT '',
  user_firstname VARCHAR(50) NOT NULL DEFAULT '',
  user_lastname VARCHAR(50) NOT NULL DEFAULT '',
  user_nickname VARCHAR(50) NOT NULL DEFAULT '',
  user_icq INTEGER NOT NULL DEFAULT 0,
  user_email VARCHAR(100) NOT NULL DEFAULT '',
  user_url VARCHAR(100) NOT NULL DEFAULT '',
  user_ip VARCHAR(15) NOT NULL DEFAULT '',
  user_domain VARCHAR(200) NOT NULL DEFAULT '',
  user_browser VARCHAR(200) NOT NULL DEFAULT '',
  dateYMDhour TIMESTAMP NOT NULL default 'epoch',
  user_level INTEGER NOT NULL DEFAULT 0,
  user_aim VARCHAR(50) NOT NULL DEFAULT '',
  user_msn VARCHAR(100) NOT NULL DEFAULT '',
  user_yim VARCHAR(50) NOT NULL DEFAULT '',
  user_idmode VARCHAR(20) NOT NULL DEFAULT '',
  PRIMARY KEY  (ID),
  UNIQUE (user_login)
);
CREATE INDEX ${tableusers}_user_login_idx ON ".$tableusers."(user_login);
COMMIT;
";
$q = $wpdb->query($query);

$random_password = substr(md5(uniqid(microtime())),0,6);

$query = "INSERT INTO $tableusers (user_login, user_pass, user_firstname, user_lastname, user_nickname, user_icq, user_email, user_url, user_ip, user_domain, user_browser, dateYMDhour, user_level, user_aim, user_msn, user_yim, user_idmode) VALUES ('admin', MD5('$random_password'), '', '', 'site admin', '0', '$admin_email', '', '127.0.0.1', '127.0.0.1', '', 'epoch', '10', '', '', '', 'nickname')";
$q = $wpdb->query($query);

// Do final updates
upgrade_all();
fix_sequences();
?>

<p>User setup successful!</p>
<?php printf(_LANG_INST_STEP3_SETUP, $random_password); ?>
<p><?php echo _LANG_INST_STEP3_DONE; ?></p>
<p><?php echo _LANG_INST_CAUTIONS; ?></p>
<?php
	break;
}
?>
</body>
</html>
