<?php
include("../config.php3");
include($BIB."bib_generic.php3");

set_time_limit($TIME_LIMIT);

# on récupère ce qu'il y a dans $DATABASE et on le met dans $DATABASE2
$rows = main_db_query("SELECT * FROM Members");
echo db_num_rows($rows);
$r=db_num_rows($rows);

while($m = db_fetch_array($rows))
{
	# on ne prend que s'il y a un player
	$player = getplayer($m[Id]);
	if (!empty($player[NickName]))
	{
		# on se connecte sur DATABASE
		switchBase($DATABASE2);

		# on verifie ensuite que le mail n'existe pas déjà dans la base (c'est l'identifiant unique)
		$once = db_fetch_array(mysql_query("SELECT Id FROM Members WHERE Email='".$m[Email]."'"));

		# si l'email n'est pas déjà présent
		if (!$once)
		{
			$r--;
			# on inscrit les nouvelles données du membre
			$req = "INSERT INTO Members (".
				"NickName,".
			  	"Time,Password, Email, IP, Host, Browser,IsOff,IsSuspect,".
				"Gender,Name,FirstName,Address,Zip,Town,Country,Age,".
				"InfoLetter,InfoTickets,LikeSport1,LikeSport2,LikeSport3,".
				"CompetSport,CompetLevel,HobbySport,HobbyFrequency)".
				" VALUES (".
				"'$player[NickName]',".
			  	"'$m[Time]','$m[Password]','$m[Email]','$m[IP]', '$m[Host]', '$m[Browser]','$m[IsOff]','$m[IsSuspect]',".
				"'$m[Gender]','$m[Name]','$m[FirstName]','$m[Address]','$m[Zip]','$m[Town]','$m[Country]','$m[Age]',".
				"'$m[InfoLetter]','$m[InfoTickets]','$m[LikeSport1]','$m[LikeSport2]','$m[LikeSport3]',".
				"'$m[CompetSport]','$m[CompetLevel]','$m[HobbySport]','$m[HobbyFrequency]')";
				
		    $x = mysql_query($req);
			if (!$x)
			{
				echo "query failed ! ".$m[Id]." ".$m[Email]."<br>";
				echo $req."<br>";
			}
		}
		else
		{
			echo "déjà dans la base : ".$m[Id]." ".$m[Email]."<br>";
		}
		# on se connecte sur DATABASE
		switchBase($DATABASE);
	}
	else
	{
		echo "empty : ".$m[Id]." ".$m[Email]."<br>";
	}
	flush();
}
echo "<br>".$r."<br>";
echo "Terminé !";
?>