<?php

require '../system/start.php';
require '../system/functions.php';
$query = mysql_fetch_assoc(mysql_query("select * from `forum_topics` where `id` = ".int($_GET['id']).""));
$q = mysql_fetch_assoc(mysql_query("select * from `forum_forums` where `id` = ".$query['id_forum'].""));
$total = mysql_result(mysql_query("select count(*) from `forum_posts` where `id_topic` = ".$query['id'].""),0);
$str['mesto'] = $query['title'];
$str['block'] = $set['site'].' / <a href="index.php">Форум</a>';
include '../style/'.$style.'/head.php';
echo '<div class="where"><img class="ico" src="../style/'.$style.'/ico/themes.gif" alt="" /><b>'.$query['title'].'</b></div>';
if(empty($query['title']))
{
    echo '<div class="forum1">Тема не найдена!</div>';
    include '../style/'.$style.'/foot.php';
    exit;
}
$posts = mysql_query("select * from `forum_posts` where `id_topic` = ".$query['id']." order by `id` limit ".$page.",".$set['str']."");
if ($page == 0) {  $post_number = 1 * $set['str'] - ($set['str']-1); } else { $post_number = 1 * $set['str'] - ($set['str']-1) + $page; }
while($row = mysql_fetch_assoc($posts))
{
    $i++;
    if($i%2)
    {
        echo '<div class="forum1">';
    }
    else
    {
        echo '<div class="forum2">';
    }
	
	
	$us = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `login` = '" . $row['login'] . "'"));
	 
	echo '<b>'.$post_number.'.</b> ';
	
	if(empty($us['foto'])) {
			echo '<img src="../style/'.$style.'/'.$us['gender'].'.png"  width="60" height="60" align="left" alt="" style="margin-right:4px;border-right:1px solid #99ccff"/>';
		} elseif(!empty($us['foto'])) {
			echo '<img src="../files/avatars/'.$us['foto'].'"  width="60" height="60" align="left" alt="" style="margin-right:4px;border-right:1px solid #99ccff"/>';
		}
		
		if ($us['gender'] == 1)
			$pol = '<img class="ico" src="../style/'.$style.'/ico/m.png" alt="" />';
		if ($us['gender'] == 2)
			$pol = '<img class="ico" src="../style/'.$style.'/ico/w.png" alt="" />';
		
		echo $pol . '<a href="../p/'.$us['login'].'">'.$us['login'].'</a>';
              echo status($us['id']);
             
           	
		echo'<br/>';



	echo '<div class="ftext">';
              if($user['id'] != $us['id']):
              echo  '<a href="../pages/mail.php?act=send&amp;login='.$us['login'].'"><img align="right" class="ico" src="../style/'.$style.'/ico/mess.png" alt="" /></a>';
              endif;
              
	echo 'Имя: '.$us['name'].'<br/>';
   
	if(!empty($us['rate'])) 
		echo '	Рейтинг: '.$us['rate'].'<br/>';
	else
		echo '	Рейтинг: 0<br/>';

	echo '
		</div>
		<div class="clear"></div>
		</div>';
echo '<div class="imgright"><a href="addpost.php?id='.$query['id'].'&amp;to='.$row['login'].'">Отв</a>/<a href="addpost.php?id=' . $query['id'] . '&amp;refid=' . $row['id'] . '">Цит</a>/<a href="">Спам</a></div><br/><br/>';
    echo '<div class="ftext">'.text($row['text']).'<br/>';
    echo '<font color="999999">('.clock($row['time']).')</font>';
    
    if(!empty($row['url_file']))
    {
        echo '<hr/><b>Прикреплёный файл</b><br/><a href="../forum/files/'.$row['url_file'].'">'.$row['url_file'].'</a>';
    }
    echo '</div>';
    if($user['level'] == 3 || $user['level'] == 6)
    {
        echo '
	    [<a href="control_post.php?act=edit&amp;pid='.$row['id'].'">изменить</a>]
	    [<a href="control_post.php?act=delete&amp;pid='.$row['id'].'">удалить</a>]';
    }
    echo '</div>';
    $post_number++;
}
if($total > $set['str'])
{
	pages($page, $total, 'topic.php?id='.$query['id'].'&amp;', $set['str']);
}
if($query['status'] == 1 && $user)
{
echo '
<div class="mess">
<form action="addpost.php" method="post">
<div>
Быстрый ответ:<br/>
<textarea cols="22" rows="2" name="text" id="text"></textarea><br/>
<input name="tid" type="hidden" value="'.$query['id'].'"/>
<input type="submit" value="Написать"/>
</div>
</form>
</div>
<div class="write">
<a href="addpost.php?id='.$query['id'].'">Добавить файл</a>
</div>';
}
echo '<div class="forum1">
 <a href="../pages/info.php?act=bbcode">BBcode</a> |
 <a href="../pages/info.php?act=smiles">Смайлы</a><br/>
</div>';
echo '<div class="on2">
<img class="ico" src="../style/'.$style.'/ico/newpost.png" alt=""/> <a href="forum.php?id='.$q['id'].'">Назад</a></div>
';
include '../style/'.$style.'/foot.php';
?>