<?php

          include '../../system/core.php';
  
          ///////бан форума/////
          if($user['id'])
          {

          $banf = mysql_fetch_assoc(mysql_query("SELECT * FROM `ban_forum` WHERE `who` = '".$user['id']."'"));
  
          if($banf['end'] > time())
          {
   $_title = 'Бан';
          include '../../system/header.php';

           echo "<div class='tegi'>Доступ к форуму ограничен</div>";
	
          
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
          include '../../system/nvg.php';
          echo '<div class="post2">
          Ограничил к доступу: '.ustatus($banf['ho']).' <b>'.uname($banf['ho']).'</b> '.uaccess($banf['ho']).'<br>
          
          Причина: <b>'.smiles(bbcode($banf['why'])).'</b><br>

          Дата бана по форуму: <b>'.times($banf['time']).'</b><br>
  
          Дата освобождения: <b>'.date('d.m.Y в H:i',$banf['end']).'</b>
  
          </div>';

           include '../../system/footer.php';
           exit;
 
          }
          }
          //////////////бан форума///////////
          /////////////переадресация если не авториз.//////
          if(!$user['id'])
          {
          
          header('Location: /index.php/?m=guest');
          exit;
          
          
          }
          /////////////переадресация если не авториз.//////
          /////////////голосования .//////
          switch($_GET['m'])
          {
  
          case 'vote':
$_title = 'Добавить опрос';
          include '../../system/header.php';

          $id = TextGuard($_GET['id']);
  
          if(empty($id) or !is_numeric($id)){
  
          header('Location: /forum'); exit;
          
          }

  $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$id.'"'));

  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$forum_t['pr'].'"'));

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_pr['r'].'"'));

  if($forum_t == 0 or $forum_pr == 0 or $forum_r == 0 or $user['status'] < 1 && $user['id'] != $forum_t['author']){
  header('Location: /forum'); exit;
  }

  $forum_vote = mysql_fetch_array(mysql_query('select * from `forum_vote` where `t` = "'.$id.'" limit 1'));
  if($forum_vote != 0){
  mysql_query("DELETE FROM `forum_vote` WHERE `id` = '".$forum_vote['id']."'");
  header('Location: /forum/t'.$id.'');
  }else{
  
             echo "<div class='tegi'>Добавление опроса</div>";
	
         
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
          include '../../system/nvg.php';
  
  if(isset($_POST['submit'])){

  $quest = TextGuard($_POST['quest']);
  if(empty($quest)) $err[] = 'Введите вопрос.';
  $select_1 = TextGuard($_POST['select_1']);
  if(empty($select_1)) $select_1_p = 0; else $select_1_p = 1;
  $select_2 = TextGuard($_POST['select_2']);
  if(empty($select_2)) $select_2_p = 0; else $select_2_p = 1;
  $select_3 = TextGuard($_POST['select_3']);
  if(empty($select_3)) $select_3_p = 0; else $select_3_p = 1;
  $select_4 = TextGuard($_POST['select_4']);
  if(empty($select_4)) $select_4_p = 0; else $select_4_p = 1;
  $select_5 = TextGuard($_POST['select_5']);
  if(empty($select_5)) $select_5_p = 0; else $select_5_p = 1;
  $selects = $select_1_p+$select_2_p+$select_3_p+$select_4_p+$select_5_p;
  if($selects < 2) $err[] = 'Для создания голосования нужно указать как минимум 2 варианта ответа.';

  if(!$err){

  		mysql_query("INSERT INTO `forum_vote`(
			`t`,`quest`,`select_1`,`select_2`,`select_3`,`select_4`,`select_5`
			)VALUES(
			'".$id."','".$quest."','".$select_1."','".$select_2."','".$select_3."','".$select_4."','".$select_5."'
			)");

  header('Location: /forum/t'.$id.''); exit;
  
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  
  }

 
  echo '<div class="glav">
  <form action="" method="post">
  Вопрос:<br><input name="quest"/><br>
  Вариант 1:<br><input name="select_1"/><br>
  Вариант 2:<br><input name="select_2"/><br>
  Вариант 3:<br><input name="select_3"/><br>
  Вариант 4:<br><input name="select_4"/><br>
  Вариант 5:<br><input name="select_5"/><br>
  <input type="submit" value="Добавить" name="submit"/>
  </form></div>';

  }
  break;
/////////////голосования .//////
/////////////кто голосовал .//////
  case 'vote_members':
$_title = 'Кто проголосовал';
          include '../../system/header.php';

  $id = TextGuard($_GET['id']);
  
  if(empty($id) or !is_numeric($id)){
  header('Location: /forum'); exit;
  }

  $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$id.'"'));

  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$forum_t['pr'].'"'));

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_pr['r'].'"'));

  if($forum_t == 0 or $forum_pr == 0 or $forum_r == 0){
  header('Location: /forum'); exit;
  }

  $forum_vote = mysql_fetch_array(mysql_query('select * from `forum_vote` where `t` = "'.$id.'" limit 1'));
  if($forum_vote == 0){
  header('Location: /forum/t'.$id.'');
  }
  
              echo "<div class='tegi'>Кто голосовал</div>";
	
          
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
          include '../../system/nvg.php';
  
  $cop = $user['on_page'];
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_t` WHERE `pr`='".$id."'"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  
  $forum_votes = mysql_query("SELECT * FROM `forum_votes` WHERE `vote`='".$forum_vote['id']."' ORDER BY `id` desc LIMIT $start,$cop");

  while($forum_votes2 = mysql_fetch_assoc($forum_votes)){
  echo '<div class="post2">'.ustatus($forum_votes2['who']).' <a href="/us'.$forum_votes2['who'].'">'.uname($forum_votes2['who']).'</a> '.uaccess($forum_votes2['who']).' проголосовал за <b>'.$forum_vote['select_'.$forum_votes2['select']].'</b></div>';
  }

  echo '<div class="spis">Стр. ';
  if($p-2>0) echo '<a href="/forum/t'.$id.'/vote_members?p=1"><<</a> ';
  if($p-1>0) echo '<a href="/forum/t'.$id.'/vote_members?p='.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/forum/t'.$id.'/vote_members?p=1'.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/forum/t'.$id.'/vote_members?p=1'.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/forum/t'.$id.'/vote_members?p=1'.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/forum/t'.$id.'/vote_members?p=1'.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/forum/t'.$id.'/vote_members?p=1'.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/forum/t'.$id.'/vote_members?p=1'.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/forum/t'.$id.'/vote_members?p=1'.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/forum/t'.$id.'/vote_members?p=1'.ceil($ca/$cop).'">>></a>';
  echo '</div>';
  break;
  /////////////кто голосовал .//////
  /////////////Новый раздел .//////
  case 'nr':
$_title = 'Добавить раздел';
          include '../../system/header.php';

  if($user['status'] < 2){
  header('Location: /forum'); exit;
  }

            echo "<div class='tegi'>Добавление раздела</div>";
	
          
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
          include '../../system/nvg.php';
          
  if(isset($_POST['submit'])){

  $name = TextGuard($_POST['name']);

  if(!$err){
  
  		mysql_query("INSERT INTO `forum_r`(
			`name`
			)VALUES(
			'".$name."'
			)");
    
  header('Location: ?'); exit;
  
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  
  }

 
  echo '<div class="glav">
  <form action="?m=nr" method="post">
  Название:<br><input name="name"/><br>
  <input type="submit" value="Добавить" name="submit"/>
  </form></div>';
  
  break;
  /////////////новый раздел .//////
  /////////////удаление раздела .//////
 case 'dr':

  if($user['status'] < 2){
  header('Location: /forum'); exit;
  }

  $id = TextGuard($_GET['id']);
  
  if(empty($id) or !is_numeric($id)){
  header('Location: ?'); exit;
  }

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$id.'"'));

  if($forum_r == 0){
  header('Location: ?'); exit;
  }

  $forum_pr = mysql_query('select * from `forum_pr` where `r` = "'.$id.'"');
  while($forum_pr2 = mysql_fetch_array($forum_pr)){
  mysql_query("DELETE FROM `forum_pr` WHERE `id` = '".$forum_pr2['id']."'");
  }

  $forum_t = mysql_query('select * from `forum_t` where `r` = "'.$id.'"');
  while($forum_t2 = mysql_fetch_array($forum_t)){
  mysql_query("DELETE FROM `forum_t` WHERE `id` = '".$forum_t2['id']."'");
  }

  $forum_m = mysql_query('select * from `forum_m` where `r` = "'.$id.'"');
  while($forum_m2 = mysql_fetch_array($forum_m)){
  mysql_query("DELETE FROM `forum_m` WHERE `id` = '".$forum_m2['id']."'");
  }

  mysql_query("DELETE FROM `forum_r` WHERE `id` = '$id'");

  header('Location: ?'); exit;

  break;
  /////////////удаление раздела .//////
  /////////////новый подраздел .//////
  case 'npr':
$_title = 'Новый подраздел';
          include '../../system/header.php';

  if($user['status'] < 2){
  header('Location: /forum'); exit;
  }

  $id = TextGuard($_GET['id']);
  
  if(empty($id) or !is_numeric($id)){
  header('Location: ?'); exit;
  }

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$id.'"'));

  if($forum_r == 0){
  header('Location: ?'); exit;
  }
  
             echo "<div class='tegi'>Добавление подраздела</div>";
		
		
          
 
  if(isset($_POST['submit'])){

  $name = TextGuard($_POST['name']);
  if(empty($name)) $err[] = 'Название осталось пустым...';

  

  if(!$err){
  
  		mysql_query("INSERT INTO `forum_pr`(
			`r`,
			`name`
			)VALUES(
			'".$id."',
			'".$name."'
			)");
 

			
  header('Location: /forum/r'.$id.''); exit;
  
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  
  }

 
  echo '<div class="glav">
  <form action="?m=npr&amp;id='.$id.'" method="post">
  Название:<br><input name="name"/><br>
  
  <input type="submit" value="Добавить" name="submit"/>
  </form></div>';

  break;
/////////////новый подраздел .//////
/////////////удаление подраздела .//////
 case 'dpr':

  if($user['status'] < 2){
  header('Location: /forum'); exit;
  }

  $pr = TextGuard($_GET['pr']);
  
  if(empty($pr) or !is_numeric($pr)){
  header('Location: ?'); exit;
  }

  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$pr.'"'));

  if($forum_pr == 0){
  header('Location: /forum'); exit;
  }

  $forum_t = mysql_query('select * from `forum_t` where `pr` = "'.$pr.'"');
  while($forum_t2 = mysql_fetch_array($forum_t)){
  mysql_query("DELETE FROM `forum_t` WHERE `id` = '".$forum_t2['id']."'");
  }

  $forum_m = mysql_query('select * from `forum_m` where `pr` = "'.$pr.'"');
  while($forum_m2 = mysql_fetch_array($forum_m)){
  mysql_query("DELETE FROM `forum_m` WHERE `id` = '".$forum_m2['id']."'");
  }

  mysql_query("DELETE FROM `forum_pr` WHERE `id` = '$pr'");
  mysql_query("DELETE FROM `forum_pr_rules` WHERE `pr` = '$pr'");

  header('Location: /forum/r'.$id.''); exit;

  break;
  /////////////удаление подраздела .//////
  /////////////редактирование раздел .//////
  case 'er':
$_title = 'Редактировать';
          include '../../system/header.php';

  if($user['status'] < 2){
  header('Location: /forum'); exit;
  }

  $id = TextGuard($_GET['id']);
  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$id.'" limit 1'));

  if(empty($id) or !is_numeric($id) or $forum_r == 0){
  header('Location: /forum'); exit;
  }

            echo "<div class='tegi'>Редактирование раздела</div>";
		
          
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
          include '../../system/nvg.php';
          
  if(isset($_POST['submit'])){
  
  $text = TextGuard($_POST['text']);
  if(empty($text)) $err[] = 'Название осталось пустым...';
  
  if(!$err){
  mysql_query("UPDATE `forum_r` SET `name`='".$text."' WHERE `id` = '".$id."' limit 1");
  header('Location: /forum'); exit;
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  }

  echo '<div class="glav">
  <form action="/forum?m=er&amp;id='.$id.'" method="post">
  Название:<br><input name="text" value="'.$forum_r['name'].'"/><br>
  <input type="submit" value="Сохранить" name="submit"/>
  </form></div>';

  break;
  /////////////редактирование раздела .//////
/////////////редактирование подраздела .//////
  case 'epr':
$_title = 'Редактировать';
          include '../../system/header.php';

  if($user['status'] < 2){
  header('Location: /forum'); exit;
  }

  $id = TextGuard($_GET['id']);
  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$id.'" limit 1'));

  if(empty($id) or !is_numeric($id) or $forum_pr == 0){
  header('Location: /forum/r'.$forum_pr['r'].''); exit;
  }

     
            echo "<div class='tegi'>Редактирование подраздела</div>";
		
          
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
          include '../../system/nvg.php';
          
  if(isset($_POST['submit'])){
  
  $text = TextGuard($_POST['text']);
  if(empty($text)) $err[] = 'Название осталось пустым...';
  
  if(!$err){
  mysql_query("UPDATE `forum_pr` SET `name`='".$text."' WHERE `id` = '".$id."' limit 1");
  header('Location: /forum/r'.$forum_pr['r'].''); exit;
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  }

  echo '<div class="glav">
  <form action="/forum?m=epr&amp;id='.$id.'" method="post">
  Название:<br><input name="text" value="'.$forum_pr['name'].'"/><br>
  <input type="submit" value="Сохранить" name="submit"/>
  </form></div>';

  break;
/////////////редактирование подраздела .//////
/////////////главная .//////
  #Главная
  default:
$_title = 'Форум';
          include '../../system/header.php';

    
            echo "<div class='tegi'>Форум</div>";
       
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
          include '../../system/nvg.php';
          
  if($user['status'] >= 2) echo '<div class="post2"> 
  <a href="?m=nr"><b>Новый раздел</b></a></div>';
  
  echo '<div class="post2">
  <img src="/images/ttema.png"/> Мои: <a href="/us'.$user['id'].'?m=f_t">Темы</a> | <a href="/us'.$user['id'].'?m=f_m">Посты</a> |</div>';
  
  $forum_r = mysql_query('select * from `forum_r` order by `id`');
  while($forum_r2 = mysql_fetch_array($forum_r)){
  echo '<div class="tegi"><img src="/images/global.png"/> <a href="/forum/r'.$forum_r2['id'].'"  ><b>'.$forum_r2['name'].'</b></a> ('.mysql_result(mysql_query('select count(`id`) from `forum_t` where `r` = "'.$forum_r2['id'].'"'),0).'/'.mysql_result(mysql_query('select count(`id`) from `forum_m` where `r` = "'.$forum_r2['id'].'"'),0).')';
  
  if($user['status'] >= 2) echo ' [<a href="?m=er&amp;id='.$forum_r2['id'].'"  >ред</a>] [<a href="?m=dr&amp;id='.$forum_r2['id'].'"  >уд</a>]';

  
  echo '</div>';
  
  $forum_pr = mysql_query('select * from `forum_pr` where `r` = "'.$forum_r2['id'].'" order by `id`');
  while($forum_pr2 = mysql_fetch_array($forum_pr)){
  echo '<a href="/forum/pr'.$forum_pr2['id'].'"><div class="post2">'.$forum_pr2['name'].' ('.mysql_result(mysql_query('select count(`id`) from `forum_t` where `r` = "'.$forum_r2['id'].'" and `pr` = "'.$forum_pr2['id'].'"'),0).'/'.mysql_result(mysql_query('select count(`id`) from `forum_m` where `r` = "'.$forum_r2['id'].'" and `pr` = "'.$forum_pr2['id'].'"'),0).')<br>';
echo '</div></a>';
  }
  
  
  

    
  }

  
  break;
  /////////////главная .//////
  /////////////раздел .//////
  case 'r':
$_title = 'Форум';
          include '../../system/header.php';

  $id = TextGuard($_GET['id']);
  
  if(empty($id) or !is_numeric($id)){
  header('Location: /forum'); exit;
  }
  
  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$id.'"'));

  if($forum_r == 0){
  header('Location: /forum'); exit;
  }

 echo "<div class='tegi'>".$forum_r['name']."</div>";
		
		
          
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
          include '../../system/nvg.php';
          
  if($user['status'] >= 2) echo '<div class="post2">
  <a href="?m=npr&amp;id='.$id.'"><b>Новый подраздел</b></a></div>';

  
  $forum_pr = mysql_query('select * from `forum_pr` where `r` = "'.$id.'"');
  while($forum_pr2 = mysql_fetch_array($forum_pr)){
  echo '<div class="post1"><a href="/forum/pr'.$forum_pr2['id'].'" ><b>'.$forum_pr2['name'].'</b></a> ('.mysql_result(mysql_query('select count(`id`) from `forum_t` where `r` = "'.$forum_pr2['r'].'" and `pr` = "'.$forum_pr2['id'].'"'),0).'/'.mysql_result(mysql_query('select count(`id`) from `forum_m` where `r` = "'.$forum_pr2['r'].'" and `pr` = "'.$forum_pr2['id'].'"'),0).')';
  if($user['status'] >= 2) echo ' [<a href="/forum?m=epr&amp;id='.$forum_pr2['id'].'" >ред</a>] [<a href="?m=dpr&amp;pr='.$forum_pr2['id'].'"  >уд</a>]';
  echo '</div>';

  }
  
  break;
  /////////////раздел .//////
  /////////////подраздел .//////
  case 'pr':
  $_title = 'Форум';
          include '../../system/header.php';

  $id = TextGuard($_GET['id']);
  
  if(empty($id) or !is_numeric($id)){
  header('Location: /forum'); exit;
  }

  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$id.'"'));

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_pr['r'].'"'));

  if($forum_pr == 0){
  header('Location: /forum'); exit;
  }
  
echo "<div class='tegi'>Форум</div>";
		
		
          echo '<div class="tegi"><a href="/forum/r'.$forum_pr['r'].'"  >'.$forum_r['name'].'</a> | '.$forum_pr['name'].'</b>
          </div>';
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
          include '../../system/nvg.php';
          
  if($user['id']){
  echo '<div class="poste"><img src="/modules/forum/images/nt.png"/> <a href="/forum/nt'.$id.'" > Новая тема</a></div>';
  }
  

  $cop = $user['on_page'];
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_t` WHERE `pr`='".$id."'"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  $forum_t = mysql_query("SELECT * FROM `forum_t` WHERE `pr`='".$id."' ORDER BY `check` desc,`time` desc LIMIT $start,$cop");

  while($forum_t2 = mysql_fetch_assoc($forum_t)){
  echo '<div class="post2">';
  
  if($forum_t2['check'] == 0){
  
  if($forum_t2['status'] == 0) echo '<img src="/modules/forum/images/the.png"/> '; elseif($forum_t2['status'] == 1) echo '<img src="/modules/forum/images/closed.png"/> ';
  
  }else{
  echo '<img src="/modules/forum/images/check.png"/> ';
  }
  
  $t_m = mysql_result(mysql_query('select count(`id`) from `forum_m` where `t` = "'.$forum_t2['id'].'"'),0);
  echo '<a href="/forum/t'.$forum_t2['id'].'">'.$forum_t2['name'].'</a> ('.$t_m.') '.uname($forum_t2['last']).' <a href="/forum/t'.$forum_t2['id'].'/p'.ceil(($t_m+1)/10).'">>></a> </div>
  ';
  
  }
echo '</div>';
  echo '<div class="spis">Стр. ';
  if($p-2>0) echo '<a href="/forum/pr'.$id.'/p1"><<</a> ';
  if($p-1>0) echo '<a href="/forum/pr'.$id.'/p'.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/forum/pr'.$id.'/p'.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/forum/pr'.$id.'/p'.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/forum/pr'.$id.'/p'.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/forum/pr'.$id.'/p'.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/forum/pr'.$id.'/p'.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/forum/pr'.$id.'/p'.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/forum/pr'.$id.'/p'.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/forum/pr'.$id.'/p'.ceil($ca/$cop).'">>></a></div>';
 echo '</div>';

  break;
  /////////////подраздел .//////
  /////////////скачать тему .//////
          case 'txt':

          $id = TextGuard($_GET['id']);
  
          if(empty($id) or !is_numeric($id))
          {
  
          header('Location: /forum'); exit;
  
          }




          $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$id.'"'));

          $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$forum_t['pr'].'"'));

          $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_pr['r'].'"'));
 

          if($forum_r == 0 or $forum_pr == 0 or $forum_t == 0)
          {
          
          header('Location: /forum'); exit;
  
          }
          
          ob_clean();

          ob_implicit_flush();
          
          header('Content-Type: text/plain; charset=utf-8', true);

          header('Content-Disposition: attachment; filename="'.$forum_r['id'].'_'.$forum_pr['id'].'_'.$forum_t['id'].'.txt";');
          
          echo "
          My-Css.Ru\r\n
          - - -\r\n
          $forum_r[name] | $forum_pr[name] | $forum_t[name]\r\n
          - - -\r\n";

          $post_i = 1;

          $forum_m = mysql_query("SELECT * FROM `forum_m` WHERE `t`='".$id."' ORDER BY `id`");
  
          while($forum_m2 = mysql_fetch_array($forum_m))
          {

          $author = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$forum_m2['author'].'"'));

          echo "
          ".$post_i++.". ".$author[login]." (".times($forum_m2[time]).")\r\n";
  
          if(!empty($forum_m2['cit'])){
            
          $cit = mysql_fetch_array(mysql_query('select * from `forum_m` where `id` = "'.$forum_m2['cit'].'"'));
            
          $cit_author = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$cit['author'].'"'));

          echo "
          Цитата ".$cit_author[login].":\r\n".$cit[text]."\r\n";
          }
   
          echo "
          ".$forum_m2['text']."\r\n\r\n";
    
          }
          
          echo "
          http://forcss.ru/forum/t$id\r\n";
          
          exit;
  
          break;
          
          /////////////скачать тему .//////
          /////////////тема .//////
  
          case 't':

 

$_title = 'Тема';
          include '../../system/header.php';



          $id = TextGuard($_GET['id']);
  
          if(empty($id) or !is_numeric($id))
          {
  
          header('Location: /forum'); exit;
  
          }




          $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$id.'"'));

          $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$forum_t['pr'].'"'));

          $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_pr['r'].'"'));










          if($forum_r == 0 or $forum_pr == 0 or $forum_t == 0)
          {
    
          header('Location: /forum'); exit;
  
          }
          
          
          
          
          /////////////визиты в тему .//////

          $forum_visit = mysql_fetch_array(mysql_query('select `who`,`t` from `forum_visit` where `t` = "'.$id.'" and `who` = "'.$user['id'].'" limit 1'));
  
          if($forum_visit == 0)
          {
	
          mysql_query("INSERT INTO `forum_visit`(
			
          `r`,
			
          `pr`,
	
          `t`,
  
          `who`,
  
          `time`
	
          )VALUES(
			
          '".$forum_r['id']."',
			
          '".$forum_pr['id']."',
			
          '".$id."',
			
          '".$user['id']."',
			
          '".time()."'
			
          )");  
  
          }
          else
          {
          
          mysql_query("UPDATE `forum_visit` SET `time`='".time()."' WHERE `who`='".$user['id']."' and `t` = '".$id."' limit 1");
        
          }
          /////////////визиты в тему .//////

/////////////подписаться .//////
  
          if(isset($_GET['rss']))
          {
  
          $forum_rss = mysql_fetch_array(mysql_query('select * from `forum_rss` where `t` = "'.$id.'" and `who` = "'.$user['id'].'" limit 1'));
          
          if($forum_rss == 0){
			
          mysql_query("INSERT INTO `forum_rss`(
          
          `t`,
          
          `who`
          
          )VALUES(
			
          '".$id."',
			
          '".$user['id']."'
			
          )");  
          
          }
          else
          {
          
          mysql_query("DELETE FROM `forum_rss` WHERE `t` = '".$id."' and `who` = '".$user['id']."'");
          
          }

          header('Location: /forum/t'.$id.'/p'.$p.'');
          
          }
		  

/////////////подписаться .//////

/////////////закрыто,открыто .//////

          if(isset($_GET['check']) && $user['status'] >= 1)
            {
            
          if($forum_t['check'] == 0)
          {
  
          mysql_query("UPDATE `forum_t` SET `check`='1' WHERE `id` = '".$id."' limit 1");
  mysql_query("INSERT INTO `adm_log`(
			`who`,
			`ho`,
			`text`,
      `time`
			)VALUES(
      '".$forum_t['author']."',
      '".$user['id']."',
      'Закрепил тему на форуме [url=/forum/t".$forum_t['id']."]".$forum_t['name']."[/url]',
      '".time()."'
			)");
          }
          else
          {

          mysql_query("UPDATE `forum_t` SET `check`='0' WHERE `id` = '".$id."' limit 1");
mysql_query("INSERT INTO `adm_log`(
			`who`,
			`ho`,
			`text`,
      `time`
			)VALUES(
      '".$forum_t['author']."',
      '".$user['id']."',
      'Открелил тему на форуме [url=/forum/t".$forum_t['id']."]".$forum_t['name']."[/url]',
      '".time()."'
			)");
          }
  
          header('Location: /forum/t'.$id.'/p'.$p.'');
          
          }

/////////////закрыто,открыто .//////
    
          $forum_rss = mysql_fetch_array(mysql_query('select * from `forum_rss` where `t` = "'.$id.'" and `who` = "'.$user['id'].'" limit 1'));

		   
          echo ' <div class="tegi"><a href="/forum"  ><b>Форум</a> | <a href="/forum/r'.$forum_pr['r'].'"  >'.$forum_r['name'].'</a> | <a href="/forum/pr'.$forum_pr['id'].'"  >'.$forum_pr['name'].'</a> | '.$forum_t['name'].'</b></div></div>';
          echo '</div>';
		  
		    echo '<div class="start">';
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
         include '../../system/nvg.php';
         if($forum_t['status'] == 1) echo '<div class="poste"><img src="/modules/forum/images/closed.png"/> <b>Закрыто</b></div>';
         
          $cop = $user['on_page'];
  
          $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_m` WHERE `t`='".$id."'"),0);
  
          $cp = ceil($ca/$cop);
  
          if(isset($_GET['p']) && is_numeric($_GET['p'])){
  
          $p = $_GET['p'];
  
          if($_GET['p']>$cp) $p = $cp;
  
          if($_GET['p']<1)$p = 1;
  
          }else{
  
          $p = 1;
          
          }
          
          $start = $p*$cop-$cop;
  
  
          if($p == 1) $post_i = $p;
    
          elseif($p == 2) $post_i = ($p+9);
          
          else $post_i = ($p*10)-9;
  
          echo '<div class="post2"><small><a href="/forum/t'.$id.'/p'.$p.'">Обновить</a>';
  
          if($user['status'] >= 1)
          {
  
          if($forum_t['status'] == 0) echo ' | <a href="/forum/t'.$id.'/status">Закрыть</a>';
          else
          echo ' | <a href="/forum/t'.$id.'/status">Открыть</a>';
  }
  
          $forum_rss = mysql_fetch_array(mysql_query('select * from `forum_rss` where `t` = "'.$id.'" and `who` = "'.$user['id'].'" limit 1'));
  
          echo ($forum_rss == 0 ? ' | <a href="/forum/t'.$id.'/p'.$p.'?rss">Подписаться</a>' : ' | <a href="/forum/t'.$id.'/p'.$p.'/?rss">Отписаться</a>');
  
          if($user['status'] > 1) echo ' | <a href="/forum/ted'.$id.'">Изменить</a> | <a href="/forum/tdel'.$id.'">Удалить</a> | <a href="/forum/t'.$id.'/p'.$p.'?och&amp;pid='.$id.'">Очистить</a>';
  
          if($user['status'] >= 1)
          {
  
          if($forum_t['check'] == 0) echo ' | <a href="/forum/t'.$id.'/p'.$p.'?check">Закрепить</a>'; else echo ' | <a href="/forum/t'.$id.'/p'.$p.'?check">Открепить</a>';
  
  }
  
  
  
  
  
          if($forum_t['author'] == $user['id'] or $user['status'] >= 1)
          {
   
          $forum_vote = mysql_fetch_array(mysql_query('select * from `forum_vote` where `t` = "'.$id.'" limit 1'));
          
          echo ($forum_vote == 0 ? ' | <a href="/forum/t'.$id.'/vote">Добавить опрос</a>' : ' | <a href="/forum/t'.$id.'/vote">Удалить опрос</a>');
if($forum_t['top'] == 0) echo ' | <a href="/forum/t'.$id.'/intop">Закрепить тему в топ</a>';
if($forum_t['top'] == 1) echo ' | <a href="/forum/t'.$id.'/notop">Открепить тему с топа</a>';


          }
          
          
          
          
          
          echo '<br>';
          /////////////сказать спасибо .//////
          $thnx = mysql_fetch_array(mysql_query('select * from `forum_t_thnx` where `t` = "'.$id.'" and `user` = "'.$user['id'].'" limit 1'));
          
          if($thnx == 0 && $forum_t['author'] != $user['id'])
          {
          
          if(isset($_GET['thnx']))
          {
          
          mysql_query("INSERT INTO `forum_t_thnx`(
          
          `t`,
          `user`,
          `ho`,
          `time`
	
          )VALUES(
	
          '".$id."',
          
          '".$user['id']."',
          
          '".$forum_t['author']."',
	
          '".time()."'
          
          )");
          
          header('Location: /forum/t'.$id.'/p'.$p.''); exit;
          
          }
          
          echo 'Полезная тема?<br><a href="/forum/t'.$id.'/p'.$p.'?thnx">Сказать спасибо</a> автору<br/>';
    
          }
          else
          {
          
          echo 'Сказали спасибо: <a href="/forum/t'.$id.'/sps">'.mysql_result(mysql_query('select count(`id`) from `forum_t_thnx` where `t` = "'.$id.'"'),0).'</a> чел.';
          
          }
          /////////////сказать спасибо .//////
          /////////////голосование .//////
          echo '</small></div>';

          if($forum_t['status'] == 0){
          $forum_vote = mysql_fetch_array(mysql_query('select * from `forum_vote` where `t` = "'.$id.'" limit 1'));
  
          if($forum_vote != 0)
          {
  
          if(isset($_POST['add_vote']))
          {
  
          $vote = TextGuard($_POST['vote']);
  
          if(empty($vote) or !is_numeric($vote) or $vote <= 0 or $vote >= 6)
          {
          
          header('Location: /forum/t'.$id.'/p'.$p.''); exit;
          
          }
  
          if(mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_votes` WHERE `vote`='".$forum_vote['id']."' and `who` = '".$user['id']."'"),0) == 0)
          {
          
          mysql_query("INSERT INTO `forum_votes`(
          `who`,
          
          `vote`,
	
          `select`
	
          )VALUES(
	
          '".$user['id']."',
          
          '".$forum_vote['id']."',
	
          '".$vote."'
          
          )");
          
          }
          else
          {
          
          header('Location: /forum/t'.$id.'/p'.$p.''); exit;
          
          }
          
          header('Location: /forum/t'.$id.'/p'.$p.''); exit;
          
          }
  
          echo '<div class="tegi"><b>Опрос: </b>'.$forum_vote['quest'];

 

          echo '</div><div class="post2">';

        if(empty($forum_vote['select_1'])) $fvs1 = 0; else $fvs1 = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_votes` WHERE `vote`='".$forum_vote['id']."' and `select` = '1'"),0);
        
        if(empty($forum_vote['select_2'])) $fvs2 = 0; else $fvs2 = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_votes` WHERE `vote`='".$forum_vote['id']."' and `select` = '2'"),0);
        
        if(empty($forum_vote['select_3'])) $fvs3 = 0; else $fvs3 = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_votes` WHERE `vote`='".$forum_vote['id']."' and `select` = '3'"),0);
        
        if(empty($forum_vote['select_4'])) $fvs4 = 0; else $fvs4 = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_votes` WHERE `vote`='".$forum_vote['id']."' and `select` = '4'"),0);
        
        if(empty($forum_vote['select_5'])) $fvs5 = 0; else $fvs5 = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_votes` WHERE `vote`='".$forum_vote['id']."' and `select` = '5'"),0);
  
        $vote_all = round($fvs1+$fvs2+$fvs3+$fvs4+$fvs5);
  
        if(mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_votes` WHERE `vote`='".$forum_vote['id']."' and `who` = '".$user['id']."'"),0) == 0)
        {
  
        echo '<form action="/forum/t'.$id.'/p'.$p.'" method="post"><table cellpadding="0" cellspacing="0">';
  
        if(!empty($forum_vote['select_1'])) echo '<tr><td><input type="radio" value="1" name="vote"/></td><td style="padding-left:10px;">
        
        '.$forum_vote['select_1'].'<br>
        
        <img src="/modules/forum/img.php?p='.round(100/($vote_all/$fvs1)).'&amp;k='.$fvs1.'&amp;a='.$vote_all.'" alt="*"/>
        </td></tr>';
          
        if(!empty($forum_vote['select_2'])) echo '<tr><td><input type="radio" value="2" name="vote"/></td><td style="padding-left:10px;">
        '.$forum_vote['select_2'].'<br>
        
        
        <img src="/modules/forum/img.php?p='.round(100/($vote_all/$fvs2)).'&amp;k='.$fvs2.'&amp;a='.$vote_all.'" alt="*"/></td></tr>';
          
          if(!empty($forum_vote['select_3'])) echo '<tr><td><input type="radio" value="3" name="vote"/></td><td style="padding-left:10px;">'.$forum_vote['select_3'].'<br>
          
          
          <img src="/modules/forum/img.php?p='.round(100/($vote_all/$fvs3)).'&amp;k='.$fvs3.'&amp;a='.$vote_all.'" alt="*"/></td></tr>';
          
          if(!empty($forum_vote['select_4'])) echo '<tr><td><input type="radio" value="4" name="vote"/></td><td style="padding-left:10px;">'.$forum_vote['select_4'].'<br>
          
          <img src="/modules/forum/img.php?p='.round(100/($vote_all/$fvs4)).'&amp;k='.$fvs4.'&amp;a='.$vote_all.'" alt="*"/></td></tr>';
          
          if(!empty($forum_vote['select_5'])) echo '<tr><td><input type="radio" value="5" name="vote"/></td><td style="padding-left:10px;">'.$forum_vote['select_5'].'<br>
          
          <img src="/modules/forum/img.php?p='.round(100/($vote_all/$fvs5)).'&amp;k='.$fvs5.'&amp;a='.$vote_all.'" alt="*"/></td></tr>';

          echo '</table><br><input type="submit" name="add_vote" value="Проголосовать"/></form>';
  
          }else{
  
          echo '<table cellpadding="0" cellspacing="0">';
  
          if(!empty($forum_vote['select_1']))
          {
  
          echo '<tr><td>'.$forum_vote['select_1'].'</td><td style="padding-left:10px;">
          <img src="/modules/forum/img.php?p='.round(100/($vote_all/$fvs1)).'&amp;k='.$fvs1.'&amp;a='.$vote_all.'" alt="*"/></td></tr>';
    
          }
          
          if(!empty($forum_vote['select_2']))
          {
  
          echo '<tr><td>'.$forum_vote['select_2'].'</td><td style="padding-left:10px;">
          <img src="/modules/forum/img.php?p='.round(100/($vote_all/$fvs2)).'&amp;k='.$fvs2.'&amp;a='.$vote_all.'" alt="*"/></small></td></tr>';
    
  }
  
          if(!empty($forum_vote['select_3']))
          {
  
          echo '<tr><td>'.$forum_vote['select_3'].'</td><td style="padding-left:10px;">
          <img src="/modules/forum/img.php?p='.round(100/($vote_all/$fvs3)).'&amp;k='.$fvs3.'&amp;a='.$vote_all.'" alt="*"/></small></td></tr>';
    
          }
  
          if(!empty($forum_vote['select_4']))
          {
    
          echo '<tr><td>'.$forum_vote['select_4'].'</td><td style="padding-left:10px;">
          
          <img src="/modules/forum/img.php?p='.round(100/($vote_all/$fvs4)).'&amp;k='.$fvs4.'&amp;a='.$vote_all.'" alt="*"/></td></tr>';
    
          }
 
          if(!empty($forum_vote['select_5']))
          {
  
          echo '<tr><td><b>'.$forum_vote['select_5'].'</b></td><td style="padding-left:10px;">
          <img src="/modules/forum/img.php?p='.round(100/($vote_all/$fvs5)).'&amp;k='.$fvs5.'&amp;a='.$vote_all.'" alt="*"/></td></tr>';
    
          }
 
          echo '</div>';
 
          }
  
          echo '</table><small>В голосовании приняли участие: <a href="/forum/t'.$id.'/vote_members">'.mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_votes` WHERE `vote`='".$forum_vote['id']."'"),0).'</a> чел.</small><br>';
    
          echo '</div>';
          
          }
  }
  /////////////голосование .//////
////////////// удаление сообщения /////////
            if(isset($_GET['dp']))
          {
  
          $pid = TextGuard($_GET['pid']);
  
          if(empty($pid) or !is_numeric($pid)){
  
          header('Location: ?'); exit;
          
          }

          $forum_m = mysql_fetch_array(mysql_query('select * from `forum_m` where `id` = "'.$pid.'"'));


          if($forum_m == 0)
          {
          
          header('Location: ?'); exit;
          
          }

  
          if(!$user['id'] && $user['status'] < 1)
          {
  
          header('Location: /forum/t'.$forum_m['t'].'/p'.$p.'');
          exit;
          
          }
  $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$forum_m['t'].'"'));
$forum_m_author = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$forum_m['author'].'"'));

      mysql_query("DELETE FROM `forum_m` WHERE `id` = '$pid'");

        mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`,
      `sort`
			)VALUES(
      '".$forum_m_author['id']."',
      '".$user['id']."',
      'удалил ваш пост:[br]".$forum_m['text']." в теме [url=/forum/t".$forum_m['t']."]".$forum_t['name']."[/url]!',
      '".time()."',
      '0',
      '2'
			)");
          header('Location: /forum/t'.$id.'/p'.$p.'');
          
          }
          
 /////////////удаление сообщения//////////
////////////// Очистка /////////
            if(isset($_GET['och']))
          {
  
          $pid = TextGuard($_GET['pid']);
  
          if(empty($pid) or !is_numeric($pid)){
  
          header('Location: ?'); exit;
          
          }
       

          $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$pid.'"'));


          if($forum_t == 0)
          {
          
          header('Location: ?'); exit;
          
          }

  
          if(!$user['id'] && $user['status'] < 1)
          {
  
          header('Location: /forum/t'.$forum_m['t'].'/p'.$p.'');
          exit;
          
          }
$top_id = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_m` WHERE `t` = '".$pid."' ORDER BY `time` ASC LIMIT 1"));

mysql_query("DELETE FROM `forum_m` WHERE `id` != '".$top_id['id']."' AND `t` = '".$pid."'");
			mysql_query("INSERT INTO `forum_m`(
			`r`,
			`pr`,
			`t`,
      `author`,
      `text`,
      `time`
			)VALUES(
			'".$forum_r['id']."',
			'".$forum_pr['id']."',
			'".$id."',
			'".$user['id']."',
			'[b]Тема очищена[/b]',
			'".time()."'
			)");

 mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`,
      `sort`
			)VALUES(
      '".$forum_t['author']."',
      '".$user['id']."',
      ' очистил вашу тему [url=/forum/t".$forum_t['id']."]".$forum_t['name']."[/url]',
      '".time()."',
      '0',
      '2'
			)");
          mysql_query("INSERT INTO `adm_log`(
			`who`,
			`ho`,
			`text`,
      `time`
			)VALUES(
      '".$forum_t['author']."',
      '".$user['id']."',
      'Очистил тему на форуме [url=/forum/t".$forum_t['id']."]".$forum_t['name']."[/url] пользователя',
      '".time()."'
			)");


          header('Location: /forum/t'.$id.'/p'.$p.'');
          
          }
          
 /////////////Очистка темы//////////
////////////// голосование за пост //////////
          if(isset($_GET['v']))
          {
  
  
          $pid = TextGuard($_GET['pid']);

          $go = TextGuard($_GET['go']);
          
          $forum_v = mysql_fetch_array(mysql_query('select * from `forum_v` where `t` = "'.$id.'" and `m` = "'.$pid.'" and `who` = "'.$user['id'].'"  limit 1'));

          if(empty($pid) or !is_numeric($pid) or empty($go) or $go != "p" && $go != "m" or $forum_v != 0)
          {
  
          header('Location: ?'); exit;
          
          }

          if($go == "p") $status = 1; elseif($go == "m") $status = 2;

          $forum_m = mysql_fetch_array(mysql_query('select * from `forum_m` where `id` = "'.$pid.'"'));

          if($forum_m == 0 or $forum_m['author'] == $user['id'])
          {
          
          header('Location: ?'); exit;
  
          }

          $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$forum_m['t'].'"'));

          if($forum_t == 0)
          {
  
          header('Location: ?'); exit;
  
          }
            $forum_vss = mysql_fetch_array(mysql_query('select * from `forum_v` where `ho` = '.$forum_m['author'].' and `who` = "'.$user['id'].'" ORDER BY `id` DESC limit 1'));
  if((time()-$forum_vss['time']) < ((60*60)*12)){ $err[] = 'Рейтинг можно изменять раз в сутки!';
  }else{
          mysql_query("INSERT INTO `forum_v`(
			
          `t`,
          
          `m`,
          
          `who`,
			
          `ho`,
			
          `time`,
			
          `status`
			
          )VALUES(
			
          '".$id."',
			
          '".$pid."',
			
          '".$user['id']."',
			
          '".$forum_m['author']."',
			
          '".time()."',
			
          '".$status."'
			
          )");

  $forum_m_author = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$forum_m['author'].'"'));
  if($forum_m_author != 0){
  
  if($status == 1){
  
  mysql_query("UPDATE `user` SET `rating`='".($forum_m_author['rating']+0.01)."' WHERE `id`='".$forum_m_author['id']."' limit 1");
  
    	 mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`,
      `sort`
			)VALUES(
      '".$forum_m_author['id']."',
      '".$user['id']."',
      'оценил [b]положительно[/b] ваш пост:[br]".$forum_m['text']." в теме [url=/forum/t".$forum_m['t']."]".$forum_t['name']."[/url]!',
      '".time()."',
      '0',
      '2'
			)");

  }elseif($status == 2){

  mysql_query("UPDATE `user` SET `rating`='".($forum_m_author['rating']-0.01)."' WHERE `id`='".$forum_m_author['id']."' limit 1");
  
    	 mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`,
      `sort`
			)VALUES(
      '".$forum_m_author['id']."',
      '".$user['id']."',
      'оценил [b]отрицательно[/b] ваш пост:[br]".$forum_m['text']." в теме [url=/forum/t".$forum_m['t']."]".$forum_t['name']."[/url]!',
      '".time()."',
      '0','2'
			)");

  }
  
  }
  }
  }
//////////// конец голосования за пост ///////////// 
/////////посты .//////
  
  if($ca > 0)
  {
  
  $forum_m = mysql_query("SELECT * FROM `forum_m` WHERE `t`='".$id."' ORDER BY `id` LIMIT $start,$cop");
  while($forum_m2 = mysql_fetch_assoc($forum_m))
  {
  
  echo '<div class="post1"><table cellpadding="0" cellspacing="4"><tr><td style="width: 40px; vertical-align: top; height: 40px; margin: 0; padding:0; border: 0;" id="mail_avatar">'; 
if (file_exists($_SERVER['DOCUMENT_ROOT'].'/modules/profile/ava/'.$forum_m2['author'].'.jpg')) {
echo '<img src="/modules/profile/ava/'.$forum_m2['author'].'.jpg" alt="Ava" width="40" height="35">';
}
else
{
echo '<img src="/modules/profile/images/noava.png" alt="Ava" style="max-width:40px;">';
}
echo '</td><td style="vertical-align: top;" id="mail_textarea">'.ustatus($forum_m2['author']).' <a href="/us'.$forum_m2['author'].'">'.uname($forum_m2['author']).'</a> '.uaccess($forum_m2['author']).''.ced($forum_m2['author']).'';
  
  if($forum_t['author'] == $forum_m2['author']) echo '<font color="green"><b>[автор]</b></font> ';
  echo '<font color="grey">('.times($forum_m2['time']).')</font>';
  
  if($forum_t['status'] != 1){
  if($forum_m2['del2'] != 1){
  if($forum_m2['author'] == $user['id'] or $user['status'] >= 1) echo ' [<a href="/forum/edit'.$forum_m2['id'].'">ред</a>] ';
  if($forum_m2['author'] != $user['id']) echo ' [<a href="/forum/t'.$id.'/otv'.$forum_m2['author'].'">отв</a>] [<a href="/forum/cit'.$forum_m2['id'].'">цит</a>]';
  if($user['status'] >= 1) echo ' [<a href="/forum/t'.$id.'/p'.$p.'?dp&amp;pid='.$forum_m2['id'].'">уд</a>]';
  }
  }
  
  if($forum_t['status'] == 0){
  if($forum_m2['author'] != $user['id']){
  $forum_vs = mysql_fetch_array(mysql_query('select * from `forum_v` where `t` = "'.$id.'" and `m` = "'.$forum_m2['id'].'" and `who` = "'.$user['id'].'"  limit 1'));
  $forum_vss = mysql_fetch_array(mysql_query('select * from `forum_v` where `ho` = '.$forum_m2['author'].' and `who` = "'.$user['id'].'" ORDER BY `id` DESC limit 1'));
  
  if((time()-$forum_vss['time']) < ((60*60)*12)){ 
  echo '';
  }else{
  if($forum_vs == 0) echo ' <a href="/forum/t'.$id.'?v&amp;pid='.$forum_m2['id'].'&amp;go=p&amp;p='.$p.'">+</a> | <a href="/forum/t'.$id.'?v&amp;pid='.$forum_m2['id'].'&amp;go=m&amp;p='.$p.'">-</a>';
  }}}
  
  echo ' (<font color="green">'.mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_v` WHERE `t` = '".$id."' and `m` = '".$forum_m2['id']."' and `status` = '1'"),0).'</font>/<font color="red">'.mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_v` WHERE `t` = '".$id."' and `m` = '".$forum_m2['id']."' and `status` = '2'"),0).'</font>)<br></td></tr></table>';

/////////посты .//////
/////////// цитаты в сообщении //////////

  if(!empty($forum_m2['cit'])){
  $cit = mysql_fetch_array(mysql_query('select * from `forum_m` where `id` = "'.$forum_m2['cit'].'"'));
  $cit_author = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$cit['author'].'"'));
  echo 'Цитата <a href="/us'.$cit_author['id'].'">'.uname($cit_author['id']).'</a>:<br><div class="cit">'.smiles(bbcode($cit['text'])).'</div>';
  }
  
/////////////// конец цитаты в теме /////////////
   
  echo ''.$post_i++.'. '.smiles(bbcode($forum_m2['text'])).'';
  if(!empty($forum_m2['file'])) echo '<br><b>Прикрепленный файл: <a href="/modules/forum/files/'.$forum_m2['file'].'">'.$forum_m2['file'].'</a> ('.round(filesize('files/'.$forum_m2['file'].'')/1024).' кб)</b>';

//////////посл ред//////////////

   if($forum_m2['del2'] != 1){
   $poste = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_post_edit` where `post` = '".$forum_m2['id']."'"), 0);
   if($poste!=0)
  {
   $postee = mysql_query('select * from `forum_post_edit` where `post` = "'.$forum_m2['id'].'" order by `time` desc limit 1');
   while($poste2 = mysql_fetch_array($postee))
  {
  
echo '<br/>____________________________<br/>Редактировано '.$poste.' раз. Посл. ред. '.ustatus($poste2['user']).' <a href="/us'.$poste2['user'].'">'.uname($poste2['user']).'</a> '.uaccess($poste2['user']).'<i> '.times($poste2['time']).'</i>';
 }}}



  echo '<br/>';

echo '<br/><b>Статус:</b> '.grad_status($forum_m2['author']).'';

 
  
echo '</div>';
  }
  }
  
  //////////////посл ред/////////////
  
  if($forum_t['status'] != 1){
  
  if(isset($_POST['text'])){
  
  $text = TextGuard($_POST['text']);
    
  if(empty($text)) $err[] = 'Сообщение осталось пустым...';
  
  $myfm = mysql_query("SELECT * FROM `forum_m` WHERE `author`='".$user['id']."' ORDER BY `time` desc");
  while($myfm2 = mysql_fetch_assoc($myfm)){  
  $myfm_timeout = $myfm2['time'];
  
    if((time()-$myfm_timeout) < 5) $err[] = 'Писать можно только раз в 5 секунд...';
  }

  $forum_rep = mysql_fetch_array(mysql_query('select * from `forum_m` where `author` = "'.$user['id'].'" and `t` = "'.$id.'" and `text` = "'.$text.'"'));
  
 
  
/////////загрузка файла .//////
  if($user['file'] == 1){
  if(@file_exists($_FILES['filename']['tmp_name'])){
  if($_FILES['filename']['size'] != 0 and $_FILES['filename']['size'] > 1024000) $err[] = 'Слишком большой файл...';
  
  $filetype = array ( 'jpg', 'gif', 'png', 'jpeg', 'bmp', 'zip', 'rar', '7z', 'txt', 'mp3', 'avi', 'mp4', '3gp' );
  $upfiletype = substr($_FILES['filename']['name'],  strrpos( $_FILES['filename']['name'], "." )+1);  
  
  if(!in_array($upfiletype,$filetype)) $err[] = 'Вы пытаетесь загрузить недопустимый формат файла...';
  
  }}
  /////////загрузка файла .//////
  if(!$err){
	
	if($user['file'] == 1){
	if(@file_exists($_FILES['filename']['tmp_name'])) $fn = date('dmY').'_fn'.rand(1234,5678).'_'.$_FILES['filename']['name']; else $fn = NULL;
	if(@file_exists($_FILES['filename']['tmp_name'])){  
  move_uploaded_file($_FILES['filename']['tmp_name'], "files/".$fn."");
  }}
  
			mysql_query("INSERT INTO `forum_m`(
			`r`,
			`pr`,
			`t`,
      `author`,
      `text`,
      `time`,
      `file`
			)VALUES(
			'".$forum_r['id']."',
			'".$forum_pr['id']."',
			'".$id."',
			'".$user['id']."',
			'".$text."',
			'".time()."',
			'".$fn."'
			)");

  mysql_query("UPDATE `forum_t` SET `last`='".$user['id']."',`ltime`='".time()."' WHERE `id`='".$id."' limit 1");

  $forum_rss = mysql_query("SELECT * FROM `forum_rss` WHERE `t`='".$id."'");
  while($forum_rss2 = mysql_fetch_assoc($forum_rss)){
    	
    	if($forum_rss2['who'] != $user['id']){
    	 mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`,
      'sort'
			)VALUES(
      '".$forum_rss2['who']."',
      '".$user['id']."',
      'ответил в теме [url=/forum/t".$id."/p".$p."]".$forum_t['name']."[/url]!',
      '".time()."',
      '0',
      '3'
			)");
  }
  }
  
  header('Location: /forum/t'.$id.'/p'.$p.''); exit;
  
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  
  }
 if($user['id']) $on_page = $user['on_page']; else $on_page = 10;

  echo '<div class="glav"><form action="/forum/t'.$id.'/p'.$p.'" method="post" enctype="multipart/form-data">
  Сообщение: [<a href="#">Обн.</a>]<br/>
  <textarea name="text" rows="3" style="width:98%;"></textarea><br>';
  if($user['file'] == 1) echo 'Файл:<br><input type="file" name="filename"/><br>';
  echo '<input type="submit" value="Написать"/> <a href="/smiles.php" >Смайлы</a> | <a href="/bbcode.php">BB-коды</a> | Файл: <a href="/forum/t'.$id.'/p'.$p.'?file">';
  if($user['file'] == 0) echo 'вкл'; elseif($user['file'] == 1) echo 'выкл';
  echo '</a></form></div>';

  if(isset($_GET['file'])){
  
  if($user['file'] == 0) $file = 1; else $file = 0;
    mysql_query("UPDATE `user` SET `file`='".$file."' WHERE `id`='".$user['id']."' limit 1");
  header('Location: /forum/t'.$id.'/p'.$p.''); exit;
  
  }


 
  }



  echo '<div class="spis">Стр. ';
  if($p-2>0) echo '<a href="/forum/t'.$id.'/p1"><<</a> ';
  if($p-1>0) echo '<a href="/forum/t'.$id.'/p'.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/forum/t'.$id.'/p'.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/forum/t'.$id.'/p'.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/forum/t'.$id.'/p'.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/forum/t'.$id.'/p'.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/forum/t'.$id.'/p'.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/forum/t'.$id.'/p'.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/forum/t'.$id.'/p'.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/forum/t'.$id.'/p'.ceil($ca/$cop).'">>></a>';
  
  $link = 't'.$id.'';
  
  echo '</div><div class="post2">';
  
    
          echo 'В теме: <a href="/forum/t'.$id.'/who">'.mysql_result(mysql_query('select count(`id`) from `user` where `self` LIKE "%'.$link.'%" and `online` > "'.(time()-360).'"'),0).' человек</a>, <a href="/forum/t'.$id.'/vis">'.mysql_result(mysql_query('select count(`id`) from `forum_visit` where `t` = "'.$id.'"'),0).'</a> заходили<br>
          
          
          
          <img src="/modules/forum/images/download.png"/> <a href="/forum/?m=txt&amp;id='.$id.'">Скачать тему</a> | <img src="/modules/forum/images/files.png"/> <a href="/forum/t'.$id.'/files">Файлы топика</a></div>';
  echo '</div></div>';
  break;
  /////////тема .//////
  /////////изминение темы .//////
  case 'ted':
  $_title = 'Редактировать';
          include '../../system/header.php';

  if($user['status'] < 1){
  header('Location: /forum'); exit;
  }

  $id = TextGuard($_GET['id']);
  $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$id.'" limit 1'));

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_t['r'].'" limit 1'));

  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$forum_t['pr'].'" limit 1'));

  if(empty($id) or !is_numeric($id) or $forum_t == 0 or $forum_r == 0 or $forum_pr == 0){
  header('Location: /forum'); exit;
  }

  	  
         echo ' <div class="tegi"><a href="/forum" ><b>Форум</a> | <a href="/forum/r'.$forum_pr['r'].'" >'.$forum_r['name'].'</a> | <a href="/forum/pr'.$forum_pr['id'].'" >'.$forum_pr['name'].'</a> | '.$forum_t['name'].'</b></div></div>';
         echo '</div>';	  
	
  if(isset($_POST['submit'])){

  $text  = TextGuard($_POST['text']);
  if(empty($text)) $err[] = 'Название осталось пустым...';

  $r  = TextGuard($_POST['r']);

  $pr  = TextGuard($_POST['pr']);

  if(!$err){
  
  if($r != $forum_r['id'] || $pr != $forum_pr['id']){

  $forum_r2 = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$r.'" limit 1'));
  $forum_pr2 = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$pr.'" limit 1'));

  		mysql_query("INSERT INTO `forum_m`(
			`r`,
			`pr`,
			`t`,
      `author`,
      `text`,
      `time`,
      `file`
			)VALUES(
			'".$forum_r['id']."',
			'".$forum_pr['id']."',
			'".$id."',
			'".$user['id']."',
			'Тема перенесена в [b]".$forum_r2['name']."[/b]/[b]".$forum_pr2['name']."[/b]!',
			'".time()."',
			'".$fn."'
			)");

  }

  mysql_query("UPDATE `forum_t` SET `name`='".$text."',`r`='".$r."',`pr`='".$pr."' WHERE `id` = '".$id."' limit 1");
  header('Location: /forum/t'.$id.''); exit;
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  }

  echo '<div class="mist">
  <form action="" method="post">
  Название:<br><input name="text" value="'.$forum_t['name'].'"/><br>
  Перенести в:<br><select name="r">';
  
  $t_forum_r = mysql_query('select * from `forum_r`');
  while($t_forum_r2 = mysql_fetch_array($t_forum_r)){
  echo '<option type="checkbox" value="'.$t_forum_r2['id'].'">'.$t_forum_r2['name'].'</option>';
  }
  
  echo '</select> <br/> <select name="pr">';

  $t_forum_pr = mysql_query('select * from `forum_pr`');
  while($t_forum_pr2 = mysql_fetch_array($t_forum_pr)){
  echo '<option type="checked" value="'.$t_forum_pr2['id'].'"'; if($t_forum_pr2['id'] == ''.$t_forum_pr2['id'].'') echo 'selected';  
echo '>'.$t_forum_pr2['name'].'</option>';
  }


  echo '</select><br><input type="submit" value="Сохранить" name="submit"/>
  </form></div>';
    
  break;
  /////////изминение темы .//////
 
  /////////удаление темы .//////
  case 'tdel':
  if($user['status'] < 1){
  header('Location: /forum'); exit;
  }

  $id = TextGuard($_GET['id']);
  $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$id.'" limit 1'));

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_t['r'].'" limit 1'));

  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$forum_t['pr'].'" limit 1'));

  if(empty($id) or !is_numeric($id) or $forum_t == 0 or $forum_r == 0 or $forum_pr == 0){
  header('Location: /forum'); exit;
  }

  $forum_m = mysql_query('select * from `forum_m` where `t` = "'.$id.'"');
  while($forum_m2 = mysql_fetch_array($forum_m)){
  mysql_query("DELETE FROM `forum_m` WHERE `id` = '".$forum_m2['id']."'");
  }

  mysql_query("DELETE FROM `forum_t` WHERE `id` = '$id'");

  header('Location: /forum'); exit;
  break;
  case 'status':
  
  $id = TextGuard($_GET['id']);
  
  if(empty($id) or !is_numeric($id)){
  header('Location: ?'); exit;
  }

  $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$id.'"'));

  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$forum_t['pr'].'"'));

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_pr['r'].'"'));
  
   if($user['status'] < 1){
  header('Location: /forum/t'.$id.'/p'.ceil(($forum_m+1)/10).''); exit;
  }
  
  if($forum_t == 0 or $forum_pr == 0 or $forum_r == 0){
  header('Location: ?'); exit;
  }

if($forum_t['status'] == 0){
  $status = 1;
  $text_s = 'Закрыл';
  }else{
  $status = 0;
  $text_s = 'Открыл';  
  }

  if($forum_t['status'] == 0){
  $status = 1;
  $status_text = 'Тема закрыта';
  }else{
  $status = 0;
  $status_text = 'Тема открыта';  
  }
  mysql_query("UPDATE `forum_t` SET `status`='".$status."' WHERE `id`='".$id."' limit 1");

			mysql_query("INSERT INTO `forum_m`(
			`r`,
			`pr`,
			`t`,
      `author`,
      `text`,
      `time`
			)VALUES(
			'".$forum_r['id']."',
			'".$forum_pr['id']."',
			'".$id."',
			'".$user['id']."',
			'[b]".$status_text."[/b]',
			'".time()."'
			)");



  mysql_query("INSERT INTO `adm_log`(
			`who`,
			`ho`,
			`text`,
      `time`
			)VALUES(
      '".$forum_t['author']."',
      '".$user['id']."',
      '".$text_s." тему на форуме [url=/forum/t".$forum_t['id']."]".$forum_t['name']."[/url]',
      '".time()."'
			)");

  mysql_query("UPDATE `forum_t` SET `last`='".$user['id']."',`ltime`='".time()."' WHERE `id`='".$id."' limit 1");


  $forum_m = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_m` WHERE `t`='".$id."'"),0);

  header('Location: /forum/t'.$id.'/p'.ceil(($forum_m+1)/10).''); exit;
  
  break;
  /////////удаление темы .//////
  /////////кто в теме .//////
  case 'who':
 $_title = 'Кто в теме?';
          include '../../system/header.php';
  $id = TextGuard($_GET['id']);
  
  if(empty($id) or !is_numeric($id)){
  header('Location: ?'); exit;
  }

  $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$id.'"'));

  if($forum_t == 0){
  header('Location: ?'); exit;
  }

  $link = '/forum/t'.$id.'';

  
 echo ' <div class="tegi"><b>В теме "'.$forum_t['name'].'</b></div></div>';
 echo '</div>';
 echo '<div class="start">';
 /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
 include '../../system/nvg.php';
         
  echo '<div class="post1">';
  $forum_who = mysql_query("SELECT * FROM `user` WHERE `self` LIKE '%".$link."%' and `online` > '".(time()-360)."'");
  while($forum_who2 = mysql_fetch_array($forum_who)){
  echo ''.ustatus($forum_who2['id']).' <a href="/us'.$forum_who2['id'].'">'.uname($forum_who2['id']).'</a> '.uaccess($forum_who2['id']).', ';
  }
  echo '</div><div class="spis"><a href="/forum/t'.$id.'">Назад</a></div>';
  
  break;
  /////////кто в теме .//////
  /////////кто был в теме .//////
  case 'visits':
$_title = 'Кто заходил?';
          include '../../system/header.php';
  $id = TextGuard($_GET['id']);
  
  if(empty($id) or !is_numeric($id)){
  header('Location: ?'); exit;
  }

  $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$id.'"'));

  if($forum_t == 0){
  header('Location: ?'); exit;
  }

  $in = mysql_result(mysql_query('select count(`id`) from `forum_visit` where `t` = "'.$id.'"'),0);
  
   
  echo ' <div class="tegi"><b>В тему "'.$forum_t['name'].'</b>" зашло '.$in.' человек</b></div></div>';
  echo '</div>';		  
  echo '<div class="start">';
 
         
  $cop = $user['on_page'];
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_visit` WHERE `t`='".$id."'"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  
  if($ca > 0){  
  $forum_visit = mysql_query("SELECT * FROM `forum_visit` WHERE `t`='".$id."' ORDER BY `time` desc LIMIT $start,$cop");
  while($forum_visit2 = mysql_fetch_assoc($forum_visit)){
  echo '<div class="post1">'.ustatus($forum_visit2['who']).' <a href="/us'.$forum_visit2['who'].'">'.uname($forum_visit2['who']).'</a> '.uaccess($forum_visit2['who']).' ('.times($forum_visit2['time']).')</div>';
  }}else{
  echo '';
  }

  echo '<div class="spis">Стр. ';
  if($p-2>0) echo '<a href="/forum/t'.$id.'/vis/p1"><<</a> ';
  if($p-1>0) echo '<a href="/forum/t'.$id.'/vis/p'.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/forum/t'.$id.'/vis/p'.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/forum/t'.$id.'/vis/p'.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/forum/t'.$id.'/vis/p'.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/forum/t'.$id.'/vis/p'.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/forum/t'.$id.'/vis/p'.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/forum/t'.$id.'/vis/p'.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/forum/t'.$id.'/vis/p'.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/forum/t'.$id.'/vis/p'.ceil($ca/$cop).'">>></a>';
  echo '</div><div class="levo"><a href="/forum/t'.$id.'">Назад</a></div>';

  break;
  /////////кто был в теме .//////

  /////////ответить .//////
  case 'otv':
$_title = 'Ответить';
          include '../../system/header.php';
  if(!$user['id']){
  header('Location: ?'); exit;
  }

  $id = TextGuard($_GET['id']);

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

$user_otv = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$otv.'" limit 1'));
$forum_12 = mysql_fetch_array(mysql_query('select * from `forum_m` where `id` = "'.$id.'"'));
  $forum_otv = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$forum_12['t'].'"'));
  
  
  

  if(empty($id) or !is_numeric($id)){
  header('Location: ?'); exit;
  }

$forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$id.'"'));

  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$forum_t['pr'].'"'));

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_pr['r'].'"'));

  if($forum_t == 0){
  header('Location: ?'); exit;
  }
  
  if($forum_t['status'] == 1){
  header('Location: /forum/t'.$id.''); exit;
  }
  
  $otv2 = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$otv.'"'));

  $nicks = mysql_query("SELECT * FROM `nicks` where `who` = '".$otv2."' ORDER BY `id` DESC LIMIT 1");
  while($nicks2 = mysql_fetch_assoc($nicks)){
  
  $nick = $nicks2['new'];
  
  }
  
  if(empty($nick)) $nick = ''.$otv2['id'].'';

         
        echo ' <div class="tegi"><b><a href="?m=r&amp;id='.$forum_pr['r'].'"  >'.$forum_r['name'].'</a> | <a href="?m=pr&amp;id='.$forum_pr['id'].'"  >'.$forum_pr['name'].'</a> | <a href="?m=t&amp;id='.$forum_t['id'].'"  >'.$forum_t['name'].'</a></b></div></div>';
        echo '</div>';
		  



  if(isset($_POST['text'])){
  
  $text = TextGuard($_POST['text']);
  
  
  if(empty($text)) $err[] = 'Сообщение осталось пустым';

  $myfm = mysql_query("SELECT * FROM `forum_m` WHERE `author`='".$user['id']."' ORDER BY `time` desc");
  while($myfm2 = mysql_fetch_assoc($myfm)){  
  $myfm_timeout = $myfm2['time'];
  
    if((time()-$myfm_timeout) < 10) $err[] = 'Писать можно только раз в 10 секунд';

  }

  $forum_rep = mysql_fetch_array(mysql_query('select * from `forum_m` where `author` = "'.$user['id'].'" and `t` = "'.$id.'" and `text` = "'.$text.'"'));
  
 

/////////файлы .//////
  if(@file_exists($_FILES['filename']['tmp_name'])){
  if($_FILES['filename']['size'] != 0 and $_FILES['filename']['size'] > 1024000) $err[] = 'Слишком большой файл...';
  
  $filetype = array ( 'jpg', 'gif', 'png', 'jpeg', 'bmp', 'zip', 'rar', '7z', 'txt' );
  $upfiletype = substr($_FILES['filename']['name'],  strrpos( $_FILES['filename']['name'], "." )+1);  
  
  if(!in_array($upfiletype,$filetype)) $err[] = 'Вы пытаетесь загрузить недопустимый формат файла';
  
  }
  /////////файлы .//////
  if(!$err){

	if(@file_exists($_FILES['filename']['tmp_name'])) $fn = date('dmY').'_fn'.rand(1234,5678).'_'.$_FILES['filename']['name']; else $fn = NULL;
	if(@file_exists($_FILES['filename']['tmp_name'])){  
  move_uploaded_file($_FILES['filename']['tmp_name'], "files/".$fn."");
  }

			 mysql_query("INSERT INTO `forum_m`(
			`r`,
			`pr`,
			`t`,
      `author`,
      `text`,
      `time`,
      `file`
			)VALUES(
			'".$forum_r['id']."',
			'".$forum_pr['id']."',
			'".$id."',
			'".$user['id']."',
			'[b]".$user_otv['login']."[/b], ".$text."',
			'".time()."',
			'".$fn."'
			)");

  mysql_query("UPDATE `forum_t` SET `last`='".$user['id']."',`ltime`='".time()."' WHERE `id`='".$id."' limit 1");

  $forum_m = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_m` WHERE `t`='".$id."'"),0);


  		mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`,
      `sort`
			)VALUES(
      '".$otv."',
      '".$user['id']."',
      'ответил вам в теме [url=/forum/t".$id."/p".ceil(($forum_m+1)/10)."]".$forum_t['name']."[/url]!',
      '".time()."',
      '0',
      '3'
			)");
  
  header('Location: /forum/t'.$id.'/p'.ceil(($forum_m+1)/10).'');
  
    $forum_rss = mysql_query("SELECT * FROM `forum_rss` WHERE `t`='".$id."'");
  while($forum_rss2 = mysql_fetch_assoc($forum_rss)){
    	
    	if($forum_rss2['who'] != $user['id'] && $forum_rss2['who'] != $otv2['id']){
    	 mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`,
      `sort`
			)VALUES(
      '".$forum_rss2['who']."',
      '".$user['id']."',
      'ответил в теме [url=/forum/t".$forum_t['id']."/p".ceil(($forum_m+1)/10)."]".$forum_t['name']."[/url]!',
      '".time()."',
      '0',
      '3'
			)");
  }
  }
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  
  }
 $forum_m = mysql_fetch_array(mysql_query('select * from `forum_m` where `author` = "'.$user['id'].'"'));
 
  echo '<div class="post2">
  Сообщение для <a href="/us'.$otv.'">'.uname($otv).'</a>
  <form action="/forum/t'.$id.'/otv'.$otv.'?" method="post">
  <textarea name="text" style="width:80%;" rows="3"></textarea><br>
  <input type="submit" value="Написать"/> <a href="/smiles.php" >Смайлы</a> | <a href="/bbcode.php">BB-коды</a>
  </form></div>';
  
  break;
  /////////ответить .//////
  /////////цитата .//////
  case 'cit':
  $_title = 'Цитировать';
          include '../../system/header.php';
  if(!$user['id']){
  header('Location: ?'); exit;
  }

  $id = TextGuard($_GET['id']);

  if(empty($id) or !is_numeric($id)){
  header('Location: ?'); exit;
  }

  $forum_m = mysql_fetch_array(mysql_query('select * from `forum_m` where `id` = "'.$id.'"'));

  $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$forum_m['t'].'"'));

  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$forum_t['pr'].'"'));

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_pr['r'].'"'));

 if($forum_m['del2'] == 1){
 header('Location: /forum/t'.$forum_m['t'].''); exit;
 }
 
  if($forum_t == 0){
  header('Location: /forum'); exit;
  }
  
  if($forum_t['status'] == 1){
  header('Location: /forum/t'.$forum_t['id'].''); exit;
  }

  if($forum_m['author'] == $user['id']){
  header('Location: /forum/t'.$forum_t['id'].''); exit;
  }

  
  $cit2 = mysql_fetch_array(mysql_query('select * from `forum_m` where `id` = "'.$id.'" and `t` = "'.$forum_t['id'].'"'));
  if($cit2 == 0){
  header('Location: /forum/t'.$forum_t['id'].'');exit;
  }
  $cit2_author = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$cit2['author'].'" '));

  $nicks = mysql_query("SELECT * FROM `nicks` where `who` = '".$cit2_author['id']."' ORDER BY `id` DESC LIMIT 1");
  while($nicks2 = mysql_fetch_assoc($nicks)){
  
  $nick = $nicks2['new'];
  
  }
  
  if(empty($nick)) $nick = $us['login'];

       
      echo ' <div class="tegi"><b><a href="?m=r&amp;id='.$forum_pr['r'].'"  >'.$forum_r['name'].'</a> | <a href="?m=pr&amp;id='.$forum_pr['id'].'"  >'.$forum_pr['name'].'</a> | <a href="?m=t&amp;id='.$forum_t['id'].'"  >'.$forum_t['name'].'</a></b></div></div>';
      echo '</div>';	  
      echo '<div class="start">';
      /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
      include '../../system/nvg.php';
         
  echo '<div class="post1">Цитата: <a href="/us'.$cit2_author['id'].'">'.uname($cit2_author['id']).'</a>:<div class="cit">'.smiles(bbcode($cit2['text'])).'</div></div>';
  
  if(isset($_POST['text'])){
  
  $text = TextGuard($_POST['text']);
  

  
  if(empty($text)) $err[] = 'Сообщение осталось пустым...';

  $myfm = mysql_query("SELECT * FROM `forum_m` WHERE `author`='".$user['id']."' ORDER BY `time` desc");
  while($myfm2 = mysql_fetch_assoc($myfm)){  
  $myfm_timeout = $myfm2['time'];
  
    if((time()-$myfm_timeout) < 5) $err[] = 'Писать можно только раз в 5 секунд...';

  }

  $forum_rep = mysql_fetch_array(mysql_query('select * from `forum_m` where `author` = "'.$user['id'].'" and `t` = "'.$forum_t['id'].'" and `text` = "'.$text.'"'));
  
 
  /////////файл .//////
  if(@file_exists($_FILES['filename']['tmp_name'])){
  if($_FILES['filename']['size'] != 0 and $_FILES['filename']['size'] > 1024000) $err[] = 'Слишком большой файл...';
  
  $filetype = array ( 'jpg', 'gif', 'png', 'jpeg', 'bmp', 'zip', 'rar', '7z', 'txt' );
  $upfiletype = substr($_FILES['filename']['name'],  strrpos( $_FILES['filename']['name'], "." )+1);  
  
  if(!in_array($upfiletype,$filetype)) $err[] = 'Вы пытаетесь загрузить недопустимый формат файла...';
  
  }
/////////файл .//////
  if(!$err){

	if(@file_exists($_FILES['filename']['tmp_name'])) $fn = date('dmY').'_fn'.rand(1234,5678).'_'.$_FILES['filename']['name']; else $fn = NULL;
	if(@file_exists($_FILES['filename']['tmp_name'])){  
  move_uploaded_file($_FILES['filename']['tmp_name'], "files/".$fn."");
  }

			mysql_query("INSERT INTO `forum_m`(
			`r`,
			`pr`,
			`t`,
      `author`,
      `text`,
      `cit`,
      `time`,
      `file`
			)VALUES(
			'".$forum_r['id']."',
			'".$forum_pr['id']."',
			'".$forum_t['id']."',
			'".$user['id']."',
			'".$text."',
			'".$id."',
			'".time()."',
			'".$fn."'
			)");

  mysql_query("UPDATE `forum_t` SET `last`='".$user['id']."',`ltime`='".time()."' WHERE `id`='".$forum_t['id']."' limit 1");

  
  $forum_m2 = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_m` WHERE `t`='".$forum_t['id']."'"),0);

  		mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`
			)VALUES(
      '".$cit2_author['id']."',
      '".$user['id']."',
      'процитировал ваш пост:[br]".$cit2['text']." в теме [url=/forum/t".$forum_t['id']."/p".ceil(($forum_m2+1)/10)."]".$forum_t['name']."[/url]!',
      '".time()."',
      '0'
			)");


  header('Location: /forum/t'.$forum_t['id'].'/p'.ceil(($forum_m2+1)/10).'');
  

    $forum_rss = mysql_query("SELECT * FROM `forum_rss` WHERE `t`='".$id."'");
  while($forum_rss2 = mysql_fetch_assoc($forum_rss)){
    	
    	if($forum_rss2['who'] != $user['id'] && $forum_rss2['who'] != $cit2_author['id']){
    	 mysql_query("INSERT INTO `op`(
			`who`,
			`ho`,
			`text`,
      `time`,
      `read`,
      `sort`
			)VALUES(
      '".$forum_rss2['who']."',
      '".$user['id']."',
      'ответил в теме [url=/forum/t".$forum_t['id']."/p".ceil(($forum_m2+1)/10)."]".$forum_t['name']."[/url]!',
      '".time()."',
      '0',
      '3'
			)");
  }
  }  
  
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  
  }
  
  echo '<div class="post2">
  <form action="/forum/cit'.$id.'" method="post" enctype="multipart/form-data">
  Сообщение:<br><textarea name="text" style="width:98%;" rows="3"></textarea><br>
  Файл:<br><input type="file" name="filename"/><br>  
  <input type="submit" value="Написать"/> <a href="/smiles.php" >Смайлы</a> | <a href="/bbcode.php">BB-коды</a></form></div>';
  
  break;
  /////////цитата .//////
  /////////новая тема .//////
  case 'nt':
  $_title = 'Новая тема';
          include '../../system/header.php';
  $id = TextGuard($_GET['id']);
  
  if(empty($id) or !is_numeric($id)){
  header('Location: ?'); exit;
  }

  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$id.'"'));

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_pr['r'].'"'));

  if($forum_pr == 0){
  header('Location: ?'); exit;
  }

  
          echo ' <div class="tegi"><b><a href="?m=r&amp;id='.$forum_pr['r'].'"  >'.$forum_r['name'].'</a> | <a href="?m=pr&amp;id='.$forum_pr['id'].'"  >'.$forum_pr['name'].'</a></b></div></div>';
          echo '</div>';
		  
		    echo '<div class="start">';
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
         include '../../system/nvg.php';

  if(isset($_POST['submit'])){

  $name = TextGuard($_POST['name']);

  $text = TextGuard($_POST['text']);

  $myfem = mysql_query("SELECT * FROM `forum_t` WHERE `author`='".$user['id']."' ORDER BY `time` desc");
  while($myfem2 = mysql_fetch_assoc($myfem)){  
  $myfme_timeout = $myfem2['time'];
  
    if((time()-$myfme_timeout) < 5) $err[] = 'Создавать темы можно раз в 5 секунд';
  }


  
  if(empty($text)) $err[] = 'Сообщение осталось пустым';

  if(empty($name)) $err[] = 'Название темы осталовь пустым';

  if(!$err){
  
  		mysql_query("INSERT INTO `forum_t`(
			`r`,
			`pr`,
			`name`,
			`status`,
      `author`,
      `last`,
      `ltime`,
      `time`
			)VALUES(
			'".$forum_r['id']."',
			'".$forum_pr['id']."',
			'".$name."',
			'0',
			'".$user['id']."',
			'".$user['id']."',
			'".time()."',
			'".time()."'
			)");

  $tid = mysql_insert_id();

			mysql_query("INSERT INTO `forum_m`(
			`r`,
			`pr`,
			`t`,
      `author`,
      `text`,
      `time`
			)VALUES(
			'".$forum_r['id']."',
			'".$forum_pr['id']."',
			'".$tid."',
			'".$user['id']."',
			'".$text."',
			'".time()."'
			)");

			mysql_query("INSERT INTO `forum_rss`(
			`t`,
      `who`
			)VALUES(
			'".$tid."',
			'".$user['id']."'
			)");  
    
  header('Location: /forum/t'.$tid.'');
  
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  
  }

 
  echo '<div class="post2">
  <form action="?m=nt&amp;id='.$id.'" method="post">
  Тема:<br><input name="name"/><br>
  Сообщение:<br><textarea name="text" style="width:98%;" rows="3"/></textarea><br>
  
  <input type="submit" value="Добавить" name="submit"/> <a href="/smiles.php" >Смайлы</a> | <a href="/bbcode.php">BB-коды</a></form></div>';
  
  break;
  /////////новая тема .//////
  /////////ред. поста .//////
  case 'edit':
  $_title = 'Изменить';
          include '../../system/header.php';
  $id = TextGuard($_GET['id']);
  
  if(empty($id) or !is_numeric($id)){
  header('Location: /forum/'); exit;
  }

  $forum_m = mysql_fetch_array(mysql_query('select * from `forum_m` where `id` = "'.$id.'"'));
  if($forum_m == 0 or $forum_m['author'] != $user['id'] && $user['status'] < 1){
  header('Location: /forum/t'.$forum_m['t'].''); exit;
  }

  
  if($forum_m['author'] != $user['id'] || $forum_m['author'] != $user['id'] and $user['status'] < 1){
  header('Location: /forum/t'.$forum_m['t'].''); exit;
  }
  

  $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$forum_m['t'].'"'));

  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$forum_t['pr'].'"'));

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_pr['r'].'"'));
 if($forum_m['del2'] == 1){
 header('Location: /forum/t'.$forum_m['t'].''); exit;
 }
  if($forum_t == 0){
  header('Location: ?'); exit;
  }

 
          echo ' <div class="tegi"><b><a href="/forum/r'.$forum_pr['r'].'"  >'.$forum_r['name'].'</a> | <a href="/forum/pr'.$forum_pr['id'].'"  >'.$forum_pr['name'].'</a> | <a href="/forum/t'.$forum_t['id'].'"  >'.$forum_t['name'].'</a></b></div></div>';
          echo '</div>';
		  
		    echo '<div class="start">';
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
         include '../../system/nvg.php';
         
  if(isset($_POST['text'])){
  
  $text = TextGuard($_POST['text']);
    
  if(empty($text)) $err[] = 'Сообщение осталось пустым...';

  if(!$err){
  
  mysql_query("UPDATE `forum_m` SET `text`='".$text."' WHERE `id`='".$id."' limit 1");
  ///посл ред
  mysql_query("INSERT INTO `forum_post_edit`(`post`,`user`,`message`,`time`)VALUES('".$forum_m['id']."','".$user['id']."','".$text."','".time()."')");
  ///посл ред
  $forum_m = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_m` WHERE `t`='".$forum_t['id']."'"),0);
  header('Location: /forum/t'.$forum_t['id'].'/p'.ceil(($forum_m+1)/10).''); exit;
  
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }
  
  }
  
  echo '<div class="post2"><form action="" method="post">
  Сообщение:<br><textarea name="text" style="width:98%;" rows="3">'.$forum_m['text'].'</textarea><br>
  <input type="submit" value="Сохранить"/>
  </form></div>';
  
  break;
  /////////ред. поста .//////
  /////////поиск .//////
  case 'search':
  
   $_title = 'Поиск';
          include '../../system/header.php';

          echo ' <div class="tegi"><b><a href="/forum"  >Форум</a> | Поиск</b></div></div>';
          echo '</div>';
		  
		    echo '<div class="start">';
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
         include '../../system/nvg.php';

  echo '<div class="post2">
  <form action="/forum/search" method="post">
  <input name="text"/><br>
  Где искать?<br><select name="to"><option value="1">в темах</option><option value="2">в сообщениях</option></select><br>
  <input type="submit" value="Поиск" name="submit"/>
  </div>';
  
  if(isset($_POST['submit'])){
  
  echo '<div class="post2">Результаты поиска:</div>';
  
  $text = TextGuard($text);
  $to = TextGuard($to);
  
  if(strlen($text) <2) $err[] = 'Минимальная длина звпроса 2 симлова...';
  
  if(!$err){

  $cop = $user['on_page'];
  
  if($to == 1){
  
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_t` where `name` LIKE '%".$text."%'"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  $search = mysql_query("SELECT * FROM `forum_t` where `name` LIKE '%".$text."%' ORDER BY `id` DESC LIMIT $start,$cop");
  while($search2 = mysql_fetch_assoc($search)){
  
  $search2_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$search2['r'].'"'));
  $search2_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$search2['pr'].'"'));
  echo '<div class="post1"><a href="/forum/r'.$search2_r['id'].'"  >'.$search2_r['name'].'</a> | <a href="/forum/pr'.$search2_pr['id'].'"  >'.$search2_pr['name'].'</a></div><div class="post2">';
  if($search2['status'] == 0) echo '<img src="/modules/forum/images/the.png"/>';
  elseif($search2['status'] == 1) echo '<img src="/modules/forum/images/closed.png"/>';

  
  echo ' <a href="/forum/t'.$search2['id'].'">'.$search2['name'].'</a> ('.mysql_result(mysql_query('select count(`id`) from `forum_m` where `t` = "'.$search2['id'].'"'),0).') <a href="/forum/t'.$search2['id'].'/p'.ceil(((mysql_result(mysql_query('select count(`id`) from `forum_m` where `t` = "'.$search2['id'].'"'),0))+1)/10).'">></a><br>
  '.ustatus($search2['author']).' <a href="/us'.$search2['author'].'">'.uname($search2['author']).'</a>/'.ustatus($search2['last']).' <a href="/us'.$search2['last'].'">'.uname($search2['last']).'</a> ('.times($search2['ltime']).')';
  echo '</div>';
  
  }
  
  }elseif($to == 2){

  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_m` where `text` LIKE '%".$text."%'"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  $search = mysql_query("SELECT * FROM `forum_m` where `text` LIKE '%".$text."%' ORDER BY `id` DESC LIMIT $start,$cop");
  while($search2 = mysql_fetch_assoc($search)){
  
  $search2_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$search2['r'].'"'));
  $search2_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$search2['pr'].'"'));
  $search2_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$search2['t'].'"'));

  echo '<div class="tegi"><a href="/forum/r'.$search2_r['id'].'"  >'.$search2_r['name'].'</a> | <a href="/forum/pr'.$search2_pr['id'].'"  >'.$search2_pr['name'].'</a> | <a href="/forum/t'.$search2_t['id'].'"  >'.$search2_t['name'].'</a></div><div class="post2">'.ustatus($search2['author']).' <a href="/us'.$search2['author'].'"><b>'.uname($search2['author']).'</b></a> '.uaccess($search2['author']).' ('.times($search2['time']).')<br>';

  if(!empty($search2['cit'])){
  $cit = mysql_fetch_array(mysql_query('select * from `forum_m` where `id` = "'.$search2['cit'].'"'));
  $cit_author = mysql_fetch_array(mysql_query('select * from `user` where `id` = "'.$cit['author'].'"'));

  echo 'Цитата:<br><div class="cit"><b>'.$cit_author['login'].'</b>: '.smiles(bbcode($cit['text'])).'</div>';
  }
   
  echo ''.smiles(bbcode($search2['text'])).'
  </div>';
  }}

  if($ca == 0) echo '<div class="err" align="center"><b>По вашему запросу ничего не найдено...</b></div>';
  
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';  
  }
  
  }
  
  break;
  /////////поиск .//////
  /////////файлы в теме .//////
  case 'files':
  $_title = 'Файлы';
          include '../../system/header.php';
  $id = TextGuard($_GET['id']);
  
  if(empty($id) or !is_numeric($id)){
  header('Location: /forum'); exit;
  }

  $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$id.'"'));

  $forum_pr = mysql_fetch_array(mysql_query('select * from `forum_pr` where `id` = "'.$forum_t['pr'].'"'));

  $forum_r = mysql_fetch_array(mysql_query('select * from `forum_r` where `id` = "'.$forum_pr['r'].'"'));

  if($forum_t == 0 or $forum_pr == 0 or $forum_r == 0){
  header('Location: /forum'); exit;
  }

    $forum_rss = mysql_fetch_array(mysql_query('select * from `forum_rss` where `t` = "'.$id.'" and `who` = "'.$user['id'].'" limit 1'));

  $cop = $user['on_page'];
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_m` where `t` = '".$id."' and  `file` != ''"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p']) && $ca != 0){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  
    
          echo ' <div class="tegi"><b>В теме "'.$forum_t['name'].'" '.$ca.' файлов</b></div></div>';
          echo '</div>';
		  
		    echo '<div class="start">';
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
         include '../../system/nvg.php';
         
  if($ca != 0){
  $forum_m = mysql_query("SELECT * FROM `forum_m` where `t` = '".$id."' and `file` != '' ORDER BY `id` DESC LIMIT $start,$cop");
  while($forum_m2 = mysql_fetch_assoc($forum_m)){
  
  echo '<div class="post2">'.ustatus($forum_m2['author']).' <a href="/us'.$forum_m2['author'].'">'.uname($forum_m2['author']).'</a> '.uaccess($forum_m2['author']).' <font color="gray">('.times($forum_m2['time']).')</font><br><a href="/modules/forum/files/'.$forum_m2['file'].'">'.$forum_m2['file'].'</a> ('.round(filesize('files/'.$forum_m2['file'].'')/1024).' кб)</b></div>';
  
  }

  echo '<div class="spis">Стр. ';
  if($p-2>0) echo '<a href="/forum/t'.$id.'/files?p=1"><<</a> ';
  if($p-1>0) echo '<a href="/forum/t'.$id.'/files?p='.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/forum/t'.$id.'/files?p='.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/forum/t'.$id.'/files?p='.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/forum/t'.$id.'/files?p='.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/forum/t'.$id.'/files?p='.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/forum/t'.$id.'/files?p='.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/forum/t'.$id.'/files?p='.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/forum/t'.$id.'/files?p='.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/forum/t'.$id.'/files?p='.ceil($ca/$cop).'">>></a>';
  echo '</div>';
  
  }else{
  echo '<div class="err"><b>Файлов нет!</b></div>';
  }
  
          echo '<div class="levo"><a href="/forum/t'.$id.'">Назад</div>';
       break;
       /////////файлы темы .//////
       /////////сказали спасибо .//////
  case 'sps':
  $_title = 'Сказали спасибо';
          include '../../system/header.php';
$id = TextGuard($_GET['id']);
  
  if(empty($id) or !is_numeric($id)){
  header('Location: ?'); exit;
  }

  $forum_t = mysql_fetch_array(mysql_query('select * from `forum_t` where `id` = "'.$id.'"'));

  if($forum_t == 0){
  header('Location: ?'); exit;
  }

  $in = mysql_result(mysql_query('select count(`id`) from `forum_t_thnx` where `t` = "'.$id.'"'),0);

 
          echo ' <div class="tegi"><b>Сказали спасибо '.$in.' человек</b></div></div>';
          echo '</div>';
		  
		    echo '<div class="start">';
		  /////////////////////////////////////////////////		 

//////////////////////////////////////////////////////
         include '../../system/nvg.php';

  $cop = $user['on_page'];
  $ca = mysql_result(mysql_query("SELECT COUNT(*) FROM `forum_t_thnx` WHERE `t`='".$id."'"),0);
  $cp = ceil($ca/$cop);
  if(isset($_GET['p']) && is_numeric($_GET['p'])){
  $p = $_GET['p'];
  if($_GET['p']>$cp) $p = $cp;
  if($_GET['p']<1)$p = 1;
  }else{
  $p = 1;
  }
  $start = $p*$cop-$cop;
  
  if($ca > 0){  
  $tht = mysql_query("SELECT * FROM `forum_t_thnx` WHERE `t`='".$id."' ORDER BY `time` desc LIMIT $start,$cop");
  while($txt2 = mysql_fetch_assoc($tht)){
  echo '<div class="post2">'.ustatus($txt2['user']).' <a href="/us'.$txt2['user'].'">'.uname($txt2['user']).'</a> '.uaccess($txt2['user']).' ('.times($txt2['time']).')</div>';
  }}else{
  echo '';
  }

  echo '<div class="spis">Стр. ';
  if($p-2>0) echo '<a href="/forum/t'.$id.'/sps/p1"><<</a> ';
  if($p-1>0) echo '<a href="/forum/t'.$id.'/sps/p'.($p-1).'"><</a> ';

  if($p-3>0) echo '<a href="/forum/t'.$id.'/sps/p'.($p-3).'">'.($p-3).'</a> | ';
  if($p-2>0) echo '<a href="/forum/t'.$id.'/sps/p'.($p-2).'">'.($p-2).'</a> | ';  
  if($p-1>0) echo '<a href="/forum/t'.$id.'/sps/p'.($p-1).'">'.($p-1).'</a> | ';
  
  echo '<b>'.$p.'</b>';
  if($p+1<=$cp) echo ' | <a href="/forum/t'.$id.'/sps/p'.($p+1).'">'.($p+1).'</a>';
  if($p+2<=$cp) echo ' | <a href="/forum/t'.$id.'/sps/p'.($p+2).'">'.($p+2).'</a>';
  if($p+3<=$cp) echo ' | <a href="/forum/t'.$id.'/sps/p'.($p+3).'">'.($p+3).'</a>';

  if($p+1<=$cp) echo ' <a href="/forum/t'.$id.'/sps/p'.($p+1).'">></a>';
  if($p+2<=$cp) echo ' <a href="/forum/t'.$id.'/sps/p'.ceil($ca/$cop).'">>></a>';
  echo '</div><div class="levo"><a href="/forum/t'.$id.'">Назад</a></div>';
          break;  
    /////////сказали спасибо .//////
          
          }

          include '../../system/footer.php';

?>