<?php
/*---------------------------------------------------+
| PHP-Fusion 6 Content Management System
+----------------------------------------------------+
| Copyright © 2002 - 2007 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
+----------------------------------------------------+
/*---------------------------------------------------+
| Advanced News System v.2.00.2
+----------------------------------------------------+
| Advanced Forum Threads List Panel - (AFTLP)
| Modder: Shedrock / Xandra - Fuzed Themes
| Special Credit: Xandra - Thank you for all your help
| Support: http://phpfusion-themes.com
+----------------------------------------------------*/
if (!defined("IN_FUSION")) { header("Location:../../index.php"); exit; }
	include LOCALE.LOCALESET."extra/forum_threads_list_panel.php";

$imageold = THEME."forum/folder.gif";
$imagenew = THEME."forum/foldernew.gif";
$imagelocked = THEME."forum/folderlock.gif";
$imagehot = THEME."forum/folderhot.gif";

$result = dbquery(
	"SELECT tf.*, tt.*, tu.user_id, user_name, MAX(tp.post_id) as last_id,
	COUNT(tp.post_id) as count_posts FROM ".$db_prefix."forums tf
	INNER JOIN ".$db_prefix."threads tt USING(forum_id)
	INNER JOIN ".$db_prefix."posts tp USING(thread_id)
	INNER JOIN ".$db_prefix."users tu ON tt.thread_lastuser=tu.user_id
	WHERE ".groupaccess('forum_access')." GROUP BY thread_id 
	ORDER BY thread_lastpost DESC LIMIT 0,".$settings['numofthreads']
);
if (dbrows($result) != 0) {
	$i = 0;
	opentable($locale['ftl100']);
	echo "<table cellpadding='0' cellspacing='1' width='100%' class='tbl-border'>
<tr>
<td align='center' class='$class' height='24'> </td>
<td align='center' class='$class'><span class='small'><b>".$locale['ftl120']."</b></span></td>
<td align='center' class='$class'><span class='small'><b>".$locale['ftl124']."</b></span></td>
<td align='center' class='$class'><span class='small'><b>".$locale['ftl123']."</b></span></td>
<td align='center' class='$class'><span class='small'><b>".$locale['ftl107']."</b></span></td>
<td align='center' class='$class'><span class='small'><b>".$locale['ftl108']."</b></span></td>
</tr>\n";

	while ($data = dbarray($result)) {
		if ($i % 2 == 0) { $row_color = "tbl1"; } else { $row_color = "tbl2"; }
		$thread_author = dbarray(dbquery("SELECT user_name FROM ".$db_prefix."users WHERE user_id='".$data['thread_author']."'"));
		if (iMEMBER) {
			$new_posts = dbcount("(thread_id)", "posts", "thread_id='".$data['thread_id']."' and post_datestamp>'$lastvisited'");
		} else { $new_posts = 0; }
		$data2 = dbarray(dbquery("SELECT * FROM ".$db_prefix."posts WHERE thread_id='".$data['thread_id']."' ORDER BY post_id DESC LIMIT 1"));
		$post_message = $data2['post_smileys'] == 1 ? parsesmileys($data2['post_message']) : $data2['post_message'];
		$post_message = phpentities(nl2br(parseubb($post_message)));
		if ($data['thread_locked']) { $folder_image = $imagelocked; }
		else {
			if ($new_posts > 0){

/*******************************************************************
* Start Threads Marked As Read Mod
********************************************************************/
/*
				$viewed_result = dbquery("SELECT threads FROM ".$db_prefix."viewed_threads WHERE user_id = '".$userdata['user_id']."'");
				if (dbrows($viewed_result) != 0) {
					$viewed_data = dbarray($viewed_result);
					$viewed_data2 = explode(".", $viewed_data['threads']);
					$viewed = array();
					for($i = 0; $i < count($viewed_data2); $i ++) {
						$viewed_data = explode("-", $viewed_data2[$i]);
						$viewed[$viewed_data[0]] = $viewed_data[1];
					}
					if (!isset($viewed[$data['thread_id']]) || $viewed[$data['thread_id']] < $data['thread_lastpost']) {
						$folder_image = $imagenew;
					} else { $folder_image = $imageold; }
				} else
*/
/*******************************************************************
* End Threads Marked As Read Mod
********************************************************************/

				$folder_image = $imagenew;
			} elseif ($data['count_posts'] > 20) { $folder_image = $imagehot; }
			else { $folder_image = $imageold; }
		}

	echo "<tr>
<td align='center' class='$row_color'><img src='$folder_image' alt=''></td>
<td width='35%' class='$row_color'>
<span class='small'><strong>".$data['forum_name']."</strong></span><br>
<span class='small'><a href='".FORUM."viewthread.php?forum_id=".$data['forum_id']."&thread_id=".$data['thread_id']."&pid=".$data['last_id']."#post_".$data['last_id']."' title='header=[ ".str_replace("]", "]]", str_replace("[", "[[", trimlink($data['thread_subject'], 30)))."] body=[".str_replace("]", "]]", str_replace("[", "[[", trimlink($post_message, 250)))."]'>".trimlink($data['thread_subject'], 30)."</a></span>
</td>
<td align='center' class='$row_color'><a href='".BASEDIR."profile.php?lookup=".$data['thread_author']."'>".$thread_author['user_name']."</a></td>
<td align='center' width='40' class='$row_color'><span class='small'>".$data['thread_views']."</span></td>
<td align='center' width='45' class='$row_color'><span class='small'>".($data['count_posts']-1)."</span></td>
<td align='center' width='25%' class='$row_color'>
<span class='small'>".showdate("forumdate", $data['thread_lastpost'])."</span><br>
<span class='small'><a href='".BASEDIR."profile.php?lookup=".$data['thread_lastuser']."'>".$data['user_name']."</a></span><a href='".FORUM."viewthread.php?forum_id=".$data['forum_id']."&thread_id=".$data['thread_id']."&pid=".$data['last_id']."#post_".$data['last_id']."' title='".$locale['ftl125']."'><img src='".IMAGES."icon_minipost_new.gif' alt='' border='0'></a>
</td>
</tr>\n";
		$i++;
	}
	echo "</table><br>\n";

/*******************************************************************
* Start search - added for ease by Shedrock
********************************************************************/

	echo"<table border='0' width='100%' cellpadding='0' cellspacing='0'>
<tr>
<td align='left' valign='bottom' class='small'>";

if (iMEMBER) {
	echo"<img src='".IMAGES."icon_unanswered.gif' alt=''> <a href='".FORUM."unanswered.php'>".$locale['ftl102']."</a><br>
<img src='".IMAGES."icon_allthreads.gif' alt=''> <a href='".FORUM."all.php'>".$locale['ftl103']."</a>";
}

echo"</td>
<td align='right' valign='bottom' class='forum'>
<form name='search' method='post' action='".BASEDIR."search.php?stype=f'><span class='small'>".$locale['ftl104']." </span>
<input type='text' name='stext' class='textbox' style='width:150px' size='20'>
<input type='submit' name='search' value='".$locale['ftl105']."' class='button'>
</form>
</td>
</tr>";

/*******************************************************************
* End search
********************************************************************/

	if (iMEMBER) {
		echo "<tr>
<td style='padding-bottom:0px;' align='center' colspan='5' class='tbl'><hr>
<img src='".IMAGES."icon_threads.gif' alt='' border='0'> <span class='small'><a href='".FORUM."my_threads.php'>".$locale['ftl110']."</a></span>  
<img src='".IMAGES."icon_threads.gif' alt='' border='0'> <span class='small'><a href='".FORUM."my_posts.php'>".$locale['ftl111']."</a></span>  
<img src='".IMAGES."icon_threads.gif' alt='' border='0'> <span class='small'><a href='".FORUM."new.php'>".$locale['ftl112']."</a></span>
</td>
</tr>\n";
	}
	echo "</table>\n";
	closetable();
}
?>