<?php
require('config.php');
if(empty($_COOKIE['newposts']) || !empty($_GET['np'])) {
setcookie("newposts", time());
$_COOKIE['newposts'] = time();
}
// Pagination
$page=mysql_real_escape_string($_GET['page']);
$pagination ='';
$startat = $page * $rpp;
$q=mysql_unbuffered_query("SELECT count(*) FROM {$db_prefix}question");
if(!$q) die('Script is not installed.');
$row = mysql_fetch_row($q);
$pages = ($row[0] + $rpp - 1) / $rpp - 1;
for ($k=0; $k<$pages; $k++) {
if ($k != $page)
$pagination .= " <a href='main_forum.php?page=$k'>".($k+1)."</a>";
else
$pagination .= " <strong><".($k+1)."></strong>";
}
// Get number of users
$q = mysql_unbuffered_query("SELECT count(*) FROM {$db_prefix}user");
$row = mysql_fetch_row($q);
$users=$row[0];
// Fetch Users
// THIS QUERY IS SO FRIGGIN CONFUSING
$sql="SELECT q. * , a1.a_datetime, a1.a_name, a1.a_email, a1.a_id
FROM forum_question AS q
LEFT JOIN forum_answer AS a1 ON q.id = a1.question_id
LEFT JOIN forum_answer AS a2 ON a1.question_id = a2.question_id
AND a1.a_id < a2.a_id
WHERE a2.a_id IS NULL
ORDER BY q.sticky DESC , q.id DESC LIMIT $startat, $rpp";
// OREDER BY id DESC is order result by descending
$result=mysql_unbuffered_query($sql);
// Start Template
include('header.php');
?>
<h2>Forum</h2>
<div style="width:100%;text-align: left;float:left;"><a href="?np=1">Seen New Posts</a></div>
<div>
<div>
<div style="width:50%" class="mfheader">Topic</div>
<div style="width:13%" class="mfheader">Created by</div>
<div style="width:10%" class="mfheader">Views</div>
<div style="width:8%" class="mfheader">Replies</div>
<div style="width:15%" class="mfheader">Last Post</div>
</div>
<?php
while($rows=mysql_fetch_array($result)):
if(preg_match("/guest/i", $rows['name'])){
list($rows['email'],$ip) = explode('|',$rows['email']);
if(preg_match('/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/', $rows['email'])) {
list($login,$server)=explode('@',$rows['email']);
$namelink = '<script language="javascript" type="text/javascript">DisplayMail("'.$server.'", "'.$login.'", "'.$rows['name'].'","onmouseover=\"Tip(\'Posted on '.$rows['datetime'].'\')\"");</script>';
} else
$namelink = '<span onmouseover="Tip(\'Posted on '.$rows['datetime'].'\')">'.$rows['name'].'</span>';
}
else
$namelink ='<a href="view_profile.php?id='.$rows['name'].'" onmouseover="Tip(\'Posted on '.$rows['datetime'].'\')">'.$rows['name'].'</a>';
// security for registered globals
$new='';
//check if there is a post at all
if(!empty($rows['a_id'])) {
$datetime=$rows['a_datetime'];
$postdate = '<a href="view_topic.php?id='.$rows['id'].'#b'.$rows['a_id'].'" onmouseover="Tip(\'Last Posted By '.$rows['a_name'].'\')">'.$rows['a_datetime'].'</a>';
} else {
$datetime=$rows['datetime'];
$postdate=$rows['datetime'];
}
// Separate Date/Time
$ArrDate=explode(' ',$datetime);
$date=explode('/',$ArrDate[0]);
$time=explode(':',$ArrDate[1]);
// Check if new
if(mktime($time[0],$time[1],$time[2],$date[1],$date[0],'20'.$date[2]) > $_COOKIE['newposts'])
$new='_new';
if($rows['locked'])
$pic ='lock'.$new;
else
$pic = 'folder'.$new;
?>
<div>
<div style="width:50%;text-align: left;" class="mfrow">
<img src='<?=$pic?>.gif' alt='Locked' border='0' style='padding-right: 3px;' />
<?php
if ($rows['sticky'])
echo "<img src='sticky.gif' alt='Sticky' border='0' style='padding-right: 3px;' />";
?>
<a href="view_topic.php?id=<?=$rows['id'] ?>"><?=$rows['topic'] ?></a>
</div>
<div style="width:13%" class="mfrow"> <?=$namelink ?></div>
<div style="width:10%" class="mfrow"> <?=$rows['view'] ?></div>
<div style="width:8%" class="mfrow"> <?=$rows['reply'] ?></div>
<div style="width:15%" class="mfrow"> <?=$postdate?></div>
</div>
<?php endwhile;
$topic='';
if ($_SESSION['logged_in'] || $guest_question)
$topic='<a href="create_topic.php"><strong>Create New Topic</strong> </a>';
?>
<div style="background:#E6E6E6;float:left;width:100%;">
<div class="mffooter" style="float:left;text-align:left;"><?= $topic ?></div>
<form method="post" action="search.php">
<div class="mffooter" style="float:right;text-align:right;">
<input type="text" name="searchstr" style="padding:0px; width:120px;" />
<input type="submit" value="Search" style="padding:0px;" />
</div>
</form>
</div>
<div style="width:100%;text-align: right;float:left;"><?=$pagination ?></div>
</div>
<div style="float:left;width:100%;">
<h3>Forum Key</h3>
<p>
<table>
<tr>
<td width="20" align="left"><img src="folder_new.gif" alt="New posts" /></td>
<td>New posts</td>
<td width="20" align="center"><img src="folder.gif" alt="No new posts" /></td>
<td>No new posts</td>
<td width="20" align="center"><img src="sticky.gif" alt="Sticky" /></td>
<td>Sticky</td>
</tr>
<tr>
<td><img src="lock_new.gif" alt="New posts [ Locked ]" /></td>
<td>New posts [ Locked ]</td>
<td><img src="lock.gif" alt="No new posts [ Locked ]" /></td>
<td>No new posts [ Locked ]</td>
</tr>
</table>
There are <?=$users ?> registered users.</p>
</div>
<?php include('footer.php') ?>