<?php $root = "/home/jfusion/Public/html/joefusion.com" ?>
<?php require("$root/inc/header.php"); ?>

<?php require("$root/inc/body_nav.php"); ?>
<?

// import variables from the URL
import_request_variables("G", "imp_");
$date = $imp_date;

// init
$jdir = dir($root . "/inside/journal/j");
$jlist = array ();

// list the journal directory
// include only readable, non-temp files
while ($entry = $jdir->read() ) {
  if (!(strstr($entry, "temp")) ) {
    $file = $jdir->path . '/' . $entry;
    if ( is_file($file) && is_readable($file) && (fileperms($file) == "33188") ) {
      $jlist[sizeof($jlist)] = $entry;
    }
  }
}
$jdir->close();
rsort($jlist);
reset($jlist);



// if no $date is passed, or it is invalid, then do a default page
if ( !$date || (strstr($date, "..")) || (strstr($date, "/"))
  || (strstr($date, "temp")) || !file_exists(($jdir->path . "/" . $date)) ) {

  // list links for older entries
  echo $cell_beg;
  echo "<div class=\"hed\">Journal Entries by Date</div>\n";
  reset($jlist);
  echo '<table width="470" cellspacing="0" cellpadding="0" border="0">' . "\n";
  echo "<tr>\n";
  
  // break up the links into a table of $cols columns
  $cols = 4;
  $width = floor(470/$cols);
  for ($j = 0; $j < $cols; $j++) {
    echo '<td width="' . $width . '" align="center" valign="top">' . "\n";
    echo '<div class="sec">';
    for ($i = $j; $i < sizeof($jlist); $i += $cols) {
      $val = $jlist[$i];
      echo "<a href=\"/inside/journal/?date=$val\">$val</a><br>";
    }
    echo "</div></td>\n";
  }
  echo "</tr></table>\n";
  echo $cell_end;


  // include most recent entries, up to $totalsize limit
  // (note this is a bad estimate, as filesize != rendered html length)
  //reset($jlist);
  //$totalsize = 0;
  //$file = $jdir->path . '/' . $jlist[0];
  //echo $cell_beg;
  //echo '<div class="hed">' . $jlist[0] . "</div>\n";
  //echo '<div><p class="jrn">';
  //include($file);
  //echo '</p></div>';
  //echo $cell_end;

// else, list out just the date-specified entry
} else {
  // find prev & next
  $prev = -1;
  while ( (list($key, $val) = each ($jlist)) && ($val != $date) ) {
    $prev = $key;
  }
  echo $cell_beg;
  echo '<div class="hed">' . $date . "</div>\n";
  echo '<div><p class="jrn">';
  include($jdir->path . "/" . $date);
  echo '</p></div>';
  // add links for next and previous
  echo '<table width="470" cellspacing="0" cellpadding="0" border="0">' . "\n";
  echo '<tr><td width="135" align="left"><div class="sec">'. "\n";
  if ( ($prev + 2) < sizeof($jlist) ) {
    echo "<a href=\"/inside/journal/?date=" . $jlist[$prev + 2];
    echo '">&nbsp;&nbsp;&lt;- ' . $jlist[$prev + 2] . '</a>';
  }
  echo '</div></td>' . "\n" . '<td width="200" align="center"><div class="sec">' . "\n";
  echo '<a href="/inside/journal/">index</a>';
  echo '</div></td>' . "\n" . '<td width="135" align="right"><div class="sec">' . "\n";
  if ($prev >= 0) {
    echo "<a href=\"/inside/journal/?date=" . $jlist[$prev];
    echo '">' . $jlist[$prev] . ' -&gt;&nbsp;&nbsp;</a>';
  }
  echo "</div></td></tr></table>\n";
  echo $cell_end;
}


?>
<?php echo $table_end ?>

<?php require("$root/inc/footer.php"); ?>

