<?php

          include 'system/core.php';
  
          include 'system/header.php';

          switch($_GET['m'])
          {
  
          default:
///////////Главная//////////////
          
         

	  $forum_t = mysql_result(mysql_query('select count(`id`) from `forum_t`'),0);
	  $forum_post = mysql_result(mysql_query('select count(`id`) from `forum_m`'),0);
	  $forum_news = mysql_result(mysql_query('select count(`id`) from `forum_t` where `time` > "'.(time()-((60*60)*24)).'"'),0);
	  $forum_news2 = mysql_result(mysql_query('select count(`id`) from `forum_m` where `time` > "'.(time()-((60*60)*24)).'"'),0);
	  $files = mysql_result(mysql_query('select count(`id`) from `zc_f` where `status` = "0"'),0);
	  $files_new = mysql_result(mysql_query('select count(`id`) from `zc_f` where `status` = "0" and `time` > "'.(time()-((60*60)*24)).'"'),0);
          
         
  
          $news = mysql_query('select * from `news` order by `time` desc limit 1');
		 
  echo '<a href="news/"><div class="tegi"><font color="white"><b> Новости </b></font></div></a>';

          while($news2 = mysql_fetch_array($news))
          {
          echo '<div class="news"><div class="newss">';
         echo '<div class="name"><b>'.$news2['name'].'</b> ('.times($news2['time']).')</div>'; 
          echo smiles(bbcode($news2['text'])).'<br>

          Добавил: '.ustatus($news2['author']).' <a href="/us'.$news2['author'].'">'.uname($news2['author']).'</a> '.uaccess($news2['author']).' <br>

          <span><a href="/news/com'.$news2['id'].'">Комментарии</a> ('.mysql_result(mysql_query('select count(`id`) from `news_com` where `news` = "'.$news2['id'].'"'),0).')</span>';

          }

          
       echo '</div>';
       

           $day = mysql_query("SELECT * FROM `user` WHERE `day` = '".date('d')."' and `m` = '".date('m')."' ORDER BY `id` DESC limit 10  ");
          echo '<div class="poste"><b>Именинники:</b> ';
          while($day2 = mysql_fetch_assoc($day))
          {
          echo ''.ustatus($day2['id']).' <a href="/us'.$day2['id'].'">'.uname($day2['id']).'</a> '.uaccess($day2['id']).', ';
          }
          echo'</div>';



				
echo ' <a href="forum/"><div class="tegi"><b> Форум ('.$forum_t.'/'.$forum_post.') (<font color="green"><b>+'.$forum_news.'</b></b></font>/<font color="red"><b>+'.$forum_news2.'</b></font>)</div></a>';


$pop = mysql_fetch_assoc(mysql_query(' SELECT COUNT(`id`) AS `count`, `t` FROM `forum_m` WHERE `time` > '.(time()-999999).' GROUP BY `t` ORDER BY `count` DESC LIMIT 1'));
 
    {
    $pop2 = mysql_fetch_array(mysql_query("SELECT * FROM `forum_t` WHERE `id` = '".$pop['t']."'"));


$forum_post = mysql_result(mysql_query('select count(`id`) from `forum_m` where `time` > "'.(time()-((60*60)*24)).'"and `t` = "'.$pop2['id'].'"'),0);

    if($user['id']) $on_page = $user['on_page']; else $on_page = 10;
if ($pop)
echo '<div class="post2">';
     if($pop2['check'] == 0)
          {
  
          if($pop2['status'] == 0) echo '<img src="/img/thema.png" wight="20" height="20"/> '; else echo '<img src="/img/thema_zak.png" wight="20" height="20"/> ';
   
          }
          else
          {
  
          echo '<img src="/img/thema_vip.png" wight="20" height="20"> ';
  
          }
    echo '<a href="/forum/t'.$pop2['id'].'">'.$pop2['name'].'</a> ('.$forum_post.' за сутки) '.uname($pop2['last']).' <a href="forum/t'.$pop2['id'].'/p'.ceil(($last_m+1)/$on_page).'">>></a> <span class="boom">[Актуал.]</span></div>';
    }

$toptheme = mysql_query("SELECT * FROM `forum_t` WHERE `top` = 1 ORDER BY `time` DESC");

if(mysql_num_rows($toptheme) > 0){
while($top_t = mysql_fetch_assoc($toptheme)){

$last_m2 = mysql_result(mysql_query('select count(`id`) from `forum_m` where `t` = "'.$top_t['id'].'"'),0);

echo '<div class="post2">';
if($top_t['check'] == 0)
          {
  
          if($top_t['status'] == 0) echo '<img src="/img/thema.png" wight="20" height="20"/> '; else echo '<img src="/img/thema_zak.png" wight="20" height="20"/> ';
   
          }
          else
          {
  
          echo '<img src="/img/thema_vip.png" wight="20" height="20"> ';
  
          }
  
	echo '<a href="/forum/t'.$top_t['id'].'"><b>'.$top_t['name'].'</b></a> ('.$last_m2.') '.uname($top_t['last']).' <a href="forum/t'.$top_t['id'].'/p'.ceil(($last_m2+1)/$on_page).'">>></a> <b>[Топ]</b></div>';
}
}

 

$last = mysql_query('select * from `forum_t` where `top` != 1 and `id` != "'.$pop2['id'].'" order by `ltime` desc limit 5');

 

while($last2 = mysql_fetch_array($last))
{

echo '<div class="poste">';


          $last_m = mysql_result(mysql_query('select count(`id`) from `forum_m` where `t` = "'.$last2['id'].'"'),0);
  
          if($last2['check'] == 0)
          {
  
          if($last2['status'] == 0) echo '<img src="/img/thema.png" wight="20" height="20"/> '; else echo '<img src="/img/thema_zak.png" wight="20" height="20"/> ';
   
          }
          else
          {
  
          echo '<img src="/img/thema_vip.png" wight="20" height="20"> ';
  
          }
  
          if($user['id']) $on_page = $user['on_page']; else $on_page = 10;
  
          echo '<a href="/forum/t'.$last2['id'].'">'.$last2['name'].'</a> ('.$last_m.') '.uname($last2['last']).' <a href="forum/t'.$last2['id'].'/p'.ceil(($last_m+1)/$on_page).'">>></a><br>';
  
          echo '</div>';
  
       

}
          /////Счетчики//////
          $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 '<a href="/zc"><div class="tegi"><b>Обменник ('.$files.') (<font color="red">+'.$files_new.'</font>)</b></div></a>';

          if(mysql_result(mysql_query('select count(`id`) from `zc_f`'),0) != 0)
          {
  
          $zc = mysql_query('select * from `zc_f` where `status` = "0" order by `time` desc limit 3');
  
          while($zc2 = mysql_fetch_array($zc))
          {
  
          echo '<a href="/zc/f'.$zc2['id'].'"><div class="post2"><img src="/img/Zip.png" wight="20" height="20"> '.$zc2['name'].'</div></a>';
  
          }
  
          }
          else
          {
  
          echo '<div class="post">Файлов нет</div>';
  
          }
		

	  echo '<div class="tegi"><font color="white"><b>Меню </font></b></div>';
		  $users = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `user`"), 0);
$ced = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `ced`"), 0);
  $adm = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `user` WHERE `status` >= 1 AND `status` <= 4"), 0);

 
		  echo '<a href="/ced"><div class="men"><img src="/img/pozor.png" wight="20" height="20"> Доска позора ('.$ced.')</div></a>';
		  echo '<a href="/servis"><div class="men"><img src="/img/servis.png" wight="20" height="20"> Сервисы</div></a>';
		  echo '<a href="/rules"><div class="men"><img src="/img/thema_zak.png" wight="20" height="20"> Правила</div></a>';
          echo '<a href="/users.php"><div class="men"><img src="/img/pozor.png" wight="20" height="20"> Пользователи ('.$users.')</div></a>';
		  echo '<a href="/adm.php"><div class="men"><img src="/img/admin.png" wight="18" height="18"> Администрация ('.$adm.')</div></a>';
		  
		           include 'system/footer.php';
		
  break;    
  case 'guest': 
         
          if($user['id'])
          {
          header('Location: /index.php'); exit;
          }
          
echo '<div class="poste"><b>Сайт закрыт от гостей</b></div>';

include 'system/footer.php';
  
  break;
  case 'auth':

          if($user['id'])
          {
    
          header('Location: /index.php'); exit;
  
          }
  
        echo '<div class="tegi">Авторизация</div></div>';
        
        echo ' <div class="start">';
        echo '<div class="post1"><span><a href="?m=password">Забыли пароль?</a></span></div>'; 
        
          if(isset($_GET['process']))
          {
  
          $type = TextGuard($_POST['type']);
  
          $login = TextGuard($_POST['login']);
  
          $password = TextGuard($_POST['password']);

   
          if($type == 1)
          {
  
          if(empty($login)) $err[] = 'Вы не ввели логин';
  
          }
          elseif($type == 2)
          {
  
          if(empty($login) or !is_numeric($login)) $err[] = 'Введите ID.';

          }
  
          if(empty($password)) $err[] = 'Вы не ввели пароль';
  
          if($type == 1)
          {
  
          $dbinfo = mysql_fetch_array(mysql_query("SELECT `login`,`password` FROM `user` WHERE `login` = '".$login."' and `password`='".$password."' LIMIT 1"));
  
          }
          elseif($type == 2)
          {
  
          $dbinfo = mysql_fetch_array(mysql_query("SELECT `id`,`password`,`login` FROM `user` WHERE `id` = '".$login."' and `password`='".$password."' LIMIT 1"));

          }
  
          if(!empty($login) && !empty($password)) if($dbinfo==0) $err[] = 'Введенные данные не верны ';
          
          if(!$err)
          {
  
          mysql_query("INSERT INTO `logs`(`who`,`time`,`vh`,`ip`,`ua`)VALUES('".$dbinfo['login']."','".time()."','1','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['HTTP_USER_AGENT']."')");
  
          setcookie('ulogin', $dbinfo['login'], time()+86400*365, '/');
	
          setcookie('upassword', $password, time()+86400*365, '/');
  
          header('Location: /index.php');
  
          }
          else
          {
    
          echo '<div class="err">';
  
          mysql_query("INSERT INTO `logs`(`who`,`time`,`vh`,`ip`,`ua`)VALUES('".$login."','".time()."','0','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['HTTP_USER_AGENT']."')");
          
          foreach($err as $err_info)
          {
    
          echo $err_info.'<br>';
  
          }
  
          echo '</div>';
  
          }
        
          }
              
          echo '<div class="glav"><form action="?m=auth&process" method="post">
  
          Ваш <select name="type"><option value="1">Ник</option><option value="2">ID</option></select><br>
  
          <input name="login" value="'.$login.'"/><br>Пароль:<br><input type="password" name="password" value="'.$password.'"/><br>
    
  
          <input type="submit" value="Вход"/>
  
          </form></div></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>';
          
          break;
          case 'exit':
  
          if(!$user['id'])
          {
    
          header('Location: /?m=auth'); exit;
  
          }
  
 echo '<div class="tegi">Выход</div>';
          echo '<div class="post2">Вы действительно хотите выйти?<br/><a href="/?m=exit_ok">Да, выйти</a></div>';
$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);      
include 'system/footer.php';
          break;
         case 'exit_ok':
  
          if(!$user['id'])
          {
    
          header('Location: /?m=auth'); exit;
  
          }
  
          setcookie('ulogin', $login, time()-86400*365, '/');
	
          setcookie('upassword', $password, time()-86400*365, '/');
  
          header('Location: /index.php');

          break;
          case 'registration':
   
        if($user['id'])
{
header('Location: /index.php'); exit;
}
echo '<div class="tegi">Регистрация</div>';
echo '<div class="post1"><span><a href="?m=auth">Авторизация</a></span></div>';
if(isset($_GET['process'])){
$login = TextGuard($_POST['login']);
$password = TextGuard($_POST['password']);
$dei = TextGuard($_POST['dei']);
$password2 = TextGuard($_POST['password2']);
$sex = TextGuard($_POST['sex']);
$secret_word = TextGuard($_POST['secret_word']);
$captcha = TextGuard($_POST['captcha']);
if(empty($login)){ echo '<div class="err">Вы не ввели логин</div>';
}else{
$dbinfo = mysql_fetch_array(mysql_query("SELECT `login` FROM `user` WHERE `login` = '".$login."' LIMIT 1"));
if(!empty($login))if($dbinfo!=0){ echo '<div class="err">Такой логин уже существует</div>';
}else{
if(!preg_match('|^[a-za-я0-9\-]+$|i', $login)){ echo '<div class="err">В логине присутствуют запрещенные символы</div>';
}else{
if(strlen($login) <2 or strlen($login)>20){ echo '<div class="err">Логин слишком длинный или короткий</div>';
}else{
if(empty($password)){ echo  '<div class="err">Вы не ввели пароль</div>';
}else{
if(!preg_match('|^[a-z0-9\-]+$|i', $password)){ echo '<div class="err">В пароле присутствуют запрещенные символы</div>';
}else{
if(strlen($password) <2 or strlen($password)>50){ echo '<div class="err">Пароль слишком длинный или короткий</div>';
}else{
if(empty($password2)){ echo '<div class="err">Вы не ввели повторный пароль</div>';
}else{
if(empty($secret_word)){ echo '<div class="err">Вы не ввели секретное слово</div>';
}else{
if(!preg_match('|^[a-zа-я0-9\-]+$|i', $password)){ echo '<div class="err">В секретном слове присутствуют запрещенные символы</div>';
}else{
if(strlen($secret_word) <2 or strlen($secret_word)>50){ echo '<div class="err">Секретное слово слишком длинное или короткое</div>';
}else{
if(empty($captcha)){ echo '<div class="err">Введите проверочный код.</div>';
}else{
if($captcha != $_SESSION['control']){ echo '<div class="err">Вы ввели неверный код с картинки.</div>';
}else{
mysql_query("INSERT INTO `user`(
`login`,
`password`,
`dei`,
`registration`,
`secret_word`,
`rating`,
`ip`,
`ua`,
`sex`,
`on_page`
)VALUES(
'".$login."',
'".$password."',
'".$dei."',
'".time()."',
'".$secret_word."',
'0',
'".$_SERVER['REMOTE_ADDR']."',
'".$_SERVER['HTTP_USER_AGENT']."',
'".$sex."',
'10'
)");
$reg_id = mysql_insert_id();
mysql_query("INSERT INTO `reg`(
`who`,
`ok`
)VALUES(
'".$reg_id."',
'0'
)");
mysql_query("INSERT INTO `gradient`(
`id`,
`who`,
`start`,
`end`
)VALUES(
'".$reg_id."',
'".$reg_id."',
'0',
'0'
)");
mysql_query("INSERT INTO `grad_status`(
`id`,
`who`,
`start`,
`end`
)VALUES(
'".$reg_id."',
'".$reg_id."',
'0',
'0'
)");
$regaa = mysql_query("SELECT * FROM `user` WHERE `status` > '2'");
while($regaa2 = mysql_fetch_assoc($regaa)){
mysql_query("INSERT INTO `op`(
`who`,
`ho`,
`text`,
`time`,
`read`
)VALUES(
'".$regaa2['id']."',
'3',
'произошла новая регистрация [url=/admin?m=reg]подтвердить[/url]',
'".time()."',
'0'
)");
}
setcookie('ulogin', $login, time()+86400*365, '/');
setcookie('upassword', $password, time()+86400*365, '/');
echo '<div class="msg">Вы <u>успешно</u> зарегистрировались!<br>Ваш логин: <u>'.$login.'</u> | Ваш пароль: <u>'.$password.'</u></div>';
}}}}}}}}}}}}}}
echo '<div class="glav"><form action="?m=registration&process" method="post">
*Ваш логин:<br><input name="login" value="'.$login.'"/><br>
*Ваш пароль:<br><input name="password" value="'.$password.'"/><br>
*Повторить пароль:<br><input name="password2" value="'.$password2.'"/><br>
Ваш пол:<br>
<input type="radio" name="sex" value="1" checked="checked" /> Муж
<input type="radio" name="sex" value="2" /> Жен<br/>
Секретное слово:<br><input name="secret_word" value="'.$secret_word.'"/><br>
Код: <img src="/captcha.php" alt="'.$code.'"/>:<br><input name="captcha"/><br>
<input type="submit" value="Регистрация"/></form></div></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>';
  
  break;
  case 'password':
  
  if($user['id']){
  header('Location: /index.php'); exit;
  }
  
  
        echo '<div class="tegi">Восстановление пароля</div>';
        
        echo '<div class="post2"><a href="?m=auth">Авторизация</a></div>'; 
  
  if(isset($_GET['process'])){
  $login = TextGuard($_POST['login']);
  $secret_word = TextGuard($_POST['secret_word']);
  if(empty($login)) $err[] = 'Вы не ввели логин';
  if(empty($secret_word)) $err[] = 'Вы не ввели секретное слово';
  $dbinfo = mysql_fetch_array(mysql_query("SELECT `login`,`secret_word`,`password` FROM `user` WHERE `login` = '".$login."' and `secret_word`='".$secret_word."' LIMIT 1"));
  if(!empty($login) && !empty($secret_word)) if($dbinfo==0) $err[] = 'Введенные данные не верны';
  if(!$err){
  echo '<div class="msg"><u>Успешно</u><br/><b>Ваш пароль: <u>'.$dbinfo['password'].'</u></b></div>';
  }else{
  echo '<div class="err">';
  foreach($err as $err_info){
  echo $err_info.'<br>';
  }
  echo '</div>';
  }}
  
  echo '<div class="glav"><form action="?m=password&process" method="post">
  Логин:<br><input name="login" value="'.$login.'"/><br>
  Секретное слово:<br><input name="secret_word" value="'.$secret_word.'"/><br>
  <input type="submit" value="Напомнить"/>
  </form></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);      
     
  include 'system/footer.php';
  break;
  
  }

?>