<?php

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// HamLogWeb
//
// Par F5AGL - GRIP 2007-2008
//
// Email : f5agl@zapgillou.fr
//
// Cette création est mise à disposition selon le Contrat Paternité-Pas d'Utilisation Commerciale-Pas de Modification 2.0 France 
// disponible en ligne http://creativecommons.org/licenses/by-nc-nd/2.0/fr/ 
// ou par courrier postal à Creative Commons, 171 Second Street, Suite 300, San Francisco, California 94105, USA.
// 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Fichier : testmysql.php 
//
// Description : Gestionnaire d'installation de HamLogWeb
//
//               Ce script a pour objectif de valider les données MYSQL saisies depuis install.php avant l'exécution de do_install.php
//
// Paramètres : 
//	
//	- mode     : complet ou maj
//      - site_www : adresse http du site HamLogWeb 	(ex: http://toto.free.fr/F5AGL)
//      - url      : adresse du serveur 		(ex: toto.free.fr)
//  	- path     : chemin d'installation de HamLogWeb (ex : /F5AGL)
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


// paramètres transmis via l'url
$mode=$_GET['mode'];
$site_www=$_GET['site_www'];
$url=$_GET['url'];
$path=$_GET['path'];

// paramètres transmis via le formulaire
$db_host=$_POST['db_host'];
$db_login=$_POST['db_login'];
$db_psw=$_POST['db_psw'];
$db_base=$_POST['db_base'];
$db_table=$_POST['db_table'];

function ArretInstall()
	{
	?>
	<br>
	<table style="background-color: rgb(255, 102, 102); width: 65%; text-align: left; margin-left: auto; margin-right: auto;"border="0" cellpadding="2" cellspacing="2">
  	<tbody>
    	<tr>
      	<td>
      	<div style="text-align: center;"><span style="font-family: Arial; font-weight: bold;"><br>Echec des tests MySQL pr&eacute;liminaires &agrave; l'installation de <span style="color: rgb(0, 0, 153);">HamLog</span><span
 	style="color: rgb(51, 51, 51);">Web</span>.</span><br
 	style="font-family: Arial; font-weight: bold;">
	<span style="font-family: Arial; font-weight: bold;"><br>MySQL tests failure for your <span style="color: rgb(0, 0, 153);">HamLog</span><span
 	style="color: rgb(51, 51, 51);">Web</span>.</span><br
 	style="font-family: Arial; font-weight: bold;">
     	</div>
      	<div style="text-align: center;"><span
 	style="font-family: Arial; font-weight: bold;">Contr&ocirc;lez les informations MySQL fournies par votre h&eacute;bergeur.</span><br
 	style="font-family: Arial; font-weight: bold;">
	<span
 	style="font-family: Arial; font-weight: bold;">Please control MySQL information giving by your provider.</span><br
 	style="font-family: Arial; font-weight: bold;">
      	</div>
      	<div style="text-align: center;"><span
 	style="font-family: Arial; font-weight: bold;">Si vous avez besoin d'aide, utilisez le / If you need help, use <a href="http://www.zapgillou.fr/hamlogweb/forum">forum</a> de&nbsp;</span><span
 	style="font-family: Arial; font-weight: bold;"><span
	 style="color: rgb(0, 0, 153);">HamLog</span><span
	 style="color: rgb(51, 51, 51);">Web</span></span><span
	 style="font-family: Arial; font-weight: bold;"><br>
      	<br>
      	</span></div>
      	</td>
    	</tr>
  	</tbody>
	</table>
	<br>
	<hr style="width: 100%; height: 2px;">
	<div style="text-align: center;"><small><span
	 style="font-family: Comic Sans MS; font-weight: bold;"><span
	 style="color: rgb(0, 0, 153);">HamLog</span><span
	 style="color: rgb(102, 102, 102);">Web</span></span>&nbsp;-
	par / by <a href="mailto:hamweb@zapgillou.fr">F5AGL</a><br>
	Distribu&eacute; sous&nbsp;<a
	 href="http://creativecommons.org/licenses/by-nc-nd/2.0/fr/deed.en">Creative
	Commons Licence</a><br>
	<small><small><small><small><small><small>&nbsp;</small></small></small></small></small></small></small></div>
	<div style="text-align: center;">
	<a href="http://www.php.net/"><img src="./img/php.png"
	 style="border: 0pt none ;"></a> <a
	 href="http://www.nvu.com/"><img src="./img/nvu.gif"
	 style="border: 0pt none ;"></a> <a
	 href="http://www.getfirefox.com/"><img
	 src="./img/firefox.gif" style="border: 0pt none ;"></a>
	<a rel="license"
	 href="http://creativecommons.org/licenses/by-nc-nd/2.0/fr/"><img
	 alt="Creative Commons License" style="border-width: 0pt;"
	 src="http://i.creativecommons.org/l/by-nc-nd/2.0/fr/80x15.png"></a></div>
	</body>
	</html>
	<?php
	exit();
	}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=ISO-8859-1"
 http-equiv="content-type">
  <title>HamLogWeb - Installation</title>
</head>

<body>
<div style="text-align: center;"><b><span
 style="font-family: Comic Sans MS; color: rgb(153, 0, 0);"></span></b><big
 style="font-family: Comic Sans MS; font-weight: bold; color: rgb(0, 0, 153);"><big><big><big>HamLog</big></big></big></big><big
 style="font-family: Comic Sans MS; color: rgb(102, 102, 102); font-weight: bold;"><big><big><big>Web</big></big></big></big><span
 style="font-family: Comic Sans MS; font-weight: bold;"><span
 style="color: rgb(153, 0, 0);"><br>
par / by F5AGL</span></span>
<div style="text-align: left;"><span
 style="font-family: Comic Sans MS; font-weight: bold;"><span
 style="color: rgb(153, 0, 0);"><br>
</span></span>
<div style="text-align: center;"><span
 style="font-family: Comic Sans MS; font-weight: bold;"><span
 style="color: rgb(153, 0, 0);"><?php 
if ($mode=="complet") { echo "INSTALLATION COMPLETE / FULL INSTALL"; }
if ($mode=="maj")     { echo "MISE A JOUR D'UN SITE EXISTANT / UPDATING AN EXISTING WEB SITE"; }
?></span></span>



<?php

// Test des paramètres mysql uniquement si il s'agit d'une installation complète



if ($mode=="complet")
	{
	?>
	<br>
	<br>
	<table style="width: 80%; text-align: left; margin-left: auto; margin-right: auto;"border="0" cellpadding="2" cellspacing="2">
  	<tbody><tr>
	<td style="width: 384px; font-family: Arial; font-weight: bold;">Test de connexion au serveur MySQL / Testing MySQL server connection</td>
	<?php
	// Test de connexion au serveur MySQL
	$link = @mysql_connect($db_host,$db_login,$db_psw);
	if (!($link==false))
		{
		?>
		<td style="text-align: center; font-family: Arial; font-weight: bold; width: 118px;">
		<span style="color: rgb(0, 102, 0);">OK</span></td>
      		<td style="font-family: Arial; width: 456px; font-style: italic;"><small></small></td></tr>
		<?php
		}
	else
		{
		?>
		<td style="text-align: center; font-family: Arial; font-weight: bold; width: 118px;">
		<span style="color: rgb(204, 0, 0);">ECHEC / FAILED</span></td>
      		<td style="font-family: Arial; width: 456px; font-style: italic;"><small><?php echo "mysql_error: ".mysql_error(); ?></small></td></tr></tbody></table>
		<?php
		ArretInstall();
		}
	?>

    	<tr>
      	<td style="width: 384px; font-family: Arial; font-weight: bold;">Test de connexion &agrave; la base MySQL / Testing MySQL database connection</td>
	<?php
	// Test de connexion à la base MySQL
	$db_selected = mysql_select_db($db_base, $link); 
	if (!($db_selected==false))
		{
		?>
		<td style="text-align: center; font-family: Arial; font-weight: bold; width: 118px;">
		<span style="color: rgb(0, 102, 0);">OK</span></td>
      		<td style="font-family: Arial; width: 456px; font-style: italic;"><small></small></td></tr>
		<?php
		}
	else
		{
		?>
		<td style="text-align: center; font-family: Arial; font-weight: bold; width: 118px;">
		<span style="color: rgb(204, 0, 0);">ECHEC / FAILED</span></td>
      		<td style="font-family: Arial; width: 456px; font-style: italic;"><small><?php echo "mysql_error: ".mysql_error(); ?></small></td></tr></tbody></table>
		<?php
		ArretInstall();
		}
	?>
	

        <tr>
	<td style="width: 384px; font-family: Arial; font-weight: bold;">Test de cr&eacute;ation d'une table MySQL / Testing MySQL table append</td>
	<?php
	// Test de création d'une table MySQL
	$sql = 'CREATE TABLE `'.$db_table.'_TEST` (	`QSO_DATE` date NOT NULL default \'0000-00-00\',
  							`TIME_ON` time NOT NULL default \'00:00:00\',
  							`CALL` varchar(15) NOT NULL default \'\',
  							`BAND` varchar(15) NOT NULL default \'\',
  							`MODE` varchar(10) NOT NULL default \'\',
  							`DXCC` varchar(5) NOT NULL default \'\',
  							`QSL_SENT` varchar(5) NOT NULL default \'\'
						 ) TYPE=MyISAM;';

	$result = mysql_query($sql);
	if (!($result==false))
		{
		?>
		<td style="text-align: center; font-family: Arial; font-weight: bold; width: 118px;">
		<span style="color: rgb(0, 102, 0);">OK</span></td>
      		<td style="font-family: Arial; width: 456px; font-style: italic;"><small></small></td></tr>
		<?php
		}
	else
		{
		?>
		<td style="text-align: center; font-family: Arial; font-weight: bold; width: 118px;">
		<span style="color: rgb(204, 0, 0);">ECHEC / FAILED</span></td>
      		<td style="font-family: Arial; width: 456px; font-style: italic;"><small><?php echo "mysql_error: ".mysql_error(); ?></small></td></tr></tbody></table>
		<?php
		ArretInstall();
		}

	$sql = 'DROP TABLE `'.$db_table.'_TEST`;';
	$result = mysql_query($sql);
	

	?>

  	</tbody>
	</table>

	<?php


	// fermeture session sur le serveur MySQL
	//mysql_close($link);
	}




?>


<BR>
<div style="text-align: center;"><big><a
 href="do_install.php?mode=<?php echo $mode; ?>&site_www=<?php echo $site_www; ?>&url=<?php echo $url; ?>&path=<?php echo $path; ?>&db_host=<?php echo $db_host; ?>&db_login=<?php echo $db_login; ?>&db_psw=<?php echo $db_psw; ?>&db_base=<?php echo $db_base; ?>&db_table=<?php echo $db_table; ?>"><small
 style="font-weight: bold; font-family: Arial;">CLIQUEZ ICI
POUR LANCER L'INSTALLATION / CLICK HERE TO BEGINNING THE INSTALLATION</small></a>
</big></div><BR>


<hr style="width: 100%; height: 2px;">
<div style="text-align: center;"><small><span
 style="font-family: Comic Sans MS; font-weight: bold;"><span
 style="color: rgb(0, 0, 153);">HamLog</span><span
 style="color: rgb(102, 102, 102);">Web</span></span>&nbsp;-
par <a href="mailto:hamweb@zapgillou.fr">F5AGL</a><br>
Distribu&eacute; sous&nbsp;<a
 href="http://creativecommons.org/licenses/by-nc-nd/2.0/fr/deed.en">Creative
Commons Licence</a><br>
<small><small><small><small><small><small>&nbsp;</small></small></small></small></small></small></small></div>
<div style="text-align: center;">
<a href="http://www.php.net/"><img src="./img/php.png"
 style="border: 0pt none ;"></a> <a
 href="http://www.nvu.com/"><img src="./img/nvu.gif"
 style="border: 0pt none ;"></a> <a
 href="http://www.getfirefox.com/"><img
 src="./img/firefox.gif" style="border: 0pt none ;"></a>
<a rel="license"
 href="http://creativecommons.org/licenses/by-nc-nd/2.0/fr/"><img
 alt="Creative Commons License" style="border-width: 0pt;"
 src="http://i.creativecommons.org/l/by-nc-nd/2.0/fr/80x15.png"></a></div>
</body>
</html>

		