<?php 
include ("jpgraph.php");
include ("jpgraph_scatter.php");

$host="sql.free.fr";
$base="a190754";
$passe="m5cn57dk"; 
$dbh = @mysql_connect("$host","$base","$passe");

$select_base=@mysql_selectdb("$base"); 
 if (!$select_base) 
    echo "<font color=\#CC0000\><b>Problème base de données</b></font><br>" ; 

$sql="SELECT * FROM CARACT_PROFILS";
$result=@mysql_query($sql, $dbh); 
if($result == FALSE)
	{echo "problème";}
else
{
	$qte=mysql_num_rows($result);
}


if ($ID_Profil != '')

	{	$sql1="SELECT * FROM CARACT_PROFILS WHERE ORDRE='$ID_Profil'";	
		$selection=$ID_Profil;
	}
else
	{	$sql1="SELECT * FROM CARACT_PROFILS WHERE ORDRE=1";	
		$selection=1;
	}



$Ref=$selection;

$result1=@mysql_query($sql1, $dbh); 
if($result1 == FALSE)
		{echo "problème";}	

$sql2="SELECT * FROM PROFILS WHERE NUM='$selection'";
$result2=@mysql_query($sql2, $dbh); 
if($result2 == FALSE)
	{echo "problème";}

$sql_graph=@mysql_query($sql2, $dbh); 
$row = mysql_fetch_array($sql_graph);
$Nom_Profil ="";
$Nom_Profil = $row[1]; 
//echo $Nom_Profil; 
while($row = mysql_fetch_array($sql_graph)) 
{ 
$datax[] = $row[2]; 
$datay[] = $row[3]; 
//echo $row[2];echo "xxx>";echo $row[3];echo "<br>";

} 


$graph = new graph(1000, 200);
$graph->img->SetMargin(2,10,40,40); 
$graph->img->SetAntiAliasing();
$graph->SetScale("linlin");
$graph->SetShadow();

$graph->title->Set($Nom_Profil);
$graph->title->SetFont(FF_FONT1,FS_BOLD);

$sp1 = new ScatterPlot($datay,$datax);
$sp1->SetLinkPoints(true,"blue",2);

$sp1->mark->SetType(MARK_FILLEDCIRCLE);
$sp1->mark->SetFillColor("red");
$sp1->mark->SetWidth(0.1);

$graph->Add($sp1);
$graph->Stroke("Draw_Profil.png");
?>  

<HTML>
<head>
<script language="JavaScript">
<!--
document.write("<img src='COMPTEUR.PHP3?avant="+document.referrer+"&f=FREE' width=1 height=1 >");
// -->
</script>
</head>



<body  background="ARCHER.GIF">
<?php 
if (isset($_POST['envoie']))
{
	$ID_Profil = $_POST['selection'];
}
?>
<script LANGUAGE="VBScript">
sub Set_Profil()
PROFILS.ID_Profil.value=PROFILS.selection.value
PROFILS.SUBMIT
end sub
</script>

<div align="center">
  <noscript>  <img src="COMPTEUR.PHP3?avant=NoScript&f=FREE" width=1 height=1 > </noscript>
<h2 align='center'><font color='#800000'><i><u>
  PROFILS<br><font size=1></u></div>
<font size=1>
<form name="PROFILS" action="<? echo $PHP_SELF ?>"    method="POST" >
 <INPUT  type=hidden style="WIDTH: 61px; HEIGHT: 22px" size=8 name=ID_Profil value="<?php echo $ID_Profil ?>" />

  <div align="center">
	    <select name="selection" onChange="Set_Profil()">
		<?
		while ($row=mysql_fetch_array($result,MYSQL_NUM))
		{ echo "<option value=".$row[12];
		 if (trim($row[12]) == trim($ID_Profil))
		  echo " selected";
		echo ">".$row[0]."</option>";
		}
		?>
	    </select>
		<input type="submit" name="envoie" value="Envoyer (2 fois pour Firefox)" />
  </div>

  <div align="center"><br>
    <br>
  </div>
</u>  <p align="left"> 


</p>
<p align="center"> 

<TABLE border=1>
	<tr>
	<?
	for ($i=0;$i<12;$i++)
	{echo"<td bgcolor=grey><b>". mysql_field_name($result,$i)."</b></td>";}
	echo"<tr>";	

while ($row=mysql_fetch_array($result1,MYSQL_ASSOC))
{
	$cpt=0;
	foreach ($row as $elem)
	{
		if ($cpt < 12)
		{echo "<td align=center><b>$elem</b></td>";}
	$cpt++;
	}
	echo"</tr>";
}
?>
	</tr>
</TABLE>

<div align="center">
	<font size=2><br>Copiez/collez les X et Y dans  <a href="PROFILS.XLS">PROFILS.XLS </a>pour obtenir le tracé du profil.</font>
</div>

<DIV align=left>
	<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<a href="Draw_Profil.png?<?echo time()?>">
	<IMG style="WIDTH: 473px; HEIGHT: 104px" height=101 src="Draw_Profil.png?<?echo time()?>" width=426>

</a>
<font size=2><br><b> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<u>cliquez sur le profil pourl'agrandir</FONT>
</DIV>

<DIV align=center>&nbsp;</DIV>

<div align="center">
    <table border=1 bgcolor="#ffffcc" style="WIDTH: 161px; HEIGHT: 616px">
        <tr> 
        	<td bgcolor=grey align=center><font face=Arial size="2"><b>X</font></td>
	        <td bgcolor=yellow align=center><font face=Arial size="2"><b>Y</font></td>
        </tr>
	<?
	echo "<tr>";
	$cpt=0;
	while ($row=mysql_fetch_array($result2,MYSQL_ASSOC))
	{
	foreach ($row as $elem)
		{
		if ($cpt > 1)
			{echo "<td>$elem</td>";	}
		$cpt++;
		}
	echo"</tr>";
	$cpt=0;
	}
	?>
    </table>
</div>

</FORM>

</BODY>
</HTML>
