<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="content-type" content="text/html">
  <title>SimpleBooks Viewer</title>
  </head>
  <style type="text/css">
    @import "basic.css";
  </style>
  <body>
  <div id="container">
  <?php
  
    $book 
trim($_GET['book']); // Need better cleaner.
    
$page strval(intval($_GET['page']));
    
    
$handle = @fopen("$book/$book-inf.txt""r");
    if (
$handle)
    {
      
$title fgets($handle4096);
      
$maxpages strval(intval(fgets($handle4096)));
    }
    else
    {
      print 
"<h2>Load Error</h2>";
      
print_bottom();
      exit();
    }
    
    if(
$page $maxpages)
    {
      print 
"<h2>Not A Page</h2>";
      
print_bottom();
      exit();
    }    
  
?>
  <h2><?php echo $title?></h2>
  <?php
    
if($page == 0)
    {
      if(
file_exists("$book/cover.jpg"))
        print 
"<img src=\"$book/cover.jpg\" />";
      else
        print 
"<div style=\"text-align: center;\">(No Cover)</div>";
      
print_bottom();
      exit();        
    }

    
$handle = @fopen("$book/$book-$page.txt""r");
    if (
$handle)
    {
      while (!
feof($handle))
      {
          
$buffer fgets($handle4096);
          echo 
$buffer;
      }
    }
    else
    {
      print 
"<h2 style=\"border: 0px;\">Load Error</h2>";
      
print_bottom();
      exit();
    }
    
    
print_bottom();


  function 
print_bottom() {
    global 
$page$book$maxpages;
?>
  <div style="border-top: 2px Double #000000; text-align: right;"><?php echo $page?></div>
  <?php
    
if ($page != 0)
      print 
"<a href=\"viewer.php?book=$book&page=".($page-1)."\" style=\"float:left;\">Back</a>";
      
    if (
$page != $maxpages)
      print 
"<a href=\"viewer.php?book=$book&page=".($page+1)."\" style=\"float:right;\">Next</a>";
  
?>
  </div>
  </body>
</html>
<?php
  
}
?>