<?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 INCLUDES."forum_functions_include.php";
require_once FORUM."subheader.php";
if ($settings_forum['show_panel'] == 1){
	require_once BASEDIR."side_left.php";
}
include LOCALE.LOCALESET."forum/main.php";
include_once INCLUDES."countries.php";

$posts_per_page = $settings_forum['threadn'];;

if (!FUSION_QUERY || !isset($forum_id) || !isNum($forum_id) || !isset($thread_id) || !isNum($thread_id)) fallback("index.php");

$result = dbquery("
	SELECT f.*, f2.forum_name AS forum_cat_name
	FROM ".$db_prefix."forums f
	LEFT JOIN ".$db_prefix."forums f2 ON f.forum_cat=f2.forum_id
	WHERE f.forum_id='".$forum_id."'
");
if (dbrows($result)) {
	$fdata = dbarray($result);
	if (!checkgroup($fdata['forum_access']) || !$fdata['forum_cat']) fallback("index.php");
} else {
	fallback("index.php");
}

$can_post = checkgroup($fdata['forum_posting']);
$settings3 = dbarray(dbquery("SELECT * FROM ".$db_prefix."attachment_settings"));
$forum_mods = explode(".", $fdata['forum_moderators']);

if (iMEMBER && in_array($userdata['user_id'], $forum_mods)) { define("iMOD", true); } else { define("iMOD", false); }

$result = dbquery("SELECT * FROM ".$db_prefix."threads WHERE thread_id='".$thread_id."' AND forum_id='".$fdata['forum_id']."'");
if (dbrows($result)) { $tdata = dbarray($result); } else { fallback("index.php"); }

$caption = $fdata['forum_cat_name']." | <a href='viewforum.php?forum_id=".$fdata['forum_id']."'>".$fdata['forum_name']."</a>";
$result = dbquery("UPDATE ".$db_prefix."threads SET thread_views=thread_views+1 WHERE thread_id='$thread_id'");

if (iMEMBER && $can_post && isset($_POST['postquickreply'])) {
	$flood = false;
	$message = stripinput(censorwords($_POST['message']));
	if ($message != "") {
		$result = dbquery("SELECT MAX(post_datestamp) AS last_post FROM ".$db_prefix."posts WHERE post_author='".$userdata['user_id']."'");
		if (dbrows($result) > 0) {
			$data = dbarray($result);
			if ((time() - $data['last_post']) < $settings['flood_interval']) {
				$flood = true;
				$result = dbquery("INSERT INTO ".$db_prefix."flood_control (flood_ip, flood_timestamp) VALUES ('".USER_IP."', '".time()."')");
				if (dbcount("(flood_ip)", "flood_control", "flood_ip='".USER_IP."'") > 4) {
					$result = dbquery("UPDATE ".$db_prefix."users SET user_status='1' WHERE user_id='".$userdata['user_id']."'");
				}
				fallback("viewforum.php?forum_id=$forum_id");
			}
		}
		if (!$flood) {
			$sig = ($userdata['user_sig'] ? '1' :'0');
			$smileys = isset($_POST['disable_smileys']) ? "0" : "1";
			$subject = "RE: ".$tdata['thread_subject'];
			$result = dbquery("UPDATE ".$db_prefix."forums SET forum_lastpost='".time()."', forum_lastuser='".$userdata['user_id']."' WHERE forum_id='$forum_id'");
			$result = dbquery("UPDATE ".$db_prefix."threads SET thread_lastpost='".time()."', thread_lastuser='".$userdata['user_id']."' WHERE thread_id='$thread_id'");
			$result = dbquery("INSERT INTO ".$db_prefix."posts (forum_id, thread_id, post_subject, post_message, post_showsig, post_smileys, post_author, post_datestamp, post_ip, post_edituser, post_edittime) VALUES ('$forum_id', '$thread_id', '$subject', '$message', '$sig', '$smileys', '".$userdata['user_id']."', '".time()."', '".USER_IP."', '0', '0')");
			$newpost_id = mysql_insert_id();
			$result = dbquery("UPDATE ".$db_prefix."users SET user_posts=user_posts+1 WHERE user_id='".$userdata['user_id']."'");
			redirect("postify.php?post=reply&error=0&forum_id=$forum_id&thread_id=$thread_id&post_id=$newpost_id");
		}
	}
}

opentable($locale['500']);
echo "<table cellpadding='0' cellspacing='0' width='98%' align='center'>
<tr><td class='smallalt'>
Вернуться на сайт: <a href='../index.php'>".$settings['sitename']."</a><br /><br />
<a href='index.php'>".$settings_forum['forumname']."</a> | $caption</td>\n";
if (iMEMBER && $can_post) {
	echo "<td align='right'>\n";
	if (!$tdata['thread_locked']) {
		echo "<a href='post.php?action=reply&amp;forum_id=$forum_id&amp;thread_id=$thread_id'><img src='".THEME."forum/reply.gif' alt='".$locale['565']."' style='border:0px;'></a>\n";
	}
	echo "<a href='post.php?action=newthread&amp;forum_id=$forum_id'><img src='".THEME."forum/newthread.gif' alt='".$locale['566']."' style='border:0px;'></a></td>\n";
}
echo "</tr></table>\n";

$res_array = dbarray(dbquery("SELECT poll_id FROM ".$db_prefix."forum_thread_polls WHERE thread_id='$thread_id'"));
//Polls
if (isset($_POST['cast_vote'])) {
		if (isset($poll_id) && !isNum($poll_id)) {
			header("location: ".$_SERVER['HTTP_REFERER']);
		}	
        $result = dbquery("SELECT * FROM ".$db_prefix."forum_poll_votes WHERE vote_user='".$userdata['user_id']."' AND poll_id='$poll_id'");
        if (!dbrows($result)) {
                $result = dbquery("INSERT INTO ".$db_prefix."forum_poll_votes VALUES('', '".$userdata['user_id']."', '$voteoption', '$poll_id')");
                header("location: ".$_SERVER['HTTP_REFERER']);
        }
}
$result = dbquery("SELECT * FROM ".$db_prefix."forum_polls WHERE poll_index= 'F' AND poll_id= '".$res_array['poll_id']."'");
if (dbrows($result) != 0) {
        $data = dbarray($result);
        $poll_title = $data['poll_title'];
        for ($i=0; $i<=9; $i++) {
                if ($data["poll_opt_".$i]) $poll_option[$i] = $data["poll_opt_".$i];
        }
        if (iMEMBER) $result2 = dbquery("SELECT * FROM ".$db_prefix."forum_poll_votes WHERE vote_user='".$userdata['user_id']."' AND poll_id='".$data['poll_id']."'");
        if ( (!iMEMBER || !dbrows($result2)) && $data['poll_ended'] == 0) {
        if (!iMEMBER) {
                $poll =  ""; $i = 0; $num_opts = count($poll_option);
                $forum_poll_votes = dbcount("(vote_opt)", "forum_poll_votes", "poll_id='".$data['poll_id']."'");
                
                while ($i < $num_opts) {
                        $num_votes = dbcount("(vote_opt)", "forum_poll_votes", "vote_opt='$i' AND poll_id='".$data['poll_id']."'");
                        $opt_votes = ($forum_poll_votes ? number_format(100 / $forum_poll_votes * $num_votes) : 0);
                        $poll .= "<div>".$poll_option[$i]."</div>
<div><img src='".FORUM."images/bar_left.gif' height='12'><img src='".FORUM."images/bar.gif' alt='".$poll_option[$i]."' width='$opt_votes' height='12'><img src='".FORUM."images/bar_right.gif' height='12'></div>
<div>".$opt_votes."% [".$num_votes." ".($num_votes == 1 ? $locale['103'] : $locale['104'])."]</div><br>\n";
                        $i++;
                }
        } else {
                $poll = ""; $i = 0; $num_opts = count($poll_option);
                while ($i < $num_opts) {
                        $poll .= "<input type='radio' name='voteoption' value='$i'> $poll_option[$i]<br><br>\n";
                        $i++;
                        }
                }
                echo "<table width='98%' align='center'><tr><td><form name='voteform' method='post' action='".FUSION_SELF.(FUSION_QUERY ? "?".FUSION_QUERY : "")."'>
<hr><b>$poll_title</b><br><hr><br>
$poll<center><input type='hidden' name='poll_id' value='".$data['poll_id']."'>\n";
                if (iMEMBER) {
                        echo "<input type='submit' name='cast_vote' value='".$locale['101']."' class='button'></center>\n";
                }
                echo "</form></td></tr></table>\n";
        } else {
                $poll =  ""; $i = 0; $num_opts = count($poll_option);
                $forum_poll_votes = dbcount("(vote_opt)", "forum_poll_votes", "poll_id='".$data['poll_id']."'");
               echo "<table width='98%' align='center'><tr><td>";
                while ($i < $num_opts) {
                        $num_votes = dbcount("(vote_opt)", "forum_poll_votes", "vote_opt='$i' AND poll_id='".$data['poll_id']."'");
                        $opt_votes = ($forum_poll_votes ? number_format(100 / $forum_poll_votes * $num_votes) : 0);
                        $poll .= "<div>".$poll_option[$i]."</div>
<div><img src='".FORUM."images/bar_left.gif' height='12'><img src='".FORUM."images/bar.gif' alt='".$poll_option[$i]."' width='$opt_votes' height='12'><img src='".FORUM."images/bar_right.gif' height='12'></div>
<div>".$opt_votes."% [".$num_votes." ".($num_votes == 1 ? $locale['103'] : $locale['104'])."]</div><br>\n";
                        $i++;
                }
                echo "<hr><b>".$poll_title."</b><br><hr><br>
$poll\n</td></tr></table>";
        }
}
//-----------------------


$rows = dbcount("(thread_id)", "posts", "thread_id='$thread_id'");

if (isset($pid) && isNum($pid)) {
	$reply_count = dbcount("(post_id)", "posts", "thread_id='".$tdata['thread_id']."' AND post_id<='".$pid."'");
	if ($reply_count > $posts_per_page) $rowstart = ((ceil($reply_count / $posts_per_page)-1)*$posts_per_page);
}

if (!isset($rowstart) || !isNum($rowstart)) $rowstart = 0;

if ($rows > $posts_per_page) {
	echo "
	<div align='center' style='margin-top:5px;margin-bottom:5px;'>
		".makePageNav($rowstart,$posts_per_page,$rows,3,FUSION_SELF."?forum_id=$forum_id&amp;thread_id=$thread_id&amp;")."
	</div>\n";
}
if (iMEMBER && $can_post) {
	if (iMOD || iSUPERADMIN) {
		echo "<form name='modopts' method='post' action='options.php?forum_id=$forum_id&amp;thread_id=$thread_id'>"; //fox fadmin
	}
}



echo "<table cellpadding='0' cellspacing='1' width='98%' align='center' class='tbl-border'>\n";

if ($rows != 0) {
	$result = dbquery(
		"SELECT * FROM ".$db_prefix."posts
		LEFT JOIN ".$db_prefix."users ON ".$db_prefix."posts.post_author=".$db_prefix."users.user_id
		WHERE thread_id='$thread_id' ORDER BY post_datestamp LIMIT $rowstart,$posts_per_page"
	);
	$numrows = dbrows($result);
	$postcount = $rowstart + 1;
	$i = 0;
	while ($data = dbarray($result)) {
		$i++;
		$message = $data['post_message'];
		if ($data['post_smileys']) { $message = parsesmileys($message); }
		$message = parseubb($message);
		$message = preg_replace("/([^\s]{130})/", "$1\n", $message);
		$message = nl2br($message);
		if ($data['post_edittime'] != "0") {
			if ($data['post_author'] != $data['post_edituser']) {
				$data2 = dbarray(dbquery("SELECT user_id,user_name FROM ".$db_prefix."users WHERE user_id='".$data['post_edituser']."'"));
				$edituser = "<a href='../profile.php?lookup=".$data2['user_id']."'>".$data2['user_name']."</a>";
			} else {
				$edituser = "<a href='../profile.php?lookup=".$data['user_id']."'>".$data['user_name']."</a>";
			}
			$edittime = showdate("forumdate", $data['post_edittime']);
		}
		$icq = $data['user_icq'];
		if (empty($data['user_icq'])){
			$icqon = "";
		}
		else
		{
			$icqon = "<a href=http://www.icq.com/".$data['user_icq']."#pager><img src=http://status.icq.com/online.gif?img=5&icq=".$data['user_icq']." border='0' alt='".$data['user_icq']."' align='absmiddle'></a>";
		}
		$is_mod = in_array($data['user_id'], $forum_mods) && $data['user_level'] < "102" ? true : false;
		echo "
		<tr><td width='145' class='tbl2'><a name='post_".$data['post_id']."' id='post_".$data['post_id']."'></a>";
		echo "<a href='viewthread.php?forum_id=$forum_id&amp;thread_id=".$data['thread_id']."&amp;pid=".$data['post_id']."#post_".$data['post_id']."' on ># $postcount</a>\n";
	    $postcount ++;
		echo "</td><td class='tbl2'>";
		if ($i == 1) {
		echo "<b>Тема: </b>".$data['post_subject'];
		} else {
			echo "&nbsp;";
		}
		echo "</td></tr><tr>
		<td valign='top' rowspan='3' width='145' class='tbl1'><a href='../profile.php?lookup=".$data['user_id']."'>".$data['user_name']."</a><br>
		<span class='alt'>".($is_mod ? $locale['userf1'] : getuserlevel($data['user_level']))."</span><br><br>\n";
		if ($data['user_avatar'] != "") {
			echo "<img src='".IMAGES."avatars/".$data['user_avatar']."' alt='".$locale['567']."'><br><br>\n";
			$height = "185";
		} else {
			$height = "185";
			echo "<center><img src='".FORUM."images/noava.gif' alt='".$locale['567']."'></center><br><br>\n";
		}
		
		// Status1
		
		echo "<b>".$data['user_stat']."</b><br>\n";

		// Status
		$result2 = dbquery("SELECT user_posts FROM ".$db_prefix."users WHERE user_id='".$data['user_id']."'");
		$data2 = dbarray($result2);
		$num_posts = $data2['user_posts'];
		if ($data['user_level']==103){
			echo "<br />Администратор<br /><img src='".FORUM."images/admin.gif'><br />";
		} else {
		if ($num_posts >= $settings_forum['stat_1'] & $num_posts < $settings_forum['stat_2']) {echo "<br />".$settings_forum['stat_sig_1']."<br /><img src='".FORUM."images/warn0.gif'><br />";}
		if ($num_posts >= $settings_forum['stat_2'] & $num_posts < $settings_forum['stat_3']) {echo "<br />".$settings_forum['stat_sig_2']."<br /><img src='".FORUM."images/warn1.gif'><br />";}
		if ($num_posts >= $settings_forum['stat_3'] & $num_posts < $settings_forum['stat_4']) {echo "<br />".$settings_forum['stat_sig_3']."<br /><img src='".FORUM."images/warn2.gif'><br />";}
		if ($num_posts >= $settings_forum['stat_4'] & $num_posts < $settings_forum['stat_5']) {echo "<br />".$settings_forum['stat_sig_4']."<br /><img src='".FORUM."images/warn3.gif'><br />";}
		if ($num_posts >= $settings_forum['stat_5'] & $num_posts < $settings_forum['stat_6']) {echo "<br />".$settings_forum['stat_sig_5']."<br /><img src='".FORUM."images/warn4.gif'><br />";}
		if ($num_posts >= $settings_forum['stat_6']) {echo "<br />".$settings_forum['stat_sig_6']."<br /><img src='".FORUM."images/warn5.gif'><br />";}
		}
		echo "<span class='alt'>".$locale['502']."</span> ".$data['user_posts']."<br>\n";
		
		if ($data['user_location']) {
			if (!isset($ft_csm['user'][$data['user_id']])) { $ft_csm['user'][$data['user_id']] = csm_getLocation($data['user_location']); }
			echo "<span class='alt'>".$locale['503']."</span> ".$ft_csm['user'][$data['user_id']]."<br>\n";
		}
		echo "<span class='alt'>".$locale['504']."</span> ".showdate("%d.%m.%y", $data['user_joined'])."<br />";
		echo "<span class='alt'>".$locale['UGM_000']."</span>
".($data['user_gender'] != 0 ? ($data['user_gender'] == 1 ? $locale['UGM_001'] : $locale['UGM_002']) : $locale['u048'])."";
		$lastvisit = (time() - $data['user_lastvisit']);
		if ($lastvisit < 60) $status = "<font color='#006600'>".$locale['572']."</font>";
		else $status = "<font color='#AA0000'>".$locale['573']."</font>";
		echo "<br /><span class='alt'>".$locale['574']."</span>".$status."\n";
		if (!empty($data['user_icq'])){
		echo "<br /><span class='alt'>ICQ статус </span>".$icqon."\n";
				}
		echo "</td><td class='tbl1' ><table cellspacing='0' cellpadding='0' width='100%'>
		<tr><td class='tbl1'>".$locale['505'].showdate("forumdate", $data['post_datestamp'])."</td>
		<td align='right' class='tbl1'>\n";
		if (iMEMBER && $can_post) {
			if (!$tdata['thread_locked']) {
				if ($userdata['user_id'] == $data['post_author'] || iMOD || iSUPERADMIN) {
					echo "<a href='post.php?action=edit&amp;forum_id=$forum_id&amp;thread_id=".$data['thread_id']."&amp;post_id=".$data['post_id']."'><img src='".THEME."forum/edit.gif' alt='".$locale['568']."' style='border:0px;'></a>\n";
				}
				echo "<a href='post.php?action=reply&amp;forum_id=$forum_id&amp;thread_id=".$data['thread_id']."&amp;post_id=".$data['post_id']."&amp;quote=".$data['post_id']."'><img src='".THEME."forum/quote.gif' alt='".$locale['569']."' style='border:0px;'></a>\n";
				if (iMOD || iSUPERADMIN && $data['post_ip'] != "0.0.0.0" && file_exists(THEME."forum/ip.gif")) echo "<img src='".THEME."forum/ip.gif' alt='".$locale['570']."' title='".$data['post_ip']."' style='border:0px;'>\n";
				if (iMOD || iSUPERADMIN) echo "<input type='checkbox' name='selpost[".$data['post_id']."]' value='1'>\n"; //fox fadmin
			} else {
				if (iMOD || iSUPERADMIN) {
					echo "<a href='post.php?action=edit&amp;forum_id=$forum_id&amp;thread_id=".$data['thread_id']."&amp;post_id=".$data['post_id']."'><img src='".THEME."forum/edit.gif' alt='".$locale['568']."' style='border:0px;'></a>\n";
					if ($data['post_ip'] != "0.0.0.0" && file_exists(THEME."forum/ip.gif")) echo "<img src='".THEME."forum/ip.gif' alt='".$locale['570']."' title='".$data['post_ip']."' style='border:0px;'>\n";
					echo "<input type='checkbox' name='selpost[".$data['post_id']."]' value='1'>\n"; //fox fadmin
				}
			}
		}
		echo "</td></tr></table></td></tr><tr><td valign='top' height='$height' class='tbl1'>";
		echo "<table cellspacing='0' cellpadding='0' width='100%'>

		<tr><td class='tbl1' valign='top' width='75%'>$message</td>

		<td align='right' class='tbl1' width='25%' valign='top'>\n";

		$result2 = dbquery("
		SELECT * 
		FROM ".$db_prefix."forum_attachments 
		WHERE post_id='".$data['post_id']."'
		");
		if (dbrows($result2) != 0) {
			echo "<script language='javascript'>
			function flip(wich) {
				document.getElementById(wich).style.display = (document.getElementById(wich).style.display == 'none' ? 'block' : 'none');
				}
			</script>";
	$wuattach = dbarray($result2);
	$a_id = $wuattach['attach_id'];	

$result2 = dbquery("
	SELECT *
	FROM ".$db_prefix."forum_attachments
	WHERE post_id='".$data['post_id']."'
");


echo "<FIELDSET><LEGEND>Прикрепленные файлы</LEGEND>";
while ($attach = dbarray($result2)){
		$a_id = $attach['attach_id'];
		if ($attach['attach_ext'] == ".gif" || $attach['attach_ext'] == '.jpeg' || $attach['attach_ext'] == ".jpg" || $attach['attach_ext'] == ".png") {
			$fileimg = FORUM."attachments/".$attach['attach_name'];
			$imginfo = getimagesize($fileimg);

			//resize proportional
			$imgwidth = $imginfo[0];
			$imgheight = $imginfo[1];
			$img_wprop = ($imgwidth / 240);
			$img_hresult = ($imgheight / $img_wprop);
			$img_height = intval($img_hresult);
			$img_width = 240; 

			if ($imginfo[0] < 240 AND $imginfo[1] < 180) {
				$view_attach = "
				<img src='".FORUM."attachments/".$attach['attach_name']."'	border='0'>
				<br>".$attach['attach_name']." &nbsp; 
				( width:".$imginfo[0]." height:".$imginfo[1]." )
			";
			} else {
				$view_attach = "
				<a target='_blank' href='".FORUM."attachments/".$attach['attach_name']."'>
				<img src='".FORUM."attachments/".$attach['attach_name']."'
				width='".$img_width."' height='".$img_height."' alt='click to enlarge' border='0'>
				</a><br>".$attach['attach_name']." &nbsp; 
				( width:".$imginfo[0]." height:".$imginfo[1]." )
				";
			}

		} else if($attach['attach_ext'] == ".swf") {
			//swf support
			$view_attach = "
			<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='80%' height='180'>
			<param name='MOVIE' value='".FORUM."attachments/".$attach['attach_name']."'>
			<param name='QUALITY' value='HIGH'>
			<embed src='".FORUM."attachments/".$attach['attach_name']."' quality='high' type='application/x-shockwave-flash' width='80%' height='180'>
			</object>
			";

		} else {
			//file attach
			if ($settings['attach_view'] == "1"){
			if (iMEMBER){
			$view_attach = "
			- <a href='".FORUM."attachments/".$attach['attach_name']."'>
			".$attach['attach_name']." &nbsp; ".parsebytesize($attach['attach_size'])."
			</a>";
			}else { echo "<div class='quote'><center>Для просмотра вложения <a href='".BASEDIR."register.php'><b>зарегистрируйтесь</b></a></center></div>"; }
			} else {
			$view_attach = "- <a href='".FORUM."attachments/".$attach['attach_name']."'>
			".$attach['attach_name']." &nbsp; ".parsebytesize($attach['attach_size'])."
			</a>";			

			}

		}

		echo " $view_attach <br> ";

	}

	echo "</FIELDSET>";

}

		echo "</td></tr><tr><td colspan='2' align='left' class='tbl1'>";
		if ($data['post_edittime'] != "0") {
			echo "
			<br><br>
			<span class='small2'>[".$locale['508']."<b>$edituser</b>".$locale['509']."$edittime]</span>";
		}
		if ($data['user_sig'] != "") { echo "<br /><br />\n--------------------<br />".parseubb(parsesmileys(nl2br($data['user_sig']))); } else {
	echo "\n\n&nbsp;";
}
		echo "
		</td></tr></table>";
/*$result2 = dbquery("
	SELECT *
	FROM ".$db_prefix."forum_attachments
	WHERE post_id='".$data['post_id']."'
");

if (dbrows($result2) != 0) {

	echo "<script language='javascript'>
		function flip(wich) {
			document.getElementById(wich).style.display = (document.getElementById(wich).style.display == 'none' ? 'block' : 'none');
		}
	</script>";

	$wuattach = dbarray($result2);
	$a_id = $wuattach['attach_id'];

	echo "<hr>";
	echo "<a href='javascript:void(0)'
		style='font-size:12px;font-weight:bold;font-variant:small-caps;padding:4px;''
		onClick=flip(".$a_id.");>
	<img border='0' src='".FORUM."toggle.png' alt='' height='14' width='14'>
	attached file(s)...
	</a>

	<div style='display: none;' id='$a_id'>";

$result2 = dbquery("
	SELECT *
	FROM ".$db_prefix."forum_attachments
	WHERE post_id='".$data['post_id']."'
");

	while ($attach = dbarray($result2)){

		$a_id = $attach['attach_id'];

		if ($attach['attach_ext'] == ".gif" || $attach['attach_ext'] == ".jpg" || $attach['attach_ext'] == ".png") {

			$fileimg = FORUM."attachments/".$attach['attach_name'];
			$imginfo = getimagesize($fileimg);

			//resize proportional
			$imgwidth = $imginfo[0];
			$imgheight = $imginfo[1];
			$img_wprop = ($imgwidth / 240);
			$img_hresult = ($imgheight / $img_wprop);
			$img_height = intval($img_hresult);
			$img_width = 240; 

			if ($imginfo[0] < 240 AND $imginfo[1] < 180) {
				$view_attach = "<br><hr><br>
				<img src='".FORUM."attachments/".$attach['attach_name']."'	border='0'>
				<br>".$attach['attach_name']." &nbsp; 
				( width:".$imginfo[0]." height:".$imginfo[1]." )
				";
			} else {
				$view_attach = "<br><hr><br>
				<a target='_blank' href='".FORUM."attachments/".$attach['attach_name']."'>
				<img src='".FORUM."attachments/".$attach['attach_name']."'
				width='".$img_width."' height='".$img_height."' alt='click to enlarge' border='0'>
				</a><br>".$attach['attach_name']." &nbsp; 
				( width:".$imginfo[0]." height:".$imginfo[1]." )
				";
			}
		} else if($attach['attach_ext'] == ".swf") {
			//swf support
			$view_attach = "<br><hr><br>
			<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='80%' height='180'>
			<param name='MOVIE' value='".FORUM."attachments/".$attach['attach_name']."'>
			<param name='QUALITY' value='HIGH'>
			<embed src='".FORUM."attachments/".$attach['attach_name']."' quality='high' type='application/x-shockwave-flash' width='80%' height='180'>
			</object>
			";
		} else {
			//file attach
			if ($settings['attach_view'] == "1"){
			if (iMEMBER){
			$view_attach = "<br><hr><br>
			- <a href='".FORUM."attachments/".$attach['attach_name']."'>
			".$attach['attach_name']." &nbsp; ".parsebytesize($attach['attach_size'])."
			</a>";
			}else { echo "<div class='quote'><center>Для просмотра вложения <a href='/register.php'><b>зарегистрируйтесь</b></a></center></div>"; }
			} else {
			$view_attach = "<br><hr><br>
			- <a href='".FORUM."attachments/".$attach['attach_name']."'>
			".$attach['attach_name']." &nbsp; ".parsebytesize($attach['attach_size'])."
			</a>";
			
			}
		}
		echo " $view_attach <br> ";
	}
	echo "</div>";
}*/

		
		echo "</td></tr><tr><td class='tbl1'>\n";
		echo "<span class='alt'><a href=\"#top\" title=\"наверх\">^ наверх ^</a></span>\n";
		if ($data['user_aim']) {
			echo "<a href='aim:goim?screenname=".str_replace(" ", "+", $data['user_aim'])."' target='_blank'><img src='".THEME."forum/aim.gif' alt='".$data['user_aim']."' style='border:0px;'></a> ";
		}
		if ($data['user_icq']) {
			echo "<a href='http://icq.com/people/about_me.php?uin=".$data['user_icq']."' target='_blank'><img src='".THEME."forum/icq.gif' alt='".$data['user_icq']."' style='border:0px;'></a> ";
		}
		if ($data['user_msn']) {
			echo "<a href='mailto:$data[user_msn]'><img src='".THEME."forum/msn.gif' alt='".$data['user_msn']."' style='border:0px;'></a> ";
		}
		if ($data['user_yahoo']) {
			echo "<a href='http://uk.profiles.yahoo.com/$data[user_yahoo]' target='_blank'><img src='".THEME."forum/yahoo.gif' alt='".$data['user_yahoo']."' style='border:0px;'></a> ";
		}
		if ($data['user_web']) {
			if (!strstr($data['user_web'], "http://")) { $urlprefix = "http://"; } else { $urlprefix = ""; }
			echo "<a href='".$urlprefix."".$data['user_web']."' target='_blank'><img src='".THEME."forum/web.gif' alt='".$data['user_web']."' style='border:0px;'></a> ";
		}
		if (iMEMBER && $data['user_id'] != $userdata['user_id']) echo "<a href='".BASEDIR."messages.php?msg_send=".$data['user_id']."'><img src='".THEME."forum/pm.gif' alt='".$locale['571']."' style='border:0px;'></a>\n";
echo "</td>
		</td></tr>\n";
	}
}

echo "</table>\n";

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

echo "<table cellpadding='0' cellspacing='0' width='100%' style='margin-top:5px;'>\n<tr>\n";
$forum_list = ""; $current_cat = "";
$result = dbquery(
	"SELECT f.forum_id, f.forum_name, f2.forum_name AS forum_cat_name
	FROM ".$db_prefix."forums f
	INNER JOIN ".$db_prefix."forums f2 ON f.forum_cat=f2.forum_id
	WHERE ".groupaccess('f.forum_access')." AND f.forum_cat!='0' ORDER BY f2.forum_order ASC, f.forum_order ASC"
);
while ($data = dbarray($result)) {
	if ($data['forum_cat_name'] != $current_cat) {
		if ($current_cat != "") $forum_list .= "</optgroup>\n";
		$current_cat = $data['forum_cat_name'];
		$forum_list .= "<optgroup label='".$data['forum_cat_name']."'>\n";
	}
	$sel = ($data['forum_id'] == $fdata['forum_id'] ? " selected" : "");
	$forum_list .= "<option value='".$data['forum_id']."'$sel>".$data['forum_name']."</option>\n";
}
$forum_list .= "</optgroup>\n";

echo "
<td align='left' class='tbl'>".$locale['540']."<br>
<select name='jump_id' class='textbox' onChange=\"jumpForum(this.options[this.selectedIndex].value);\">
$forum_list</select></td>\n";

if (iMEMBER && $can_post) {
	if (iMOD || iSUPERADMIN) {
		echo "<td align='right' class='tbl'>
		<form name='modopts' method='post' action='options.php?forum_id=$forum_id&amp;thread_id=$thread_id'>
		".$locale['520']."<br>
		<select name='step' class='textbox'>
<option value='none'>&nbsp;</option>
<option value='renew'>".$locale['527']."</option>
<option value='delete'>".$locale['521']."</option>
<option value='seldelete'>Удалить выделенное</option>\n";
		if (!$tdata['thread_locked']) { 
			echo "<option value='lock'>".$locale['522']."</option>\n";
		} else {
			echo "<option value='unlock'>".$locale['523']."</option>\n";
		}
		if (!$tdata['thread_sticky']) {
			echo "<option value='sticky'>".$locale['524']."</option>\n";
		} else {
			echo "<option value='nonsticky'>".$locale['525']."</option>\n";
		}
		echo "<option value='move'>".$locale['526']."</option>\n";
		echo "</select>
		<input type='submit' name='go' value='".$locale['528']."' class='button'>
		</form></td></tr>\n";
	}
}
echo "</table>\n";
if (iMEMBER) {
	echo "<table cellpadding='0' cellspacing='0' width='100%'>\n<tr>\n";
	if ($settings['thread_notify']) {
		echo "<td valign='top' class='tbl'>";
		if (dbcount("(thread_id)", "thread_notify", "thread_id='$thread_id' AND notify_user='".$userdata['user_id']."'")) {
			$result = dbquery("UPDATE ".$db_prefix."thread_notify SET notify_datestamp='".time()."', notify_status='1' WHERE thread_id='$thread_id' AND notify_user='".$userdata['user_id']."'");
			$notify_link = "<a href='postify.php?post=off&amp;forum_id=$forum_id&amp;thread_id=$thread_id'>".$locale['515']."</a>";
		} else {
			$notify_link = "<a href='postify.php?post=on&amp;forum_id=$forum_id&amp;thread_id=$thread_id'>".$locale['516']."</a>";
		}
		echo "$notify_link</td>\n";
	}
	if ($can_post) {
		echo "<td align='right' class='tbl'>";
		if (!$tdata['thread_locked']) {
			echo "<a href='post.php?action=reply&amp;forum_id=$forum_id&amp;thread_id=$thread_id'><img src='".THEME."forum/reply.gif' alt='".$locale['565']."' style='border:0px;'></a>\n";
		}
		echo "<a href='post.php?action=newthread&amp;forum_id=$forum_id'><img src='".THEME."forum/newthread.gif' alt='".$locale['566']."' style='border:0px;'></a>\n";
		echo "</td>\n";
	}
	echo "</tr>\n</table>\n";
}
closetable();
tablebreak();

if (iMEMBER && $can_post && !$tdata['thread_locked']) {
opentable($locale['512']);
	echo "<table align='center' cellpadding='0' cellspacing='1' class='tbl-border' width='60%'><tr><td>";
	opensidex("Форма быстрого ответа ->","off");
	echo "<form name='inputform' method='post' action='".FUSION_SELF."?forum_id=$forum_id&amp;thread_id=$thread_id'>
<table align='center' cellpadding='0' cellspacing='1' class='tbl-border' width='100%'><tr>
<td align='center' class='tbl1'><textarea name='message' cols='90' rows='7' class='textbox'></textarea><br>
	<input type='button' value='b' class='button' style='font-weight:bold;width:20px;' onClick=\"addText('message', '[b]', '[/b]');\">
<input type='button' value='i' class='button' style='font-style:italic;width:20px;' onClick=\"addText('message', '[i]', '[/i]');\">
<input type='button' value='u' class='button' style='text-decoration:underline;width:20px;' onClick=\"addText('message', '[u]', '[/u]');\">
<input type='button' value='s' class='button' style='font-style:italic;width:20px;' onClick=\"addText('message', '[s]', '[/s]');\">
<input type='button' value='url' class='button' style='width:35px;' onClick=\"insertURL('message')\";>
<input type='button' value='mail' class='button' style='width:35px;' onClick=\"addText('message', '[mail]', '[/mail]');\">
<input type='button' value='magnet' class='button' style='width:50px;' onClick=\"insertMagnet('message')\";>
<input type='button' value='img' class='button' style='width:30px;' onClick=\"addText('message', '[img]', '[/img]');\">
<input type='button' value='left' class='button' style='width:40px;' onClick=\"addText('message', '[left]', '[/left]');\">
<input type='button' value='center' class='button' style='width:45px;' onClick=\"addText('message', '[center]', '[/center]');\">
<input type='button' value='right' class='button' style='width:40px;' onClick=\"addText('message', '[right]', '[/right]');\">
<input type='button' value='small' class='button' style='width:40px;' onClick=\"addText('message', '[small]', '[/small]');\">
<input type='button' value='offtopic' class='button' style='width:50px;' onClick=\"addText('message', '[offtopic]', '[/offtopic]');\">
<input type='button' value='color' class='button' style='width:40px;' onClick=\"addText('message', '[color=]', '[/color]');\">
<input type='button' value='border' class='button' style='width:40px;' onClick=\"addText('message', '[border]', '[/border]');\">
<input type='button' value='size' class='button' style='width:40px;' onClick=\"insertSize('message')\";>
<input type='button' value='scroll' class='button' style='width:40px;' onClick=\"addText('message', '[scroll]', '[/scroll]');\">
<input type='button' value='marquee' class='button' style='width:55px;' onClick=\"addText('message', '[marquee]', '[/marquee]');\">
<input type='button' value='blink' class='button' style='width:50px;' onClick=\"addText('message', '[blink]', '[/blink]');\">
<input type='button' value='code' class='button' style='width:40px;' onClick=\"addText('message', '[code]', '[/code]');\">
<input type='button' value='quote' class='button' style='width:45px;' onClick=\"addText('message', '[quote]', '[/quote]');\">
<input type='button' value='flash' class='button' style='width:45px;' onClick=\"addText('message', '[flash width=400 height=300]', '[/flash]');\">
<input type='button' value='hide' class='button' style='width:45px;' onClick=\"addText('message', '[hide]', '[/hide]');\">
</td>


	</td></tr><td class='tbl1' align='center'>
	".@$locale['462']."<select name='bbcolor' class='textbox' style='width:90px;' onChange=\"addText('message', '[color=' + this.options[this.selectedIndex].value + ']', '[/color]');this.selectedIndex=0;\">

	<option value=''>Default</option>
<option value='black' style='background-color:black'>Black</option>
<option value='white' style='background-color:white'>White</option>
<option value='skyblue' style='background-color:skyblue'>Skyblue</option>
<option value='royalblue' style='background-color:royalblue'>Royalblue</option>
<option value='blue' style='background-color:blue'>Blue</option>
<option value='darkblue' style='background-color:darkblue'>Darkblue</option>
<option value='purple' style='background-color:purple'>Purple</option>
<option value='orange' style='background-color:orange'>Orange</option>
<option value='yellow' style='background-color:yellow'>Yellow</option>
<option value='gold' style='background-color:gold'>Gold</option>
<option value='tomato' style='background-color:tomato'>Tomato</option>
<option value='coral' style='background-color:coral'>Coral</option>
<option value='orangered' style='background-color:orangered'>Orangered</option>
<option value='crimson' style='background-color:crimson'>Crimson</option>
<option value='red' style='background-color:red'>Red</option>
<option value='firebrick' style='background-color:firebrick'>Firebrick</option>
<option value='darkred' style='background-color:darkred'>Darkred</option>
<option value='green' style='background-color:green'>Green</option>
<option value='limegreen' style='background-color:limegreen'>Limegreen</option>
<option value='seagreen' style='background-color:seagreen'>Seagreen</option>
<option value='deeppink' style='background-color:deeppink'>Deeppink</option>
<option value='purple' style='background-color:purple'>Purple</option>
<option value='indigo' style='background-color:indigo'>Indigo</option>
<option value='burlywood' style='background-color:burlywood'>Burlywood</option>
<option value='sandybrown' style='background-color:sandybrown'>Sandybrown</option>
<option value='sienna' style='background-color:sienna'>Sienna</option>
<option value='choclate' style='background-color:chocolate'>Chocolate</option>
<option value='teal' style='background-color:teal'>Teal</option>
<option value='silver' style='background-color:silver'>Silver</option>
<option value='gray' style='background-color:gray'>Gray</option>
	</select></td>
</tr><tr><td align='center' class='tbl2'>".displaysmileys("message")."<br>
<input type='checkbox' name='disable_smileys' value='1'>".$locale['513']."</td></tr><tr>
<td align='center' class='tbl1'><input type='submit' name='postquickreply' value='".$locale['514']."' class='button'></td>
</tr></table></form>\n";
closesidex();
echo"</td></tr></table>";
	closetable();
}

echo "<script type='text/javascript'>
function jumpForum(forumid) {
	document.location.href='".FORUM."viewforum.php?forum_id='+forumid;
}
</script>\n";

echo "<table border='0' cellpadding='0' cellspacing='1' width='100%'class='tbl-border'><tr><td class='forum-caption' width='5%'>&nbsp;</td>
	<td class='forum-caption' align='left' width='95%'><b>Тему просматривают</b></td></tr>
	<tr><td class='tbl2' align='middle' width='5%'>";

$filename = "".THEME."forum/whosonline.gif";
if (file_exists($filename)) {
	echo "<img src=".$filename." align='left'>";
} else {
	echo "<img src='".THEME."images/blank.gif' width='40'>";
}     
	echo "</td><td width='95%' align='left' class='tbl1'>";

// Online Users Panel Code
if ($settings['maintenance'] != "1") {
	@$cond = ($userdata['user_level'] != 0 ? "'".$userdata['user_id']."'" : "'0' AND online_ip='".FUSION_IP."'");
	$result = dbquery("SELECT * FROM ".$db_prefix."online WHERE online_user=".$cond."");
	if (dbrows($result) != 0) {
		$result = dbquery("UPDATE ".$db_prefix."online SET online_lastactive='".time()."' WHERE online_user=".$cond."");
	} else {
		$name = ($userdata['user_level'] != 0 ? $userdata['user_id'] : "0");
		@$result = dbquery("INSERT INTO ".$db_prefix."online VALUES('$name', '".FUSION_IP."', '".time()."')");
	}
	if (isset($_POST['login'])) {
		@$result = dbquery("DELETE FROM ".$db_prefix."online WHERE online_user='0' AND online_ip='".FUSION_IP."'");
	} else if (isset($logout)) {
		@$result = dbquery("DELETE FROM ".$db_prefix."online WHERE online_ip='".FUSION_IP."'");
	}
	$result = dbquery("DELETE FROM ".$db_prefix."online WHERE online_lastactive<".(time()-60)."");
	$result = dbquery("SELECT * FROM ".$db_prefix."online WHERE online_user='0'");
	echo "<span class='small'>".$locale['011']." <b>".dbrows($result)."</b> </span><br>\n";
	$result = dbquery(
		"SELECT ton.*, user_id,user_name FROM ".$db_prefix."online ton
		LEFT JOIN ".$db_prefix."users tu ON ton.online_user=tu.user_id
		WHERE online_user!='0'"
	);

	$members = dbrows($result);
	if ($members != 0) {
		$i = 1;
		echo $locale['012'];
		while($data = dbarray($result)) {
			echo "<a href='".BASEDIR."profile.php?lookup=".$data['user_id']."' class='side'>".$data['user_name']."</a>";
			if ($i != $members) echo ", ";
			$i++;
		}
		echo "<br>\n";
	} else {
		echo $locale['013']."<br>\n";
	}
	
}

	echo "</td></tr></table>\n";
	
	echo "<table border='0' cellpadding='0' cellspacing='1' width='100%'class='tbl-border'>
	<tr><td class='tbl2' align='middle' width='5%'>&nbsp;</td><td width='95%' class='tbl2'>
<div align='right'>Вернуться на сайт: <a href='../index.php'>".$settings['sitename']."</a><br /><form name='search' method='post' action='".BASEDIR."search.php?stype=f'>
	<input type='textbox' name='stext' class='textbox' style='width:150px' onfocus=this.value='' value='Что найти?'>
	<input type='submit' name='search' value='".$locale['550']."' class='button'>
	</form></div>
	</td></tr></table>";
if ($settings_forum['show_panel'] == 1){
	require_once BASEDIR."side_right.php";
}
require_once FORUM."footer.php";
?>
