<?php
// ------------------------------------------------------------------------- //
//                XOOPS - PHP Content Management System                      //
//                       <http://www.xoops.org/>                             //
// ------------------------------------------------------------------------- //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
// ------------------------------------------------------------------------- //


function install_header(){
    ?>
	<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
	<html>
	<head>
	<title>XOOPS Custom Installation</title>
	<meta http-equiv="Content-Type" content="text/html; charset=<?php echo _CHARSET;?>">
	<meta name="AUTHOR" content="XOOPS">
	<meta name="GENERATOR" content="XOOPS-- http://www.xoops.org/">
	<style type='text/css' media='all'><!-- @import url(xoops.css); --></style>
	<link rel='stylesheet' type='text/css' media='all' href='install/style.css' />
	</head>
	<body>
	<div style='text-align:center'><img src='images/logo.gif' /><h3>XOOPS Installation</h3></div><br />
<?php
}

function install_footer(){
    ?>
	<br /><br /><div style='text-align:center'><small>Install.php v1.1 for XOOPS</small><br /><br /><a href='http://www.xoops.org/'><img src='images/s_poweredby.gif' alt='XOOPS' /></a></div>
	</body>
	</html>
<?php
}
$op = "langselect";

if ( isset($HTTP_POST_VARS) ) {
	foreach ($HTTP_POST_VARS as $k=>$v) {
		$$k = $v;
	}
}
if ( !empty($lang) ) {
	setcookie("install_lang", $lang);
	$language = $lang;
} else {
	$language = isset($HTTP_COOKIE_VARS['install_lang']) ? $HTTP_COOKIE_VARS['install_lang'] : "english";
}
include_once("modules/system/cache/config.php");
if ( file_exists("language/".$language."/global.php") ) {
	include_once("language/".$language."/global.php");
} elseif ( file_exists("language/english/global.php") ) {
	include_once("language/english/global.php");
}
if ( file_exists("install/language/".$language."/install.php") ) {
	include_once("install/language/".$language."/install.php");
} elseif ( file_exists("install/language/english/install.php") ) {
	include_once("install/language/english/install.php");
}
include_once("class/module.textsanitizer.php");
$myts = new MyTextSanitizer();

//echo $language;
if ( $op == "langselect" ) {
	include_once("class/xoopslists.php");
	install_header();
	echo "<div style='text-align:center;'><h4>"._INSTALL_L0."</h4>
	<table width='70%'><tr><td align='center'>";
	$langarr = XoopsLists::getDirListAsArray("./install/language/");
	echo "Choose language to be used for the installation process<br />
	<form action='install.php' method='post'><select name='lang'>";
	foreach ($langarr as $lang) {
		echo "<option value='".$lang."'>".$lang."</option>";
	}
	echo "</select>&nbsp;<input type='hidden' name='op' value='start' />
	<input type='submit' value='"._INSTALL_L14."' />
	</form>";
	echo "</td></tr></table></div>";
	install_footer();
	exit();
}

if ( $op == "start" ) {
	install_header();
	echo "<div style='text-align:center;'><h4>"._INSTALL_L0."</h4>
	<table width='70%'><tr><td align='center'>";
	@chmod("mainfile.php", 0777);
	if ( !is_writeable("mainfile.php") ) {
		echo _INSTALL_L70;
	} else {
		echo _INSTALL_L71."<br />
		<form action='install.php' method='post'>
		<input type='hidden' name='op' value='dbform' />
		<input type='submit' value='"._INSTALL_L14."' />
		</form>";
	}
	echo "</td></tr></table></div>";
	install_footer();
	exit();
}


if ( $op == "dbform" ) {
	define("XOOPS_ROOT_PATH", ".");
	include("class/xoopsformloader.php");
	$filepath = (!empty($REQUEST_URI)) ? dirname($REQUEST_URI) : dirname($SCRIPT_NAME);
	$filepath = str_replace("\\", "/", $filepath);
	if ( substr($filepath, 0, 1) == "/" ) {
		$filepath = substr($filepath,1);
	}
	if ( substr($filepath, -1) == "/" ) {
		$filepath = substr($filepath, 0, -1);
	}
	$xoops_url = !empty($filepath) ? "http://".$HTTP_HOST."/".$filepath : "http://".$HTTP_HOST;
	$root_path = str_replace("\\","/",getcwd());
	$dbhost = "localhost";
	$prefix = "xoops";
	$db_pconnect = 1;
	install_header();
	include("install/dbform.php");
	install_footer();
	exit();
}
if ( $op == "dbconfirm" ) {
	install_header();
	$error = array();
	if ( empty($dbhost) ) {
		$error[] = sprintf(_INSTALL_L57, "<b>"._INSTALL_L27."</b>");
	}
	if ( empty($dbname) ) {
		$error[] = sprintf(_INSTALL_L57, "<b>"._INSTALL_L29."</b>");
	}
	if ( empty($prefix) ) {
		$error[] = sprintf(_INSTALL_L57, "<b>"._INSTALL_L30."</b>");
	}
	if ( empty($root_path) ) {
		$error[] = sprintf(_INSTALL_L57, "<b>"._INSTALL_L55."</b>");
	}
	if ( empty($xoops_url) ) {
		$error[] = sprintf(_INSTALL_L57, "<b>"._INSTALL_L56."</b>");
	}
	if (!empty($error)) {
		foreach ( $error as $err ) {
			echo "<span style='color:#ff0000;'>".$err."</span><br />";
		}
		define("XOOPS_ROOT_PATH", ".");
		include("class/xoopsformloader.php");
		include("install/dbform.php");
		install_footer();
		exit();
	}
	echo "<h4 style='text-align:left;'>"._INSTALL_L53."</h4>
	<form action='install.php' method='post'>
	<table border='0' cellpadding='0' cellspacing='0' valign='top' width='100%'><tr><td class='bg2'>
	<table width='100%' border='0' cellpadding='4' cellspacing='1'>
	<tr><td class='bg3'><b>"._INSTALL_L51."</b></td><td class='bg1'>".$myts->makeTboxData4Preview($database)."</td></tr>
	<tr><td class='bg3'><b>"._INSTALL_L27."</b></td><td class='bg1'>".$myts->makeTboxData4Preview($dbhost)."</td></tr>
	<tr><td class='bg3'><b>"._INSTALL_L28."</b></td><td class='bg1'>".$myts->makeTboxData4Preview($dbuname)."</td></tr>
	<tr><td class='bg3'><b>"._INSTALL_L52."</b></td><td class='bg1'>".$myts->makeTboxData4Preview($dbpass)."</td></tr>
	<tr><td class='bg3'><b>"._INSTALL_L29."</b></td><td class='bg1'>".$myts->makeTboxData4Preview($dbname)."</td></tr>
	<tr><td class='bg3'><b>"._INSTALL_L30."</b></td><td class='bg1'>".$myts->makeTboxData4Preview($prefix)."</td></tr>
	";
	$yesno = empty($db_pconnect) ? _INSTALL_L24 : _INSTALL_L23;
	echo "<tr><td class='bg3'><b>"._INSTALL_L54."</b></td><td class='bg1'>".$yesno."</td></tr>
	<tr><td class='bg3'><b>"._INSTALL_L55."</b></td><td class='bg1'>".$root_path."</td></tr>
	<tr><td class='bg3'><b>"._INSTALL_L56."</b></td><td class='bg1'>".$xoops_url."</td></tr>
	<tr><td class='bg3'>&nbsp;</td><td class='bg1'>
	<input type='hidden' name='database' value='".$myts->makeTboxData4PreviewInForm($database)."' />
	<input type='hidden' name='dbhost' value='".$myts->makeTboxData4PreviewInForm($dbhost)."' />
	<input type='hidden' name='dbuname' value='".$myts->makeTboxData4PreviewInForm($dbuname)."' />
	<input type='hidden' name='dbpass' value='".$myts->makeTboxData4PreviewInForm($dbpass)."' />
	<input type='hidden' name='dbname' value='".$myts->makeTboxData4PreviewInForm($dbname)."' />
	<input type='hidden' name='prefix' value='".$myts->makeTboxData4PreviewInForm($prefix)."' />
	<input type='hidden' name='db_pconnect' value='".intval($db_pconnect)."' />
	<input type='hidden' name='root_path' value='".$myts->makeTboxData4PreviewInForm($root_path)."' />
	<input type='hidden' name='xoops_url' value='".$myts->makeTboxData4PreviewInForm($xoops_url)."' />
	<input type='hidden' name='op' value='dbsave' />
	<input type='submit' value='"._INSTALL_L47."' />&nbsp;<input type='button' value='"._INSTALL_L42."' onclick='javascript:history.go(-1);' />
	</td></tr></table></td></tr></table>
	</form>";
	install_footer();
	exit();
}

if ( $op == "dbsave" ) {
	install_header();
	$content = "<"."?php
// ------------------------------------------------------------------------- //
//                XOOPS - PHP Content Management System                      //
//                       <http://www.xoops.org/>                             //
// ------------------------------------------------------------------------- //
//  This program is free software; you can redistribute it and/or modify     //
//  it under the terms of the GNU General Public License as published by     //
//  the Free Software Foundation; either version 2 of the License, or        //
//  (at your option) any later version.                                      //
//                                                                           //
//  This program is distributed in the hope that it will be useful,          //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
//  GNU General Public License for more details.                             //
//                                                                           //
//  You should have received a copy of the GNU General Public License        //
//  along with this program; if not, write to the Free Software              //
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
// ------------------------------------------------------------------------- //

if ( !defined(\"XOOPS_MAINFILE_INCLUDED\") ) {
	define(\"XOOPS_MAINFILE_INCLUDED\",1);

	// "._INSTALL_L55."
	// "._INSTALL_L59."
	define(\"XOOPS_ROOT_PATH\",\"".$myts->oopsHtmlSpecialChars($myts->oopsAddSlashes($root_path))."\");

	// "._INSTALL_L56."
	// "._INSTALL_L58."
	define(\"XOOPS_URL\", \"".$myts->oopsHtmlSpecialChars($myts->oopsAddSlashes($xoops_url))."\");

	// "._INSTALL_L51."
	// "._INSTALL_L66."
	\$xoopsConfig['database'] = \"".$myts->oopsHtmlSpecialChars($myts->oopsAddSlashes($database))."\";

	// "._INSTALL_L30."
	// "._INSTALL_L63."
	\$xoopsConfig['prefix'] = \"".$myts->oopsHtmlSpecialChars($myts->oopsAddSlashes($prefix))."\";

	// "._INSTALL_L27."
	// "._INSTALL_L67."
	\$xoopsConfig['dbhost'] = \"".$myts->oopsHtmlSpecialChars($myts->oopsAddSlashes($dbhost))."\";

	// "._INSTALL_L28."
	// "._INSTALL_L65."
	\$xoopsConfig['dbuname'] = \"".$myts->oopsHtmlSpecialChars($myts->oopsAddSlashes($dbuname))."\";

	// "._INSTALL_L52."
	// "._INSTALL_L68."
	\$xoopsConfig['dbpass'] = \"".$myts->oopsHtmlSpecialChars($myts->oopsAddSlashes($dbpass))."\";

	// "._INSTALL_L29."
	// "._INSTALL_L64."
	\$xoopsConfig['dbname'] = \"".$myts->oopsHtmlSpecialChars($myts->oopsAddSlashes($dbname))."\";

	// "._INSTALL_L54." ("._INSTALL_L23."=1 "._INSTALL_L24."=0)
	// "._INSTALL_L69."
	\$xoopsConfig['db_pconnect'] = ".intval($db_pconnect).";

	include(XOOPS_ROOT_PATH.\"/include/common.php\");
}

?".">";
	if ( !$file = fopen("mainfile.php","w") ) {
		echo _INSTALL_L60;
		install_footer();
		exit();
	}
	if ( fwrite($file,$content) == -1 ) {
		echo _INSTALL_L61;
		fclose($file);
		install_footer();
		exit();
	}
	fclose($file);
	echo "<div style='text-align:center;'>"._INSTALL_L62."<br />
	<form action='install.php' method='post'>
	<input type='hidden' name='op' value='mainfile' />
	<input type='submit' value='"._INSTALL_L14."' />
	</form></div>";
	install_footer();
	exit();
}

function mainfile_settings(){
	global $HTTP_HOST, $REQUEST_URI, $SCRIPT_NAME;
	install_header();
	echo "<div style='text-align:center'>";
	$xoops_root_path = XOOPS_ROOT_PATH;
	$xoops_url = XOOPS_URL;
	if ( $xoops_root_path == "/path/to/xoops/directory" || !defined("XOOPS_ROOT_PATH") || $xoops_url == "http://url_to_xoops_directory" || !defined("XOOPS_URL") ) {
		echo "<table width=\"70%\"><tr><td>";
		if ( $xoops_root_path == "/path/to/xoops/directory" || !defined(XOOPS_ROOT_PATH) ) {
			echo _INSTALL_L1."<br /><br />
			<b>define(\"XOOPS_ROOT_PATH\",\"/path/to/xoops/directory\");</b><br /><br />
			"._INSTALL_L2."<br /><br />
			<b>define(\"XOOPS_ROOT_PATH\",\"<span style='color:#ff0000;'>".str_replace("\\","/",getcwd())."\");</span></b><br /><br />";
		}
		if ( $xoops_url == "http://url_to_xoops_directory" || !defined("XOOPS_URL") ) {
			$filepath = (!empty($REQUEST_URI)) ? ($REQUEST_URI) : $SCRIPT_NAME;
			printf(_INSTALL_L3, "<br /><br /><b>define(\"XOOPS_URL\",\"http://url_to_xoops_directory\");</b><br /><br />", "<br /><br /><b>define(\"XOOPS_URL\",\"<span style='color:#ff0000;'>http://".$HTTP_HOST."/".str_replace("/", "", dirname($filepath))."\");</span></b>");
		}
		echo "</td></tr></table>
		<br /><br /><input type='button' value='"._INSTALL_L4."' onclick='location=\"install.php\"' /></div>";
		install_footer();
		exit();
	} else {
		$detected = str_replace("\\","/",getcwd());
		if ( substr($detected, -1) == "/" ) {
			$detected = substr($detected, 0, -1);
		}
		// some servers wont allow getcwd()
		if ( empty($detected) ) {
			echo _INSTALL_L11."<b>".XOOPS_ROOT_PATH."</b><br />";
			echo _INSTALL_L12."<b>".XOOPS_URL."</b><br /><br />";
			echo _INSTALL_L13."<br /><br />\n";
		} elseif ( $xoops_root_path != $detected ) {
			echo "<p>\n";
			echo "<font color=\"#ff0000\">"._INSTALL_L5."</font><br />";
			echo _INSTALL_L6."<br />\n";
			echo _INSTALL_L7."<b>".XOOPS_ROOT_PATH."</b><br />";
			echo _INSTALL_L8."<b>".$detected."</b><br />";
			echo "<b>"._INSTALL_L9."</b><br /><br />\n";
			echo _INSTALL_L10."\n";
			echo "</p>\n";
		} else {
			echo _INSTALL_L11."<b>".XOOPS_ROOT_PATH."</b><br />";
			echo _INSTALL_L12."<b>".XOOPS_URL."</b><br /><br />";
			echo _INSTALL_L13."<br /><br />\n";
		}
		echo "<form action='install.php' method='post'>";
		echo "<input type='hidden' name='op' value='initial' />\n";
		echo "<input type='submit' name='submit' value='"._INSTALL_L14."' />\n";
		echo "</form>\n";
		install_footer();
		exit();
	}
}

function install_init(){
	global $xoopsConfig;
	install_header();
	if($xoopsConfig[dbhost]=="" || $xoopsConfig[dbname] == "" || $xoopsConfig[prefix] =="" || !isset($xoopsConfig[dbhost]) || !isset($xoopsConfig[dbuname]) || !isset($xoopsConfig[dbpass]) || !isset($xoopsConfig[dbname]) || !isset($xoopsConfig[prefix])){
		echo "<div style='text-align:center'>\n";
		echo _INSTALL_L15."<br /><br />\n";
		echo "<table width=\"70%\">\n";
		if($xoopsConfig[dbhost]=="" || !isset($xoopsConfig[dbhost])){
			echo "<tr><td>".sprintf(_INSTALL_L16, "<b>\$xoopsConfig['dbhost']</b>")."</td></tr>\n";
		}
		if(!isset($xoopsConfig[dbuname])){
			echo "<tr><td>".sprintf(_INSTALL_L17, "<b>\$xoopsConfig['dbuname']</b>")."</td></tr>\n";
		}
		if(!isset($xoopsConfig[dbpass])){
			echo "<tr><td>".sprintf(_INSTALL_L18, "<b>\$xoopsConfig['dbpass']</b>")."</td></tr>\n";
		}
		if($xoopsConfig[dbname] == "" || !isset($xoopsConfig[dbname])){
			echo "<tr><td>".sprintf(_INSTALL_L19, "<b>\$xoopsConfig['dbname']</b>")."</td></tr>\n";
		}
		if ( $xoopsConfig['prefix'] =="" || !isset($xoopsConfig['prefix']) ) {
			echo "<tr><td>".sprintf(_INSTALL_L20, "<b>\$xoopsConfig['prefix']</b>")."</td></tr>\n";
		}
		echo "</table>\n";
		echo "<br /><br /><form action='/' method='post'><input type='button' value='"._INSTALL_L4."' onclick='location=\"install.php?op=initial\"' /></form></div>\n";
		install_footer();
		exit();
	}
	$xoopsDB = new Database();
	$xoopsDB->setPrefix($xoopsConfig['prefix']);
	if ( !$xoopsDB->connect($xoopsConfig['dbhost'], $xoopsConfig['dbuname'], $xoopsConfig['dbpass'], $xoopsConfig['dbname'], $xoopsConfig['db_pconnect']) ) {
		echo "<div><p>"._INSTALL_L21."<br /><br />";
		echo "<b>".$xoopsConfig['dbname']."</b></p>";
		echo "<p>"._INSTALL_L22."</p>";
		echo "<form action='install.php' method='post'>";
		echo "<input type='hidden' name='op' value='createDB' />";
		echo "<input type='submit' value='"._INSTALL_L23."' />&nbsp;";
		echo "<input type='button' onclick='location=\"install.php?op=initial&\"' value='"._INSTALL_L24."' /></form></div>";
		install_footer();
		exit();
	}
	$xoopsDB->close();	
	echo "<table width=\"60%\" align=\"center\">\n";
	echo "<tr><td>"._INSTALL_L25."<br /><br />\n";
	echo "<b>"._INSTALL_L26."</b><br /><br />\n";
	echo "&nbsp;"._INSTALL_L27."&nbsp;<b>".$xoopsConfig[dbhost]."</b><br />\n";
	echo "&nbsp;"._INSTALL_L28."&nbsp;<b>".$xoopsConfig[dbuname]."</b><br />\n";
	echo "&nbsp;"._INSTALL_L29."&nbsp;<b>".$xoopsConfig[dbname]."</b><br />\n";
	echo "&nbsp;"._INSTALL_L30."&nbsp;<b>".$xoopsConfig[prefix]."</b><br /><br />\n";
	//echo "<b>Site Configuration</b><br /><br />\n";
	//echo "&nbsp;URL (Virtual Path):&nbsp;<b>".$xoopsConfig[xoops_url]."</b><br /><br />\n";
	echo "</td></tr><tr><td align=\"center\"><form action=\"install.php\" method=\"post\">\n";
	echo _INSTALL_L13."<br /><br />\n";
	echo "<input type='hidden' name='op' value='siteInit' />\n";
	echo "<input type='submit' name='submit' value='"._INSTALL_L14."' />\n";
	echo "</form>\n";
	echo "</td></tr></table>\n";
	install_footer();
}

function install_createDB(){
	global $xoopsConfig;
	mysql_connect($xoopsConfig['dbhost'], $xoopsConfig['dbuname'], $xoopsConfig['dbpass']);
	$result = mysql_query("CREATE DATABASE ".$xoopsConfig['dbname']."");
	if ( !$result ) {
		echo "<div><b>"._INSTALL_L31."</b></div>";
		install_footer();
		exit();
	}
	echo "<div><b>".sprintf(_INSTALL_L43, $xoopsConfig['dbname'])."</b>";
	echo "<form action='install.php' method='post'>";
	echo "<input type='hidden' name='op' value='initial' />";
	echo "<input type='submit' value='"._INSTALL_L14."' />";
	echo "</form></div>";
	install_footer();
}

function install_createTables($adminname, $adminpass, $adminmail){
	global $xoopsConfig, $xoopsDB;
	$myts = new MytextSanitizer();
	$madetables = array();


#
# Table structure for table 'admingroups'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix(groups)."` (
  `groupid` int(5) NOT NULL auto_increment,
  `name` varchar(50) NOT NULL default '',
  `description` text,
  `type` varchar(10) NOT NULL,
  PRIMARY KEY  (`groupid`),
  KEY `type` (`type`)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("groups"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("groups"));
}
#
# Dumping data for table 'groups'
#

$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(groups)." VALUES (1,'webmaster','webmasters of this site','Admin')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(groups)." VALUES (2,'Registered Users','Registered Users Group','User')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(groups)." VALUES (3,'Anonymous Users','Anonymous Users Group','Anonymous')");
# --------------------------------------------------------

#
# Table structure for table 'groups_users_link'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix(groups_users_link)."` (
  `groupid` int(5) NOT NULL default '0',
  `uid` int(5) NOT NULL default '0',
  KEY `groupid_uid` (`groupid`,`uid`)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("groups_users_link"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("groups_users_link"));
}
#
# Dumping data for table '".$xoopsDB->prefix(groups_users_link'
#

$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(groups_users_link)." VALUES (1,1)");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(groups_users_link)." VALUES (2,1)");
# --------------------------------------------------------

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix("groups_modules_link")."` (
  `groupid` int(5) NOT NULL default '0',
  `mid` int(5) NOT NULL default '0',
  `type` char(1) NOT NULL default '',
  KEY `groupid_type_mid` (`groupid`, `type`, `mid`)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("groups_modules_link"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("groups_modules_link"));
}
#
# Dumping data for table '".$xoopsDB->prefix(groups_modules_link'
#

$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_modules_link")." VALUES (1,1,'A')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_modules_link")." VALUES (1,2,'A')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_modules_link")." VALUES (1,1,'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_modules_link")." VALUES (1,2,'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_modules_link")." VALUES (2,1,'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_modules_link")." VALUES (2,2,'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_modules_link")." VALUES (3,1,'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_modules_link")." VALUES (3,2,'R')");
# --------------------------------------------------------



#
# Table structure for table 'banner'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix(banner)."` (
  `bid` int(4) NOT NULL auto_increment,
  `cid` int(2) NOT NULL default '0',
  `imptotal` int(8) NOT NULL default '0',
  `impmade` int(8) NOT NULL default '0',
  `clicks` int(8) NOT NULL default '0',
  `imageurl` varchar(255) NOT NULL default '',
  `clickurl` varchar(255) NOT NULL default '',
  `date` int(10) NOT NULL default '0',
  PRIMARY KEY  (`bid`),
  KEY `idxbannercid` (`cid`),
  KEY `idxbannerbidcid` (`bid`,`cid`)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("banner"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("banner"));
}
#
# Dumping data for table 'banner'
#
# --------------------------------------------------------

$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("banner")." (bid, cid, imptotal, impmade, clicks, imageurl, clickurl, date) VALUES (1, 1, 0, 1, 0, '".XOOPS_URL."/images/banners/xoops_banner.gif', 'http://www.xoops.org/', 1008813250)");

#
# Table structure for table 'bannerclient'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix(bannerclient)."` (
  `cid` int(2) NOT NULL auto_increment,
  `name` varchar(60) NOT NULL default '',
  `contact` varchar(60) NOT NULL default '',
  `email` varchar(60) NOT NULL default '',
  `login` varchar(10) NOT NULL default '',
  `passwd` varchar(10) NOT NULL default '',
  `extrainfo` text NOT NULL,
  PRIMARY KEY  (`cid`),
  KEY `idxbannerclientlogin` (`login`)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("bannerclient"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("bannerclient"));
}
#
# Dumping data for table 'bannerclient'
#
# --------------------------------------------------------

$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("bannerclient")." (cid, name, contact, email, login, passwd, extrainfo) VALUES (1, 'XOOPS', 'XOOPS Dev Team', 'webmaster@xoops.org', '', '', '')");

#
# Table structure for table 'bannerfinish'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix(bannerfinish)."` (
  `bid` int(4) NOT NULL auto_increment,
  `cid` int(2) NOT NULL default '0',
  `impressions` int(8) NOT NULL default '0',
  `clicks` int(8) NOT NULL default '0',
  `datestart` int(10) NOT NULL default '0',
  `dateend` int(10) NOT NULL default '0',
  PRIMARY KEY  (`bid`),
  KEY `idxbannerfinishcid` (`cid`)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("bannerfinish"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("bannerfinish"));
}
#
# Dumping data for table 'bannerfinish'
#


# --------------------------------------------------------

#
# Table structure for table 'metafooter'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix(metafooter)."` (
  `meta` text NOT NULL,
  `footer` text NOT NULL
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("metafooter"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("metafooter"));
}
#
# Dumping data for table 'metafooter'
#
$result = $xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(metafooter)." VALUES ('', '\n<a href=\"http://www.xoops.org/\"><img src=\"".XOOPS_URL."/images/s_poweredby.gif\" alt=\"XOOPS Official Website\" target=\"_blank\" /></a>\n\n')");


# --------------------------------------------------------
#
# Table structure for table 'modules'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix("modules")."` (
  `mid` int(5) UNSIGNED NOT NULL auto_increment,
  `name` varchar(150) NOT NULL default '',
  `version` int(5) NOT NULL default '100',
  `last_update` int(10) NOT NULL default '0',
  `weight` int(3) DEFAULT '0' NOT NULL,
  `isactive` TINYINT(1) DEFAULT '0' NOT NULL,
  `dirname` varchar(25) NOT NULL default '',
  `hasmain` tinyint(1) NOT NULL default '0',
  `hasadmin` tinyint(1) NOT NULL default '0',
  `hassearch` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`mid`),
  KEY `hasmain` (`hasmain`),
  KEY `hasadmin` (`hasadmin`),
  KEY `hassearch` (`hassearch`),
  KEY `dirname` (`dirname`),
  KEY name (name(15))
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("modules"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("modules"));
}
#
# Dumping data for table 'xoops_modules'
#

$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("modules")." VALUES (1,'System Admin',100,1020877924,0,1,'system',0,1,0)");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("modules")." VALUES (2, 'News', 101, 1020877924, 1, 1, 'news', 1, 1, 1)");

    

#
# Table structure for table 'newblocks'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix("newblocks")."` (
  `bid` int(5) UNSIGNED NOT NULL auto_increment,
  `mid` int(5) UNSIGNED NOT NULL default '0',
  `func_num` int(5) NOT NULL default '0',
  `options` varchar(255) NOT NULL default '',
  `name` varchar(150) NOT NULL default '',
  `position` tinyint(1) NOT NULL default '0',
  `title` varchar(150) NOT NULL default '',
  `content` text NOT NULL,
  `side` tinyint(1) NOT NULL default '0',
  `weight` int(5) NOT NULL default '0',
  `visible` tinyint(1) NOT NULL default '0',
  `type` char(1) NOT NULL default '',
  `c_type` char(1) NOT NULL default '',
  `isactive` TINYINT(1) DEFAULT '0' NOT NULL,
  PRIMARY KEY  (`bid`),
  KEY `mid` (`mid`),
  KEY `visible` (`visible`),
  KEY `side_visible_mid` (`side`, `visible`, `mid`),
  KEY mid_funcnum (mid, func_num)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("newblocks"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("newblocks"));
}
#
# Dumping data for table 'xoops_newblocks'
#

$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(newblocks)." VALUES (1, 1, 1, '', 'User Block', 1, '', '', 0, 0, 1, 'S', '', 1)");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(newblocks)." VALUES (2, 1, 2, '', 'Login Block', 1, '', '', 0, 0, 1, 'S', '', 1)");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(newblocks)." VALUES (3, 1, 3, '', 'Search Block', 1, '', '', 0, 0, 1, 'S', '', 1)");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(newblocks)." VALUES (4, 1, 4, '', 'Waiting Contents Block', 1, '', '', 0, 0, 1, 'S', '', 1)");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(newblocks)." VALUES (5, 1, 5, '', 'Main Menu Block', 0, '', '', 0, 0, 1, 'S', '', 1)");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(newblocks)." VALUES (6, 1, 6, '320|250|poweredby.gif', 'Site Info Block', 0, '', '', 0, 1, 1, 'S', 'H', 1)");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(newblocks)." VALUES (7, 2, 1, '', 'News Topics Block', 0, '', '', 0, 0, 1, 'M', '', 1)");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(newblocks)." VALUES (8, 2, 2, '', 'Big Story Block', 0, '', '', 1, 0, 1, 'M', '', 1)");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(newblocks)." VALUES (9, 2, 3, 'counter|10', 'Top News Block', 0, '', '', 4, 0, 1, 'M', 'H', 1)");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(newblocks)." VALUES (10, 2, 4, 'published|10', 'Recent News Block', 0, '', '', 3, 0, 1, 'M', 'H', 1)");


#
# Table structure for table 'priv_msgs'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix("priv_msgs")."` (
  `msg_id` int(8) NOT NULL auto_increment,
  `msg_image` varchar(100) default NULL,
  `subject` varchar(100) default NULL,
  `from_userid` int(5) unsigned NOT NULL default '0',
  `to_userid` int(5) unsigned NOT NULL default '0',
  `msg_time` int(10) NOT NULL default '0',
  `msg_text` text,
  `read_msg` tinyint(1) NOT NULL default '0',
  PRIMARY KEY  (`msg_id`),
  KEY `to_userid` (`to_userid`),
  KEY `idxprivmsgstouseridreadmsg` (`to_userid`,`read_msg`),
  KEY `idxprivmsgsmsgidfromuserid` (`msg_id`,`from_userid`)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("priv_msgs"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("priv_msgs"));
}
#
# Dumping data for table 'priv_msgs'
#



# --------------------------------------------------------

#
# Table structure for table 'ranks'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix("ranks")."` (
  `rank_id` int(5) NOT NULL auto_increment,
  `rank_title` varchar(50) NOT NULL default '',
  `rank_min` int(10) NOT NULL default '0',
  `rank_max` int(10) NOT NULL default '0',
  `rank_special` int(2) NOT NULL default '0',
  `rank_image` varchar(255) default NULL,
  PRIMARY KEY  (`rank_id`),
  KEY `rank_min` (`rank_min`),
  KEY `rank_max` (`rank_max`),
  KEY `idxranksrankminrankmaxranspecial` (`rank_min`,`rank_max`,`rank_special`),
  KEY `idxranksrankspecial` (`rank_special`)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("ranks"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("ranks"));
}
#
# Dumping data for table 'ranks'
#

$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(ranks)." VALUES (2,'Just popping in',0,20,0,'')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(ranks)." VALUES (3,'Not too shy to talk',21,40,0,'star.gif')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(ranks)." VALUES (4,'Quite a regular',41,70,0,'stars2.gif')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(ranks)." VALUES (5,'Just can\'t stay away',71,150,0,'stars3.gif')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(ranks)." VALUES (6,'Home away from home',151,10000,0,'stars4.gif')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(ranks)." VALUES (7,'Webmaster',-1,-1,1,'redstars5.gif')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(ranks)." VALUES (8,'Moderator',-1,-1,1,'stars5.gif')");
# --------------------------------------------------------


#
# Table structure for table 'session'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix("session")."` (
  `uid` int(5) unsigned NOT NULL default '0',
  `time` int(10) NOT NULL default '',
  `ip` varchar(15) NOT NULL default '',
  `hash` varchar(32) NOT NULL default '',
  KEY `uid` (`uid`),
  KEY `time` (`time`),
  KEY `hash_ip` (`hash`,`ip`),
  KEY `uid_ip` (`uid`,`ip`)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("session"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("session"));
}
#
# Dumping data for table 'session'
#


# --------------------------------------------------------

#
# Table structure for table 'smiles'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix("smiles")."` (
  `id` int(10) NOT NULL auto_increment,
  `code` varchar(50) default NULL,
  `smile_url` varchar(100) default NULL,
  `emotion` varchar(75) default NULL,
  PRIMARY KEY  (`id`)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("smiles"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("smiles"));
}
#
# Dumping data for table 'smiles'
#


$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (1,':-D','icon_biggrin.gif','Very Happy')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (2,':-)','icon_smile.gif','Smile')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (3,':-(','icon_frown.gif','Sad')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (4,':-o','icon_eek.gif','Surprised')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (5,':-?','icon_confused.gif','Confused')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (6,'8-)','icon_cool.gif','Cool')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (7,':lol:','icon_lol.gif','Laughing')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (8,':-x','icon_mad.gif','Mad')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (9,':-P','icon_razz.gif','Razz')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (10,':oops:','icon_redface.gif','Embaressed')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (11,':cry:','icon_cry.gif','Crying (very sad)')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (12,':evil:','icon_evil.gif','Evil or Very Mad')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (13,':roll:','icon_rolleyes.gif','Rolling Eyes')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (14,';-)','icon_wink.gif','Wink')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (15,':pint:','icon_drink.gif','Another pint of beer')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (16,':hammer:','icon_hammer.gif','ToolTimes at work')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(smiles)." VALUES (17,':idea:','icon_idea.gif','I have an idea')");
# --------------------------------------------------------

#
# Table structure for table 'users'
#

$result = $xoopsDB->queryF("CREATE TABLE `".$xoopsDB->prefix("users")."` (
  `uid` int(5) unsigned NOT NULL auto_increment,
  `name` varchar(60) NOT NULL default '',
  `uname` varchar(25) NOT NULL default '',
  `email` varchar(60) NOT NULL default '',
  `url` varchar(100) NOT NULL default '',
  `user_avatar` varchar(30) default NULL,
  `user_regdate` int(10) NOT NULL default '',
  `user_icq` varchar(15) default NULL,
  `user_from` varchar(100) default NULL,
  `user_sig` text,
  `user_viewemail` tinyint(1) NOT NULL default '0',
  `actkey` varchar(8) default NULL,
  `user_aim` varchar(18) default NULL,
  `user_yim` varchar(25) default NULL,
  `user_msnm` varchar(25) default NULL,
  `pass` varchar(32) NOT NULL default '',
  `posts` int(8) default '0',
  `attachsig` TINYINT(1) default '0',
  `rank` int(5) NOT NULL default '0',
  `level` int(5) NOT NULL default '1',
  `theme` varchar(100) NOT NULL default '',
  `timezone_offset` float(3,1) NOT NULL default '0.0',
  last_login INT(10) DEFAULT '0' NOT NULL,
  `umode` varchar(10) NOT NULL default '',
  `uorder` tinyint(1) NOT NULL default '0',
  `user_occ` varchar(100) default NULL,
  `bio` tinytext NOT NULL,
  `user_intrest` varchar(150) default NULL,
  PRIMARY KEY  (`uid`),
  KEY `idxusersuname` (`uname`),
  KEY `idxusersemail` (`email`),
  KEY `idxusersuiduname` (`uid`,`uname`),
  KEY `idxusersunamepass` (`uname`,`pass`)
)");

if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("users"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("users"));
}
#
# Dumping data for table 'users'
#

$temp = md5($adminpass);
$regdate = time();
$dbadminname= $myts->makeTboxData4Save($adminname);
$result = $xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix(users)." VALUES (1,'','".$dbadminname."','".$adminmail."','".XOOPS_URL."/','001.gif','".$regdate."','','','',1,NULL,'','','','".$temp."',0,0,7,5,'phpkaox','0.0',".time().",'flat',0,'','','')");

#
# Table structure for table 'groups_blocks_link'
#
$result = $xoopsDB->queryF("CREATE TABLE ".$xoopsDB->prefix("groups_blocks_link")." (
  groupid int(5) NOT NULL default '0',
  block_id int(5) NOT NULL default '0',
  type char(1) NOT NULL default ''
)");
if (!$result) {
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("groups_blocks_link"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("groups_blocks_link"));
}

#
# Dumping data for table 'groups_blocks_link'
#
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (1, 8, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (1, 7, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (1, 5, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (1, 4, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (1, 2, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (1, 1, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (2, 3, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (2, 10, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (2, 9, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (2, 6, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (2, 8, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (3, 3, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (3, 10, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (3, 9, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (3, 6, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (3, 8, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (1, 6, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (1, 9, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (1, 10, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (1, 3, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (2, 7, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (2, 5, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (2, 2, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (2, 1, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (3, 7, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (3, 5, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (3, 2, 'R')");
$xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("groups_blocks_link")." VALUES (3, 1, 'R')");

# --------------------------------------------------------

#
# Table structure for table 'stories'
#

$result = $xoopsDB->queryF("CREATE TABLE ".$xoopsDB->prefix("stories")." (
  storyid int(8) unsigned NOT NULL auto_increment,
  uid int(5) NOT NULL default '0',
  title varchar(255) default NULL,
  created int(10) NOT NULL default '0',
  published int(10) NOT NULL default '0',
  hostname varchar(20) NOT NULL default '',
  nohtml tinyint(1) NOT NULL default '0',
  nosmiley tinyint(1) NOT NULL default '0',
  hometext text NOT NULL,
  bodytext text NOT NULL,
  counter int(8) unsigned NOT NULL default '0',
  topicid int(8) unsigned NOT NULL default '1',
  ihome tinyint(1) NOT NULL default '0',
  notifypub tinyint(1) NOT NULL default '0',
  type varchar(10) NOT NULL default '0',
  topicdisplay tinyint(1) NOT NULL default '0',
  topicalign char(1) NOT NULL default 'R',
  PRIMARY KEY  (storyid),
  KEY idxstoriestopic (topicid),
  KEY ihome (ihome),
  KEY uid (uid),
  KEY published_ihome (published,ihome),
  KEY title (title(40)),
  KEY created (created)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("stories"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix(stories));
}
#
# Dumping data for table 'stories'
#
$result = $xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("stories")." VALUES ( '1', '1', 'Welcome to XOOPS!!', '".time()."', '".time()."','150.0.0.0', '0', '0', 'This is the first article in XOOPS. You can delete it. Pelase read carefully the README file for some details, CREDITS files to see from where comes the things and remember that this is a free software under the GPL License (COPYING file for details). Hope you enjoy this software. Please report any bug you have found to the support team at xoops.sourceforge.net.', '', '1', '1', '0', '0', 'admin',1,'R');");


# --------------------------------------------------------

#
# Table structure for table 'topics'
#

$result = $xoopsDB->queryF("CREATE TABLE ".$xoopsDB->prefix("topics")." (
  topic_id int(4) unsigned NOT NULL auto_increment,
  topic_pid int(4) unsigned NOT NULL default '0',
  topic_imgurl varchar(20) NOT NULL default '',
  topic_title varchar(50) NOT NULL default '',
  PRIMARY KEY  (topic_id),
  KEY pid (topic_pid)
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("topics"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("topics"));
}
#
# Dumping data for table 'topics'
#
$result = $xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("topics")." VALUES (1,0,'xoops.gif','XOOPS')");


# --------------------------------------------------------

#
# Table structure for table 'comments'
#

$result = $xoopsDB->queryF("CREATE TABLE ".$xoopsDB->prefix("comments")." (
  comment_id int(8) unsigned NOT NULL auto_increment,
  pid int(8) unsigned NOT NULL default '0',
  item_id int(8) unsigned NOT NULL default '0',
  date int(10) NOT NULL default '0',
  user_id int(5) NOT NULL default '0',
  ip varchar(15) NOT NULL default '',
  subject varchar(255) default NULL,
  comment text NOT NULL,
  nohtml tinyint(1) NOT NULL default '0',
  nosmiley tinyint(1) NOT NULL default '0',
  noxcode tinyint(1) NOT NULL default '0',
  icon varchar(25) NOT NULL default '',
  PRIMARY KEY  (comment_id),
  KEY pid (pid),
  KEY item_id (item_id),
  KEY user_id (user_id),
  KEY subject (subject(40))
)");
if(!$result){
	for($i=0;$i<sizeof($madetables);$i++){
		$xoopsDB->queryF("DROP table ".$madetables[$i]."");
	}
	die ("<b>".sprintf(_INSTALL_L44, $xoopsDB->prefix("comments"))."</b>");
}else{
	array_push($madetables, $xoopsDB->prefix("comments"));
}
#
# Dumping data for table 'comments'
#


# --------------------------------------------------------


	$output = "<p>";
	foreach($madetables as $table){
		$output .= sprintf(_INSTALL_L45, $table)."<br />";
	}
	$output .= "</p>";
	echo "<div align='center'><table width='60%' border='0'><tr><td>\n";
	echo $output;
	echo "</t></tr></table><br /><br /><b>"._INSTALL_L32."</b><br />\n";
	echo "<table width='60%' border='0'><tr><td>";
	$writeok = array();
	$writeok[] = XOOPS_ROOT_PATH."/images/avatar/users/";
	$writeok[] = XOOPS_ROOT_PATH."/modules/system/cache/config.php";
	$writeok[] = XOOPS_ROOT_PATH."/modules/system/cache/mainmenu.php";
	$writeok[] = XOOPS_ROOT_PATH."/modules/system/cache/adminmenu.php";
	$writeok[] = XOOPS_ROOT_PATH."/modules/system/cache/badwords.php";
	$writeok[] = XOOPS_ROOT_PATH."/modules/system/cache/badips.php";
	$writeok[] = XOOPS_ROOT_PATH."/modules/system/cache/badunames.php";
	$writeok[] = XOOPS_ROOT_PATH."/modules/xoopspoll/cache/pollsblock.inc.php";
	$writeok[] = XOOPS_ROOT_PATH."/modules/news/cache/config.php";
	$writeok[] = XOOPS_ROOT_PATH."/modules/mydownloads/cache/config.php";
	$writeok[] = XOOPS_ROOT_PATH."/modules/mylinks/cache/config.php";
	$writeok[] = XOOPS_ROOT_PATH."/modules/headlines/cache/";
	$writeok[] = XOOPS_ROOT_PATH."/modules/xoopsfaq/cache/";
	$filelist = "";
	foreach ($writeok as $wok) {
		if ( file_exists($wok) ) {
			@chmod($wok, 0666);
			if (!is_writeable($wok)) {
				$filelist .= "<li>".$wok."</li>";
			}
		}
	}
	if ( $filelist != "" ) {
		echo _INSTALL_L46."<br /><ul>".$filelist."</ul>";
	}
//	$makedir = array(XOOPS_ROOT_PATH."/images/avatar/users/", XOOPS_ROOT_PATH."/modules/headlines/cache/", XOOPS_ROOT_PATH."/modules/xoopsfaq/cache/");
//	$dirlist = "";
//	foreach ($makedir as $mdir) {
//		if (!mkdir($mdir, 0777)) {
//			$dirlist .= "<li>".$mdir."</li>";
//		}
//	}
//	if ( $dirlist != "" ) {
//		echo _INSTALL_L72."<br /><ul>".$dirlist."</ul>";
//	}
	echo "</td></tr></table><br />"._INSTALL_L33."<br />\n";
	echo _INSTALL_L35."\n";
	echo "<br /><br /></div>\n";

}

switch ($op) {

	case "siteInit":
		include_once("mainfile.php");
		install_header();
		echo "<form action='install.php' method='post'>\n";
		echo "<table align='center' width='70%'>\n";
		echo "<tr><td colspan='2'>"._INSTALL_L36."</td></tr>\n";
		echo "<tr><td align='right'><b>"._INSTALL_L37."</b></td><td><input type=\"text\" name=\"adminname\" /></td></tr>\n";
		echo "<tr><td align='right'><b>"._INSTALL_L38."</b></td><td><input type='text' name='adminmail' value='".$xoopsConfig['adminmail']."' maxlength='60' /></td></tr>\n";
		echo "<tr><td align='right'><b>"._INSTALL_L39."</b></td><td><input type='text' name='adminpass' /></td></tr>\n";
		echo "<tr><td align='center' colspan='2'><input type='hidden' name='op' value='createTables' />\n";
		echo "<input type='submit' name='submit' value='"._INSTALL_L40."' /></td></tr>\n";
		echo "</table></form>\n";
		install_footer();
		break;
	case "createDB":
		include_once("mainfile.php");
		install_header();
		include_once("include/config.php");
		install_createDB();
		break;
	case "createTables":
		include_once("mainfile.php");
		if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+([\.][a-z0-9-]+)+$",$adminmail)) {
			install_header();
			echo "<div style='text-align:center'><b>"._INSTALL_L73."</b>\n";
			echo "<br /><br /><input type='button' value='"._INSTALL_L42."' onclick='javascript:history.go(-1);' /></div>\n";
			install_footer();
			exit();
		}
		if ( !isset($adminname) || !isset($adminpass) || !isset($adminmail) || $adminmail == "" || $adminname =="" || $adminpass =="") {
			install_header();
			echo "<div style='text-align:center'><b>"._INSTALL_L41."</b>\n";
			echo "<br /><br /><input type='button' value='"._INSTALL_L42."' onclick='javascript:history.go(-1);' /></div>\n";
			install_footer();
			exit();
		}
		//include_once("mainfile.php");
		include_once("include/config.php");
		include_once("class/module.textsanitizer.php");
		install_header();
		install_createTables($adminname, $adminpass, $adminmail);
		install_footer();
		break;

	case "drop":
		include_once("mainfile.php");
		install_header();
		$myTables = array('groups','groups_users_link','groups_modules_link','groups_blocks_link','bannerclient','banner','bannerfinish','metafooter','priv_msgs','ranks','session','smiles','users','newblocks','modules','comments','topics','stories');

		for ( $i = 0; $i < sizeof($myTables); $i++ ) {
			$xoopsDB->queryF("DROP table ".$xoopsDB->prefix($myTables[$i])."");
		}
		echo "<br /><br /><b>Tables Dropped</b>";
		install_footer();
		break;
	case "initial":
		include_once("mainfile.php");
		install_init();
		break;
	case "mainfile":
		include_once("mainfile.php");
		mainfile_settings();
		break;
	default:
		include_once("mainfile.php");
		mainfile_settings();
}
?>