<?
include ('logue.php');
include ('entete2.php');

$galaxi = $_POST["verif1"];
$system = $_POST["verif2"];
$position = $_POST["verif3"];
$iddepart = $_POST["verif4"];
$mission = $_POST["verif5"];
$Exdate = $_POST["verif6"];
$vruines = $_POST["verif7"];


$sql = "SELECT idjoueur FROM matgraph_users WHERE id='$iddepart' ";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
$row = mysql_fetch_array($res);

if($vruines == 0) {
	$vitesse = 4;
} else {
	$vitesse = 2;
}
	//cc = coordonnées
	$sqlcc = "SELECT galaxi,system,position FROM matgraph_users WHERE id='$iddepart' ";
	$rescc = db_mysql_Query($sqlcc)or die('erreur sql<br>'.$sqlcc.'<br>'.mysql_error());
	$rowcc = mysql_fetch_array($rescc);

	$Dif_position = $_POST['verif3'] - $rowcc[position] ;
	if ($Dif_position < 0) { $Dif_position = -$Dif_position ; }

	$Dif_system = $_POST['verif2'] - $rowcc[system] ;
	if ($Dif_system < 0) { $Dif_system = -$Dif_system ; }

	$Dif_galaxi = $_POST['verif1'] - $rowcc[galaxi] ;
	if ($Dif_galaxi < 0) { $Dif_galaxi = -$Dif_galaxi ; }

	if(($Dif_system + $Dif_galaxi + $Dif_position) == 0)
	{
		$temps = (60*4) / $vitesse;
	}elseif(($Dif_system + $Dif_galaxi) == 0)
	{
		$temps_position = $Dif_position*0.5 ;
		$temps = (600 * ( 5 + $temps_position) / $vitesse)/10 ;
	}elseif($Dif_galaxi == 0)
	{
		$temps_position = $Dif_position*0.5 ;
		$temps_system = $Dif_system*1 ;
		$temps = (600 * ( 20 + $temps_position + $temps_system) / $vitesse)/13.5 ;
	}else
	{
		$temps_position = $Dif_position*0.03 ;
		$temps_system = $Dif_system*0.3 ;
		$temps_galaxi = $Dif_galaxi*30 ;
		$temps = (600 * ( 40 + $temps_position + $temps_system + $temps_galaxi) / $vitesse)/10 ;
	}
	
$duree = $temps;

ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $_POST["verif6"], $thetime);
$arrive = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

$diftemps = $duree- ($arrive-time() );
$newDate =  strftime("%Y-%m-%d %H:%M:%S", time()+$diftemps );

if ($row[idjoueur] == $idlogin && $mission == "aller") {
	$sql = "UPDATE matgraph_mobil_vruines SET mission='retour', date = '$newDate' WHERE date ='$Exdate' AND mission='aller' AND galaxi='$galaxi' AND system='$system' AND position='$position' AND iddepart='$iddepart'";
	$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
}
echo '<script language="javascript" type="text/javascript">
<!--
window.location.replace("apercu.php");
-->
</script>';

?>
