<?
function Pushing_Systeme_test($id_envoyeur,$pts_envoyeur,$id_destinataire,$pts_destinataire,$fer,$or,$cristal,$naquadah,$militaires,$eppzs,$malps,$prs,$grs) {
	$update=array();
	// config
	//en % (80% minimum donc 20%)
	$seuille_de_tolerance = 80;
	// en heures
	$delais_avant_push = 48;
	$coef_or = 1.33;
	$coef_cristal = 2;
	$coef_naquadah = 4;
	$coef_malps = 3900;
	$coef_prs = 8000;
	$coef_grs = 40000;
	$coef_eppzs = 10000;
	
	//vérification des ressources et autres
	if ( $fer < 0 OR $fer == "" ) { $fer = 0; } else { $fer = round($fer); }
	if ( $or < 0 OR $or == "" ) { $or = 0; } else { $or = round($or); }
	if ( $cristal < 0 OR $cristal == "" ) { $cristal = 0; } else { $cristal = round($cristal); }
	if ( $naquadah < 0 OR $naquadah == "" ) { $naquadah = 0; } else { $naquadah = round($naquadah); }
	if ( $militaires < 0 OR $militaires == "" ) { $militaires = 0; } else { $militaires = round($militaires); }
	if ( $eppzs < 0 OR $eppzs == "" ) { $eppzs = 0; } else { $eppzs = round($eppzs); }
	if ( $malps < 0 OR $malps == "" ) { $malps = 0; } else { $malps = round($malps); }
	if ( $prs < 0 OR $prs == "" ) { $prs = 0; } else { $prs = round($prs); }
	if ( $grs < 0 OR $grs == "" ) { $grs = 0; } else { $grs = round($grs); }

	// calcul des valeurs en fer de "produit"
	$grs = $grs * $coef_grs;
	$eppzs = $eppzs * $coef_eppzs;
	$prs = $prs * $coef_prs;
	$malps = $malps * $coef_malps;
	$naquadah = $naquadah * $coef_naquadah;
	$cristal = $cristal * $coef_cristal;
	$or = round( $or * $coef_or );
	
	
	$query = "SELECT pts FROM matgraph_users WHERE idjoueur='".$id_envoyeur."'";
	$sql = db_mysql_Query($query);
	list($pts_envoyeur) = mysql_fetch_array($sql);
	
	$query = "SELECT pts FROM matgraph_users WHERE idjoueur='".$id_destinataire."'";
	$sql = db_mysql_Query($query);
	list($pts_destinataire) = mysql_fetch_array($sql);
	
	if($pts_destinataire > $pts_envoyeur){
		$id_fort = $id_destinataire;
		$id_faible = $id_envoyeur;
	}else{
		$id_fort = $id_envoyeur;
		$id_faible = $id_destinataire;
	}
	
	$query = "SELECT id_fort,id_faible,fer_fort,orr_fort,cristal_fort,naquadah_fort,militaires_fort,eppzs_fort,malps_fort,prs_fort,grs_fort,fer_faible,orr_faible,cristal_faible,naquadah_faible,militaires_faible,eppzs_faible,malps_faible,prs_faible,grs_faible,dates_echanges FROM pushing_systeme_test WHERE id_fort='".$id_fort."' AND id_faible='".$id_faible."'";
	$sql = db_mysql_Query($query);
	$num = mysql_num_rows($sql);
	if($num>0){
		$row = mysql_fetch_array($sql);
		if($id_envoyeur == $row['id_fort'] && $id_destinataire == $row['id_faible']){
			$update['fer_fort']=$row['fer_fort'].";".$fer;
			$update['orr_fort']=$row['orr_fort'].";".$or;
			$update['cristal_fort']=$row['cristal_fort'].";".$cristal;
			$update['naquadah_fort']=$row['naquadah_fort'].";".$naquadah;
			$update['militaires_fort']=$row['militaires_fort'].";".$militaires;
			$update['eppzs_fort']=$row['eppzs_fort'].";".$eppzs;
			$update['malps_fort']=$row['malps_fort'].";".$malps;
			$update['prs_fort']=$row['prs_fort'].";".$prs;
			$update['grs_fort']=$row['grs_fort'].";".$grs;
			
			$update['fer_faible']=$row['fer_faible'].";0";
			$update['orr_faible']=$row['orr_faible'].";0";
			$update['cristal_faible']=$row['cristal_faible'].";0";
			$update['naquadah_faible']=$row['naquadah_faible'].";0";
			$update['militaires_faible']=$row['militaires_faible'].";0";
			$update['eppzs_faible']=$row['eppzs_faible'].";0";
			$update['malps_faible']=$row['malps_faible'].";0";
			$update['prs_faible']=$row['prs_faible'].";0";
			$update['grs_faible']=$row['grs_faible'].";0";
		}elseif($id_envoyeur == $row['id_faible'] && $id_destinataire == $row['id_fort']){
			$update['fer_faible']=$row['fer_faible'].";".$fer;
			$update['orr_faible']=$row['orr_faible'].";".$or;
			$update['cristal_faible']=$row['cristal_faible'].";".$cristal;
			$update['naquadah_faible']=$row['naquadah_faible'].";".$naquadah;
			$update['militaires_faible']=$row['militaires_faible'].";".$militaires;
			$update['eppzs_faible']=$row['eppzs_faible'].";".$eppzs;
			$update['malps_faible']=$row['malps_faible'].";".$malps;
			$update['prs_faible']=$row['prs_faible'].";".$prs;
			$update['grs_faible']=$row['grs_faible'].";".$grs;
			
			$update['fer_fort']=$row['fer_fort'].";0";
			$update['orr_fort']=$row['orr_fort'].";0";
			$update['cristal_fort']=$row['cristal_fort'].";0";
			$update['naquadah_fort']=$row['naquadah_fort'].";0";
			$update['militaires_fort']=$row['militaires_fort'].";0";
			$update['eppzs_fort']=$row['eppzs_fort'].";0";
			$update['malps_fort']=$row['malps_fort'].";0";
			$update['prs_fort']=$row['prs_fort'].";0";
			$update['grs_fort']=$row['grs_fort'].";0";	
		}
		$update['dates_echanges']=$row['dates_echanges'].";".time();
		$req = "UPDATE pushing_systeme_test SET fer_fort='".$update['fer_fort']."',orr_fort='".$update['orr_fort']."',cristal_fort='".$update['cristal_fort']."',naquadah_fort='".$update['naquadah_fort']."',militaires_fort='".$update['militaires_fort']."',eppzs_fort='".$update['eppzs_fort']."',malps_fort='".$update['malps_fort']."',prs_fort='".$update['prs_fort']."',grs_fort='".$update['grs_fort']."',fer_faible='".$update['fer_faible']."',orr_faible='".$update['orr_faible']."',cristal_faible='".$update['cristal_faible']."',naquadah_faible='".$update['naquadah_faible']."',militaires_faible='".$update['militaires_faible']."',eppzs_faible='".$update['eppzs_faible']."',malps_faible='".$update['malps_faible']."',prs_faible='".$update['prs_faible']."',grs_faible='".$update['grs_faible']."',dates_echanges='".$update['dates_echanges']."' WHERE id_fort='".$id_fort."' AND id_faible='".$id_faible."'";
		$res=db_mysql_Query($req);
	}else{
		if($id_envoyeur == $id_fort && $id_destinataire == $id_faible){
			$update['fer_fort']=$fer;
			$update['orr_fort']=$or;
			$update['cristal_fort']=$cristal;
			$update['naquadah_fort']=$naquadah;
			$update['militaires_fort']=$militaires;
			$update['eppzs_fort']=$eppzs;
			$update['malps_fort']=$malps;
			$update['prs_fort']=$prs;
			$update['grs_fort']=$grs;
			
			$update['fer_faible']="0";
			$update['orr_faible']="0";
			$update['cristal_faible']="0";
			$update['naquadah_faible']="0";
			$update['militaires_faible']="0";
			$update['eppzs_faible']="0";
			$update['malps_faible']="0";
			$update['prs_faible']="0";
			$update['grs_faible']="0";
		}elseif($id_envoyeur == $id_faible && $id_destinataire == $id_fort){
			$update['fer_faible']=$fer;
			$update['orr_faible']=$or;
			$update['cristal_faible']=$cristal;
			$update['naquadah_faible']=$naquadah;
			$update['militaires_faible']=$militaires;
			$update['eppzs_faible']=$eppzs;
			$update['malps_faible']=$malps;
			$update['prs_faible']=$prs;
			$update['grs_faible']=$grs;
			
			$update['fer_fort']="0";
			$update['orr_fort']="0";
			$update['cristal_fort']="0";
			$update['naquadah_fort']="0";
			$update['militaires_fort']="0";
			$update['eppzs_fort']="0";
			$update['malps_fort']="0";
			$update['prs_fort']="0";
			$update['grs_fort']="0";	
		}
		$update['dates_echanges']=time();
		$req = "INSERT INTO pushing_systeme_test VALUES ('','".$id_fort."','".$id_faible."','".$update['fer_fort']."','".$update['orr_fort']."','".$update['cristal_fort']."','".$update['naquadah_fort']."','".$update['militaires_fort']."','".$update['eppzs_fort']."','".$update['malps_fort']."','".$update['prs_fort']."','".$update['grs_fort']."','".$update['fer_faible']."','".$update['orr_faible']."','".$update['cristal_faible']."','".$update['naquadah_faible']."','".$update['militaires_faible']."','".$update['eppzs_faible']."','".$update['malps_faible']."','".$update['prs_faible']."','".$update['grs_faible']."','".$update['dates_echanges']."')";
		$res=db_mysql_Query($req);
	}
}
?>
