<?php
echo '<style type="text/css">
body, td, tr {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12px;
	
}
.style2 {color: #FF0000}
</style>
<html>
<body background="../images/viral_background1.jpg">
<div align="center"><img src="../images/headerfix.jpg" width="639" height="137" border="1"></div>
<table bgcolor="#CCCCCC" width="639" border="0" align="center">
<tr>
<td>
<h1 align="center">Check Database Settings </h1>
</td>
</tr>
</table>';
 if (!isset($_POST['username']) || !isset($_POST['host']) || !isset($_POST['dbname'])){
echo '
<table width="639" border="0" align="center" bgcolor="#FFFFFF">

  <form name="form1" method="post" action="">
    <tr>
      <td bgcolor="#CCCCCC">DB Username </td>
      <td bgcolor="#CCCCCC"><input name="username" type="text" id="username"></td>
    </tr>
    <tr>
      <td>DB Password </td>
      <td><input name="password" type="text" id="password"></td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC">DB Host </td>
      <td bgcolor="#CCCCCC"><input name="host" type="text" id="host"></td>
    </tr>
    <tr>
      <td>DB Name </td>
      <td><input name="dbname" type="text" id="dbname" /></td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC">&nbsp;</td>
      <td bgcolor="#CCCCCC">&nbsp;</td>
    </tr>
    <tr>
      <td>Email </td>
      <td><input name="email" type="text" id="email"></td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC">Login password </td>
      <td bgcolor="#CCCCCC"><input name="pass" type="text" id="pass"></td>
    </tr>
</table>
  <p  align="center">&nbsp;</p>
  <div align="center">
  <input type="submit" name="Submit" value="Check settings">
  </div>';
  
}
else
{ 
	$conn=@mysql_connect ( $_POST['host'], $_POST['username'] , $_POST['password'] );
	if ($conn)
	{
		$dbres=@mysql_select_db (  $_POST['dbname'] );
		if ($dbres)
		{
			include ("../lib/inc.general.functions.php");
			FFileRead("../templates/constants.php.html", $content);
			$content=str_replace("{host}", $_POST['host'], $content);
			$content=str_replace("{db_name}", $_POST['dbname'], $content);
			$content=str_replace("{user}", $_POST['username'], $content);
			$content=str_replace("{password}", $_POST['password'], $content);
			$content=str_replace("{email}", $_POST['email'], $content);
			FFileWrite("../config/constants.php", $content);
			include("inc.all.php");
			execute_sql("install.sql"); 	
			$q->query("INSERT INTO members SET id='1',password=MD5('".$_POST['pass']."')");
		//$q->query($query);
			$q->query("UPDATE settings SET value='".$_POST['email']."' WHERE name='emailing_from_email'");
			//$q->query($query);
			$full='http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; 
			$full=str_replace("install/step1.php","",$full);
			$q->query("UPDATE settings SET value='".$full."' WHERE name='site_full_url'");
		//	$q->query($query);
			echo '
			 <div style="color:#FFFFFF" align="center">Database ok , please click Next to continue
			  <br><input type="button" value="Next Step >>" onClick="javascript: window.location.href=\'install_c.php\';"></div>
			';
		}
		else
		{
			echo '
<form name="form1" method="post" action="">
<table width="639" border="0" align="center" bgcolor="#FFFFFF">
  <tr>
    <td bgcolor="#CCCCCC">DB Username </td>
    <td bgcolor="#CCCCCC"><input name="username" type="text" id="username" /></td>
  </tr>
  <tr>
    <td>DB Password </td>
    <td><input name="password" type="text" id="password" /></td>
  </tr>
  <tr>
    <td bgcolor="#CCCCCC">DB Host </td>
    <td bgcolor="#CCCCCC"><input name="host" type="text" id="host" /></td>
  </tr>
  <tr>
    <td>DB Name </td>
    <td><input name="dbname" type="text" id="dbname" /></td>
  </tr>
  <tr>
    <td bgcolor="#CCCCCC">&nbsp;</td>
    <td bgcolor="#CCCCCC">&nbsp;</td>
  </tr>
    <tr>
      <td>Email </td>
      <td><input name="email" type="text" id="email"></td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC">Login password </td>
      <td bgcolor="#CCCCCC"><input name="pass" type="text" id="pass"></td>
    </tr>
</table>
<p align="center">&nbsp;</p>
  <div align="center">
			  <center>
			    <span class="style2"> Connect to db failed, please check your connection settings and retry!</span>
			  </center>
			  <input type="submit" name="Submit" value="ReCheck settings">
			  ';
		}
	}
	else
	{
		echo '
<form name="form1" method="post" action="">
  <table width="639" border="0" align="center" bgcolor="#FFFFFF">
    <tr>
      <td bgcolor="#CCCCCC">DB Username </td>
      <td bgcolor="#CCCCCC"><input name="username" type="text" id="username" /></td>
    </tr>
    <tr>
      <td>DB Password </td>
      <td><input name="password" type="text" id="password" /></td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC">DB Host </td>
      <td bgcolor="#CCCCCC"><input name="host" type="text" id="host" /></td>
    </tr>
    <tr>
      <td>DB Name </td>
      <td><input name="dbname" type="text" id="dbname" /></td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC">&nbsp;</td>
      <td bgcolor="#CCCCCC">&nbsp;</td>
    </tr>
    <tr>
      <td>Email </td>
      <td><input name="email" type="text" id="email"></td>
    </tr>
    <tr>
      <td bgcolor="#CCCCCC">Login password </td>
      <td bgcolor="#CCCCCC"><input name="pass" type="text" id="pass"></td>
    </tr>
  </table>
  <p align="center">&nbsp;</p>
  <div align="center">
		  <center>
		    <span class="style2">Connect to db failed, please check your connection settings and retry!</span>
		  </center>
		  <input type="submit" name="Submit" value="ReCheck settings">
		  ';
	}
	


}
echo '
  </div>
</form>
<p align="center">&nbsp;</p>
<div align="center">
</div>
</body>
</html>';
?>