<?php
/***********************************************
 *
 *   COMPANY: Telmanik Technologies
 *	 WEBSITE: TELMANIK.COM
 *   PROJECT: Website Content Management System
 *   LICENSE: Copyright Telmanik CMS Press
 *   VERSION: 1.01 Beta
 *
 *************************************************/

 error_reporting(0);
 
 

		  $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
		$pos = strpos($url,"/install/step2.php?lang".$output.""); 
		$site_inst = substr($url,0,$pos); 
		$site_inst_path=str_replace('/install/step2.php?lang'.$output.'', '', $_SERVER['SCRIPT_FILENAME']); 

$error = '';

if (isset($_POST['connect_info']))
{



		
	$dbserver = $_POST['dbserver'];
	$database_connect = $_POST['db_name'];
	$dbuser = $_POST['db_user'];
	$dbpass = $_POST['db_pass'];


	
	$link = @mysql_connect($dbserver, $dbuser,$dbpass);
	
	if (! $link)
	{
		$error .= '<li>Database connection Error. ' . mysql_error() . '</li>';
	}
	else
	{
		$suc = mysql_select_db($database_connect, $link);
		
		if (! $suc)
		{
			$error .= '<li> Error Occured ! ' . mysql_error() . ' Try Again !</li>';
		}
	}

	if ($error == '')
	{
		$fp = fopen('../Connections/telmanik_press.php', 'w');
		fputs($fp, '<?php');

$main_config = <<<EOT

error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED);
    
session_start(); 

\$hostname_telmanik_press     = '$dbserver';
\$database_telmanik_press     = '$database_connect';
\$username_telmanik_press     = '$dbuser';
\$password_telmanik_press     = '$dbpass';

\$telmanik_press = mysql_connect("\$hostname_telmanik_press","\$username_telmanik_press","\$password_telmanik_press") or trigger_error(mysql_error(),E_USER_ERROR); 

\$db = mysql_select_db("\$database_telmanik_press", \$telmanik_press) or die ("Couldn't select database.");


\$config = array();

\$config['basedir']        =  '$site_inst_path'; 
\$config['baseurl']        =  '$site_inst';



EOT;
			
	fputs($fp, $main_config);
	fclose($fp);

	require './template/header.php';
?>

<p class="config-created"><?php $translate->__('Step 2 Completed and configured successfully.'); ?></p>

<form method="post" action="db.php?lang<?php echo $output;?>">
<input type="submit" class="install_it" name=submit value="<?php $translate->__('Next Step'); ?>"> 
<input type="hidden" name="dbserver" value="<?php echo $dbserver; ?>"> 
<input type="hidden" name="db_name" value="<?php echo $db_name; ?>"> 
<input type="hidden" name="db_user" value="<?php echo $db_user; ?>"> 
<input type="hidden" name="db_pass" value="<?php echo $db_pass; ?>"> 
<input type="hidden" name="action" value="create_tables">
</form>

<?php
			
		require 'template/footer.php';            
		exit(0);
	}
}
else 
{
	
	$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
	$site_url = str_replace('/install/step2.php?lang'.$output.'', '', $url);
	
	
	
	$db_name = $db_user = $db_pass = '';
	$dbserver = 'localhost';
}
require 'template/header.php';

if ($error != '')
{
	echo '<div class="error"><ul>' . $error . '</ul></div>';
}

?>


<h1><?php $translate->__('Database & website settings'); ?></h1>



<form name="myform2" method="POST" action="">

<table width="96%" border="0" cellspacing="2" cellpadding="2" align="center">


<tr>
<td width="30%"><?php $translate->__('MySQL database server name'); ?></td>
<td width="70%"><input type="text" name="dbserver" size="33" value="<?php echo $dbserver;?>"> <?php $translate->__('default:'); ?>    <i><?php $translate->__('localhost'); ?></i></td>
</tr>

<tr>
<td width="30%"><?php $translate->__('Database name'); ?></td>
<td width="70%"><input type="text" name="db_name" size="33" value="<?php echo $db_name;?>"></td>
</tr>

<tr>
<td width="30%"><?php $translate->__('Database user name'); ?></td>
<td width="70%"><input type="text" name="db_user" size="33" value="<?php echo $db_user;?>"></td>
</tr>

<tr>
<td width="30%"><?php $translate->__('Database password'); ?></td>
<td width="70%"><input type="text" name="db_pass" size="33"  value="<?php echo $db_pass;?>"></td>
</tr>




<tr>
<td width="30%">&nbsp;</td>
<td width="70%"><input type="submit" class="install_it" name="connect_info" value="<?php $translate->__('Continue Installation'); ?>"><br><br></td>
</tr>

</table>
</form>

<?php

require 'template/footer.php';

?>
