<?


$id_forum=intval($_GET['id_forum']);

$q = mysql_query("SELECT * FROM `$mysql[pref]forum_f` WHERE `id` = '$id_forum';");

if(mysql_num_rows($q) != 0)

{

$forum = mysql_fetch_array($q);

}

else

{

header ("Location: index.php?".SID."&");


exit;

}


echo "<div class=\"title\">$forum[name]</div><hr />\n";


if ($mail_in_new>0)echo "<div class=\"privat\"><img src=\"../SYSTEM/themes/$them/img/mail0.gif\" alt=\"\" /> <a href=\"../mail.php?act=in\">Приват</a> [$mail_in_new]</div><hr />\n";


//echo "<div class=\"str\"><a href=\"index.php\">Форумы</a></div><hr />";


$k_razd=0;

$q = mysql_query("SELECT * FROM `$mysql[pref]forum_r` WHERE `id_f` = '$id_forum'");

while ($razdeles = mysql_fetch_array($q))

{

$razd[$k_razd]=$razdeles;

$k_razd++;

}


if ($k_razd>0)

{

usort ($razd, "sroom");



for ($i=0;$i<$k_razd;$i++)

{


echo "<div class=\"mess\">\n";

if (isset($user) && $user['level']>1 && $user['slinks']==0)

{

echo "<a href=\"set_r.php?id_forum=$id_forum&amp;id_razd=".$razd[$i]['id']."\">\n";

}

echo "<img src=\"../SYSTEM/themes/$them/img/forum/razd.gif\" alt=\"\" />";

if (isset($user) && $user['level']>1 && $user['slinks']==0)

{

echo "</a>\n";

}

echo " <a href=\"index.php?id_forum=$id_forum&amp;id_razd=".$razd[$i]['id']."\"><b><span style=\"color:$color[forum_razd_name]\">".$razd[$i]['name']."</span></b></a>\n";



$id_razd=$razd[$i]['id'];

$g = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]forum_t` WHERE `id_f` = '$id_forum' AND `id_r` = '$id_razd';");

$k_t=mysql_result($g, 0);

$p = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]forum_p` WHERE `id_f` = '$id_forum' AND `id_r` = '$id_razd';");

$k_p=mysql_result($p, 0);

if ($k_t>0)

{


$g = mysql_query("SELECT MAX(time_last) FROM `$mysql[pref]forum_t` WHERE `id_f` = '$id_forum' AND `id_r` = '$id_razd';");

$id_p=mysql_result($g, 0);

$g = mysql_query("SELECT * FROM `$mysql[pref]forum_t` WHERE `id_f` = '$id_forum' AND `time_last` = '$id_p' AND `id_r` = '$id_razd';");

$last_them = mysql_fetch_array($g, 1);


//echo "<br />\n";


//echo "($k_p/$k_t)<br />";


$g = mysql_query("SELECT MAX(time_last) FROM `$mysql[pref]forum_t` WHERE `id_f` = '$id_forum' AND `id_r` = '$id_razd';");

$id_p=mysql_result($g, 0);

$g = mysql_query("SELECT * FROM `$mysql[pref]forum_t` WHERE `id_f` = '$id_forum' AND `time_last` = '$id_p' AND `id_r`='$id_razd';");

$last_them =mysql_fetch_array($g, 1);

echo "<br />Тема: <a href=\"index.php?id_forum=$id_forum&amp;id_razd=$id_razd&amp;id_them=$last_them[id]\"><b><span style=\"color:$color [forum_theme_name]\"><font color=\"#FFA500\">$last_them[name]</font></span></b></a><br />\n";

echo  "Сообщение: $last_post[nick]<br />\n";


$id_them=$last_them['id'];

$p = mysql_query("SELECT COUNT(*) FROM `$mysql[pref]forum_p` WHERE `id_f` = '$id_forum' AND `id_r` = '$id_razd' AND `id_t` = '$id_them';");

$k_p=mysql_result($p, 0);


if ($k_p>0)

{

$p = mysql_query("SELECT MAX(id) FROM `$mysql[pref]forum_p` WHERE `id_f` = '$id_forum' AND `id_r` = '$id_razd' AND `id_t` = '$id_them';");

$id_p=mysql_result($p, 0);

$p = mysql_query("SELECT * FROM `$mysql[pref]forum_p` WHERE `id_f` = '$id_forum' AND `id` = '$id_p' AND `id_r` = '$id_razd' AND `id_t` = '$id_them';");

$last_post = mysql_fetch_array($p);


}


echo "<br /><small><span style=\"color:$color[post_time]\">[".vremja($last_them['time_last']+$timesdvig)."]</span></small>";

}

else

{

echo "<br />\n";


echo "<span style=\"color:$color[no_them]\">[Нет тем]</span>";


}


echo "</div>\n";

echo "<br />\n";



}



}

else

{

echo "Нет разделов<br />\n";

}



echo "<hr />\n";

if (isset($user) && $user['level']>1 && $user['slinks']==0)

{

echo "<a href=\"add_r.php?id_forum=$id_forum\">Добавить раздел</a><br />\n";

}



//echo "<a href=\"index.php\">&lt;&lt; К форумам</a><br />\n";

?>

