<?php
   error_reporting(E_ALL);
   if(isset($_GET['stop']) && $_GET['stop']=='yes'){
   $_SESSION=array();
   }
   $dossier_images='./';
   session_start();
   
   if (isset($_GET['select']))
   {
       $select = $_GET['select'];
       $xsel = '*'.$select.'*';
       $_SESSION['diaporama']= "";
   }
   else
   {
       $select = '';
       $xsel = '*';
   }
?>
<?php
       $diapo=glob($dossier_images.$xsel.'.JPG');
       usort($diapo, "strnatcmp");       
       $xnb=count($diapo);
       if(empty($_SESSION['diaporama']))
       {
         $_SESSION['diaporama']=$diapo;
         $nb=$xnb;
       }
       else
       {
         $nb=count($_SESSION['diaporama']);
         if ($xnb <> $nb)
         {
           $nb=$xnb;
           $img=0;
           $_SESSION['diaporama']=$diapo;
         }
       }
       if(isset($_GET['image']) && ctype_digit($_GET['image']))
       {
         $img=$_GET['image'];
         if ($img > $nb or $img > $xnb)
         {
           $img=0;
         }
       }      
       else
       {
         $img=0;
       }
       ?>
       
   <!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
   <html>
   <head> 
   <title></title>
   <meta name="Author" content="Maistriaux Yves">
   <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
   <!--link rel="stylesheet" media="screen" href="/css/214.css"-->
   <link rel="stylesheet" href="css/theme/black.css" id="theme">
   <style>
   
   </style>
   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
   <script src="/web_prez/js/url2.js"></script>
   <!-- script>
   $(document).ready(function () {
		var vv = <?php echo $img + 5 ; ?> ;
		var newUrl = "?image=" + vv ;
		setTimeout(function(){
    		                window.location.href = newUrl;
    		}, 5000);

		
    });
   </script -->
</head>
   <body width="100%" bgcolor="#222"><div style="width:100%;border:none;">

   <?php
       echo '<table style="border:none;">';
       echo '<tr><td>';
	   if($img>5 && $img<$nb){
			       echo '<a href="index.php?image=',$img-5,'"><img src="/web_prez/images/left.png" width="30px" alt="prec"></a>';
			       }
			       else
			       {
			       echo '&nbsp;';
			       }
			       echo '</td>
  			       <td colspan="3" style="text-align:center;">
			           <a href="index.php?stop=yes"><img src="/web_prez/images/reset.png" width="30px" alt="reset"></a>
  </td>				   ';
  echo '<td style="width:100px;">';

  if($img<$nb-1 && $img>=0){
    echo '<a href="index.php?image=',$img+5,'"><img src="/web_prez/images/right.png" width="30px" alt="next"></a>';
    }
    else
    {
    echo '&nbsp;';
    }
    echo '<tr>

</tr>';
       echo '<tr>';
       for ($i=$img;$i<$img+5;$i++)
       {
       ?>
       
	<td style="width:250px;text-align:center;">
	<?php
	$naname = explode ('/', $_SESSION['diaporama'][$i]);	
	echo '   <br /><br />';
	echo '   <a href="../',$naname[count($naname)-1],'" target="_blank"><img  style="width: 100%;" src="',$_SESSION['diaporama'][$i],'" alt="" /></a>';
	echo ' </td>';
	}
	?>
       </tr>
       
       <tr>
	<td style="width:100px;">
<?php
echo '</td></tr></table>';
echo '  </body>
</html>' ;
?>