<?
// GET LAST LOG ENTRIES AND ID FROM TABLES
list ($last_log,$last_image,$last_log_id,$last_image_id,$dtime) = get_latest_entries($db);

echo " <FORM METHOD=\"GET\" ACTION=\"$PHP_SELF\">\n";
echo "<TABLE WIDTH=\"800\" BORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"5\" ALIGN=\"center\">\n";
echo "<TR><TD VALIGN=\"top\" WIDTH=\"300\" HEIGHT=\"100%\">";

// --------------------------------------------------------------------------------
echo "<TABLE CLASS=\"\" ALIGN=\"center\" \"WIDTH=\"100%\" BORDER=0 CELLPADDING=4>";
// DB STATS
echo "<TR><TH CLASS=\"top\" ALIGN=\"center\" COLSPAN=\"2\">DB STATS</TH></TR>\n";
echo "<TR><TD CLASS=\"\" ALIGN=\"right\">Last in log : </TD><TD ALIGN=\"left\">$last_log</TD></TR>\n";
echo "<TR><TD CLASS=\"\" ALIGN=\"right\">Last archived : </TD><TD ALIGN=\"left\">$last_image</TD></TR>\n";
// BROWSING
echo "<TR><TH CLASS=\"top\" ALIGN=\"center\" COLSPAN=\"2\">BROWSING ARCHIVE</TH></TR>\n";
echo "<TR><TD COLSPAN=\"2\" ALIGN=\"right\">";
echo " <INPUT TYPE=\"submit\" NAME=\"show\" VALUE=\"Show\" >\n";
listbox_images($imageselect,20);
echo "</TD></TR>\n";
echo "<TR><TD COLSPAN=2 ALIGN=\"RIGHT\">\n";
echo "Show previous <SELECT style=\"width:50px;\" name=nimages size=1 >\n";
for ($i = 0; $i <= 100; $i++) {
  if ($i==$nimages) {
    echo "<OPTION SELECTED>$i";  
  } else {
    echo "<OPTION>$i";  
  }
}
echo "</SELECT> images\n";
echo "</TD></TR>";
echo "<TR><TD COLSPAN=\"2\" ALIGN=\"CENTER\">";
echo " <INPUT TYPE=\"submit\" NAME=\"show\" VALUE=\"Update\" >\n";
echo "</TD></TR>";
echo "</TABLE>\n";
// --------------------------------------------------------------------------------

echo "</TD>";

if (!isset($imageselect)) {
  $imageselect=0; // SHOW LATEST
}
// SET THE IMAGE TO SHOW
if ($imageselect==0) {
  $show_image=$last_image_id;
} else {
  $show_image=$imageselect;
}

list ($width,$height,$type,$timestamp)=getimageinfo($show_image);
list ($year,$month,$day,$hour,$minute,$second)=timestamp($timestamp);
$year= $timestamp[0] .$timestamp[1] . $timestamp[2] . $timestamp[3];

echo "<TH CLASS=\"t\">\n";
// -----------------------------------------------------------------------------------
echo "<TABLE WIDTH=\"100%\" BORDER=\"0\" CELLPADDING=\"4\">";
echo "<TR><TH COLSPAN=\"3\" ALIGN=\"center\" CLASS=\"top\">";
printf("%s-%s-%s %sh%sm%ss<BR>",$year,$month,$day,$hour,$minute,$second);
echo "</TH></TR>";
echo "<TR><TD ALIGN=\"right\">";
if ($show_image>1) {
  printf("<A HREF=\"$PHP_SELF?nimages=$nimages&imageselect=%s\"><--</A>",$show_image-1);
}
echo "</TD><TD ALIGN=\"center\">\n";
echo "<IMG SRC=\"getbindata.php?imageselect=$show_image\">";
echo "</TD><TD ALIGN=\"left\">\n";
if (($show_image+1)<=$last_image_id) {
  printf("<A HREF=\"$PHP_SELF?nimages=$nimages&imageselect=%s\">--></A>",$show_image+1);
}
echo "</TD></TR>";
echo "</TABLE>";

//echo " <INPUT TYPE=\"submit\" NAME=\"show\" VALUE=\"Show\" >\n";

// ------------------------------------------------------------------
echo "</TH>\n";
echo "</TABLE>";
echo "</FORM>";




if (($nimages>0)) {
  $itemsperrow=5;
  echo "<TABLE WIDTH=\"100%\" ALIGN=\"CENTER\" BORDER=\"0\">";
  echo "<TR><TD WIDTH=\"100%\" COLSPAN=\"2\" CLASS=\"nav\"></TD></TR>\n\n";
  echo "</TABLE>\n\n";
  
  echo "<TABLE WIDTH=\"100%\" ALIGN=\"CENTER\" BORDER=\"0\">";
  
  echo "<TR>";
  $count=0;
  for ($i=$show_image-$nimages;$i<($show_image);$i++) {
    $count++;
    list ($width,$height,$type,$timestamp)=getimageinfo($i);
    list ($year,$month,$day,$hour,$minute,$second)=timestamp($timestamp);
    $year= $timestamp[0] .$timestamp[1] . $timestamp[2] . $timestamp[3];
    if ($newTR==1) {
      echo "<TR>";
      $newTR=0;
    }

	// SNAP SHOT SIZE
	// AT SOME POINT THESE IMAGES SHOULD BE GENERATED DYNAMICALLY
    $w=100;
    $h=$w*$height/$width;
    printf("<TH COLSPAN=\"3\" CLASS=\"header\"><FONT SIZE=\"-2\">%s-%s-%s %sh%sm%ss</FONT><BR>\n",$year,$month,$day,$hour,$minute,$second);
    echo "<A HREF=\"$PHP_SELF?imageselect=$i&nimages=$nimages\"><IMG BORDER=\"0\" ALIGN=\"CENTER\" WIDTH=\"$w\" HEIGHT=\"$h\" SRC=\"getbindata.php?imageselect=$i\"></A></TH>";
    if (($count/$itemsperrow)==round($count/$itemsperrow)) {
      echo "</TR>";
      $newTR=1;
    }
  }
  echo "</TR></TABLE>";
}

?>

