<?


$k_page=1;


$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;

}



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

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

if(mysql_num_rows($q) != 0)

{

$razd = mysql_fetch_array($q);

}

else

{

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


exit;

}




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=\"menu\">*<a href=\"new.php\">Новые сообщения</a><br />";



echo "##<a href=\"reload.php?id_forum=$id_forum&amp;id_razd=$id_razd\">Обновить</a><br />";

if (isset($user))

{

echo "##<a href=\"add_t.php?id_forum=$id_forum&amp;id_razd=$id_razd\">Новая тема</a><br />";

}

echo "</div><hr />";

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

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

$k_them = mysql_result($q3, 0);





if ($k_them>0)

{


//// кол-во пунктов на страницу ////

if (isset($user))               ////

$k_p_str=$user['forum_k_t'];  ////

else $k_p_str=$set['k_p_s'];    ////

////////////////////////////////////

$k_page=k_page($k_them,$k_p_str);

$page=page();





if ($k_page<$page){$page=$k_page;}

if (0>$page){$page=1;}


$i=$k_p_str*$page-$k_p_str;

$q2 = mysql_query("SELECT * FROM `$mysql[pref]forum_t` WHERE `id_f` = '$id_forum' AND `id_r` = '$id_razd' ORDER BY crep,time_last DESC LIMIT $i, $k_p_str;");





while ($thema = mysql_fetch_array($q2))

{

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

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

{

echo "<a href=\"set_t.php?id_forum=$id_forum&amp;id_razd=$id_razd&amp;id_them=$thema[id]\">\n";

}


echo "<img src=\"../SYSTEM/themes/$them/img/forum/them_$thema[close]$thema[crep].gif\" alt=\"\" />";


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

{

echo "</a>\n";

}

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

$id_them=$thema['id'];

$g = 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($g, 0);

if ($k_p>0)

{

$g = 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($g, 0);

$g = 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($g);


echo "<a href=\"index.php?id_forum=$id_forum&amp;id_razd=$id_razd&amp;id_them=$thema[id]&amp;page=end\"> [$k_p]</a><br />\n";


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

echo "<br />\n";

echo "$thema[autor]/$last_post[nick]<br />\n";


}

else

{

echo "<br />\n";

}


echo "</div>\n";

echo "<br />\n";

}

}

else

{

echo "Нет тем<br />\n";

}


$page_p=$page-1;

$page_n=$page+1;


echo "<hr />\n<div class=\"str\">";

str("index.php?id_forum=$id_forum&amp;id_razd=$id_razd&amp;",$k_page,$page);

echo "</div>\n";

echo "<hr />\n";

if (isset($user))

{

//echo "<a href=\"add_t.php?id_forum=$id_forum&amp;id_razd=$id_razd\">Новая тема</a><br />\n";

}

echo "<a href=\"index.php?id_forum=$id_forum\">←$forum[name]</a><br />\n";

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

?>

