<?php

error_reporting(0);
            
          session_start();
            
          ob_start();

            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
          $mysql_connect = mysql_connect('localhost','nra654_pds','77777dd') or die("Ошибка");
            
          mysql_select_db('nra654_pds',$mysql_connect) or die("Ошибка");
            
          mysql_query("SET NAMES utf8");

            
            
            
          define('home', $_SERVER['DOCUMENT_ROOT']);









    
          foreach($_GET as $check_url)
          {
           
          if(!is_string($check_url) or !preg_match('#^(?:[a-z0-9_\-/]+|\.+(?!/))*$#i', $check_url))
          {

          header ('Location: '.home.'/index.php'); exit;
            
          }
            
          } unset($check_url);
  
          
            
            
            
            
            
            
            
            
           if(isset($_COOKIE['ulogin']) && isset($_COOKIE['upassword']))
           {
            
           $ulogin = trim(htmlspecialchars(mysql_escape_string($_COOKIE['ulogin'])));
	
           $upassword = trim(htmlspecialchars(mysql_escape_string($_COOKIE['upassword'])));
	

           if(empty($ulogin) or empty($upassword))
           {
  
           setcookie('ulogin', '', time()-((60*60)*24), '/');
            
           setcookie('upassword', '', time()-((60*60)*24), '/');
	
           }
  
            
            
           $user = mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `login` = '".$ulogin."' and `password`='".$upassword."' LIMIT 1"));
            
           mysql_query("UPDATE `user` SET `online`='".time()."',`ip`='".$_SERVER['REMOTE_ADDR']."',`ua`='".$_SERVER['HTTP_USER_AGENT']."',`self`='".$_SERVER['REQUEST_URI']."' WHERE `id`='".$user['id']."'");


$timeactiv=time() - $user['online'];
if($timeactiv < 120)
{
$newtimeactiv=$user['allonline']+$timeactiv;
mysql_query("UPDATE `user` SET `allonline` ='".$newtimeactiv."'  WHERE `id`='".$user['id']."'");
}

           if(isset($user['id']) && $user['login']!=$ulogin or $user['password']!=$upassword)
           {
  
           setcookie('ulogin', '', time()-((60*60)*24), '/');
            
           setcookie('upassword', '', time()-((60*60)*24), '/');
 
           }
  
           }
      

          
          
          
          
          include 'functions.php';
          
          
          
          
          
          define('standart_css', 'blue_4ika');

          
  
          if($user['id'])
          {

          $ban = mysql_fetch_assoc(mysql_query("SELECT * FROM `ban` WHERE `who` = '".$user['id']."'"));
  
          if($ban['end'] > time())
          {
  
          
          include 'header.php';
  

  
echo '<div class="verh"><font color="red"><b>Вы забанены!</b></font></div><div class="lst">

          Вас забанил: '.ustatus($ban['ho']).' <b>'.uname($ban['ho']).'</b> '.uaccess($ban['ho']).'<br>
          
          Причины: <b>'.smiles(bbcode($ban['why'])).'</b><br>

          Дата бана: <b>'.times($ban['time']).'</b><br>
  
          Дата освобождения: <b>'.date('d.m.Y в H:i',$ban['end']).'</b>
  
          </div>';
  if(isset($_POST['submit'])){

  $text = TextGuard($_POST['text']);
  if(empty($text)) $err[] = 'Сообщение осталось пустым';
  
  ////////////////////////
   $ncm = mysql_query("SELECT * FROM `polcha` WHERE `who`='".$user['id']."' ORDER BY `time` desc");
  while($ncm2 = mysql_fetch_assoc($ncm)){  
  $ncm_timeout = $ncm2['time'];
  
    if((time()-$ncm_timeout) < 5) $err[] = 'Писать можно только раз в 5 секунд';

  } 
 
    
  $ncm_rep = mysql_fetch_array(mysql_query('select * from `polcha` where `who` = "'.$user['id'].'" and `text` = "'.$text.'"'));
  
  if($ncm_rep != 0) $err[] = 'Вы уже писали подобное сообщение';
  ////////////////////

  if(!$err){

  		mysql_query("INSERT INTO `polcha`(
			`who`,`ho`,`text`,`type`,`time`
			)VALUES(
			'".$user['id']."','','".$text."','0','".time()."'
			)");

  header('Location: ?'); exit;
  
  }else{
  echo '<div class="pet"><b>';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</b></div>';
  }
  
  }
///////////////////////
  echo '<div class="mist">
  <form action="" method="post">
  Сообщение (<a href="/polcha">обн</a>):<br>
  <textarea name="text" style="width:98%;" rows="3"></textarea>
   <input type="submit" value="Написать" name="submit"/> <a href="/smiles.php">Смайлы</a> | <a href="/bbcode.php">BB-коды</a>
  </form></div>';
  
  
  $a_chat = mysql_query("SELECT * FROM `polcha` ORDER BY `id` DESC LIMIT 6");
  while($_a_chat = mysql_fetch_assoc($a_chat)){
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/'.$_a_chat['who'].'.jpg')) {
echo '<img src="/modules/profile/ava/'.$_a_chat['who'].'.jpg" alt="Ava" style="max-width:40px;">';
}
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($_a_chat['who']).' <a href="/us'.$_a_chat['who'].'">'.uname($_a_chat['who']).'</a>
  '.uaccess($_a_chat['who']).'<br/>';
 echo ''.bbcode(smiles($_a_chat['text'])).'';
  echo '</td></tr></table></div>';
  mysql_query("UPDATE `op` SET `read`='1' WHERE `id`='".$op2['id']."' limit 1");
  }
 
         $users = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `user`"), 0);
                   $users_new = mysql_result(mysql_query('select count(`id`) from `user` where `registration` > "'.(time()-((60*60)*24)).'"'),0);  
          $news = mysql_result(mysql_query('select count(`id`) from `news`'),0);
          $users_online = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `user` WHERE `online`>'".(time()-180)."'"), 0);      
          /////Счетчики//////
 echo '</b></b><div class="tegi"><span style="color: #fff;">Онлайн: <a href="/online.php" style="color:white;">'.$users_online.'</a> из <a href="/users.php" style="color:white;">'.$users.'</a></span><br />';
////
  echo '<b>Последний: </b><span style="color: #fff;">';
 $last = mysql_query("SELECT * FROM `user` ORDER BY `registration` DESC LIMIT 1");
          while($last2 = mysql_fetch_assoc($last))
          {
          
          echo ustatus($last2['id']).' <a href="/us'.$last2['id'].'">'.uname($last2['id']).' '.uaccess($last2['id']).'</span></a>';  
          }

echo '</br>';
///////
echo '<b>Ген.</b> ';
list($msec,$sec)=explode(chr(32),microtime());

          echo ' '.round((($sec+$msec)-$gtime),4).' сек.</div>';

exit;
  
          
          
          }
  



          
          $reg = mysql_fetch_assoc(mysql_query("SELECT * FROM `reg` WHERE `who` = '".$user['id']."' LIMIT 1"));
    
          if($reg!=0)
          {

          if($reg['ok'] == 0)
          {
  
          include 'header.php';
  
  
          echo '<div class="post1">
          <font color="red"><b>Ваш аккаунт не активирован!</b></font>
          </div>';

             echo '<div class="levo"><img src="/images/homepage.gif"/> <a href="/index.php">На главную</a></div></div>';
          /////Счетчики//////
          $users = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `user`"), 0);
	  $pc = mysql_result(mysql_query('select count(`id`) from `pc_code` where `status` = "0"'),0);
	  $pc_new = mysql_result(mysql_query('select count(`id`) from `pc_code` where `time` > "'.(time()-((60*60)*24)).'"'),0);
	  
          $users_new = mysql_result(mysql_query('select count(`id`) from `user` where `registration` > "'.(time()-((60*60)*24)).'"'),0);  
          $news = mysql_result(mysql_query('select count(`id`) from `news`'),0);
          $users_online = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `user` WHERE `online`>'".(time()-180)."'"), 0);      
          /////Счетчики//////
 echo '</b></b><div class="tegi"><span style="color: #fff;">Онлайн: <a href="/online.php" style="color:white;">'.$users_online.'</a> из <a href="/users.php" style="color:white;">'.$users.'</a></span><br />';
////
  echo '<b>Последний: </b><span style="color: #fff;">';
 $last = mysql_query("SELECT * FROM `user` ORDER BY `registration` DESC LIMIT 1");
          while($last2 = mysql_fetch_assoc($last))
          {
          
          echo ustatus($last2['id']).' <a href="/us'.$last2['id'].'">'.uname($last2['id']).' '.uaccess($last2['id']).'</span></a>';  
          }

echo '</br>';
///////
echo '<b>Ген.</b> ';
list($msec,$sec)=explode(chr(32),microtime());

          echo ' '.round((($sec+$msec)-$gtime),4).' сек.</div>';
exit;
  
          
          }elseif($reg['ok'] == 2)
          {
  
          
          include 'header.php';
          

          echo '<div class="post1">
          <font color="red"><b>Вы не были допущены на сайт!</b></font>
          </div>';

          echo '<div class="levo"><img src="/images/homepage.gif"/> <a href="/index.php">На главную</a></div></div>';
          /////Счетчики//////
          $users = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `user`"), 0);
	  $pc = mysql_result(mysql_query('select count(`id`) from `pc_code` where `s:tatus` = "0"'),0);
	  $pc_new = mysql_result(mysql_query('select count(`id`) from `pc_code` where `time` > "'.(time()-((60*60)*24)).'"'),0);
	  
          $users_new = mysql_result(mysql_query('select count(`id`) from `user` where `registration` > "'.(time()-((60*60)*24)).'"'),0);  
          $news = mysql_result(mysql_query('select count(`id`) from `news`'),0);
          $users_online = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `user` WHERE `online`>'".(time()-180)."'"), 0);      
          /////Счетчики//////
 echo '</b></b><div class="tegi"><span style="color: #fff;">Онлайн: <a href="/online.php" style="color:white;">'.$users_online.'</a> из <a href="/users.php" style="color:white;">'.$users.'</a></span><br />';
////
  echo '<b>Последний: </b><span style="color: #fff;">';
 $last = mysql_query("SELECT * FROM `user` ORDER BY `registration` DESC LIMIT 1");
          while($last2 = mysql_fetch_assoc($last))
          {
          
          echo ustatus($last2['id']).' <a href="/us'.$last2['id'].'">'.uname($last2['id']).' '.uaccess($last2['id']).'</span></a>';  
          }

echo '</br>';
///////
echo '<b>Ген.</b> ';
list($msec,$sec)=explode(chr(32),microtime());

          echo ' '.round((($sec+$msec)-$gtime),4).' сек.</div>';
 exit;  
  
          }
          
          }  
  
          }

?>