<?include('header.php');

$user=text($_SESSION["username"]);
require('karera/setup_status.php');
?>

<div class="menucenter">

<?
$adse=intval($_GET["ad"]);
$res1=mysql_query("select * from forum_tema where id='$adse'");

if(mysql_num_rows($res1) != 1){
echo "<div class=error>Указанная статья не найдена</div>";
include('footer.php');
exit;

}

$row1=mysql_fetch_assoc($res1);
$ogl=$row1["ogl"];
?>
<table width='100%'>
<tr>
<td style='font-size:11px;'>
<img src="images/f_st.png" border="0" align="absmiddle">
<a href="forum.php"><b>Форумы</b></a>
<img src="images/f_st.png" border="0" align="absmiddle">
<b><?=$ogl?></b>
</td>
<?if($st_users[$duser["ball_status"]]["new_forum"] == 1){?>
<td>
<a href="forum3.php?ad=<?=$adse?>" class="mesega">Новая тема</a>
</td>
<?}?>
</tr></table>
<?
$datenorm = DATE("d.m.Yг. в H:i");
if(isset($_POST["delete"])){
$delid=intval($_POST["id"]);

$res=mysql_fetch_assoc(mysql_query("SELECT ogl,user from forum where razdel='$adse' and tema='1' and id='$delid'"));
$ogl=$res["ogl"];
$userr=$res["user"];

$whois=mysql_query("SELECT user_status FROM tb_users WHERE username='$username'");
$whois=mysql_fetch_assoc($whois);
if($whois["user_status"]=='user'){
echo "<div class=error>Вы не являетесь администратором проекта!</div>";
include('footer.php');exit;

}

mysql_query("INSERT INTO forum_stop (user,text,date,stop_forum,moder) VALUES('$userr','$ogl','$datenorm','Закрыта','$user')");
mysql_query("UPDATE forum SET ban_forum='1' WHERE razdel='$adse' and tema='1' and id='$delid'");

echo "<div class=good>Тема успешно закрыта!</div>";

}

if(isset($_POST["undelete"])){
$delid=intval($_POST["id"]);

$res=mysql_fetch_assoc(mysql_query("SELECT ogl,user from forum where razdel='$adse' and tema='1' and id='$delid'"));
$ogl=$res["ogl"];
$userr=$res["user"];

$whois=mysql_query("SELECT user_status FROM tb_users WHERE username='$username'");
$whois=mysql_fetch_assoc($whois);
if($whois["user_status"]=='user'){
echo "<div class=error>Вы не являетесь администратором проекта!</div>";
include('footer.php');exit;

}

mysql_query("INSERT INTO forum_stop (user,text,date,stop_forum,moder) VALUES('$userr','$ogl','$datenorm','Открыта','$user')");
mysql_query("UPDATE forum SET ban_forum='0' WHERE razdel='$adse' and tema='1' and id='$delid'");

echo "<div class=good>Тема успешно открыта!</div>";

}

$num = 10;
$upag = "forum1.php?ad=".$adse."&";
$page = (isset($_GET['n']))? intval($_GET['n']) : 1 ;
$numpag = mysql_num_rows(mysql_query("SELECT `date` FROM `forum` WHERE `razdel`='$adse' and `tema`='1'"));
$np =$numpag;
$obpag = intval(($np - 1) / $num) + 1;
if(empty($page) or $page < 0) $page = 1;
if($page > $obpag) $page = $obpag;
$nach = $page * $num - $num;
include("navi.php");?>
<table class='reyt' width='100%' border='0' cellpadding='0' cellspacing='0'>
<thead><tr>
<th align="left" width="25px">
</th>
<th align="left">
Название темы / Автор
</th>
<th align="left">
Последнее
</th>
<th align="center">
Ответов
</th>
<th align="right" width="17px">
</th>
</tr></thead>
<?
$whois=mysql_query("SELECT * FROM tb_users WHERE username='$user'");
$whois=mysql_fetch_assoc($whois);
if(($whois["user_status"]=='admin') or ($whois["user_status"]=='moder'))
{$st_us_for = 1;}else{$st_us_for = 0;}

$tabla = mysql_query("SELECT f1.*,
(SELECT count( id ) FROM forum where status=f1.id) as comm,
(select user_status from tb_users where username=f1.user) as status_us,
(select data FROM forum where status=f1.id ORDER BY id DESC limit 1) as data_ent,
(select user FROM forum where status=f1.id ORDER BY id DESC limit 1) as user_ent,
(select user_status from tb_users where username=(select user FROM forum where status=f1.id ORDER BY id DESC limit 1)) as st_us
FROM forum as f1 where f1.razdel='$adse' and `tema`='1' order by f1.date DESC LIMIT $nach, $num");
while ($row = mysql_fetch_assoc($tabla)) {
$userr = $row["user"];
if($row["status_us"]=='user') { $cvet='0000ff'; }
$text=substr($row["text"], 0, 50);

$uss44=$row["user_ent"];
echo"<tr><td>"; ?>
<?
$avas=mysql_query("select ban_forum from forum where razdel='$adse' and status='$id'");
$avas=mysql_fetch_assoc($avas);
if($avas["ban_forum"]==0) {
?>
<img src='images/system-users.png' align='absmiddle'>
<? } else { ?>
<img src='images/system-stop.png' align='absmiddle'>
<?}?>

</td>
<td style='font-size:11px;'><a href="forum2.php?ad=<?=$row["id"]?>"><?=$row["ogl"]?></a>
<br>тему добавил: <b><?=$userr?><b></td>
<td><font class=\"main\"><?=$row["data_ent"]?><br>от <?=$uss44?>
</font></td>
<td align=center><?=$row["comm"]?></td>
<td align="left">
<?
if($st_us_for == 1){
  if($row["ban_forum"]==0) {
?>
<form action="" method="POST">
<input type=hidden name="delete">
<input type=hidden name="id" value="<?=$row["id"];?>">
<input type="image" src="images/stop_forum.png" alt="блок" title="Закрыть"></form>
<? } else { ?>
<form action="" method="POST">
<input type=hidden name="undelete">
<input type=hidden name="id" value="<?=$row["id"];?>">
<input type="image" src="images/play_forum.png" alt="блок" title="Открыть"></form>
<?
}}?></td><?
echo"</tr>";
}
?>
</tbody></table><br>
<?include ('footer.php'); ?>