<?require('header.php');?>
<div class="menucenter">
 <?
if(isset($_SESSION["username"]) && isset($_SESSION["password"]))
{
  echo "<div class='error'>Вы уже вошли...</div>";
  include('footer.php');
  exit();
}

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

$code=$_POST["code"];
$log=$_SESSION["logcaptcha"];
unset($_SESSION["logcaptcha"]);
if($code != $log)
{
echo "<div class='error'>Неправильно введён проверочный код!</div>";
require('footer.php');
exit();
}


	$username=login(strtolower($_POST['username']));
	$password=strtolower($_POST['password']);
	if( isset($_POST['username']) )
	{
		$password = myHashData($password);
	}


	if ($password==NULL)
	{
		echo "<div class='error'>&nbsp;Введите пароль!</div>";
require('footer.php');
	}else{
		$query = mysql_query("SELECT count(*) as kolvo FROM tb_users WHERE username = '$username' and password='$password'") or die(mysql_error());
		$query=mysql_fetch_array($query);
		if($query["kolvo"]<1)
		{
			echo "<div class='error'>Введены неверные данные!!! Вход невозможен!<br /> Если вы не можете войти в свой аккаунт, воспользуйтесь формой <a href='restorepass.php' style='color:red;'>востановления пароля</a></div>";
    require('footer.php');
			exit();
		}else{

	        $lastlogdate=date("d.m.Y");
			$lastip = getRealIP();

			$us_akk=mysql_query("select * from tb_users where username='$username'");
			$us_a=mysql_fetch_assoc($us_akk);

			$v=substr($lastip,0,strlen($us_a["blockip"]));

          if($us_a["system"]==0){
          if($us_a["wmlogin"] == 1) {

            echo "<div class='error'>Для данного аккаунта авторизация возможна ТОЛЬКО через WmLogin><br>
                        <a href=https://login.wmtransfer.com/GateKeeper.aspx?RID=8cfd5d8f-d3f5-4b01-92f1-a10c015f7b56>Зайти через WmLogin</a></div>";
             require('footer.php');
             exit;

          }}
			if($v != $us_a["blockip"]){

				echo "<div class='wait'>Ваш IP адрес не соответствует разрешенному для авторизации под данным логином! Вход невозможен!</div>";

			}else{
			$lastlogdate=date("Y.m.d");
			$lastip = getRealIP();
$timenow=time();

require('karera/setup_status.php');
require('karera/setup_ball.php');

$user_ball = mysql_query("SELECT *,(TO_DAYS(NOW())-TO_DAYS(`lastlogdate`)) as datanew FROM `tb_users` WHERE `username` = '$username'");
$us_b=mysql_fetch_assoc($user_ball);
if($us_b["datanew"] >= 7){
  $dat = intval($us_b["datanew"]/7);
 if($dat != 0){
  $ball_dat = $dat * $ball["no_act"];
  mysql_query("UPDATE `tb_users` SET `ball` = `ball`+'$ball_dat' WHERE `username` = '".$us_b["username"]."'");
  mysql_query("INSERT INTO tb_infoball (user, date, ball, referer, mesage) VALUES('".$us_b["username"]."', '$timenow', '$ball_dat', '---', 'Отсутствие активности')") or die(mysql_error());
 }
}

$timenow=time();
$reu_ball=mysql_query("select * from tb_users where username='$username'");
$r_b=mysql_fetch_assoc($reu_ball);

if($r_b["ball_date"]+604800 < time()){

  $datlog = explode(".",$r_b["lastlogdate"]);
  $fhour = $fmin = $fsec = 0;
  $fyear = $datlog[0];
  $fmonth = $datlog[1];
  $fday = $datlog[2];

  $unix = mktime( $fhour, $fmin, $fsec, $fmonth, $fday, $fyear );

  if($unix > $r_b["ball_date"]){

    mysql_query("UPDATE `tb_users` SET `ball` = `ball`+'".$ball["user_act"]."', `ball_date` = '".time()."' WHERE `username` = '$username'");
    mysql_query("INSERT INTO tb_infoball (user, date, ball, referer, mesage) VALUES('$username', '$timenow', '+ ".$ball["user_act"]."', '---', 'Активность в течении недели')") or die(mysql_error());

    if($r_b["referer"] != ""){
      mysql_query("UPDATE `tb_users` SET `ball` = `ball`+'".$ball["ref_act"]."' WHERE `username` = '".$r_b["referer"]."'");
      mysql_query("INSERT INTO tb_infoball (user, date, ball, referer, mesage) VALUES('".$r_b["referer"]."', '$timenow', '+ ".$ball["ref_act"]."', '---', 'Активность реферала в течении недели')") or die(mysql_error());
    }
  }

}

if($r_b["ball"] >= $st_users[1]["ball"]){$ball_status = 1;}
if($r_b["ball"] >= $st_users[2]["ball"]){$ball_status = 2;}
if($r_b["ball"] >= $st_users[3]["ball"]){$ball_status = 3;}
if($r_b["ball"] >= $st_users[4]["ball"]){$ball_status = 4;}
if($r_b["ball"] >= $st_users[5]["ball"]){$ball_status = 5;}
if($r_b["ball"] >= $st_users[6]["ball"]){$ball_status = 6;}
$timenow=time();
mysql_query("UPDATE tb_users SET lastlogdate='$lastlogdate', lastvxod='$timenow', lastiplog='$lastip', `ball_status` = '$ball_status' WHERE username='$username'");

				$_SESSION["username"]=$username;
				$_SESSION["password"]=$password;
$lastnameus = strtolower($lastnameus);
$username = strtolower($username);
 if(($lastnameus != $username) and ($lastnameus != ""))  {
    mysql_query("UPDATE tb_users set blockpay='1', lastuser='$lastnameus' where username='$username'");
    mysql_query("UPDATE tb_users set blockpay='1', lastuser='$username' where username='$lastnameus'");
  }

				?>
				<script type="text/javascript">
				location.replace("members.php");
				</script>
				<noscript>
				<meta http-equiv="refresh" content="0; url=members.php">
				</noscript>
				<?
			}
		}
	}
}else{
include('loginform1.php'); }
require('footer.php'); ?>