Location: PHPKode > projects > Free Forum System(Tech Book) > Tech-Book-Free Forum-www.webdevelopplus.com/install.php
<?php
echo "<!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\" xml:lang=\"en\" lang=\"en\">
<head>\n"; 
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-2\"/>\n";
echo "<meta http-equiv=\"DESCRIPTION\" content=\"TechBook\"/>\n";
echo "<meta http-equiv=\"KEYWORDS\" content=\"jsystems\"/>\n";
echo "<meta http-equiv=\"GENERATOR\" content=\"techBook\"/>\n";
echo "<meta http-equiv=\"AUTHOR\" content=\"JSystems\"/>\n";  
echo "<link rel='shortcut icon' href='tech.ico'/>\n";
echo "<title>techBook - Install</title>\n";  
echo "<link rel=\"STYLESHEET\" type=\"text/css\" href=\"tech.css\"/>\n";
echo "</head>\n"; 
echo "<table class=\"main\" align=\"center\"><tr><td class=\"fej\">
<h1>INSTALL</h1><h3>Install TechBook on your server</h3>
</td></tr><tr><td class=\"main\">"; 

//step=0 - start 
if ($_POST[sss_step2])
{
	//save config php
	$serverx=$_POST[serverx];
	$userx=$_POST[userx];
	$passwordx=$_POST[passwordx];
	$datax=$_POST[datax];
	$adminx=$_POST[adminx];
	$prefix=$_POST[prefixx];
	//check if filleds
	if ($serverx=="" or $userx=="" or $prefix=="" or $datax=="" or $adminx=="")
	{
		echo "<a href='install.php?step=1'><b>Some fields must be completed!</b><br>
		You can leave empty the fields: Mysql password (if no password).</a>";
	}
	else
	{
	$fp=fopen("config.php","w");
	$a0=fputs($fp,"<?\n"); 
	$a1=fputs($fp,"\$host = \"$serverx\";\n");
	$a1=fputs($fp,"\$user  = \"$userx\";\n");
	$a1=fputs($fp,"\$password  = \"$passwordx\";\n");
	$a1=fputs($fp,"\$database   = \"$datax\";\n");
	$a1=fputs($fp,"\$adminpsw = \"$adminx\";\n");  
	$a1=fputs($fp,"define(\"T_PRE\",\"$prefix\");\n");
	$a25=fputs($fp,"?>");
	fclose($fp);
	if (mysql_connect($serverx, $userx, $passwordx))
	{
    	if (mysql_select_db($datax))
    	{  
		echo "Config.php created. Now go to <a href='install.php?step=3'><b>STEP 3</b></a> to create tables.";
    	}
    	else
    	{ 
    		echo "Database not exists! <a href='install.php?step=1'><b>Go back and write again!</b></a>";
    	}
	}
	else
	{  
		echo "Can't connect to server! <a href='install.php?step=1'><b>Go back and write again!</b></a>";
	}
	}
}
else
{
$step=$_GET[step];
if ($step=="")
{   
	echo "<center><h3>Starting TechBook installation.</h3></center>";
	//test if config.php and others is writable
	if (is_writable("config.php"))
	{   
		echo "config.php: <font color='#008000'><b>WRITABLE</b></font><br>";
	}
	else
	{   
		echo "config.php: <font color='#ff0000'><b>NOT WRITABLE</b></font><br>";
	}
	
	echo "<br>If config.php is not writable, set cmod 777 for this and <a href='install.php'><b>TEST AGAIN</b></a>!<br>";
	echo "<h4><a href='install.php?step=1'>NEXT STEP</a></h4>";
}
elseif ($step==1)
{ 
	echo "<center><h3>Step 1: Base settings.</h3></center>";
	echo "Set up first the mysql username and password, database name and admin password.
	<br>Fields with <b><font color='#FF0000'>*</font></b> must be completed!<br><br>
	<form method='post' action='install.php'>
	<b><font color='#FF0000'>*</font></b> Server (most:localhost): <br><input type='textbox' value='localhost' name='serverx'><br>
	<b><font color='#FF0000'>*</font></b> Mysql username: <br><input type='textbox' value='' name='userx'><br>
	Mysql password: <br><input type='textbox' value='' name='passwordx'><br>
	<b><font color='#FF0000'>*</font></b> Database name: <br><input type='textbox' value='' name='datax'><br><hr> 
	<b><font color='#FF0000'>*</font></b> Table prefix: <br><input type='textbox' value='tech' name='prefixx'><br><hr>
	<b><font color='#FF0000'>*</font></b> Admin password: <br><input type='textbox' value='' name='adminx'><br>
	<input type='submit' value='NEXT STEP' name='sss_step2'>
	</form>";
}
elseif ($step==3)
{
	require "config.php"; 
	mysql_connect ("localhost", "$user", "$password") or die ('My SQL Error: ' . mysql_error());
	mysql_select_db ("$database");
	echo "Creating tables...<br>"; 
	
	
	mysql_query("CREATE TABLE `".T_PRE."_forums` (
  `id` bigint(20) NOT NULL auto_increment,
  `title` varchar(100) NOT NULL default '',
  `comment` varchar(100) NOT NULL default '',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=10 ;") or die ('My SQL Error: ' . mysql_error());
  echo "".T_PRE."_forums table created...<br>";

mysql_query("CREATE TABLE `".T_PRE."_page` (
  `lang` varchar(100) NOT NULL default '',
  `title` varchar(100) NOT NULL default '',
  `comment` text NOT NULL,
  `author` varchar(100) NOT NULL default '',
  `news` text NOT NULL
) TYPE=MyISAM;") or die ('My SQL Error: ' . mysql_error());
echo "".T_PRE."_page table created...<br>";

mysql_query("CREATE TABLE `".T_PRE."_posts` (
  `id` bigint(20) NOT NULL auto_increment,
  `id_topic` bigint(20) NOT NULL default '0',
  `user` varchar(50) NOT NULL default '',
  `date_pub` datetime NOT NULL default '0000-00-00 00:00:00',
  `text` longtext NOT NULL,
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=12 ;") or die ('My SQL Error: ' . mysql_error());
echo "".T_PRE."_posts table created...<br>";

mysql_query("CREATE TABLE `".T_PRE."_topics` (
  `id` bigint(20) NOT NULL auto_increment,
  `id_forum` bigint(20) NOT NULL default '0',
  `user` varchar(50) NOT NULL default '',
  `date_pub` datetime NOT NULL default '0000-00-00 00:00:00',
  `title` varchar(100) NOT NULL default '',
  `text` longtext NOT NULL,
  `locked` int(11) NOT NULL default '0',
  `viewed` bigint(20) NOT NULL default '0',
  PRIMARY KEY  (`id`)
) TYPE=MyISAM AUTO_INCREMENT=10 ;") or die ('My SQL Error: ' . mysql_error());
echo "".T_PRE."_topics table created...<br>";

mysql_query("CREATE TABLE `".T_PRE."_maxview` (
  `total` bigint(20) NOT NULL default '0',
  `most` bigint(20) NOT NULL default '0',
  `datex` datetime NOT NULL default '0000-00-00 00:00:00'
) TYPE=MyISAM;") or die ('My SQL Error: ' . mysql_error());
echo "".T_PRE."_maxview table created...<br>";

mysql_query("CREATE TABLE `".T_PRE."_visitors` (
  `ip` varchar(50) NOT NULL default '',
  `timestamp` int(11) NOT NULL default '0',
  `referer` text NOT NULL,
  `uri` text NOT NULL,
  `agent` text NOT NULL
) TYPE=MyISAM;") or die ('My SQL Error: ' . mysql_error());
echo "".T_PRE."_visitors table created...<br>"; 

mysql_query("CREATE TABLE `".T_PRE."_unique` (
  `ip` varchar(100) NOT NULL default '',
  `visits` bigint(20) NOT NULL default '0',
  `lastvisit` datetime NOT NULL default '0000-00-00 00:00:00',
  `timestamp` int(11) NOT NULL default '0'
) TYPE=MyISAM;") or die ('My SQL Error: ' . mysql_error());
echo "".T_PRE."_unique table created...<br>";  
//setup table fill :)
echo "<h4><a href='install.php?step=4'>NEXT STEP</a></h4>";
       
}
elseif ($step==4)
{
	echo "<center><h3>Step 4: Save settings</h3></center>";
	//set up page at install
	include "config.php"; 
	mysql_connect ("localhost", "$user", "$password") or die ('My SQL Error: ' . mysql_error());
	mysql_select_db ("$database");
	echo "Setting up page table...<br>";
	
	mysql_query("INSERT INTO ".T_PRE."_page VALUES ( 
	'english.php', 
	'TechBook',
	'Free, simply and fast bulletin board',
	'JSystems',
	'Fresh install of TechBook. Wellcome!')") or die ('My SQL Error: ' . mysql_error());
	
	echo "<br><br><center><b>Now the installation finished!<br>
	<h3>Please remove the <font color='#FF0000'>install.php</font> file for your secure!</h3><br>
	Enjoy!</b><br><br>Any questions, problems, suggestions: write in <a href='http://support.jsystems.ro'>JSystems Support Forum</a>.
	<br><br><a href='index.php'><b>GO TO INDEX</b></a>
	<br><a href='admin/index.php'><b>GO TO ADMIN PAGE</b></a></center>";
}

}

echo "</td></tr><tr><td class=\"lab\">
<center>TechBook Ver 1.0.0 beta, made by &copy;JSystems<br><a href=\"http://www.jsystems.ro\">www.jsystems.ro</a></center></td></tr></table>"; 
 
?>
Return current item: Free Forum System(Tech Book)