<?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 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; }

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"; }

$min = 5;	// minimum visible posts in first level.
$max = 5;	// maximum number of posts in second level (hidden).

echo "<script type='text/javascript' language='JavaScript' src='".INFUSIONS."forum_threads_list_panel/ft_boxover.js'></script>";

$imageold = THEME."forum/folder.gif";
$imagenew = THEME."forum/foldernew.gif";
$imagelocked = THEME."forum/folderlock.gif";
$imagehot = THEME."forum/folderhot.gif";

/*******************************************************************
* Start use with the BlueIce Theme for cellpic image
********************************************************************/

if (isset($userdata['user_theme']) && $userdata['user_theme'] != "Default" && file_exists(THEMES.$userdata['user_theme']."/theme.php")) {
	$theme = $userdata['user_theme'];
} else { $theme = $settings['theme']; }
$class = $theme == "BlueIce" ? "td" : "tbl2";

/*******************************************************************
* End use with the BlueIce Theme for cellpic image
********************************************************************/

$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 ".($min + $max)
);
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' width='10%' height='24'>&nbsp;</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 == $min) {
			echo "</table><br>
<div align='left'>
<img src='".INFUSIONS."forum_threads_list_panel/images/icon_displaymore.gif' alt=''>&nbsp;<a href=\"javascript:show_hide(display_more_threads)\"><b>".$locale['ftl113']."</b></a>
</div>
<div id='display_more_threads'><br>
<table cellpadding='0' cellspacing='1' width='100%' class='tbl-border'>
<tr>
<td align='center' class='$class' width='10%' height='24'>&nbsp;</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";
		}
		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($x = 0; $x < count($viewed_data2); $x ++) {
						$viewed_data = explode("-", $viewed_data2[$x]);
						$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']."&amp;thread_id=".$data['thread_id']."&amp;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)))."] delay=[0] fade=[on]\">".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']."&amp;thread_id=".$data['thread_id']."&amp;pid=".$data['last_id']."#post_".$data['last_id']."' title='".$locale['ftl125']."'><img src='".INFUSIONS."forum_threads_list_panel/images/icon_minipost_new.gif' alt='' border='0'></a>
</td>
</tr>\n";
		$i ++;
	}
	if ($i > $min) { echo "</table><br><script language='javascript' type='text/javascript'>show_hide(display_more_threads)</script></div>\n"; }
	else { echo "</table><br>\n"; }
}
else{
	opentable($locale['ftl100']);
		echo "<p align='center'>На форуме нет ниодной темы</p><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='".INFUSIONS."forum_threads_list_panel/images/icon_unanswered.gif' alt=''>&nbsp;<a href='".INFUSIONS."forum_threads_list_panel/ua_threads.php'>".$locale['ftl102']."</a><br>
<img src='".INFUSIONS."forum_threads_list_panel/images/icon_allthreads.gif' alt=''>&nbsp;<a href='".INFUSIONS."forum_threads_list_panel/allthreads.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='".BASEDIR."infusions/forum_threads_list_panel/images/icon_threads.gif' alt='' border='0'>&nbsp;<span class='small'><a href='".INFUSIONS."forum_threads_list_panel/my_threads.php'>".$locale['ftl110']."</a></span>&nbsp;&nbsp;
<img src='".BASEDIR."infusions/forum_threads_list_panel/images/icon_threads.gif' alt='' border='0'>&nbsp;<span class='small'><a href='".INFUSIONS."forum_threads_list_panel/my_posts.php'>".$locale['ftl111']."</a></span>&nbsp;&nbsp;
<img src='".BASEDIR."infusions/forum_threads_list_panel/images/icon_threads.gif' alt='' border='0'>&nbsp;<span class='small'><a href='".INFUSIONS."forum_threads_list_panel/newposts.php'>".$locale['ftl112']."</a></span>
</td>
</tr>\n";
}
echo "</table>\n";
closetable();

?>