<?php

/**
 * floten3.php
 *
 * @version 1.0
 * @copyright 2008 by Chlorel for XNova
 */
 
 /*
	Cette version présentait un bug:
	Lors de la construction d'un vaisseau, le vol du même type de vaisseau permet de dupliquer
	la flotte.
	La requete qui execute la mise à jour de la BDD (ligne 483) est correct.
	Toutefois ceci nécessite la toute derniere requete (ligne 542)
	Voir les sujets suivants pour davantage de détails:
		http://wootook.org/board/index.php/topic,2791.0.html
		http://wootook.org/board/index.php/topic,2860.0.html
		
	Avertissement: ce fichier a été modifié par Kiwille et peut ne pas etre compatible avec 
	autres versions de XNova ou votre jeu.
 */

define('INSIDE' , true);
define('INSTALL' , false);
require_once dirname(__FILE__) .'/common.php';

includeLang('fleet');	

	$TargetPlanet  = doquery("SELECT * FROM {{table}} WHERE `galaxy` = '". $_POST['galaxy'] ."' AND `system` = '". $_POST['system'] ."' AND `planet` = '". $_POST['planet'] ."' AND `planet_type` = '". $_POST['planettype'] ."';", 'planets', true);


$protection        = $game_config['noobprotection'];
$protectionpoints  = $game_config['noobprotectiontime'];
$protectionmulti   = $game_config['noobprotectionmulti'];

$fleetarray  = unserialize(base64_decode(str_rot13($_POST["usedfleet"])));
if (!is_array($fleetarray)) {
	message ("<font color=\"red\"><b>". $lang['fl_fleet_err'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
}
	
if ($user['urlaubs_modus'] != 0) {
	message ("<font color=\"red\"><b>Vous &ecirc;tes en MV. Impossible de lancer l'ordre!</b></font>", "MV activ&eacute;", 2);
}

//Pas assez de vaisseaux sur la planète?
foreach ($fleetarray as $Ship => $Count) {
	if ($Count > $planetrow[$resource[$Ship]]) message ("<font color=\"red\"><b>". $lang['fl_fleet_err'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
}

$error              = 0;
$galaxy             = intval($_POST['galaxy']);
$system             = intval($_POST['system']);
$planet             = intval($_POST['planet']);
$planettype         = intval($_POST['planettype']);
$fleetmission       = $_POST['mission'];

if ($planettype != 1 && $planettype != 2 && $planettype != 3) {
	message ("<font color=\"red\"><b>". $lang['fl_fleet_err_pl'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
}

if ($fleetmission == 8) {
	$YourPlanet = false;
	$UsedPlanet = false;
	$select     = doquery("SELECT `id_owner` FROM {{table}} WHERE galaxy = '". $galaxy ."' AND system = '". $system ."' AND planet = '". $planet ."'", "planets");
} else {
	$YourPlanet = false;
	$UsedPlanet = false;
	$select     = doquery("SELECT `id_owner` FROM {{table}} WHERE galaxy = '". $galaxy ."' AND system = '". $system ."' AND planet = '". $planet ."' AND planet_type = '". $planettype ."'", "planets");
}

if ($planetrow['galaxy'] == $galaxy &&
	$planetrow['system'] == $system &&
	$planetrow['planet'] == $planet &&
	$planetrow['planet_type'] == $planettype) {
	message ("<font color=\"red\"><b>". $lang['fl_ownpl_err'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
}

// Test d'existance de l'enregistrement dans la galaxie !
if ($fleetmission != 15 && $fleetmission != 11) { 
	if (mysql_num_rows($select) < 1 && $fleetmission != 7) {
		message ("<font color=\"red\"><b>". $lang['fl_unknow_target'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	} elseif ($fleetmission == 9 && mysql_num_rows($select) < 1) {
		message ("<font color=\"red\"><b>". $lang['fl_used_target'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	}
} elseif ($fleetmission == 15) {
	$EnvoiMaxExpedition = $_POST['maxepedition'];
	$Expedition         = $_POST['curepedition'];

	if ($EnvoiMaxExpedition == 0 ) {
		message ("<font color=\"red\"><b>". $lang['fl_expe_notech'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	} elseif ($Expedition >= $EnvoiMaxExpedition ) {
		message ("<font color=\"red\"><b>". $lang['fl_expe_max'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	}
}

$select = mysql_fetch_array($select);

if ($select['id_owner'] == $user['id']) {
	$YourPlanet = true;
	$UsedPlanet = true;
} elseif (!empty($select['id_owner'])) {
	$YourPlanet = false;
	$UsedPlanet = true;
} else {
	$YourPlanet = false;
	$UsedPlanet = false;
}

// Determinons les type de missions possibles par rapport a la planete cible
if ($fleetmission == 15) {
	// Gestion des Expéditions
	$missiontype = array(15 => $lang['type_mission'][15]);
} else {
	if ($_POST['planettype'] == "2") {
		if ($_POST['ship209'] >= 1) {
			$missiontype = array(8 => $lang['type_mission'][8]);
		} else {
			$missiontype = array();
		}
	} elseif ($_POST['planettype'] == "1" || $_POST['planettype'] == "3") {
		if ($_POST['ship208'] >= 1 && !$UsedPlanet) {
			$missiontype = array(7 => $lang['type_mission'][7]);
		} elseif ($_POST['ship210'] >= 1 && !$YourPlanet) {
			$missiontype = array(6 => $lang['type_mission'][6]);
		}
		
		if ($_POST['ship220'] >= 1 AND $_POST['planettype'] == "1" AND !$YourPlanet) {
			$missiontype = array(11 => $lang['type_mission'][11]);
		}

		if ($_POST['ship202'] >= 1 ||
		$_POST['ship203'] >= 1 ||
		$_POST['ship204'] >= 1 ||
		$_POST['ship205'] >= 1 ||
		$_POST['ship206'] >= 1 ||
		$_POST['ship207'] >= 1 ||
		$_POST['ship211'] >= 1 ||
		$_POST['ship213'] >= 1 ||
		$_POST['ship214'] >= 1 ||
		$_POST['ship215'] >= 1 ||
		$_POST['ship216'] >= 1 ||
		$_POST['ship217'] >= 1 ||
		$_POST['ship218'] >= 1) {
			if (!$YourPlanet) {
				$missiontype[1] = $lang['type_mission'][1];
				//$missiontype[5] = $lang['type_mission'][5];
			}
			$missiontype[3] = $lang['type_mission'][3];
			$missiontype[5] = $lang['type_mission'][5]; /*VDR*/
			
		}


	} elseif ($_POST['ship209'] >= 1 || $_POST['ship208']) {
		$missiontype[3] = $lang['type_mission'][3];
	}
	if ($YourPlanet)
		$missiontype[4] = $lang['type_mission'][4];

	if ( $_POST['planettype'] == 3 &&
		($_POST['ship214']         ||
		 $_POST['ship213'])        &&
		 !$YourPlanet              &&
		 $UsedPlanet) {
		$missiontype[2] = $lang['type_mission'][2];
	}
	if ( $_POST['planettype'] == 3 &&
	 $_POST['ship214'] >= 1    &&
	   !$YourPlanet            &&
	   $UsedPlanet) {
	  $missiontype[9] = $lang['type_mission'][9];
	}
}

if (empty($missiontype[$fleetmission])) {
	message ("<font color=\"red\"><b>". $lang['fl_bad_mission'] ."</b></font>", $lang['fl_error'], "fleet." . PHPEXT, 2);
}

CheckPlanetUsedFields($planetrow);

if ($TargetPlanet['id_owner'] == '') {
	$HeDBRec = $user;
} elseif ($TargetPlanet['id_owner'] != '') {
	$HeDBRec = doquery("SELECT * FROM {{table}} WHERE `id` = '". $TargetPlanet['id_owner'] ."';", 'users', true);
}

$UserPoints    = doquery("SELECT `total_points` FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". $user['id'] ."';", 'statpoints', true);
$User2Points   = doquery("SELECT `total_points` FROM {{table}} WHERE `stat_type` = '1' AND `stat_code` = '1' AND `id_owner` = '". $HeDBRec['id'] ."';", 'statpoints', true);

$MyGameLevel  = $UserPoints['total_points'];
$HeGameLevel  = $User2Points['total_points'];
$VacationMode = $HeDBRec['urlaubs_modus'];

	
	/*********************************************** DEBUT de code de Kiwille -- Protection des joueurs **********************************************************/
	if ( $protection == 1 AND $TargetPlanet['id_owner'] != '') { //Protection active(=1) et joueur existant
		if ($HeDBRec['onlinetime'] >= (time()-60 * 60 * 24 * 7)) { //Si c'est inactif, on passe la protection
			if ($_POST['mission'] == 1 OR $_POST['mission'] == 6 OR $_POST['mission'] == 9) { //Ordres: Attaque, Espionnage, Destruction

				/* ==GROS sur un PETIT== */
				if ( $HeGameLevel < $protectionpoints) { //Déjà si le petit a moins de "$protectionpoints", on continue...
					if ($MyGameLevel > ($HeGameLevel * $protectionmulti)) { //La cible est il dans ma zone d'attaque?
						message("<font color=\"lime\"><b>".$lang['fl_noob_mess_n']."</b></font>", $lang['fl_noob_title'], "fleet." . $phpEx, 2);
					}
				}
				/*==PETIT sur un GROS==*/
				if ( $MyGameLevel < $protectionpoints) { //Déjà si le petit a moins de "$protectionpoints", on continue...
					if ($HeGameLevel > ($MyGameLevel * $protectionmulti)) { //La cible est il dans ma zone d'attaque?
						message("<font color=\"red\"><b>".$lang['fl_pow_mess_n']."</b></font>", $lang['fl_pow_title'], "fleet." . $phpEx, 2);
					}
				}
				
			}
		}
	}

	//interdit d'envoyer une flotte à un joueur en MV (exception du recyclage)
	if ($VacationMode != 0 AND $_POST['mission'] != 8) {
		message("<font color=\"lime\"><b>".$lang['fl_vacation_pla']."</b></font>", $lang['fl_vacation_ttl'], "fleet." . $phpEx, 2);
	}
	
	//En cas de meme IP:
	if ($user['user_lastip']==$HeDBRec['user_lastip'] AND 
	$_POST['mission'] != 3 AND 
	$_POST['mission'] != 4 AND 
	$_POST['mission'] != 5 AND 
	$_POST['mission'] != 7 AND
	$_POST['mission'] != 8 AND
	$_POST['mission'] != 11 AND
	$_POST['mission'] != 15)  
	{
			$messageip = "Vous ne pouvez pas envoyer de flottes sur cette plan&egrave;te alors que vous avez la m&ecirc;me IP!";
			message("<font color=\"lime\"><b>".$messageip."</b></font>", "Ordre refus&eacute;e", "fleet." . $phpEx, 2);
	}
	if ($_POST['mission'] == 3 AND $user['id']!=$HeDBRec['id'] AND $user['user_lastip']==$HeDBRec['user_lastip'])	 
	{
			$messageip = "Vous ne pouvez pas transporter de ressources sur cette plan&egrave;te alors que vous avez la m&ecirc;me IP!";
			message("<font color=\"lime\"><b>".$messageip."</b></font>", "Ordre refus&eacute;e", "fleet." . $phpEx, 2);
	}
	/*********************************************** FIN de code de Kiwille -- Protection des joueurs **********************************************************/
	
	
	
	$FlyingFleets = mysql_fetch_assoc(doquery("SELECT COUNT(fleet_id) as Number FROM {{table}} WHERE `fleet_owner`='{$user['id']}'", 'fleets'));
	$ActualFleets = $FlyingFleets["Number"];
	if (($user[$resource[108]] + 1) <= $ActualFleets) {
		message("Pas de slot disponible", "Erreur", "fleet." . $phpEx, 1);
	}

	if ($_POST['resource1'] + $_POST['resource2'] + $_POST['resource3'] < 1 AND $_POST['mission'] == 3) {
		message("<font color=\"lime\"><b>".$lang['fl_noenoughtgoods']."</b></font>", $lang['type_mission'][3], "fleet." . $phpEx, 1);
	}
	if ($_POST['mission'] != 15) {
		if ($TargetPlanet['id_owner'] == '' AND $_POST['mission'] < 7) {
			message ("<font color=\"red\"><b>". $lang['fl_bad_planet01'] ."1</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
		}
		if ($TargetPlanet['id_owner'] != '' AND $_POST['mission'] == 7) {
			message ("<font color=\"red\"><b>". $lang['fl_bad_planet02'] ."2</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
		}
		if ($HeDBRec['ally_id'] != $user['ally_id'] AND $_POST['mission'] == 4) {
			message ("<font color=\"red\"><b>". $lang['fl_dont_stay_here'] ."3</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
		}
		/*if ($TargetPlanet['ally_deposit'] < 1 AND $HeDBRec != $user AND $_POST['mission'] == 5) {
			message ("<font color=\"red\"><b>". $lang['fl_no_allydeposit'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
		}*/
		if (($TargetPlanet["id_owner"] == $planetrow["id_owner"]) AND ($_POST["mission"] == 1)) {
			message ("<font color=\"red\"><b>". $lang['fl_no_self_attack'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
		}
		if (($TargetPlanet["id_owner"] == $planetrow["id_owner"]) AND ($_POST["mission"] == 6)) {
			message ("<font color=\"red\"><b>". $lang['fl_no_self_spy'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
		}
		if (($TargetPlanet["id_owner"] != $planetrow["id_owner"]) AND ($_POST["mission"] == 4)) {
			message ("<font color=\"red\"><b>". $lang['fl_only_stay_at_home'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
		}
	}

	$missiontype = array(
		1 => $lang['type_mission'][1],
		2 => $lang['type_mission'][2],
		3 => $lang['type_mission'][3],
		4 => $lang['type_mission'][4],
		5 => $lang['type_mission'][5],
		6 => $lang['type_mission'][6],
		7 => $lang['type_mission'][7],
		8 => $lang['type_mission'][8],
		9 => $lang['type_mission'][9],
		11 => $lang['type_mission'][11],
		15 => $lang['type_mission'][15],
		);

	$speed_possible = array(10, 9, 8, 7, 6, 5, 4, 3, 2, 1);

	$AllFleetSpeed  = GetFleetMaxSpeed ($fleetarray, 0, $user);
	$GenFleetSpeed  = $_POST['speed'];
	if ($GenFleetSpeed <= 0 OR $GenFleetSpeed > 10) {
		$GenFleetSpeed = 10;
	}		
	$SpeedFactor    = $_POST['speedfactor'];
	$speedallsmin   = $_POST['speedallsmin'];
	$MaxFleetSpeed  = intval(min($AllFleetSpeed));

	if (!in_array($GenFleetSpeed, $speed_possible)) {
		message ("<font color=\"red\">1 -<b>". $lang['fl_cheat_speed'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	}


	if ($MaxFleetSpeed != $speedallsmin) {
		message ("<font color=\"red\">2 - <b>". $lang['fl_cheat_speed'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	}

	if (!$_POST['planettype']) {
		message ("<font color=\"red\"><b>". $lang['fl_no_planet_type'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	}

	// Test de coherance de la destination (voir si elle se trouve dans les limites de l'univers connu
	$error     = 0;
	$errorlist = "";
	if (!$_POST['galaxy'] || !is_numeric($_POST['galaxy']) || $_POST['galaxy'] > 9 || $_POST['galaxy'] < 1) {
		$error++;
		$errorlist .= $lang['fl_limit_galaxy'];
	}
	if (!$_POST['system'] || !is_numeric($_POST['system']) || $_POST['system'] > 499 || $_POST['system'] < 1) {
		$error++;
		$errorlist .= $lang['fl_limit_system'];
	}
	if (!$_POST['planet'] || !is_numeric($_POST['planet']) || $_POST['planet'] > 16 || $_POST['planet'] < 1) {
		$error++;
		$errorlist .= $lang['fl_limit_planet'];
	}

	if ($error > 0) {
		message ("<font color=\"red\"><ul>" . $errorlist . "</ul></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	}

	// La flotte part bien de la planete courrante ??
	if ($_POST['thisgalaxy'] != $planetrow['galaxy'] |
		$_POST['thissystem'] != $planetrow['system'] |
		$_POST['thisplanet'] != $planetrow['planet'] |
		$_POST['thisplanettype'] != $planetrow['planet_type']) {
		message ("<font color=\"red\"><b>". $lang['fl_cheat_origine'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	}

	if (!isset($fleetarray) OR !is_array($fleetarray)) {
		message ("<font color=\"red\"><b>". $lang['fl_no_fleetarray'] ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	}

	$distance      = GetTargetDistance ( $_POST['thisgalaxy'], $_POST['galaxy'], $_POST['thissystem'], $_POST['system'], $_POST['thisplanet'], $_POST['planet'] );
	$duration      = GetMissionDuration ( $GenFleetSpeed, $MaxFleetSpeed, $distance, $SpeedFactor );
	$consumption   = GetFleetConsumption ( $fleetarray, $SpeedFactor, $duration, $distance, $MaxFleetSpeed, $user );

	$fleet['start_time'] = $duration + time();
	if ($_POST['mission'] == 15) {
		$StayDuration    = $_POST['expeditiontime'] * 3600;
		$StayTime        = $fleet['start_time'] + $_POST['expeditiontime'] * 3600;
	}/* elseif ($_POST['mission'] == 5) {
		$StayDuration    = $_POST['holdingtime'] * 3600;
		$StayTime        = $fleet['start_time'] + $_POST['holdingtime'] * 3600;
	}*/ else {
		$StayDuration    = 0;
		$StayTime        = 0;
	}
	$fleet['end_time']   = $StayDuration + (2 * $duration) + time();
	$FleetStorage        = 0;
	$FleetShipCount      = 0;
	$fleet_array         = "";
	$FleetSubQRY         = "";

	foreach ($fleetarray as $Ship => $Count) {
		if ($Count != 0) {
			$FleetStorage    += $pricelist[$Ship]["capacity"] * $Count;
			$FleetShipCount  += $Count;
			$fleet_array     .= $Ship .",". $Count .";";
			$NewShip 		  = intval($planetrow[$resource[$Ship]] - $Count) ;
			$FleetSubQRY     .= "`".$resource[$Ship]."` = '".$NewShip."' , ";
		}
	}

	$FleetStorage        -= $consumption;
	$StorageNeeded        = 0;
	if ($_POST['resource1'] < 1) {
		$TransMetal      = 0;
	} else {
		$TransMetal      = $_POST['resource1'];
		$StorageNeeded  += $TransMetal;
	}
	if ($_POST['resource2'] < 1) {
		$TransCrystal    = 0;
	} else {
		$TransCrystal    = $_POST['resource2'];
		$StorageNeeded  += $TransCrystal;
	}
	if ($_POST['resource3'] < 1) {
		$TransDeuterium  = 0;
	} else {
		$TransDeuterium  = $_POST['resource3'];
		$StorageNeeded  += $TransDeuterium;
	}

	$StockMetal      = floor($planetrow['metal']);
	$StockCrystal    = floor($planetrow['crystal']);
	$StockDeuterium  = floor($planetrow['deuterium']);
	$StockDeuterium -= floor($consumption) - 1;

	//***************************************** CODE KIWILLE ******************************************************
	if ($StockDeuterium < 0) { 
		//pas assez de deutérium pour faire voler la flotte
		message ("<font color=\"red\"><b>". $lang['fl_noressources'] . pretty_number($consumption) ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	}
	
	if ($StockMetal < $TransMetal OR $StockCrystal < $TransCrystal OR $StockDeuterium < $TransDeuterium) {
		//Les ressources à quai sont insuffisantes par rapport à ce qui est demandé dans le cargo de la flotte
		$Message_ressources_insuffisantes = "Les ressources demand&eacute;s en transport d&eacute;passent le stock de ressources qui est sur votre plan&egrave;te:";
		$Message_ressources_insuffisantes .= "<br><br>";
		$Message_ressources_insuffisantes .= "Vous avez besoin au minimum de ";
		$Message_ressources_insuffisantes .= pretty_number($StockMetal)." m&eacute;tal, ";
		$Message_ressources_insuffisantes .= pretty_number($StockCrystal)." cristal et ";
		$Message_ressources_insuffisantes .= pretty_number($StockDeuterium)." deut&eacute;rium.";
		$Message_ressources_insuffisantes .= "<br>Or vous avez demand&eacute; ";
		$Message_ressources_insuffisantes .= pretty_number($TransMetal)." m&eacute;tal, ";
		$Message_ressources_insuffisantes .= pretty_number($TransCrystal)." cristal et ";
		$Message_ressources_insuffisantes .= pretty_number($TransDeuterium)." deut&eacute;rium.";
		message ("<font color=\"red\"><b>".$Message_ressources_insuffisantes."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	}
	//***************************************** CODE KIWILLE ******************************************************
	
	if ( $StorageNeeded > $FleetStorage) {
		message ("<font color=\"red\"><b>". $lang['fl_nostoragespa'] . pretty_number($StorageNeeded - $FleetStorage) ."</b></font>", $lang['fl_error'], "fleet." . $phpEx, 2);
	}

	if ($TargetPlanet['id_level'] > $user['authlevel']) {
		$Allowed = true;
		switch ($_POST['mission']){
			case 1:
			case 2:
			case 6:
			case 9:
				$Allowed = false;
				break;
			case 3:
			case 4:
			case 5:
			case 7:
			case 8:
			case 11:
			case 15:
				break;
			default:
		}
		if ($Allowed == false) {
			message ("<font color=\"red\"><b>". $lang['fl_adm_attak'] ."</b></font>", $lang['fl_warning'], "fleet." . $phpEx, 2);
		}
	}

	// ecriture de l'enregistrement de flotte (a partir de l�, y a quelque chose qui vole et c'est toujours sur la planete d'origine)
	$QryInsertFleet  = "INSERT INTO {{table}} SET ";
	$QryInsertFleet .= "`fleet_owner` = '". $user['id'] ."', ";
	$QryInsertFleet .= "`fleet_mission` = '". $_POST['mission'] ."', ";
	$QryInsertFleet .= "`fleet_amount` = '". $FleetShipCount ."', ";
	$QryInsertFleet .= "`fleet_array` = '". $fleet_array ."', ";
	$QryInsertFleet .= "`fleet_start_time` = '". $fleet['start_time'] ."', ";
	$QryInsertFleet .= "`fleet_start_galaxy` = '". intval($_POST['thisgalaxy']) ."', ";
	$QryInsertFleet .= "`fleet_start_system` = '". intval($_POST['thissystem']) ."', ";
	$QryInsertFleet .= "`fleet_start_planet` = '". intval($_POST['thisplanet']) ."', ";
	$QryInsertFleet .= "`fleet_start_type` = '". intval($_POST['thisplanettype']) ."', ";
	$QryInsertFleet .= "`fleet_end_time` = '". $fleet['end_time'] ."', ";
	$QryInsertFleet .= "`fleet_end_stay` = '". $StayTime ."', ";
	$QryInsertFleet .= "`fleet_end_galaxy` = '". intval($_POST['galaxy']) ."', ";
	$QryInsertFleet .= "`fleet_end_system` = '". intval($_POST['system']) ."', ";
	$QryInsertFleet .= "`fleet_end_planet` = '". intval($_POST['planet']) ."', ";
	$QryInsertFleet .= "`fleet_end_type` = '". intval($_POST['planettype']) ."', ";
	$QryInsertFleet .= "`fleet_resource_metal` = '". $TransMetal ."', ";
	$QryInsertFleet .= "`fleet_resource_crystal` = '". $TransCrystal ."', ";
	$QryInsertFleet .= "`fleet_resource_deuterium` = '". $TransDeuterium ."', ";
	$QryInsertFleet .= "`fleet_target_owner` = '". $TargetPlanet['id_owner'] ."', ";
	$QryInsertFleet .= "`start_time` = '". time() ."';";
	doquery( $QryInsertFleet, 'fleets');


	$planetrow["metal"]     = $planetrow["metal"] - $TransMetal;
	$planetrow["crystal"]   = $planetrow["crystal"] - $TransCrystal;
	$planetrow["deuterium"] = $planetrow["deuterium"] - $TransDeuterium;
	$planetrow["deuterium"] = $planetrow["deuterium"] - $consumption;

	$QryUpdatePlanet  = "UPDATE {{table}} SET ";
	$QryUpdatePlanet .= $FleetSubQRY;
	$QryUpdatePlanet .= "`metal` = '". $planetrow["metal"] ."', ";
	$QryUpdatePlanet .= "`crystal` = '". $planetrow["crystal"] ."', ";
	$QryUpdatePlanet .= "`deuterium` = '". $planetrow["deuterium"] ."' ";
	$QryUpdatePlanet .= "WHERE ";
	$QryUpdatePlanet .= "`id` = '". $planetrow['id'] ."'";
	doquery ($QryUpdatePlanet, "planets");

	// Un peu de blabla pour l'utilisateur, affichage d'un joli tableau de la flotte expedi�e
	$page  = "<br><div><center>";
	$page .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"1\" width=\"519\">";
	$page .= "<tr height=\"20\">";
	$page .= "<td class=\"c\" colspan=\"2\"><span class=\"success\">". $lang['fl_fleet_send'] ."</span></td>";
	$page .= "</tr><tr height=\"20\">";
	$page .= "<th>". $lang['fl_mission'] ."</th>";
	$page .= "<th>". $missiontype[$_POST['mission']] ."</th>";
	$page .= "</tr><tr height=\"20\">";
	$page .= "<th>". $lang['fl_dist'] ."</th>";
	$page .= "<th>". pretty_number($distance) ."</th>";
	$page .= "</tr><tr height=\"20\">";
	$page .= "<th>". $lang['fl_speed'] ."</th>";
	$page .= "<th>". pretty_number($_POST['speedallsmin']) ."</th>";
	$page .= "</tr><tr height=\"20\">";
	$page .= "<th>". $lang['fl_deute_need'] ."</th>";
	$page .= "<th>". pretty_number($consumption) ."</th>";
	$page .= "</tr><tr height=\"20\">";
	$page .= "<th>". $lang['fl_from'] ."</th>";
	$page .= "<th>". $_POST['thisgalaxy'] .":". $_POST['thissystem']. ":". $_POST['thisplanet'] ."</th>";
	$page .= "</tr><tr height=\"20\">";
	$page .= "<th>". $lang['fl_dest'] ."</th>";
	$page .= "<th>". $_POST['galaxy'] .":". $_POST['system'] .":". $_POST['planet'] ."</th>";
	$page .= "</tr><tr height=\"20\">";
	$page .= "<th>". $lang['fl_time_go'] ."</th>";
	$page .= "<th>". date("M D d H:i:s", $fleet['start_time']) ."</th>";
	$page .= "</tr><tr height=\"20\">";
	$page .= "<th>". $lang['fl_time_back'] ."</th>";
	$page .= "<th>". date("M D d H:i:s", $fleet['end_time']) ."</th>";
	$page .= "</tr><tr height=\"20\">";
	$page .= "<td class=\"c\" colspan=\"2\">". $lang['fl_title'] ."</td>";

	$pour_historique = "\r\n \t \t";
	foreach ($fleetarray as $Ship => $Count) {
		$page .= "</tr><tr height=\"20\">";
		$page .= "<th>". $lang['tech'][$Ship] ."</th>";
		$page .= "<th>". pretty_number($Count) ."</th>";
		$pour_historique .= " - ".pretty_number($Count) ." ". $lang['tech'][$Ship]."\r\n \t \t";
	}
	$page .= "</tr><tr>";
	$page .= "<td class=\"c\" colspan=\"2\">Retour</td></tr>";
	$page .= "<tr><th colspan=\"2\"><a Href=\"fleet.php\">[ retour ]</a></th>";
	$page .= "</tr></table></div></center>";

	// Provisoire
	sleep (1);
	
	//MAJ des données
	$planetrow = doquery ("SELECT * FROM {{table}} WHERE `id` = '". $planetrow['id'] ."';", 'planets', true);

	display($page, $lang['fl_title']);


?>