<?php

require_once('conf/dbc.php');
require_once('conf/session_start.php');
require_once('conf/ban.php');

$topic = abs(intval($_GET['topic']));
  $query = "Select * from topics where id_top = '$topic' limit 1";
  $result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД');
  $row = mysqli_fetch_array($result);
 $page_title = Форум;
    require_once('conf/head.php');
      require_once('conf/top.php');
if (empty($topic)) {
  require_once('conf/notfound.php'); 
}
else {
  $query = "Select * from topics where id_top = '$topic' limit 1";
  $result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД');
  $row = mysqli_fetch_array($result);
  $close = $row['close'];
  $fix = $row['fix'];
  if (empty($row)) {
    $page_title = 'Не найдено';
    require_once('conf/head.php');
	require_once('conf/top.php');
    require_once('conf/notfound.php'); 
  }  
  else {
    $subforum = $row['id_subf'];
    $query_sub = "Select name_subf, clan, rangs_read, gruppa, rangs_com, rangs_cre,	main from  subforums where id_subf = '$subforum' limit 1";
    $result_sub = mysqli_query($dbc, $query_sub) or die ('Ошибка передачи запроса к БД');
    $row_sub = mysqli_fetch_array($result_sub);
	$com = $row_sub['rangs_com'];
	$cre = $row_sub['rangs_cre'];
	$main = $row_sub['main'];
	$gruppa = $row_sub['gruppa'];
	$clan = $row_sub['clan'];
	//////////////////////////////Проверка
$user_id = abs(intval($_SESSION['id']));
      $query_user = "Select gruppa, clan, clan_rang, admin, f_ban, lvl from users where id = '$user_id' limit 1";
      $result_user = mysqli_query($dbc, $query_user) or die ('Ошибка передачи запроса к БД');
      $row_user = mysqli_fetch_array($result_user);
	  $gruppa_us = $row_user['gruppa'];
	  $clan_us = $row_user['clan'];
	  $clan_rang_us = $row_user['clan_rang'];
	  $admin_us = $row_user['admin'];
           $lvl_us = $row_user['lvl'];
	  $f_ban_us = $row_user['f_ban'];
	  $lvl_us = $row_user['lvl'];
	  if ($row_sub['main'] == 0) {
	    if ($row_sub['clan'] == $clan_us) {
		  if ($row_sub['rangs_read'] > $clan_rang_us) {
		    ?>
            <script type="text/javascript">
            document.location.href = "error.php?err=1";
            </script>
            <?php
            exit();
		  }
		}
		else {
		  if ($row_sub['rangs_read'] <> 0) {
		    ?>
            <script type="text/javascript">
            document.location.href = "error.php?err=1";
            </script>
            <?php
            exit();
		  }
		}
	  } 
$user_id = abs(intval($_SESSION['id']));
$pdo->exec("update users set location = 'forum' where id = '$user_id' limit 1");
$query = "Select * from intopics where user_id = '$user_id' and topic='$topic'";
$result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД');
$row_sm = mysqli_fetch_array($result);
if($row_sm==0){
$row_prosm=$dbc->query("SELECT * FROM `users` WHERE`id`='$user_id' LIMIT 1")->fetch_assoc();
if($row_prosm[admin]==1){
$dbc->query("update topics set prosmotr = prosmotr +1, adm_sm=adm_sm+1 where id_top = '$topic' limit 1");}
else{
$dbc->query("update topics set prosmotr = prosmotr +1 where id_top = '$topic' limit 1");}
}
  ?>
  <br/>
  <div id="main">
    <div class="stats">
	<p class="name2"><span class="white"><img src="img/ico/forum_new.png" width="12" height="12"/> <?php 
	if ($row_sub['main'] == 1) {?><a class="white" href="forum.php?type=main">Форум игры</a><?php } 
	else {?><a href="forum.php?type=company&company=<?php echo $row_sub['clan'];?>">Форум клана</a><?php }?>
	/ <a href="subforum.php?subforum=<?php echo "$subforum";?>"><?php echo $row_sub['name_subf'];?></a> / <span class="bonus"><?php echo $row['name'];?></p></span>
	
  <?php
$err = abs(intval($_GET['err']));
  if ($err == 1) {?><div id="error"><p>Поле обязательно для ввода</p></div><?php }
  $query_up = "select page from intopics where user_id='$user_id' and topic='$topic' limit 1";
  $result_up = mysqli_query($dbc, $query_up) or die ('Ошибка передачи запроса к БД');
  $number = mysqli_fetch_array($result_up);
  if ($number == 0) {
    if (!empty($_GET['page'])) {
$cur_page = abs(intval($_GET['page']));
    }
    else {
      $cur_page = 1;
    }
    $query_up = "insert into  intopics (`user_id`, `topic`, `time_up`, `page`) values ( '$user_id', '$topic', NOW(), '$cur_page')";
    $result_up = mysqli_query($dbc, $query_up) or die ('Ошибка передачи запроса к БД'); 
  } 
  else {
    if (!empty($_GET['page'])) {
$cur_page = abs(intval($_GET['page']));
    }
    else {
      $cur_page = $number['page'];
    }
    $query_up = "update intopics set time_up = NOW(), page = '$cur_page' where topic='$topic' and user_id='$user_id'";
    $result_up = mysqli_query($dbc, $query_up) or die ('Ошибка передачи запроса к БД'); 
  }
  if ($cur_page == 1) {
    $avtor_id = $row['avtor'];
    $query_avt = "Select nick, lvl, gruppa, last_active, admin from  users where id = '$avtor_id' limit 1";
    $result_avt = mysqli_query($dbc, $query_avt) or die ('Ошибка передачи запроса к БД');
    $row_avt = mysqli_fetch_array($result_avt);
	   $last_active = $row_avt['last_active'];
		$last_active = strtotime("$last_active");
        $now = (date("Y-m-d H:i:s"));
        $now = strtotime("$now");
        $razn_last_act = ($now - $last_active);
        $lvl = $row_avt['lvl'];
  ?>

  <p>
  <?php
  if ($row_avt['gruppa'] == 'svoboda') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="on"/><img src="img/ico/svoboda.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="off"/><img src="img/ico/svobodaon.png" width="12" height="12" alt="н"/><?php }}
	  if ($row_avt['gruppa'] == 'dolg') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="on"/><img src="img/ico/dolgon.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="off"/><img src="img/ico/dolg.png" width="12" height="12" alt="н"/><?php }}
	   if ($row_avt['gruppa'] == 'naemniki') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="on"/><img src="img/ico/naemniki.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="off"/><img src="img/ico/naemniki.png" width="12" height="12" alt="н"/><?php }}
	 if ($row_avt['gruppa'] == 'renegat') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="on"/><img src="img/ico/renegat.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="off"/><img src="img/ico/renegat.png" width="12" height="12" alt="н"/><?php }}
	  if ($row_avt['gruppa'] == 'chistoenebo') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="on"/><img src="img/ico/chistoenebo.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="off"/><img src="img/ico/chistoenebo.png" width="12" height="12" alt="н"/><?php }}
 ?> <a style="text-decoration:none;" href="profile.php?id=<?php echo "$avtor_id";?>"><font color='ff5445'><?php echo $row_avt['nick'];?></font></a> 
	<span class="darkkhaki"><i> (<?php echo $row['time_cre'];?>)</i></span>
	 <?php
	 }
$moderator = abs(intval($_GET['moderator']));
	 if ($main == 0) {
	   if ($clan == $clan_us) {
	     if (6 <= $clan_rang_us) {
		 ?> <p class="zx"></p><p><a class="menu" href="topic.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>&moderator=<?php if ($moderator == 1) {echo '0';} else {echo '1';} ?>"><img src="img/ico/link.png" /> Модерировать</a></p>
	 <p class="zx"></p>
             <?php
		 }
		 else {
		   if ($avtor_id == $user_id) {
		     ?><p><img src="img/ico/point.png" />Редактировать топик</p><?php
		   }
		 }
	   }
	   if ($moderator == 1 and 6 <= $clan_rang_us) {
	   ?><p><a class="menu" href="moderator.php?topic=<?php echo "$topic";?>&type=1&page=<?php echo "$cur_page";?>"><img src="img/ico/link.png" /><?php if ($row['fix'] == 0) {?>Открепить топик<?php } else {?>Прикрепить топик<?php }?></a></p>
	 <?php
	   ?><p><a class="menu"  href="moderator.php?topic=<?php echo "$topic";?>&type=2&page=<?php echo "$cur_page";?>"><img src="img/ico/link.png" /><?php if ($row['close'] == 0) {?>Закрыть топик<?php } else {?>Открыть топик<?php }?></a></p>
	 <?php
	   ?><p><a class="menu"  href="moderator.php?topic=<?php echo "$topic";?>&type=3&page=<?php echo "$cur_page";?>"><img src="img/ico/link.png" />Переместить</a></p>
	 <?php
	   ?><p><a class="menu"  href="moderator.php?topic=<?php echo "$topic";?>&type=4&page=<?php echo "$cur_page";?>"><img src="img/ico/link.png" />Удалить топик</a></p>
	 <?php
	   ?><p><a class="menu"  href="moderator.php?topic=<?php echo "$topic";?>&type=5&page=<?php echo "$cur_page";?>"><img src="img/ico/link.png" />Изменить топик</a></p>
	 <?php
	   }
	 }
	 else {////////////////////////Главный форум
	   if ($admin_us == 1 or $admin_us == 2 or $admin_us == 3 or $admin_us == 4 or $admin_us == 5) {
		 ?><p> <p class="zx"></p><a class="menu" href="topic.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>&moderator=<?php if ($moderator == 1) {echo '0';} else {echo '1';} ?>"><img src="img/ico/link.png" />Модерировать</a></p>
	  <p class="zx"></p>
           <?php
	    if ($moderator == 1) {
	   ?><p><a class="menu"  href="moderator.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>&type=1"><?php if ($row['fix'] == 0) {?><img src="img/ico/link.png" />Открепить топик<?php } else {?><img src="img/ico/link.png" />Прикрепить топик<?php }?></a></p>
	 <?php
	   ?><p><a class="menu"  href="moderator.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>&type=2"><?php if ($row['close'] == 0) {?><img src="img/ico/link.png" />Закрыть топик<?php } else {?><img src="img/ico/link.png" />Открыть топик<?php }?></a></p>
          <?php
	   ?><p><a class="menu"  href="moderator.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>&type=3"><img src="img/ico/link.png" />Переместить топик</a></p>
	 <?php
	   ?><p><a class="menu"  href="moderator.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>&type=4"><img src="img/ico/link.png" />Удалить топик</a></p>
	 <?php
	   if ($admin_us == 3 or $admin_us == 5 and $avtor_id == $user_id) {
	   ?><p><a class="menu"  href="moderator.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>&type=5"><img src="img/ico/link.png" />Изменить топик</a></p>
	 <?php }
	   if ($admin_us == 2 or $admin_us == 1 or $admin_us == 4) {
	   ?><p><a class="menu"  href="moderator.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>&type=5"><img src="img/ico/link.png" />Изменить топик</a></p>
	 <p class="zx"></p>
          <?php }
	   }
	   }
	   else {
	     if ($avtor_id == $user_id) {
		  ?><p><a class="menu" href="moderator.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>&type=5"><img src="img/ico/link.png" />Редактировать топик</a></p>
	  <?php
		 }
	   }
	 }
	 if ($cur_page == 1) {
	 ?>
	 
	 <p <?php if ($row_avt['admin']== 1) {?>class="net"<?php } else if ($row_avt['vip'] == 1) {?><div style="background-color: #1E1E1E;"><span class="golub"><small>(vip)</small></span> <span class="net"<?php } else  if ($row_avt['admin']== 2) {?>class="red"<?php } else  if ($row_avt['admin'] == 3) {?>class="bonus"<?php }  else  if ($row_avt['admin'] == -1) {?><div style="background-color: #1E1E1E;"><span class="golub"><small>(vip)</small></span> <span class="gold"<?php } else  if ($row_avt['admin'] == 5) {?><div style="background-color: #1E1E1E;"><span class="gold">Vip</span><span class="bonus"<?php } else {?>class="white"<?php }?>><?php echo $row['text'];?></p>
	
	
  </div><?php
  }
  $query_avt = "Select id_com from  comments where id_top = '$topic'";
  $result_avt = mysqli_query($dbc, $query_avt) or die ('Ошибка передачи запроса к БД');
  $count = mysqli_num_rows($result_avt);
  ?>
 <?php
	   ?><div class="stats" style="padding-top:6px; padding-bottom:6px;">
 <p class="white"><b>Просмотров (<?php echo "$row[prosmotr]";?>) </b><?php
if($row[adm_sm]>0){?><span class="bonus"><small>(<img src="img/ok.png" width="10" height="10"/>Просмотрено администратором)</small></span><?php
}
?></p><br/>
  <p class="white"><b>Комментариев (<?php echo "$count";?>)</b></p>
  </div><?php
  if ($count <> 0) {
    $result_per_page = 10;
    $skip = (($cur_page - 1) * $result_per_page);
    $num_page = ceil($count / $result_per_page);
    if ($num_page > 0) {
	  $query_sub = "Select avtor, text, time_cre, id_com from  comments where id_top = '$topic'  order by time_cre asc limit $skip, $result_per_page";
      $result_sub = mysqli_query($dbc, $query_sub) or die ('Ошибка передачи запроса к БД');
      while ($row_sub = mysqli_fetch_array($result_sub)) {
	    $avtor_id = $row_sub['avtor'];
        $query_avt = "Select nick, gruppa, last_active, admin from  users where id = '$avtor_id' limit 1";
        $result_avt = mysqli_query($dbc, $query_avt) or die ('Ошибка передачи запроса к БД');
        $row_avt = mysqli_fetch_array($result_avt);
	    $last_active = $row_avt['last_active'];
		$last_active = strtotime("$last_active");
        $now = (date("Y-m-d H:i:s"));
        $now = strtotime("$now");
        $razn_last_act = ($now - $last_active);
		?><div class="comments"></p><?php
		if ($row_avt['gruppa'] == 'svoboda') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="н"/><img src="img/ico/svobodaon.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="н"/><img src="img/ico/svobodaon.png" width="12" height="12" alt="н"/><?php }}
	  if ($row_avt['gruppa'] == 'dolg') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="н"/><img src="img/ico/dolgon.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="н"/><img src="img/ico/dolgon.png" width="12" height="12" alt="н"/><?php }}
	 if ($row_avt['gruppa'] == 'naemniki') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="on"/><img src="img/ico/naemniki.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="off"/><img src="img/ico/naemniki.png" width="12" height="12" alt="н"/><?php }}
	 if ($row_avt['gruppa'] == 'renegat') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="on"/><img src="img/ico/renegat.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="off"/><img src="img/ico/renegat.png" width="12" height="12" alt="н"/><?php }}
	  if ($row_avt['gruppa'] == 'chistoenebo') {if ($razn_last_act < 300 ) {?><img src="img/ico/on.png" width="12" height="12" alt="on"/><img src="img/ico/chistoenebo.png" width="12" height="12" alt="н"/><?php } else {?><img src="img/ico/off.png" width="12" height="12" alt="off"/><img src="img/ico/chistoenebo.png" width="12" height="12" alt="н"/><?php }}
	 ?><span class="darkorange"><?php echo $row_avt['nick'];?></span><a href="profile.php?id=<?php echo "$avtor_id";?>"><img src="img/ico/profile.png" width="15" height="15" alt="Pda"/></a><?php echo $row_us['lvl'];?>
	 <span class="darkkhaki"><i>[<?php echo $row_sub['time_cre'];?>]</i></span>
	<p  <p <?php if ($row_avt['admin']== 1) {?>class="net"<?php } else if ($row_avt['admin'] == 4) {?><div style="background-color: #1E1E1E;"><span class="golub"><small>(vip)</small></span> <span class="net"<?php } else  if ($row_avt['admin']== 2) {?>class="red"<?php } else  if ($row_avt['admin'] == 3) {?>class="bonus"<?php }  else  if ($row_avt['admin'] == -1) {?><div style="background-color: #1E1E1E;"><span class="golub"><small>(vip)</small></span> <span class="gold"<?php } else  if ($row_avt['admin'] == 5) {?><div style="background-color: #1E1E1E;"><span class="gold">Vip</span><span class="bonus"<?php } else {?>class="white"<?php }?>><?php echo $row_sub['text'];?></p>
<p><?php
	   if ($main == 1) {
	     if ($moderator == 1) {
	       if ($admin_us == 1 or $admin_us == 2 or $admin_us == 3 or $admin_us == 4 or $admin_us == 5) {
	         ?>[<a href="moderator.php?comment=<?php echo $row_sub['id_com'];?>&type=6&page=<?php echo "$cur_page";?>">удалить</a>] 
			 <?php
			 if ($admin_us == 1 or $admin_us == 2 or $admin_us == 4) {
			   if ($row_avt['admin'] <> 1 and $row_avt['admin'] <> 2 and $row_avt['admin'] <> 4 ) {
			   ?>[<a href="moderator.php?comment=<?php echo $row_sub['id_com'];?>&type=9&page=<?php echo "$cur_page";?>">DEL</a>]<?php
			   }
			   else {
			     if($avtor_id == $user_id) {
				 ?>[<a href="moderator.php?comment=<?php echo $row_sub['id_com'];?>&type=9&page=<?php echo "$cur_page";?>">DEL</a>]<?php
				 }
			   }
			 }
			 if ($row_avt['admin'] <> 1 and $row_avt['admin'] <> 2 and $row_avt['admin'] <> 3 and $row_avt['admin'] <> 4 and $row_avt['admin'] <> 5) {?>
			   [<a href="moderator.php?avtor=<?php echo "$avtor_id";?>&type=7&page=<?php echo "$cur_page";?>&topic=<?php echo "$topic";?>">бан на форум</a>]<?php 
			 }
			 if ($admin_us == 1 or $admin_us == 2 or $admin_us == 4) {
			   if ($row_avt['admin'] <> 1 and $row_avt['admin'] <> 2 and $row_avt['admin'] <> 4) {
	         ?> [<a href="moderator.php?profile=<?php echo "$avtor_id";?>&type=8&page=<?php echo "$cur_page";?>&topic=<?php echo "$topic";?>">бан на игру</a>] <?php
			   }
			 }
	       }
		 }
	   }
	   else {
	     if ($clan == $clan_us) {
		   if ($moderator == 1) {
	         if ($cre <= $clan_rang_us) {?>[<a href="moderator.php?comment=<?php echo $row_sub['id_com'];?>&type=9&page=<?php echo "$cur_page";?>">удалить</a>]<?php }
		   }
		 }
	   }
	   ?></p>
	 </div>
	 <?php
      }
    }
  }
$phpself= filter($_SERVER['PHP_SELF']);
	  if ($cur_page > 1) {
	    echo '<a href="' . "$phpself". '?topic=' .$topic.  '&page=1"><<</a> ';
      }
	  else {
	    echo '<< ';
	  }
	  if ($cur_page > 1) {
	    echo '<a href="' . "$phpself". '?topic=' .$topic.  '&page=' . ($cur_page-1) . '"><</a> ';
      }
	  else {
	    echo '<';
	  }
	/////
	  if (($cur_page-3)>0) {
	 $k = ($cur_page-3);
	    ?><a href="<?php echo "$phpself". '?topic=' .$topic.  '&page=' . ($cur_page-3)?>"><?php echo "$k";?></a><?php
      }
	 if (($cur_page-2)>0) {
	 $k = ($cur_page-2);
	    ?> <a href="<?php echo "$phpself". '?topic=' .$topic.  '&page=' . ($cur_page-2)?>"><?php echo "$k";?></a> <?php
      }
     if (($cur_page-1)>0) {
	 $k = ($cur_page-1);
	    ?> <a href="<?php echo "$phpself". '?topic=' .$topic.  '&page=' . ($cur_page-1)?>"><?php echo "$k";?></a> <?php
      }
	?> <span class="white"><?php echo " $cur_page ";?></span><?php
	 if (($cur_page+1)<=$num_page) {
	 $k = ($cur_page+1);
	    ?> <a href="<?php echo "$phpself". '?topic=' .$topic.  '&page=' . ($cur_page+1)?>"><?php echo "$k";?></a> <?php
      }
	  	 if (($cur_page+2)<=$num_page) {
	 $k = ($cur_page+2);
	    ?> <a href="<?php echo "$phpself". '?topic=' .$topic.  '&page=' . ($cur_page+2)?>"><?php echo "$k";?></a> <?php
      }
	 if (($cur_page+3)<=$num_page) {
	 $k = ($cur_page+3);
	    ?> <a href="<?php echo "$phpself". '?topic=' .$topic.  '&page=' . ($cur_page+3)?>"><?php echo "$k";?></a> <?php
      }
	/////
	if ($cur_page < $num_page) {
	  echo '<a href="' . "$phpself" . '?topic=' .$topic.  '&page=' . ($cur_page+1) . '">></a> ';
    }
	else {
	  echo '>';
	}
	if ($cur_page < $num_page) {
	  echo ' <a href="' . "$phpself" . '?topic=' .$topic.  '&page=' . $num_page . '">>></a> ';
    }
	else {
	  echo ' >>';
	}
  if ($count <> 1000) {
  if ($admin_us <> 1 and $admin_us <> 2 and $admin_us <> 3 and $admin_us <> 4 and $admin_us <> 5) {
  if ($row['close'] <> 1) {
    if ($main == 0) {
      if ($clan == $clan_us) {
	    if ($com <= $clan_rang_us) {
	      ?>
	      <div class="stats">
          <p>Сообщение:</p>
          <form enctype="multipart/form-data" method="post" action="addcomments.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>">
          <textarea rows="2" cols="35px" name="text"></textarea>
          <div class="knopka">
          <input type="submit" style="width:20%;" class="input" value="Отправить" name="addad"/>
          </div>
          </form>
          </div> 
	      <?php
	    } 
	    else {
	    ?>
	    <div id="error">
	    <p>>>> У вас недостаточно прав для комментирования этого топика <<<</p>
	    </div>
	    <?php
	    }  
	  }
	  else {
	    if ($com == 0 and $gruppa == $gruppa_us) {
		  ?>
	      <div class="stats">
          <p>Сообщение:</p>
          <form enctype="multipart/form-data" method="post" action="addcomments.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>">
          <textarea rows="2" cols="35px" name="text"></textarea>
          <div class="knopka">
          <input type="submit" style="width:20%;" class="input" value="Отправить" name="addad"/>
          </div>
          </form>
          </div> 
	      <?php
		}
		else {
	      ?>
	      <div id="error">
	      <p>>>> Вы не можете комментировать эту тему <<<</p>
	      </div>
	      <?php
	    }
	  }
    }
	else {
	  if ($lvl_us >= 10) {
	    if ($gruppa == $gruppa_us or $gruppa == 'all' and $f_ban_us <> 1) {
		  ?>
<?php
$baned=$dbc->query("SELECT * FROM `us_ban` WHERE`usid`='".abs(intval($_SESSION['id']))."' and `type`='forum' and `time`>'".time
()."'")->fetch_assoc();
if($baned['time']<time()){ ?>
	      <div class="stats">
          <p>Сообщение:</p>
          <form enctype="multipart/form-data" method="post" action="addcomments.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>">
          <textarea rows="2" cols="35px" name="text"></textarea>
          <div class="knopka">
          <input type="submit" style="width:20%;" class="input" value="Отправить" name="addad"/>
          </div>
          </form>
          </div> 
	      <?php
}else{
echo'<hr>Вaм выдан бан на общение в форуме!<br/>Заблокированы до '.date('d.m.y. H:i:s',$baned['time']).'<br/>Заблокировал: ID:'.$baned['usban'].'<br/>Причина: '.htmlentities($baned['prich'], ENT_NOQUOTES, 'UTF-8').'<hr>';
}
		}
		else {
		  ?>
          <div id="error">
          <p>>>> Вы не можете комментировать этоу тему <<<</p>
          </div>
        <?php
		}
	  } 
	  else {
	    ?>
        <div id="error">
        <p>>>> Чтобы писать в форуме - получите 10 уровень <<<</p>
        </div>
        <?php
	  }
	}
  } 
  else {
  ?>
  <div id="error">
  <p>>>> Тема закрыта <<<</p>
  </div>
  <?php
  }
  }
  else {
    if ($row['close'] <> 1) {
$baned=$dbc->query("SELECT * FROM`us_ban` WHERE`usid`='".abs(intval($_SESSION['id']))."' and `type`='forum' and `time`>'".time()."'")->fetch_assoc();if($baned['time']<time()){
    ?>
	      <div class="stats">
          <p>Сообщение:</p>
          <form enctype="multipart/form-data" method="post" action="addcomments.php?topic=<?php echo "$topic";?>&page=<?php echo "$cur_page";?>">
          <textarea rows="2" cols="35px" name="text"></textarea>
          <div class="knopka">
          <input type="submit" style="width:20%;" class="input" value="Отправить" name="addad"/>
          </div>
          </form>
          </div> 
	      <?php
}else{echo'<hr>Вaм выдан бан на общение в форуме!<br/>Заблокированы до '.date('d.m.y. H:i:s',$baned['time']).'<br/>Заблокировал: ID:'.$baned['usban'].'<br/>Причина: '.htmlentities($baned['prich']).'<hr>';}
	}
	else {
	  ?>
      <div id="error">
      <p>>>> Тема закрыта <<<</p>
     </div>
     <?php
	}
  }
  }
  else {?><div id="error">
        <p>>>> Достигнуто максимальное количество постов в данной теме <<<</p>
        </div><?php }
  ?>
 <?php
  ?><?php
  }
}
require_once('conf/navig.php');
require_once('conf/foot.php');
mysqli_close($dbc);

?>
</body>
</html>