<?

  
///////////////////////////////////////////////////
  // This is very ugly code. It was one of my first
  // attempts at PHP back near the end of the last
  // century. Don't know if I would suggest it as
  // a good example. I did recently wrap it in my
  // new box layout.
  // --Void
  ///////////////////////////////////////////////////

  // Get local configuration
  
require('../s/functions.php');
  require(
'guestbook.inc.php');

  
$date date("d-M-Y",time());
  
$time date("h:i:s a",time());

  
// Called after a Guest is added
  
if (isset($submit_add)) {

    
$db pg_connect("dbname=$dbname user=$pguser password=$pgpasswd");

    if (!
$db) {
      echo 
"An Error Occurred!\n";
      exit;
    }

    if (
$private) {
      
$private="True";
    } else {
      
$private="False";
    }

    
$ipaddr=$_SERVER['REMOTE_ADDR'];
    
$agent=$_SERVER['HTTP_USER_AGENT'];
    
$hostname=gethostbyaddr($ipaddr);

    
$query "SELECT * FROM guestbook where owner = '$owner' and name = '$name' and gdate = '$date' and gtime = '$time'";
    
$tmpentry pg_exec($db,$query);
    
$rows = @pg_numrows($tmpentry);

    require(
'banned.inc.php');

    if (
$rows == 0) {
      
$query "INSERT INTO guestbook (owner,name,email,url,urlname,reference,private,comments,gdate,gtime,ipaddr,browser,location) VALUES ('$owner','$name','$email','$url','$urlname','$reference','$private','$comments','$date','$time','$hostname/$ipaddr','$HTTP_USER_AGENT','$location')";
      
$addentry pg_exec($db,$query);
      if (
$SendEmail) {
        
mail("$EmailAddress""$owner guestbook""The $owner guestbook has been signed by:\r\n$name - $email\r\nsee $GuestbookURL","From: $EmailName <$EmailAddress>\r\nReply-To: $email");
      }
    }

    unset(
$submit_add);
  }

  
void_mains("Guestbook",750);
  
box("{ <a href=\"add\">Sign Guestbook</A>(); } else { <a href=\"/\">main</A>(); } else { <a href=\"aboutguestbook.php\">About Guestbook</A>(); }",750);

  
box_top();
?>
<table bgcolor=0b0b0b border=0 width=750>
<tr>
<td>

<hr width="30%" size="4" align="left">
<?
$db 
pg_connect("dbname=$dbname user=$pguser password=$pgpasswd");
if (!
$db) {
  echo 
"An Error Occurred!\n";
  exit;
}
$query "SELECT * from guestbook where owner = '$owner' order by gdate,gtime";
$guests pg_exec($db,$query);
$totalrows = @pg_numrows($guests);
#pg_close($db);

if (!isset($_POST['firstrow'])) {
  
$_POST['firstrow'] = $totalrows;
}
$lastrow $_POST['firstrow'] - $rowspp;
if ( 
$lastrow ) {
  
$lastrow 0;
}
$ccolor='red';
for (
$i=$_POST['firstrow']; $i>$lastrow$i--) {
  
$guest pg_fetch_array($guests,$i-1);
  list( 
$year$month$day ) = split("[/.-]",$guest['gdate']);
  list( 
$hour$minute$second ) = split(":",$guest['gtime']);
  if (
$ccolor=='red') {
    
$ccolor='cyan';
  } else {
    
$ccolor='red';
  }
?>
<p>
  <font size="-3"><b>Record</b> <?echo $i;?></font><br>
  <b>From</b>:&nbsp;<a href="mailto:<?echo $guest['email'];?>?subject=<?echo $owner;?>-guestbook"><font color=<?echo $ccolor;?> size="+1"><?echo $guest['name'];?></font></a>
<?
  
if ($guest['location']) {
?>
 <b>in</b> <font color=<?echo $ccolor;?> size="+1"><?echo $guest['location'];?></font>
<?
  
}
?>
<?
  
if ($guest['urlname']) {
?>
<br><b>Web Site</b>:&nbsp;<a href="<?echo $guest['url'];?>" target="guesturl"><font color=<?echo $ccolor;?> size="+1"><?echo $guest['urlname'];?></font></a>
<?
  
}
?>
<br>
  <b>Date</b>: <font color=<?echo $ccolor;?> size="+1"><?print (date("l, F d, Y",mktime($hour,$minute,$second,$month,$day,$year)));?></font>&nbsp;&nbsp;&nbsp;<b>Time</b>: <font color=<?echo $ccolor;?> size="+1"><?print (date("h:i A",mktime($hour,$minute,$second,$month,$day,$year)));?> CST</font><br>
  <b>Referred By</b>:&nbsp;<font color=<?echo $ccolor;?> size="+1"><?echo $guest['reference'];?></font>
<br><br>
  <table>
  <tr>
   <td width=30></td>
   <td>
    <font color=<?echo $ccolor;?> face="Comic Sans MS,Arial,New Century Schoolbook" size=3>
    <?echo (ereg_replace("\n","<BR>\n",$guest['comments']));?>
    </font>
   </td>
  </tr>
  </table>
<hr width="30%" size="4" align="left">
<?
}
?>

</td>
</tr>
</table>
<?
  box_bottom
();
  
box_top();
?>
<table bgcolor=0b0b0b border=0 width=750>
<tr>
<td>

<table width="100%" border="0">
<tr>

<?
if (!isset($newerstart)) { $newerstart $rowspp; }
if (
$_POST['firstrow'] < $totalrows) {
  
$newerstart $_POST['firstrow'] + $rowspp;
  if (
$newerstart $totalrows) {
     
$newerstart $totalrows;
  }
}
?>
  <td align="center">
  <form method="post" name="form1" action="index.php">
  <input type="hidden" name="firstrow" value="<?=$newerstart;?>">
  <INPUT TYPE="IMAGE" name= submit SRC="images/newer_entries.gif" ALIGN="MIDDLE">
  </form>
  </td>

  <td align="center">
  <font size="2"><b>Current Record Range<br>Displayed is&nbsp;</b></font><font face="Arial" size="2" color="Red"><b><?echo $_POST['firstrow'];?> to <?echo $lastrow 1;?></b></font>
  </td>

  <td align="center">
  <form method="post" name="form2" action="index.php">
  <input type="hidden" name="firstrow" value=<?echo $lastrow;?>>
  <INPUT TYPE="IMAGE" name= submit SRC="images/older_entries.gif" ALIGN="MIDDLE">
  </form>
  </td>
</tr>
<tr>
  <td></td>
  <td align=center><font size="2"><b>Total No. of Guests </b></font><font face="Arial" size="2" color="Red"><b><?echo $totalrows;?></b></font></td>
  <td></td>
</table>

</td>
</tr>
</table>
<?
  box_bottom
();

  
box("{ <a href=\"add\">Sign Guestbook</A>(); } else { <a href=\"aboutguestbook.php\">About Guestbook</A>(); } else { <a href=\"maint\">Guestbook Maintenance</A>(); }",750);

  
finish($_SERVER['PHP_SELF']);
?>