<?php
$startTime 
microtime(true);

//  if the client claims to be internet explorer, redirect to the funny anti-ie page.
//if (substr_count($_SERVER['HTTP_USER_AGENT'], "MSIE") > 0)
//{
//    header("Location: http://www.knigga.com/ie/");
//}

// Important! You have to include it before your html code
include_once "/home/knigga5/public_html/polls/poll_cookie.php";
include_once(
"includes.php");

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<?php include("meta.html"); ?>

<meta name="keywords" content="Kristoffer, David, Knigga, Kris, computers, internet, Cisco, Microsoft, Personal Website, Vincennes University, networking, router, Kokomo, Indiana, Russiaville, Linux, Tux, resume, Visual Basic, VB, downloads, Vincennes, Active Server Page, ASP">
<meta name="description" content="This is Kristoffer David Knigga's personal website.  Included here is a description of who Kris is, what he is about, and what he does in life.  If you want to learn a lot about Kris, this site is for you.">
<meta name="abstract" content="This is Kristoffer David Knigga's personal website.  Included here is a description of who Kris is, what he is about, and what he does in life.  If you want to learn a lot about Kris, this site is for you.">

<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="0">
<META HTTP-EQUIV="Cache-Control" CONTENT="No-cache">
<link rel="alternate" type="application/rss+xml" title="www.KNIGGA.com News" href="http://www.knigga.com/rss.php">
<title> www.KNIGGA.com - home </title>
</head>
<body>
<?php

//  We'll get all of our SQL business taken care of right now


//  let's make a connection and select the db
mysql_connect($DBserver$DBuser$DBpass) or die(mysql_error());
@
mysql_select_db("knigga5_news") or die(mysql_error());


//  First, random banner picture
$sqlstring "SELECT id FROM banners ORDER BY id;";
$sqlqueryresult mysql_query($sqlstring) or die(mysql_error());
$bannerIndexArray = array();
while (
$row mysql_fetch_array($sqlqueryresult)) {
       
$bannerIndexArray[] = $row;
};

//  find out how many records there are
$number mysql_num_rows($sqlqueryresult);

//  generate the random index
$rndIndex rand(0$number 1);

//  figure out how many we need to get
$sqlstring "SELECT COUNT(id) FROM main;";
$sqlqueryresult mysql_query($sqlstring) or die(mysql_error());
$showall $_GET['all'];
while (
$row mysql_fetch_array($sqlqueryresult)) {
     
$rowCount[] = $row;
};
if (
$showall == "1")
     
$number $rowCount[0][0];
else
     
$number 5;

//  Now we'll pull the news
$sqlstring "SELECT * FROM main ORDER BY id DESC LIMIT $number;";
$sqlqueryresult mysql_query($sqlstring) or die(mysql_error());
$newsArray = array();
while (
$row mysql_fetch_array($sqlqueryresult)) {
     
$newsArray[] = $row;
};

//  get number of comments for each entry
for ($i 0$i $number$i++)
{
    
$sqlstring "SELECT COUNT(*) FROM comments WHERE id = ".$newsArray[$i]['id']." AND spam = 0;";
    
$sqlqueryresult mysql_query($sqlstring) or die(mysql_error());
    
$count mysql_fetch_array($sqlqueryresult);
    
$newsArray[$i]["comments"] = $count[0];
}

//  Done with SQL stuff, close DB
mysql_close();

?>
<p align="center"><img src="/bannerpicture.php?id=<?php echo $bannerIndexArray[$rndIndex]['id']; ?>" alt="www.KNIGGA.com"></p>
<?php include("header.html"); ?>
<!-- START POLL -->
<a name="poll"></a>
<?php
include_once "/home/knigga5/public_html/polls/booth.php";
$php_poll->set_template_set("knigga");
echo 
$php_poll->poll_process("newest");
?>
<!-- END POLL -->
<!-- START NEWS -->
<table CELLPADDING="4" ALIGN="center" width="80%">
 <tr>
  <td ALIGN="left" VALIGN="bottom">
   <h1>news</h1>
  </td>
 </tr>
<?php
for ($i 0$i $number$i++) {
?>
 <tr>
  <td ALIGN="left" VALIGN="top" width="1%">
   <a name="<?php echo $newsArray[$i]['id']; ?>"></a>
   <?php echo $newsArray[$i]['date']; ?><br><?php echo $newsArray[$i]['time']."\n"?>
  </td>
  <td ALIGN="justify" VALIGN="top">
   <?php echo $newsArray[$i]['entry']."\n"?><br>
   <font size="-2"><a href="postcomment.php?id=<?php echo $newsArray[$i]['id']; ?>">post a comment</a> | <a href="viewcomment.php?id=<?php echo $newsArray[$i]['id']; ?>">view comments (<?php echo $newsArray[$i]["comments"]; ?>)</a></font>
   <br>&nbsp;<br>
  </td>
 </tr>
<?php ?>
 <tr>
  <td colspan="2">
<?php
if ($showall == "1")
   echo 
"<font color=\"#808080\" size=\"-1\"><i><a href=\"/\"> hide old news </a></i></font>";
else
   echo 
"<font color=\"#808080\" size=\"-1\"><i><a href=\"/?all=1\"> show old news </a></i></font>";
?>
  </td>
 </tr>
</table>
<!-- END NEWS -->

<?php include("footer.html"); ?>
</body>
</html>
<?php
$endTime 
microtime(true);
$totalTime round(($endTime $startTime), 5);
echo 
"<!-- Generation Time: $totalTime -->";
?>