<?
require_once'home.php';

$q1 = @mysql_query( @"select  *  from  `forum_topic` where `id`='".$id."' ;" );
$topic = @mysql_fetch_array(@$q1);

$f = $topic ['section'];
$sf = $topic ['subfor'];

$que = @mysql_query( "select * from  `forum_subfor` where id='$sf';" );
$dtm = @mysql_fetch_array( @$que );
$s_name = $dtm['name'];

$que = @mysql_query( "select * from  `forum_sections` where id='$f';" );
$dtm = @mysql_fetch_array( @$que );
$f_name = $dtm['name'];

//echo "<dl><dt></dt></dl><a href=\"".F."\">Форумы</a>|<a href=\"".F."subfs/$f\">$f_name</a>";
//echo "|<a href=\"".F."temes/$sf\">$s_name</a>|<a href=\"".F."tema/$id/$page\">".$topic ['name']."</a><br /><dl><dt></dt></dl>";

if (empty($id)||($id==0)){
if (!empty($page))mysql_query("delete from forum_bookmarks where id='".$page."' limit 1;");

echo "<dl><dt></dt></dl><a href=\"".F."\">Форумы</a><br /><dl><dt></dt></dl>";
echo $fs1;
$q2 = @mysql_query( @"SELECT * from `forum_bookmarks` where user = '".$row['id']."' order by time desc;" );
$k = mysql_num_rows( $q2 );
if ( $k == 0 )
{
echo "<br /><b>У вас нет закладок</b><br />";
}

$post_k=$start+1;
while($mess = @mysql_fetch_array(@$q2)){
$q1 = @mysql_query( @"select  *  from  `forum_topic` where `id`='".$mess['tema']."' ;" );
$them = @mysql_fetch_array(@$q1);
$forum=mysql_fetch_array(mysql_query("SELECT * FROM `forum_sections` WHERE `id` = '$them[section]' LIMIT 1"));
$razdel=mysql_fetch_array(mysql_query("SELECT * FROM `forum_subfor` WHERE `id` = '$them[subfor]' LIMIT 1"));
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = $them[login] LIMIT 1"));

if ($them['close'] == 1) $gif = "zakr";
else if ($them['zak'] == 1) $gif = "lock";
else  $gif = "tem";

echo "$div2<img src=\"".H2."img/".$gif.".gif\" alt=\"*\"/> <a href='".F."tema/".$them['id']."'>$them[name]</a> <a href='".F."tema/".$them['id']."/end'>(".mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_message` WHERE `section` = '$forum[id]' AND `subfor` = '$razdel[id]' AND `topic` = '$them[id]'"),0).")</a> | <a href='".F."bookmarks/0/".$mess['id']."'>[удал]</a>$div9\n";




echo "<a href='".F."subfs/".$them['section']."'>$forum[name]</a> &gt; <a href='".F."temes/".$them['subfor']."'>$razdel[name]</a><br />\n";

$post1=mysql_fetch_array(mysql_query("SELECT * FROM `forum_message` WHERE `topic` = '$them[id]' AND `subfor` = '$razdel[id]' AND `section` = '$forum[id]' AND `login` = '$them[login]' LIMIT 1"));
$ank=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = $them[login] LIMIT 1"));
echo "Автор: <a href='".H2."$ank[id]' title='Анкета \"$ank[user]\"'>$ank[user]</a> (".date("d.m в H:i", $post1['time']).")<br />\n";

$post=mysql_fetch_array(mysql_query("SELECT * FROM `forum_message` WHERE `topic` = '$them[id]' AND `subfor` = '$razdel[id]' AND `section` = '$forum[id]' ORDER BY `time` DESC LIMIT 1"));
$ank2=mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = $post[login] LIMIT 1"));
echo "Посл.: <a href='".H2."$ank2[id]' title='Анкета \"$ank2[user]\"'>$ank2[user]</a> (".date("d.m в H:i", $post['time']).")<br />\n";
echo'';

}


echo $fs2;
}else{
$q1 = @mysql_query( @"select  *  from  `forum_topic` where `id`='".$id."' ;" );
$topic = @mysql_fetch_array(@$q1);
if (mysql_affected_rows() == 0){
echo $fs1;
echo '<b>Такой темы не существует!</b>';
echo $fs2;
foot();
exit;
}

if (mysql_query("Insert into forum_bookmarks set tema='".$id."',time='".time()."',user = '".$row['id']."'")){echo "<b>Закладка создана</b>\n";
header("Location: ".F."bookmarks/0");

}else{echo "Ошибка\n";

}

}
?>