<?php
			# Servicio WEB Graficación Observatorio 1.0
			
			// =====================================================================
			// TODO: Verificar que Android manda el archivo en $_FILES['File']
			// =====================================================================

				$LogFile="Log/".date("d-m-Y", time()).".txt";

                // Abrimos el archivo...
				$fout=fopen($LogFile,"a+wb");
		        // Escribimos...
				    fwrite($fout, date("d/M/Y H:i:s",time())."------------------- Inicio Intento\n");
					foreach ($_POST as $key => $value)
			  			fwrite($fout, "post: ".$key." ==> ".$value."\n");		
					foreach ($_GET as $key => $value)
			  			fwrite($fout, " get: ".$key." ==> ".$value."\n");		

				    fwrite($fout, date("d/M/Y H:i:s",time())."------------------- Fin Intento\n");
				// Cerramos el archivo...                                               
				fclose($fout);
		
	// Verificamos que los parámetros se hayan recibido...
	if(isset($_GET["ID"], $_GET["Type"], $_GET["Params"])){

		// Tomamos los parámetros en variables...
	    $ID = $_GET["ID"];
		$Type = $_GET["Type"];
		$Params = $_GET["Params"];
		$Time=time();

		// Ejecutamos los comandos en R...
		exec('echo "load(\".RData\")\nlibrary(plotly)\ngetwd();\nFunction.Graph.Plotly(\"'.$ID.'\", \"'.$Type.'\", \"'.$Params.'\");" | /usr/bin/R --vanilla', $RetValue);

		// foreach($RetValue as $RetLine){echo $RetLine."<br>\n";}

		// Mostramos el link de la gráfica...
		echo "http://www.datanlab.com/RIR/R/Graphs/".$ID.".html";

	}else{	// No se recibieron los parámetros adecuados...
		header("HTTP/1.0 400 Bad Request");
		echo "Error 100! Bad parameters.";
	}
	
?>