<?php
/*---------------------------------------------------+
| PHP-Fusion 6 Content Management System
+----------------------------------------------------+
| Copyright © 2002 - 2006 Nick Jones
| http://www.php-fusion.co.uk/
+----------------------------------------------------+
| Released under the terms & conditions of v2 of the
| GNU General Public License. For details refer to
| the included gpl.txt file or visit http://gnu.org
+----------------------------------------------------+
| Modified by PHP-Fusion SF Group
| Copyright © 2007 by SF
| http://www.rus-phpfusion.com/
+----------------------------------------------------*/
require_once "../../maincore.php";
require_once BASEDIR."subheader.php";
require_once BASEDIR."side_left.php";
include LOCALE.LOCALESET."forum/main.php";

if (file_exists(INFUSIONS."forum_threads_list_panel/locale/".$settings['locale'].".php")) {
	include INFUSIONS."forum_threads_list_panel/locale/".$settings['locale'].".php";
} else {
	include INFUSIONS."forum_threads_list_panel/locale/English.php";
}

if (!iMEMBER) fallback("index.php");

if (empty($lastvisited)) { $lastvisited = time(); }

$fcdata = dbarray(dbquery("SELECT * FROM ".$db_prefix."forums WHERE forum_id='".$data['forum_cat']."'"));

$caption .= $fcdata['forum_name']." Âñå òåìû";

opentable($locale['450']);
echo "<table width='100%' cellspacing='0' cellpadding='0'>
<tr>
<td class='smallalt'>
<a href='".BASEDIR."index.php'>".$locale['ftl126']."</a> |
$caption</td>\n";
echo "</tr>
</table>\n";

$rows = dbrows(dbquery("SELECT * FROM ".$db_prefix."threads WHERE thread_sticky='0'"));
if (!$rowstart) $rowstart = 0;
echo "<div align='center' style='margin-top:5px;margin-bottom:5px;'>
".makePageNav($rowstart,20,$rows,3,FUSION_SELF."?forum_id=$forum_id&amp;")."
</div>\n";

echo "<table cellspacing='0' cellpadding='0' border='0' width='100%' class='tbl-border'>
<tr>
<td>
<table border='0' cellspacing='1' cellpadding='0' width='100%'>
<tr>
<td width='20' class='tbl2'>&nbsp;</td>
<td style='text-align:center;' class='tbl2'><span class='small'><b>".$locale['451']."</b></span></td>
<td style='text-align:center;' width='100' class='tbl2'><span class='small'><b>".$locale['452']."</b></span></td>
<td style='text-align:center;' width='50' class='tbl2'><span class='small'><b>".$locale['453']."</b></span></td>
<td style='text-align:center;' width='50' class='tbl2'><span class='small'><b>".$locale['454']."</b></span></td>
<td style='text-align:center;' width='120' class='tbl2'><span class='small'><b>".$locale['404']."</b></span></td>
</tr>\n";

if ($rowstart == 0) {	
	$result = dbquery(
		"SELECT ".$db_prefix."threads.*, tu1.user_name as user_author, tu2.user_name as user_lastuser FROM ".$db_prefix."threads
		LEFT JOIN ".$db_prefix."users tu1 ON ".$db_prefix."threads.thread_author = tu1.user_id
		LEFT JOIN ".$db_prefix."users tu2 ON ".$db_prefix."threads.thread_lastuser = tu2.user_id
		WHERE thread_sticky='1' ORDER BY thread_lastpost DESC"
	);
	if (dbrows($result) != 0) {
		while ($data = dbarray($result)) {
			$new_posts = dbcount("(thread_id)", "posts", "thread_id='".$data['thread_id']."' and post_datestamp>'$lastvisited'");
			$thread_replies = dbcount("(thread_id)", "posts", "thread_id='".$data['thread_id']."'") - 1;
			$forum_id = $data['forum_id'];
			if ($data['thread_locked']) {
				echo "<tr>\n<td align='center' width='25' class='tbl2'><img alt='' src='".THEME."forum/folderlock.gif'></td>";
			} else  {
	        		if ($new_posts > 0) {
	        			$folder = "<img alt='' src='".THEME."forum/foldernew.gif'>";
	        		} else if ($new_posts > 19) {
        				$folder = "<img alt='' src='".THEME."forum/folderhot.gif'>";
	        		} else {
	        			$folder = "<img alt='' src='".THEME."forum/folder.gif'>";
	        		}
				echo "<tr>\n<td align='center' width='25' class='tbl2'>$folder</td>";
			}
			echo "<td class='tbl1'><img alt='' src='".THEME."forum/stickythread.gif'>
<a href='".BASEDIR."forum/viewthread.php?forum_id=$forum_id&amp;thread_id=".$data['thread_id']."'>".$data['thread_subject']."</a></td>
<td style='text-align:center;' class='tbl2'><a href='".BASEDIR."profile.php?lookup=".$data['thread_author']."'>".$data['user_author']."</a></td>
<td style='text-align:center;' class='tbl1'>".$data['thread_views']."</td>
<td style='text-align:center;' class='tbl2'>".$thread_replies."</td>
<td style='text-align:center;' class='tbl1'>".showdate("forumdate", $data['thread_lastpost'])."<br>
<span class='small'>".$locale['406']."<a href='".BASEDIR."profile.php?lookup=".$data['thread_lastuser']."'>".$data['user_lastuser']."</a></span></td>
</tr>\n";
		}
	} else {
		$threadcount = 0;
	}
}

if ($rows != 0) {
	$result = dbquery(
		"SELECT ".$db_prefix."threads.*, tu1.user_name as user_author, tu2.user_name as user_lastuser FROM ".$db_prefix."threads
		LEFT JOIN ".$db_prefix."users tu1 ON ".$db_prefix."threads.thread_author = tu1.user_id
		LEFT JOIN ".$db_prefix."users tu2 ON ".$db_prefix."threads.thread_lastuser = tu2.user_id
		WHERE thread_sticky='0' ORDER BY thread_lastpost DESC LIMIT $rowstart,20"
	);
	$numrows = dbrows($result);
	while ($data = dbarray($result)) {
		$new_posts = dbcount("(thread_id)", "posts", "thread_id='".$data['thread_id']."' and post_datestamp>'$lastvisited'");
		$thread_replies = dbcount("(thread_id)", "posts", "thread_id='".$data['thread_id']."'") - 1;
		$forum_id = $data['forum_id'];
		if ($data['thread_locked']) {
			echo "<tr>\n<td align='center' width='25' class='tbl2'><img alt='' src='".THEME."forum/folderlock.gif'></td>";
		} else  {
        		if ($new_posts > 0) {
        			$folder = "<img alt='' src='".THEME."forum/foldernew.gif'>";
        		} else if ($new_posts > 19) {
        			$folder = "<img alt='' src='".THEME."forum/folderhot.gif'>";
        		} else {
        			$folder = "<img alt='' src='".THEME."forum/folder.gif'>";
        		}
			echo "<tr>
<td align='center' width='25' class='tbl2'>$folder</td>";
		}
		$reps = dbcount("(thread_id)", "posts", "thread_id='".$data['thread_id']."'");
		$reps = ceil($reps / 20);
		$threadsubject = "<a href='".BASEDIR."forum/viewthread.php?forum_id=$forum_id&amp;thread_id=".$data['thread_id']."'>".$data['thread_subject']."</a>";
		if ($reps > 1) {
			$ctr = 0; $ctr2 = 1; $pages = "";
			while ($ctr2 <= $reps) {
				$pnum = "<a href='".BASEDIR."forum/viewthread.php?forum_id=$forum_id&amp;thread_id=".$data['thread_id']."&amp;rowstart=$ctr'>$ctr2</a> ";
				$pages = $pages.$pnum; $ctr = $ctr+20; $ctr2++;
			}
			$threadsubject .= " - (Page: ".trim($pages).")";
		}
		echo "<td class='tbl1'>$threadsubject</td>
<td style='text-align:center;' class='tbl2'><a href='".BASEDIR."profile.php?lookup=".$data['thread_author']."'>".$data['user_author']."</a></td>
<td style='text-align:center;' class='tbl1'>".$data['thread_views']."</td>
<td style='text-align:center;' class='tbl2'>".$thread_replies."</td>
<td style='text-align:center;' class='tbl1'>".showdate("forumdate", $data['thread_lastpost'])."<br>
<span class='small'>".$locale['406']."<a href='".BASEDIR."profile.php?lookup=".$data['thread_lastuser']."'>".$data['user_lastuser']."</a></span></td>
</tr>\n";
	}
} else {
	if ($threadcount == 0) {
		echo "<tr>\n<td colspan='6' class='tbl1'>".$locale['455']."</td>\n</tr>\n";
	}
}

echo "</table>
</td>
</tr>
</table>\n";

echo "<div align='center' style='margin-top:5px;margin-bottom:5px;'>
".makePageNav($rowstart,20,$rows,3,FUSION_SELF."?forum_id=$forum_id&amp;")."
</div>\n";

echo "<table width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td class='tbl1'>
<img alt='' src='".THEME."forum/foldernew.gif'> - ".$locale['456']."(<img alt='' src='".THEME."forum/folderhot.gif'> - ".$locale['457'].")<br>
<img alt='' src='".THEME."forum/folder.gif'> - ".$locale['458']."<br>
<img alt='' src='".THEME."forum/folderlock.gif'> - ".$locale['459']."</td>
</tr>
</table>\n";
closetable();

require_once BASEDIR."side_right.php";
require_once BASEDIR."footer.php";
?>