<?php
session_start();
require("inc/bd.php");
require("inc/site_config.php");
if(isset($_SERVER['HTTPS'])) {
    $is_http = "https";
}
if(!isset($_SERVER['HTTPS'])) {
    $is_http = "http";
}
if($_SESSION['login'] != '') {
  header('Location: /');
}

$refid = $_SESSION['ref'];
$s = file_get_contents('https://ulogin.ru/token.php?token=' . $_POST['token'] . '&host=' . $_SERVER['HTTP_HOST']);
$user = json_decode($s, true);
$user['network']; // соц. сеть, через которую авторизовался пользователь
$user['identity']; // уникальная строка определяющая конкретного пользователя соц. сети
$user['first_name']; // имя пользователя
$user['last_name']; // фамилия пользователя
$user['photo_big']; // фото пользователя
$network = $user['network'];
$firstname = $user['first_name'];
$lastname = $user['last_name'];
$name = "$firstname $lastname";
$ava = $user['photo_big'];
$hashq = $user['identity'];

$sql_select2 = "SELECT COUNT(*) FROM kot_user WHERE hash='$hashq'";
$result2 = mysql_query($sql_select2);
$row = mysql_fetch_array($result2);
if($row)
{	
$logc = $row['COUNT(*)'];
}
    
        if($logc == 0) {
        if($hashq != '') {
          $datas = date("d.m.Y");      
	      $data = $datas;
          $ip = $_SERVER['REMOTE_ADDR'];
          $passgen = rand(100,1000) * rand(1,100) * rand(1,100) * 100;
            $_SESSION['login'] = 1;
			$insert_sql1 = "INSERT INTO `kot_user` (`id`,`vk_name`, `pass`, `balance`, `img`, `hash`, `social`, `ip`, `ref_id`, `date_reg`) 
	VALUES ('NULL','$name','', '$bonus_reg', '$ava', '$hashq', '$hashq', '$ip', '$refid', '$data');";
mysql_query($insert_sql1);
			$_SESSION['hash'] = $hashq;
			$_SESSION['login'] = 1;
			$home_url = 'http://'.$_SERVER['HTTP_HOST'] .'/';
            header('Location: ' . $home_url);
    
        }
        }
       if($logc == 1) {
         if($hashq != '') {
         $selecter = "SELECT * FROM kot_user WHERE hash = '$hashq'";
         $result3 = mysql_query($selecter);
         $row1 = mysql_fetch_array($result3);
		 if($row1)
		{	
		$hashlog = $row1['hash'];
         
		}
         
          $_SESSION['hash'] = $hashlog;
           $_SESSION['login'] = 1;
          $home_url = 'http://'.$_SERVER['HTTP_HOST'] .'/';
            header('Location: ' . $home_url);
       }
       }

require("inc/site_config.php"); 
  ?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>Purple Admin</title>
    <!-- plugins:css -->
    <link rel="stylesheet" href="../../assets/vendors/mdi/css/materialdesignicons.min.css">
    <link rel="stylesheet" href="../../assets/vendors/css/vendor.bundle.base.css">
     <script src="../ajax/functions.js"></script>
      <script src="../script/jquery-latest.min.js"></script>
    <script src="../script/odometr.js"></script>
    <script src="../script/js.cookie.js"></script>
     <script src="https://d3js.org/d3-path.v1.min.js"></script>
	<script src="https://d3js.org/d3-shape.v1.min.js"></script>  
	
    <script src="https://www.google.com/recaptcha/api.js?onload=renderRecaptchas&render=explicit" async defer></script>
    <script src="../ajax/functions.js"></script>
    <!-- endinject -->
    <!-- Plugin css for this page -->
    <!-- End plugin css for this page -->
    <!-- inject:css -->
    <!-- endinject -->
    <!-- Layout styles -->
    <link rel="stylesheet" href="../../assets/css/style.css">
    <!-- End layout styles -->
    <link rel="shortcut icon" href="../../assets/images/favicon.png" />
  </head>
  <body>
       <script>
          window.onload = function() {
    document.querySelector('.preloader').classList.add("preloader-remove");
};
$(window).on('load', function () {
    $('.preloader').addClass("preloader-remove");     
});
      </script>
      <style>
          .preloader {
    position: fixed;
    left: 0px;
    top: 0px;
    width: 100%;
    height: 100%;
    z-index: 999999;
    display: flex;
    align-items: center;
    justify-content: center;  
    background: #fff;
    transition: all 0.5s;
    opacity: 1;
}
.preloader-remove {
    opacity: 0;
    z-index: -10;
}
.preloader-2 {
    width: auto;
    height: auto;
}
 
.preloader-2 ul {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    animation: preloader-2-rot 16s linear infinite;
}
@keyframes preloader-2-rot {
    100% {
        transform: rotate(360deg);
    }
}
.preloader-2 li {
    width: 40px;
    height: 40px;
    background: #337AB7;
    border-radius: 4px;
    animation: preloader-2-scale 0.8s linear alternate infinite;
}
@keyframes preloader-2-scale {
    100% {
        transform: scale(0.1);
        opacity: 0;
    }
}
.preloader-2 li:nth-child(1) {
    z-index: 24;
}
.preloader-2 li:nth-child(2) {
    z-index: 23;
}
.preloader-2 li:nth-child(3) {
    z-index: 22;
}
.preloader-2 li:nth-child(4) {
    z-index: 21;
}
.preloader-2 li:nth-child(5) {
    z-index: 20;
}
.preloader-2 li:nth-child(6) {
    z-index: 19;
}
.preloader-2 li:nth-child(7) {
    z-index: 18;
}
.preloader-2 li:nth-child(8) {
    z-index: 17;
}
.preloader-2 li:nth-child(9) {
    z-index: 16;
}
.preloader-2 li:nth-child(10) {
    z-index: 15;
}
.preloader-2 li:nth-child(11) {
    z-index: 14;
}
.preloader-2 li:nth-child(12) {
    z-index: 13;
}
.preloader-2 li:nth-child(13) {
    z-index: 12;
}
.preloader-2 li:nth-child(14) {
    z-index: 11;
}
.preloader-2 li:nth-child(15) {
    z-index: 10;
}
.preloader-2 li:nth-child(16) {
    z-index: 9;
}
.preloader-2 li:nth-child(17) {
    z-index: 8;
}
.preloader-2 li:nth-child(18) {
    z-index: 7;
}
.preloader-2 li:nth-child(19) {
    z-index: 6;
}
.preloader-2 li:nth-child(20) {
    z-index: 5;
}
.preloader-2 li:nth-child(21) {
    z-index: 4;
}
.preloader-2 li:nth-child(22) {
    z-index: 3;
}
.preloader-2 li:nth-child(23) {
    z-index: 2;
}
.preloader-2 li:nth-child(24) {
    z-index: 1;
}
.preloader-2 li:nth-child(25) {
    z-index: 0;
}
.preloader-2 li:nth-child(1) {
    animation-delay: 0.1s;
}
.preloader-2 li:nth-child(7) {
    animation-delay: 0.3s;
}
.preloader-2 li:nth-child(13) {
    animation-delay: 0.5s;
}
.preloader-2 li:nth-child(19) {
    animation-delay: 0.7s;
}
.preloader-2 li:nth-child(24) {
    animation-delay: 0.9s;
}
.preloader-2 li:nth-child(2) {
    animation-delay: 0.2s;
}
.preloader-2 li:nth-child(8) {
    animation-delay: 0.4s;
}
.preloader-2 li:nth-child(14) {
    animation-delay: 0.6s;
}
.preloader-2 li:nth-child(20) {
    animation-delay: 0.8s;
}
.preloader-2 li:nth-child(3) {
    animation-delay: 0.3s;
}
.preloader-2 li:nth-child(9) {
    animation-delay: 0.5s;
}
.preloader-2 li:nth-child(15) {
    animation-delay: 0.7s;
}
.preloader-2 li:nth-child(4) {
    animation-delay: 0.4s;
}
.preloader-2 li:nth-child(10) {
    animation-delay: 0.6s;
}
.preloader-2 li:nth-child(5) {
    animation-delay: 0.5s;
}
.preloader-2 li:nth-child(1) {
    animation-delay: 0.1s;
}
.preloader-2 li:nth-child(6) {
    animation-delay: 0.2s;
}
.preloader-2 li:nth-child(11) {
    animation-delay: 0.3s;
}
.preloader-2 li:nth-child(16) {
    animation-delay: 0.4s;
}
.preloader-2 li:nth-child(21) {
    animation-delay: 0.5s;
}
.preloader-2 li:nth-child(7) {
    animation-delay: 0.3s;
}
.preloader-2 li:nth-child(12) {
    animation-delay: 0.4s;
}
.preloader-2 li:nth-child(17) {
    animation-delay: 0.5s;
}
.preloader-2 li:nth-child(22) {
    animation-delay: 0.6s;
}
.preloader-2 li:nth-child(13) {
    animation-delay: 0.5s;
}
.preloader-2 li:nth-child(18) {
    animation-delay: 0.6s;
}
.preloader-2 li:nth-child(23) {
    animation-delay: 0.7s;
}
.preloader-2 li:nth-child(19) {
    animation-delay: 0.7s;
}
.preloader-2 li:nth-child(24) {
    animation-delay: 0.8s;
}
.preloader-2 li:nth-child(25) {
    animation-delay: 0.9s;
}
      </style>
      <div class="preloader">
    <div class="preloader-2">
	<ul>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
		<li></li>
	</ul>
</div>
</div>
    <div class="container-scroller">
      <div class="container-fluid page-body-wrapper full-page-wrapper">
        <div class="content-wrapper d-flex align-items-center auth">
          <div class="row flex-grow">
            <div class="col-lg-4 mx-auto">
              <div class="auth-form-light text-left p-5">
                
                <h4>Добро пожаловать на наш сайт!</h4>
                <h6 class="font-weight-light">Ввойдите чтобы продолжить</h6>
                <form class="pt-3" id="enterBlock">
                    <div class="form-group"><input type="text" id="userLogin" placeholder="Логин" class="form-control form-control-lg"></div>
                                <div class="form-group"><input id="userPass" type="password" placeholder="Пароль" class="form-control form-control-lg"></div>
                                <div style="transform: scale(0.65);margin-left: -42px;margin-top: -17px;" class="g-recaptcha" data-sitekey="<?=$sitekey?>"></div>
                                <a id="butEnter" class="btn btn-primary btn-block" style="box-shadow: 0 5px 23px 0 rgba(0, 125, 255, 0.3); color:white" onclick="login_default()">Войти</a>
                                <a id="loadEnter" class="btn btn-primary btn-block disabled" style="box-shadow: 0 5px 23px 0 rgba(0, 125, 255, 0.3); display:none">
                                    <div class="loader"></div>
                                </a>
                                <div class="btn btn-danger btn-block" id="error_enter" style="margin-top:15px;display:none;pointer-events:none"></div>
                                   
                     
                  <div class="mt-3">
                                            
                  </div>
                  <div class="my-2 d-flex justify-content-between align-items-center">
                    
                    
                  </div>
                  <div id="uLogin" data-ulogin="display=buttons;fields=photo_big,first_name,last_name;mobilebuttons=0;redirect_uri=<?=$is_http?>%3A%2F%2F<?=$_SERVER['HTTP_HOST']?>/login.php;"><a href="#" data-uloginbutton="vkontakte" style='width:100%' class="btn btn-outline btn-dark btn-facebook btn-block"><i class="mdi mdi-vk" style='color:#2c80ff;' aria-hidden="true"></i><span> Вконтакте</span></a></div>
                  <script src="//ulogin.ru/js/ulogin.js"></script>
                              
                  
                <div onclick="$('#enterBlock').hide();$('#registerBlock').fadeIn(1200);" class="text-center mt-4 font-weight-light"> Нет аккаунта? <a  class="text-primary">Создать</a>
                  </div>
                </form>
                <form class="pt-3" id="registerBlock" style="display:none;">
                    
                       
                                   
                     
             
                  <div id="uLogin1" data-ulogin="display=buttons;fields=photo_big,first_name,last_name;mobilebuttons=0;redirect_uri=<?=$is_http?>%3A%2F%2F<?=$_SERVER['HTTP_HOST']?>/login.php;"><a href="#" data-uloginbutton="vkontakte" style='width:100%' class="btn btn-outline btn-dark btn-facebook btn-block"><i class="mdi mdi-vk" style='color:#2c80ff;' aria-hidden="true"></i><span> Вконтакте</span></a></div>
                  <script src="//ulogin.ru/js/ulogin.js"></script>
                              
                  <div onclick="$('#registerBlock').hide();$('#enterBlock').fadeIn(1200);" class="text-center mt-4 font-weight-light"> Есть аккаунт? <a  class="text-primary">Войти</a>
                  </div>
                </form>
             
              </div>
            </div>
          </div>
        </div>
       
        <!-- con
        tent-wrapper ends -->
      </div>
      <!-- page-body-wrapper ends -->
    </div>
    <!-- container-scroller -->
    <!-- plugins:js -->
   
<script src="../script/jquery.bundle.js"></script>
<script src=".../script/datatables.min.js"></script>
    <!-- endinject -->
    <!-- Plugin js for this page -->
    <!-- End plugin js for this page -->
    <!-- inject:js -->
    <script src="../../assets/js/off-canvas.js"></script>
    <script src="../../assets/js/hoverable-collapse.js"></script>
    <script src="../../assets/js/misc.js"></script>
    <!-- endinject -->
  </body>
</html>