<?php
//
// Find the directories in here
//
global $title;
$curdir     getcwd();
$html_dir   "";
//
// dirdepth is the depth from DocumentRoot to the images
// DocuemntRoot  == /prod/vhost/
// images        == /prod/vhost/picts/image-subject-12/
// then dirdepth == 2
$dirdepth   2;
//
// cols == 1 - (number of columns to display)
// currently 3 columns will be displayed
$cols       2;
$inputarray opendir$curdir );
$dirarray   = array();
$filearray  = array();
$tmp_array  = array();
$data_array = array();
$filearray  array_pad$filearray101"" );
$data_array array_pad$data_array101"" );

// find the toplevel HTML dir
$dir_array explode("/"$curdir); 
for ( 
$x $dirdepth$x 0$x-- ) {
  
$html_dir array_pop($dir_array) . "/" $html_dir;
}
$html_dir "/" $html_dir;
$html_dir preg_replace("/\/$/"""$html_dir);

// get our smallest size file dir and make that the
// thumbnail location
while ( $var readdir($inputarray) ) {
  if ( 
is_dir$curdir "/" $var ) && ( $var != ".." && $var != "." 
        && 
$var != "movies" ) {
    
array_push$dirarray$var );
  }
}
sort($dirarray);
$thumbdir $dirarray[0];

// get all files per resolution(directory), in simple array
//
foreach ( $dirarray as $dir ) {
  
$dir_list opendir$curdir "/" $dir );
  while ( 
$file readdir$dir_list ) ) {
    if ( !
is_dir$curdir "/" $dir "/" $file ) && $file != "index.php" ) {
      if ( 
$file == "." || $file == ".." ) { continue; }
      
$filearray[$dir] = $filearray[$dir] . ":" $html_dir "/" $dir "/" $file;
    }
  }
}

//
// presentation time
print ("<html>
<head>
<title>" 
$title "</title>
</head>
<body>

<center>
<table>
"
);

//
// Make an array of all the picture crapola? each
// element is the links to sub images of different sizes
//
foreach ( $dirarray as $dir ) {
  
// grab the files/images as an array, sort that
  
if ( $dir == "private" ) { continue; }
  
$tmp_array explode":"$filearray[$dir] );
  
sort$tmp_array );

  
// set a counter and use that for the stuff inside 
  // each data element, this is the linkage inside each
  // table element
  
$x 0;
  foreach ( 
$tmp_array as $image ) {
    
// if the image is empty, skip it
    
if ( $image == "" ) { continue; }

    
// set the 'data_array' element for this 
    
$data_array[$x] .=
      
"<a href=\"" $image "\">$dir percent sized image</a><br>\n\t\t\t";
    
$x++;
  } 
}

//
// Now, print out the table, hopefully
// each image is the thumbnail image?
// given $thumbdir and $filearray you know that
// $filearray[$thumbdir] is the list of thumbs... go from there
//
$thumbs explode(":"$filearray[$thumbdir] );
sort($thumbs);

$col 0;
$img 0;

// set a initial tr line
print ("\t<tr align=center valign=middle>\n");

foreach ( 
$thumbs as $image ) {
  
// skip if image is ""
  
if ( $image == "" ) { continue; };

  
// If the current Column is >= max width, 
  // reset and write another row header
  
if ( $col $cols ) {
    
$col 1;
    print (
"</tr>\n\t<tr align=center valign=middle>\n");
    print (
"\t\t<td><img src=\"" $image "\"><br>\n\t\t\t"
       
$data_array[$img] . "<td>\n");
    
$img++;
  } else {
    print (
"\t\t<td><img src=\"" $image "\"><br>\n\t\t\t"
       
$data_array[$img] . "<td>\n");
    
$col++;
    
$img++;
  }
}
?>