<?php

require '../system/start.php';
require '../system/functions.php';
$query = mysql_fetch_assoc(mysql_query("select * from `forum_forums` where `id` = ".int($_GET['id']).""));
$str['mesto'] = 'Форум';
$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;
}
$q = mysql_query("select * from `forum_topics` where `id_forum` = ".$query['id']." order by `position`,`time` desc limit ".$page.",".$set['str']."");
$total = mysql_result(mysql_query("select count(*) from `forum_topics` where `id_forum` = ".$query['id'].""),0);
if(mysql_num_rows($q) == 0)
{
    echo '<div class="forum1">Темы еще не созданы!</div>';
}
else
{
    while ($row = mysql_fetch_assoc($q))
    {
        $i++;
        if($i%2)
        {
            echo '<div class="forum1">';
        }
        else
        {
            echo '<div class="forum2">';
        }
        $result = mysql_result(mysql_query("select count(*) from `forum_posts` where `id_topic` = ".$row['id'].""),0);
        $use = mysql_fetch_assoc(mysql_query("select * from `forum_posts` where `id_topic` = ".$row['id']." order by `id` desc limit 1"));
        if($row['position'] == 1)
        {
            echo '<strong>!</strong>';
        }
        if($row['status'] == 0)
        {
            echo '<strong>#</strong>';
        }
        echo '<img class="ico" src="../style/'.$style.'/ico/ftems.png" alt="" /> <a href="topic.php?id='.$row['id'].'">'.$row['title'].'</a> ('.$result.') <a href="topic.php?id='.$row['id'].'">&raquo;</a> <br/>Cообщение: '.$use['login'].' ('.clock($use['time']).')';
        if($user['level'] == 3 || $user['level'] == 6)
        {
            echo '
            <br />';
            if($row['position'] == 2)
            {
                echo '[<a href="control_topic.php?act=top&amp;tid='.$row['id'].'">закрепить</a>]';
            }
            else
            {
                echo '[<a href="control_topic.php?act=top&amp;tid='.$row['id'].'">открепить</a>]';
            }
            if($row['status'] == 0)
            {
                echo '[<a href="control_topic.php?act=edit&amp;tid='.$row['id'].'">открыть</a>]';
            }
            else
            {
                echo '[<a href="control_topic.php?act=edit&amp;tid='.$row['id'].'">закрыть</a>]';
            }
            echo '[<a href="control_topic.php?act=delete&amp;tid='.$row['id'].'">удалить</a>]';
        }
        echo '</div>';
    }
}
if($total > $set['str'])
{
	pages($page, $total, 'forum.php?id='.$query['id'].'&amp;', $set['str']);
}
echo '<div class="write"><a href="addtopic.php?id='.$query['id'].'">Создать тему</a></div>
<div class="on2">
<img class="ico" src="../style/'.$style.'/ico/newpost.png" alt="" />
<a href="new.php">Новые</a> <span style="color:#ff0000">+'.mysql_result(mysql_query("select count(*) from `forum_posts` where `time` > ".(time()-86400).""),0).'</span>
<br/>
<img class="ico" src="../style/'.$style.'/ico/newpost.png" alt="" />
<a href="index.php?act=search">Поиск</a>
</div>';
include '../style/'.$style.'/foot.php';
?>