<?php
include("_confirm.php");
global $pageInfo, $userInfo, $startTime, $startTime;
?>
   <table cellspacing="0" cellpadding="0" class="forums forums_new" align="center">
    <tr>
     <th class="alt5">Whos Online</th>
    </tr>
    <tr>
     <td class="alt8">
<?php
$timeout = $pageInfo['usersTimeout'] * 60;
$date = time() + $timeout;

if ($userInfo['loggedin']) {
 $q = mysqli_query($connection,"SELECT * FROM `online` WHERE username='{$userInfo['username']}'");
 $q = mysqli_fetch_row($q);
 if (!$q[0]) {
  mysqli_query($connection,"INSERT INTO `online` VALUES ('','{$userInfo['username']}','$date')");
 }
 else {
  mysqli_query($connection,"UPDATE `online` SET date='$date' WHERE username='{$userInfo['username']}'");
 }
}
else {
 $md5Ip= md5($_SERVER['REMOTE_ADDR']);
 $q = mysqli_query($connection,"SELECT * FROM `guests` WHERE user='$md5Ip'");
 $q = mysqli_fetch_row($q);
 if (!$q[0]) {
  mysqli_query($connection,"INSERT INTO `guests` VALUES ('','$md5Ip','$date')");
 }
 else {
  mysqli_query($connection,"UPDATE `guests` SET date='$date' WHERE user='$md5Ip'");
 }
}

$time = time();
mysqli_query($connection,"DELETE FROM `online` WHERE date < $time");
mysqli_query($connection,"DELETE FROM `guests` WHERE date < $time");

$q = mysqli_query($connection,"SELECT * FROM `online`");
$c = mysqli_num_rows($q);
if ($c == 0) {
 mysqli_query($connection,"TRUNCATE `online`");
}

$q2 = mysqli_query($connection,"SELECT * FROM `guests`");
$gc = mysqli_num_rows($q2);
if ($gc == 0) {
 mysqli_query($connection,"TRUNCATE `guests`");
}

$queryMembers = mysqli_query($connection,"SELECT * FROM `users`");
$memberCount = mysqli_num_rows($queryMembers);
$queryPosts = mysqli_query($connection,"SELECT * FROM `posts`");
$postCount = mysqli_num_rows($queryPosts);
$queryNewGuy = mysqli_query($connection,"SELECT id,username FROM `users` ORDER BY id DESC LIMIT 1");
$newGuy = mysqli_fetch_array($queryNewGuy);

echo "Our members have posted <b>{$postCount}</b> total posts and we have <b>{$memberCount}</b> members.<br />\n";
echo "Our newest member is <a href=\"members.php?id={$newGuy['id']}\">{$newGuy['username']}</a>.<br /><br />\n";
echo "There is currently {$c} member(s) and {$gc} guest(s) online.<br />\n";
if ($c > 0) echo "<br />";
echo "\n";
while ($row = mysqli_fetch_array($q)) {
 $x = mysqli_query($connection,"SELECT * FROM `users` WHERE username='".$row['username']."'");
 $x = mysqli_fetch_array($x);
 echo "<a href=\"members.php?id=".$x['id']."\">" . $row['username'] . "</a>&nbsp;&nbsp;&nbsp;\n";
}
?>
     </td>
    </tr>
   </table><br />
  </td>
 </tr>
 <tr>
  <td class="footer_wrap">
  
<div class="bottommenu">
	<span class="smalltext">
		<a href="index.php">Home</a> 
		<a href="search.php">Search</a> 
		<a href="members.php">Members List</a>
	</span>
	<div class="clearfix">&nbsp;</div>
	<?php
	  if ($userInfo['loggedin'] && $userInfo['title'] == "Administrator") {
	    echo "<a href=\"admin.php\"  class=\"adminLogin\">Administration Home</a>";
	  }
	?>
	
	<?php
	   $endTime = time();
	   $secs = $endTime - $startTime;
	   $mins = $secs / 60;
	   echo "Page generated in <b>{$secs}</b> seconds.\n";
	?>
   <!-- SonicBB Copyright (c) :: DO NOT REMOVE! -->
    Powered by SonicBB . A premium product from &nbsp; <a rel="nofollow" href="http://www.iscripts.com" target="_blank" class="no_margin">iScripts.com</a>
</div>
  </td>
 </tr>
  
</table>
</body>
</html>