<?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>autres Vidéos des étapes de conception du robot nettoyeur</h1>';
echo '<br/>';
echo '<hr/>';
echo '';
$nb_fichier = 0;
$chemin='/var/www/open-elab/movies/Leon/';
$chemin_url='/open-elab/movies/Leon/';
$dossier_textes='/texts/';

$data=[];
$data['divers']=[];
echo '<table>';
if($dossier = opendir($chemin))
{
    $files=array();
    $Files=array();
    while(false !== ($fichier = readdir($dossier)))
    {
	if($fichier != '.' && $fichier != '..' && strpos($fichier, 'index')===false && strpos($fichier, 'text')===false && $fichier != 'classement' && strpos($fichier,'photo')===false && $fichier != 'PICS')
	{
	    $LastModified=null;
	    if (file_exists($chemin . '/MEDIAINFO/' . $fichier))
	    {
	        $handle = fopen($chemin . '/MEDIAINFO/' . $fichier, "r");
		if ($handle) {
		    while (($line = fgets($handle)) !== false) {
		    	  if ( strpos($line ,'Tagged date') === true )
			  {
			      $bouts=explode($line, ':');
			      $LastModified = $bouts[1];
			  }
    	   	   }

		   fclose($handle);
      	     	}      	      
	    }
	    //Tagged date
	    
	    $files[]=$fichier;
	    if ( ! isset($LastModified))$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 ftperso($a)
    {
    if (file_exists($a)) return filemtime($a);
    return 0;
    }
    usort($files, function($a,$b){return ftperso($a)>ftperso($b);});
    rsort($files);
    foreach ($files as $fi)
    {
	$fichier = $fi;
	$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 (strlen($c))
		  $classement=$c;
	}


	if (is_array($classement))
	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))
	    {
		$images .= "<img width='30px' src=$chemin_url.'/PICS/MINI/".$fichier."_000".$i.".png'>";
	    }

	}
	$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 'classement<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=\"leon.php?class=".$classement."\"'>".$classement."</th>";
}
echo '</tr></table>';

echo 'liens<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>';
?>


