Location: PHPKode > projects > phpautotest > install.php
<?php
require 'includes/phpautotest_config.php';
require 'includes/phpautotest_functions.php';
?>
<html>
<head>
<title>phpautotest Installer</title>
<style type='text/css'>

body {
font-family: arial, verdana, tahoma, sans-serif;
font-size: 11pt;
line-height: 16pt;
color: #333333;
}

h2 {
margin-bottom: 5px;
}

input.button {
background: #336699;
color: #FFFFFF;
padding: 1px;
font-family: arial, verdana, tahoma, sans-serif;
font-size: 10pt;
}

input.text {
font-family: arial, verdana, tahoma, sans-serif;
}

a:link { color: #336699; }
a:visited { color: #336699; }
a:hover { color: #3399FF; }

</style>
</head>
<body>

<?php
switch($_POST['task'])
{
	case 'step1':
	default:
		echo
		"
		<h2>phpautotest Installer</h2>
		Welcome to the phpautotest installation program. phpautotest requires PHP and MySQL+. phpautotest is compatible with the following browsers:<p>
- IE 5.5+<br>
- Mozilla 1.2+, Firefox 1.0+<br>
- Safari 1.3.9+<br>
- Konqueror 3.4+<br>
- Opera 8.5+<br>
		<p>
		If you experience any problems during installation e-mail us at hide@address.com or visit http://phpautotest.sourceforge.net and we will be glad to assist.
		<br>
		<form action='install.php' method='POST'>
		<input type='submit' class='button' value='Continue...'>
		<input type='hidden' name='task' value='step2'>
		</form>
		";
	break;
	
	case 'step2':
		echo
		"
		<h2>MySQL Database Information</h2>
		On this page please enter the information that phpautotest will use to connect
		to the MySQL database on your server. After you click the button below, the
		install script will first attempt to connect to your database with the information
		you have provided. 
		<br><br>

		<form action='install.php' method='POST'>

		Hostname:<br>
		<input type='text' class='text' size='30' name='mysql_host' value='localhost'>
		<br><br>

		Database Name:<br>
		<input type='text' class='text' size='30' name='mysql_database'>
		<br><br>

		Username:<br>
		<input type='text' class='text' size='30' name='mysql_username'>
		<br><br>

		Password:<br>
		<input type='password' class='text' size='30' name='mysql_password'>
		<br><br>
		
		<input type='submit' class='button' value='Continue...'>
		<input type='hidden' name='task' value='step3'>

		</form>
		";
	break;
	
	case 'step3':
		$mysql_host = $_POST['mysql_host'];
		$mysql_database = $_POST['mysql_database'];
		$mysql_username = $_POST['mysql_username'];
		$mysql_password = $_POST['mysql_password'];
		
		// TEST MYSQL CONNECTION
		$db = @mysql_connect($mysql_host, $mysql_username, $mysql_password);
		if(!$db)
		{
			die("The server responded with the following error message: <i>".mysql_error()."</i><form action='install.php' method='POST'><input type='submit' class='button' value='Back...'><input type='hidden' name='task' value='step2'></form>");
		}
		
		// TEST DATABASE SELECT
		$db_selected = @mysql_select_db($mysql_database, $db);
  		if(!$db_selected)
		{
			die("Selecting the database failed<form action='install.php' method='POST'><input type='submit' class='button' value='Back...'><input type='hidden' name='task' value='step2'></form>");
		}
		
		// Update phpautotest_config.php
		$file = phpautotest_readf('includes/phpautotest_config.php');
		
		$file = preg_replace("/phpautotest_db_location\s=\s''/", 'phpautotest_db_location = \''.$mysql_host.'\'', $file);
		$file = preg_replace("/phpautotest_db_username\s=\s''/", 'phpautotest_db_username = \''.$mysql_username.'\'', $file);		
		$file = preg_replace("/phpautotest_db_name\s=\s''/", 'phpautotest_db_name = \''.$mysql_database.'\'', $file);		
		$file = preg_replace("/phpautotest_db_password\s=\s''/", 'phpautotest_db_password = \''.$mysql_password.'\'', $file);		

		$query_flag = 1;
		
		// Run installation queries
   		if(!mysql_query("CREATE TABLE cases (
  case_id smallint(5) unsigned NOT NULL auto_increment,
  description longtext NOT NULL,
  start_timestamp varchar(15) NOT NULL default '',
  PRIMARY KEY  (case_id)
) TYPE=MyISAM;"))
			{
				$query_flag = 0;
			}
   		
		if(!mysql_query("CREATE TABLE page (
  id smallint(5) unsigned NOT NULL auto_increment,
  case_id smallint(5) unsigned NOT NULL default '0',
  page_location varchar(200) NOT NULL default '',
  html_output longtext NOT NULL,
  serialized_variable_dump longtext NOT NULL,
  serialized_post_vars longtext NOT NULL,
  php_test_code longtext NOT NULL,
  html_test longtext NOT NULL,
  method enum('E','R') NOT NULL default 'E',
  PRIMARY KEY  (id)
) TYPE=MyISAM;"))
			{
				$query_flag = 0;
			}
			
   		if(!mysql_query("CREATE TABLE test_results (
  id mediumint(8) unsigned NOT NULL auto_increment,
  test_id longtext NOT NULL,
  page_id smallint(5) unsigned NOT NULL default '0',
  html_output longtext NOT NULL,
  serialized_variable_dump longtext NOT NULL,
  time_taken float unsigned NOT NULL default '0',
  PRIMARY KEY  (id)
) TYPE=MyISAM;"))
			{
				$query_flag = 0;
			}
			
		if($query_flag == 1)
		{
			echo "Tables were installed successfully.<br>";
		}
		else
		{
			die("A problem occurred during installation of tables");
		}
		
		$res = phpautotest_writef('includes/phpautotest_config.php', $file);
       	
		if($res == "fail")
		{
			die("The configuration file includes/phpautotest_config.php could not be updated. Please update it manually. The file is self-explanatory, pay particular attention to the first 16 lines.");
		}
		else
		{
			echo "Configuration file was updated successfully.<br>";
		}
					
		echo
		"
		<form action='install.php' method='POST'>

		Password:<br>
		Kindly choose a password that will be used to restrict access to phpautotest.<br>
		<input type='password' class='text' size='30' name='phpautotest_password'>
		<br><br>
		
		Install path:<br>
		Enter the URL where you installed phpautotest (example: http://www.foobar.com/phpautotest/). Do not forget the slash and at the end.<b>This is very important, make sure it is entered correctly or phpautotest will not work</b>.<br>
		<input type='textbox' class='text' size='30' name='phpautotest_install_path' value = 'http://www.foobar.com/phpautotest/'>
		<br><br>
		
		<input type='submit' class='button' value='Continue...'>
		<input type='hidden' name='task' value='step4'>

		</form>
		";
	break;
	
	case 'step4':
       	$phpautotest_password = $_POST['phpautotest_password'];
       	$phpautotest_install_path = $_POST['phpautotest_install_path'];
		
       	// Update phpautotest_config.php
		$file = phpautotest_readf('includes/phpautotest_config.php');
	
		$file = preg_replace("/phpautotest_password\s=\s''/", 'phpautotest_password = \''.$phpautotest_password.'\'', $file);		
		$file = preg_replace("/phpautotest_install_path\s=\s''/", 'phpautotest_install_path = \''.$phpautotest_install_path.'\'', $file);	
		
		$res = phpautotest_writef('includes/phpautotest_config.php', $file);
		
		if($res == "fail")
		{
			die("The configuration file includes/phpautotest_config.php could not be updated. Please update the install path on line 3 and password on line 15.");
		}
       		
       		echo
	        "
		Installation completed. Delete install.php from your server immediately.<br>To change any settings edit <i>phpautotest_config.php</i> in the includes folder.
		<form action='login.php' method='GET'>
		<input type='submit' class='button' value='Log in...'>
		</form>
	        ";
	break;
}
?>

</body>
</html>
Return current item: phpautotest