<?php
/* $Id: install.php,v 1.2 2003/02/23 22:42:03 gambitdis Exp $ */

include("config.inc.php");

?>

<html>
<head>
	<title>Speed Test - Installation Database Check</title>
	<link rel="stylesheet" href="style.css">
</head>

<body>

<h1>Speed Test</h1>
<h2>Installation Database Check</h2>


<?php

$errored = 0;

function print_message($message, $bad) {
	global $errored;
	
	if ($bad==1) {
		$errored = 1;
		echo "<font color=red><p><b>$message</b></font>";
	} else {
		echo "<font color=lime><p><b>$message</b></font>";
	}
}


$data_file = $images_path_1.'1.png';
if ( $fd = fopen ($data_file, "rb") ) {
	print_message("Payload file successfully found and opened.", 0);
} else {
	print_message("Could not access payload file.", 1);
}

	

if ($mysql == True) {

	if ($link = @mysql_connect($database["host"], $database["login"],
		$database["password"])) {
		print_message("Successfully connected to database.", 0);
	} else {
		print_message("Could not connect to the database.  Make sure that you have
			added the proper user and password.  Also, make sure that the user
			has permission to connect to the host.  You may need to explicitly
			add the host (in some cases localhost) that the user can connect 
			from.", 1);
	}

		if (mysql_select_db($database["database"])) {
			print_message("Successfully selected the database.", 0);

		$query = "INSERT INTO readings (down, speed, ip, name, browser) VALUES ('1', '12345',
			'100.255.255.254', '123.testdomain.nil', 'browser-tag')";
		if ($result = mysql_query($query)) {
			print_message("Successfully inserted test record.", 0);
			$query = "DELETE FROM readings WHERE name='123.testdomain.nil'";
			if ($result = mysql_query($query)) {
				print_message("Successfully deleted test record.", 0);
			} else {
  	 		print_message("Unable to delete test record from database.  The user
					may not have been granted the DELETE privilege.", 1);
			}
		} else {
  	 		print_message("Unable to insert test record into database.  The user
					may have not been granted the INSERT privilege.", 1);
		}

	} else {
   	print_message("Could not select database.  The user may not have
			permission to connect to the database or the database may have not
			been created.", 1);
	}


	print_message("SUCCESSFULLY PASSED TESTS.<br>You may now test your
			download speed <a href=\"./\">here</a> or upload speed <a href=\"upload/\">here</a>", 0);


} else {
	echo "MySQL database support not turned on.  Bandwidthmeter will work
		without a database, but will not log results.  You may turn on MySQL
		support in the config.inc.php file.  Please make sure to configure
		the database properly (directions are in ./docs/INSTALL).  Then reload
		this page to test whether Bandwidthmeter can connect to the database.";
}
	
	
?>
</body>
</html>
