﻿<?php 
@session_start();

unset($_SESSION);




$racine=$_SERVER['DOCUMENT_ROOT'];
require_once($racine."/library/inc.php");




/*
require_once("param.php");
require_once("fonctions.php");
require_once("fonctionsR.php");
require_once("fonctions_fichiers.php");
*/

if(Isset($_GET['location']))
	{
	if(!isset($_SESSION['reptempo']))
		{

		// On définit un nouveau répertoire
		$n=rand(5,2000);
		$createrep=RACINE."/documents/";
		$nomrep="study_externe".$n."/";
		gest_dir($createrep,$nomrep,"creation");
		
		// récupérer le fichier d'un site distant 
		$url=$_GET['location'];

		$string = file_get_contents($url, true);
//		$string=get_content($url); 
		$rep=RACINE."/documents/".$nomrep;
		if(!is_file("USERFILEpreclean"))
			{
//			echo	"l'encodage détecté est ".mb_detect_encoding($string);

			if(mb_detect_encoding($string)=="UTF-8")
				{
				echo	"<BR>";
				$string=explode("\t", $string);
				$string=implode("\t", $string);				

				}
			else
				{
				$string=mb_convert_encoding($string, "UTF-8", mb_detect_encoding($string));
				$string=stream_default_encoding($string);
	
			
				}
			$string=str_replace(",", " ", $string); 


			enrFichier($rep,"USERFILEpreclean",$string);		// On copie le fichier en local.

			if($_GET[rownames]=="yes"){
			 $_SESSION['TypeOfTable']="rownames_yes";
			}

			}
		$chemin="".$rep."/USERFILEpreclean";	// Chemin complet du fichier a exploiter 
		$_SESSION['reptempo']="documents/".$nomrep."/";
		$_SESSION['rep']=$rep."/";
		$_SESSION['chemin']=$chemin; 	// chemin du fichier d'upload en Session

		
		}

	else 
		{
		unset($_GET['location']);
		}
	}

//fichier_tableau($chemin,"USERFILEpreclean","rien");





echo	'
 <script language="javascript" type="text/javascript">
<!--
 window.location.replace("http://analyse.univ-paris1.fr/analyse.php?NOUVEAU=True&chemin='.$chemin.'&TypeOfAnalyse='.$_GET['TypeOfAnalyse'].'&REP='.$nomrep.'");
-->
</script>';



?> 
