<?php

echo '<!DOCTYPE html>';
echo '<html lang="fr">';
echo '  <head>';
echo '    <meta charset="utf-8">';
echo '    <title>open-eLab</title>';
echo '    <link rel="stylesheet" media="screen" href="/css/214.css">';
echo '    <meta name="viewport" content="width=device-width, initial-scale=1.0">';
echo '    <meta name="author" content="François Régnier">';
echo '    <meta name="description" content="Travaux libres de robotique">';
echo '    <meta name="robots" content="all">';
?>
<style>
a:visited {
    color: #629507;
}
a {
  color: #ff0f0f;
}
table {
      font-size: small;
}
th {
font-weight: bold;
}
a:link {
  color: #ff0f0f;

}
img:hover {
	  width:320px;
}
.class_sel {
	background-color: orange;
	border: inset 1px lightgrey;
}
.class_bouton {
	cursor: pointer;
	background-color: lightgreen;
}
</style>
<?php
echo '  </head>';
echo '  <body>';
echo '<div style="text-align: left; float: center;">';

echo '<h1>Vidéos des étapes de test de robots et de capteurs en cours de conception</h1>';
echo '<br/>';
echo '<hr/>';
echo '<a href="leon.php">RobLéon nettoyeur</a>' ;
echo '<br/>';
echo '<hr/>';
echo '';
$nb_fichier = 0;
$chemin='/var/www//open-elab/movies/robot/';
$chemin_url='/open-elab/movies/robot/';
$data=[];
$data['divers']=[];
echo '<table>';
if($dossier = opendir($chemin))
{
    $files=array();
    $Files=array();
    while(false !== ($fichier = readdir($dossier)))
    {
	if($fichier != '.' && $fichier != '..' && $fichier != 'index.php' && $fichier != 'texts' && $fichier != 'classement' && strpos($fichier,'photo')===false && $fichier != 'PICS')
	{
	    $files[]=$fichier;
	    $LastModified = filectime($chemin . $fichier);
	    $Files[] = array($fichier, $LastModified);
	    $nb_fichier++; // On incrémente le compteur de 1
	}
    }
    function DateCmp($a, $b) {
    	     return ($a[1]>$b[1])?-1:0;
    }
    function SortByDate(&$Files) {
    	     usort($Files, 'DateCmp');
    }
    SortByDate($Files);
    function myfilemtime($aa){if (file_exists($aa))return filemtime($aa);return 0;}
    usort($files, function($a,$b){
    return myfilemtime($a)>myfilemtime($b);});
    rsort($files);
    foreach ($files as $fi)
    {
	$fichier = $fi;//[0];
	$classement='divers';
	if (file_exists($chemin . '/classement/'.$fichier.'.txt'))
	{
		$c = file_get_contents($chemin . '/classement/'.$fichier.'.txt');
		$c = trim($c," \t\n\r\0\x0B");
		if (is_array($c))
		{
		$classement=$c;
		if (!in_array($data,$classement))
		{
			$data[$classement]=[];
		}}
	}
	$href=$chemin_url.$fichier ;
	$date_af = date ("F d Y H:i:s.", filemtime($chemin . $fichier));
	$st = stat($chemin . $fichier);
	$sst = ((float)((int)(10*$st[11]*$st[12]/(10240*1024)))/10.0) ;
	$mycontent = "";
	if (file_exists($chemin . '/texts/'.$fichier.'.txt'))
	{
		$myfile = fopen($chemin . '/texts/'.$fichier.'.txt', "r") ;
		$mycontent = fread($myfile,filesize($chemin . '/texts/'.$fichier.'.txt'));
		fclose($myfile);
        }
	$images = "";
	for ($i=0; $i<10; $i++) {
	    $nf = $chemin . '/PICS/MINI/'.$fichier.'_000'.$i.'.png' ;
	    if (file_exists($nf))
	    {
		$myfile = fopen($nf, "r") ;
		$images .= "<img width='30px' src='/open-elab/movies/robot/PICS/MINI/".$fichier."_000".$i.".png'>";
	    	fclose($myfile);
	    }
	}
	$data[$classement][$fi]=array(
		'href'=>$href,
		'fi'=>$fi,
		'date_af'=>$date_af,
		'st'=>$st,
		'sst'=>$sst,
		'mycontent'=>$mycontent,
		'images'=>$images);
    }
}
if (!isset($_REQUEST['class']))
    $cur_class='divers' ;
else
    $cur_class=$_REQUEST['class'];
//echo "<hr/><p style='background-color:#fbefbf;border: outset 1px #ffe8e8;width:250px;height:60px;'>".$cur_class."</p></hr>";

echo '<table class="classement"><tr>';
foreach($data as $classement => $reste)
{
	if ($classement == $cur_class)
		echo '<th class="class_sel">'.$classement.'</th>' ;
	else
		echo "<th class='class_bouton' onclick='document.location.href=\"index.php?class=".$classement."\"'>".$classement."</th>";
}
echo '</tr></table>';

echo '<table>';
foreach($data as $cl => $da)
{
    if ($cl == $cur_class || ($cl==''&&$cur_class=='divers'))
    {

	foreach($data[$cl] as $sfi)
	{
	    echo '<tr><th>';
	    echo '<a href="' . $sfi['href']. '">' . $sfi['fi'] . '</a></th><td>';
	    echo '</th><td>'.$sfi['date_af'];
	    echo '</td><td>'.$sfi['sst'].' Mo</td><td>' ;
	    echo $sfi['mycontent'];
	    echo '</td><td>';
	    echo $sfi['images'];
	    echo '</td></tr>';
	 }
    } // On ferme le if (qui permet de ne pas afficher index.php, etc.)
} 
echo '</table></div>';
echo '</body>';
echo '</html>';
?>


