<?php

class login{
	function __construct(){
		if(Auth()){
            return false;
        }
		$this->check();
	}

	private function check(){
        global $connect;
		$MySQL=mysqli_query($connect,'SELECT login,password FROM config');
        $row=mysqli_fetch_assoc($MySQL);

         if($_SERVER['REQUEST_METHOD']=='POST'){
            if(md5($_POST['password'].'ghj%^&gjfhbfdn34&*')==$row['password'] and $_POST['login']==base64_decode($row['login'])){
              $text=$GLOBALS['lang']['mes2']; $location=$this->Location();
              include('./inc/menu.php');
              print '<script type="text/javascript"> $.cookie("login","'.md5($_POST['login'].'ghj%^&gjfhbfdn34&*').'"); $.cookie("SESSION","'.md5(md5($_POST['password'].'ghj%^&gjfhbfdn34&*').$_SERVER['HTTP_USER_AGENT'].$_SERVER['HTTP_ACCEPT_LANGUAGE']).'"); </script>';
              include('./inc/success.php');
              return false;
            }else{
                include('./inc/forms/login.error.php'); return false;
            }
        }else{
            include('./inc/forms/login.php'); return false;
        }
	}

	private function Location(){
		$location=end(explode('?',$_SERVER['HTTP_REFERER']));
		if(!$location or $location=='login' or !is_file('./kernel/'.$location.'.class.php')){ $location='home'; }
		return $location;
	}
}