<?php
 if (ini_get('register_globals') != 1) $path = $HTTP_GET_VARS['path'];
 // else path already set

 $myimgdir = "/home/beckman/public_html/gfx/PetersHouse/Construction2004/";
 $mypath = "/gfx/PetersHouse/Construction2004/";
 // Get the titles from the text file so Pip can edit
 $dh = opendir($myimgdir) or die("Can't open directory: $myimgdir");
 while(($file = readdir($dh)) !== false) {
    if (preg_match("/^\./", $file)) continue;
    #printf("<a href='%s?d=%s'>%s</a><br/>", $_SERVER['PHP_SELF'], $file, $file);
    #if ($str == "" or preg_match("/^#/", $str)) continue;
    list($dir, $title) = array($file, $file);
    $titles[$file] = $title;
 }
 closedir($dh);

 function datesort($a,$b) {
    list($a,$x) = split("_",$a);
    list($b,$x) = split("_",$b);
    list($m,$d,$y) = split("-", $a);
    $a = date("l, F j, Y", mktime(0,0,0,$m,$d,$y));
    list($m,$d,$y) = split("-", $b);
    $b = date("l, F j, Y", mktime(0,0,0,$m,$d,$y));
    if (strtotime($a) == strtotime($b)) { return 0; }
    if (strtotime($a) <= strtotime($b)) { return 1; }
    else { return -1;}
 }
 usort($titles, "datesort");
?>
<head>
<style>
    body { background:#00003f; font-family:Arial, Verdana; color:#ffffff;}
    a { color:#e0e0e0; }
    a:hover { color:#ff9900; }
    .gray { color:#999999; }
    .darkgray { color:#666666; }
    .small { font-size:10px; }
    table.body a { color:#0000ff; }
    .body { color:#000000; font-size:13px; }
    th { color:#000000; font-weight:bold; text-align:left; }
    #header {
        text-align:center;
    }
    #ad {
        margin:auto;
        text-align:center;
    }
</style>
<title>Angryox.com: Home Addition Construction Images <? echo isset($path)?"from ".$path:"2004-2005"; ?></title>
<link rel="stylesheet" href="/angryox.css" type="text/css">
</head>
<body>

<div id="ad">
<script type="text/javascript"><!--
google_ad_client = "pub-5229596395985878";
google_alternate_color = "000000";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "image";
//2007-02-15: Front Page
google_ad_channel = "4326557342";
google_color_border = "000000";
google_color_bg = "000000";
google_color_link = "6131BD";
google_color_text = "FFFFFF";
google_color_url = "CC0000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<hr/>
<div id="header"><b>The Angry Ox House Addition/Construction Image Gallery</b></div>
<hr/>
<?php

if (empty($path)) {
   ?>
<table width="603" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr bgcolor="#FFFFFF" valign="top"> 
    <td colspan="2" height="2"><img src="/construction/tier2border-top.jpg" width="603" height="18"></td>
  </tr>
  <tr bgcolor="#FFFFFF" valign="top"> 
    <td colspan="2" height="74" align="center"><!-- #BeginEditable "body" -->
        <table width="90%" border="0" cellspacing="0" cellpadding="0" class='body'>
          <tr> 
            <td colspan="2">
			  <br/>
              Our house went under construction June 15, 2004.  We're adding about 850 square feet to our house, including adding a first floor bathroom,
              expanding the kitchen and dining room, adding a family room, and adding a master suite (master bath, walk-in closet and bedroom) on the second
              floor.  WOW!  Here are the pictures.
			</td>
          </tr>
          <tr><td colspan="2"><br/></td></tr>
          <tr> 
            <th>Directory:</th>
            <th>Date: </td>
          </tr>
		  <?
		  //krsort($titles);
		  foreach($titles as $v) {
            list($day) = split("_", $v);
            if ($day == "Tile") {
                $date = "";
            } else {
                list($m,$d,$y) = split("-", $day);
                $date = date("l, F j, Y", mktime(0,0,0,$m,$d,$y));
            }
			printf("<tr><td><a href='%s?path=%s'>%s</a></td><td>%s</td></tr>", $_SERVER['PHP_SELF'], $v, $v, $date);
		  }
		  ?>
        </table>
      </div>
      <!-- #EndEditable --></td>
  </tr>
  <tr valign="top"> 
    <td colspan="2" height="2"><img src="/construction/tier2border-bottom.jpg" width="603" height="19"></td>
  </tr>
</table>

   <?
} else {
   $fd = opendir($GLOBALS['myimgdir'].$path) or die("Can't open dir: ".$GLOBALS['myimgdir']);
   if (!isset($HTTP_GET_VARS['img'])) thumbnails($path);

   while($file = readdir($fd)) {
	  if (!eregi("\.jpg$", $file)) continue;
	  $image[] = $file;
   }

   natsort($image);
   $count=1;
   foreach($image as $v) {
	  $imag[$count++] = $v;
   }

   #echo "<pre>"; print_r($imag); echo "</pre>";
   if (isset($HTTP_GET_VARS['img'])) {
	  $count = $HTTP_GET_VARS['img'];
   } else $count = 1;

   echo "<div style='text-align:center;'>";
   printf("<a href='%s?path=%s'><b>%s Thumbnails</b></a>: %s [ ", $_SERVER['PHP_SELF'], $path, $GLOBALS['titles'][$path], $path);
   if ($count == 1) echo "<font class='gray'>&lt; &lt; Back</font>";
   else printf("<a href='%s?path=%s&img=%d'>&lt; &lt; Back</a>", $_SERVER['PHP_SELF'], $path, $count - 1);

   printf(" | <a href='%s'>Home</a> | ", $_SERVER['PHP_SELF']);

   if ($count == count($imag)) echo "<font class='gray'>Next &gt; &gt;</font>";
   else printf("<a href='%s?path=%s&img=%d'>Next &gt; &gt;</a>",  $_SERVER['PHP_SELF'], $path, $count + 1);
   echo " ]";
   ?> 
   <?php
   echo "<hr/>";
   echo "<font class='darkgray small'>".$imag[$count]."</font><br/><img src='".$GLOBALS['mypath'].$path."/".$imag[$count]."'>";
   echo "</div>";
}

function thumbnails($path) {
    if (!is_dir($GLOBALS['myimgdir'].$path."/thumbs")) {
        mkdir($GLOBALS['myimgdir'].$path."/thumbs");
    }
    $fd = opendir($GLOBALS['myimgdir'].$path) or die("Can't open ".$GLOBALS['myimgdir'].$path);
    while($file = readdir($fd)) {
        if (!eregi("\.jpg$", $file)) continue;
        if (!file_exists($GLOBALS['myimgdir'].$path."/thumbs/".$file)) {
            $cmd = "/usr/local/bin/convert ".$GLOBALS['myimgdir'].$path."/".$file." -resize 120 ".$GLOBALS['myimgdir'].$path."/thumbs/".$file;
            $foo = `$cmd`;
        }
    }
    $image = array();

   echo "<div style='text-align:center;'>";
    printf("<a href='%s?path=%s'><b>%s Thumbnails</b></a>: [ ", $_SERVER['PHP_SELF'], $path, $GLOBALS['titles'][$path]);
    printf(" <a href='%s'>Home</a> ", $_SERVER['PHP_SELF']);
    echo " ]";
    ?> </td>
        <td width='130'>&nbsp;</td>
    </tr>
    </table>
    <center>
    <?php
    echo "<hr/>";
    $fd = opendir($GLOBALS['myimgdir'].$path."/thumbs") or die("Can't open dir.");
    while($file = readdir($fd)) {
        if (!eregi("\.jpg$", $file)) continue;
        $image[] = $file;
    }

    natsort($image);
    $count=1;
    foreach($image as $v) {
        $imag[$count++] = $v;
    }

    echo "<table><tr>";
    $max = 4;
    $cur = 0;
    foreach($imag as $k => $v) {
        if ($cur%$max == 0) echo "</tr><tr>";
        printf("<td align='center' style='background:#000000; border:1px solid #666666;'><a href='%s?path=%s&img=%d'><img border='0' alt='%s'
        src='%s%s/thumbs/%s'></td>\n", 
            $_SERVER['PHP_SELF'], $path, $k, $v, $GLOBALS['mypath'], $path, $v);
        $cur++;
    }
    echo "<td colspan='".$cur%$max."'></td>";
    echo "</tr></table>";
    echo "</div>";
    exit;

}