<?PHP
@session_start();
require_once($_SERVER['DOCUMENT_ROOT']."/config.php");
require_once($_SERVER['DOCUMENT_ROOT']."/funciones.php");

$res = mysql_query("SELECT `price` FROM `tb_config` WHERE `item`='offsite'") or die(mysql_error());
$off = mysql_result($res,0,0); 
if($off=='1') { 
if(isset($_POST['username'])) {
$username = strtolower(check_email($_POST['username']));
$password = md5($_POST['password']); 
if($password == NULL) { 
echo "<img src=\"images/alert.png\" align=\"middle\"> Введите пароль!"; 
}else{   
$query = mysql_query("SELECT count(*) as kolvo FROM `b_users` WHERE `email`='$username' AND `password`='$password'") or die(mysql_error());    
$query = mysql_fetch_array($query); 
if($query["kolvo"] < 1)   {  
echo "<img src=\"images/alert.png\" align=\"middle\">  Введены неверные данные!!! Вход невозможен!"; exit(); 
}else{      
$res = mysql_fetch_assoc(mysql_query("SELECT `user_status`,`id`,`username` FROM `b_users` WHERE `email`='$username'"));   
$status = $res["user_status"];
if($status!='admin'){  
echo "<img src=\"images/alert.png\" align=\"middle\"> Вы не являетесь администратором проекта!Вход невозможен.";exit();   
}else{   
$_SESSION["username"] = $res["username"];
$_SESSION["password"] = $password;
$_SESSION["iduser"] = $res["id"];
?>
<script type="text/javascript">   location.replace("members.php");   </script> 
<noscript>   <meta http-equiv="refresh" content="0; url=members.php">   </noscript>
<?
}
}
}
}
$id_user = (isset($_SESSION["iduser"]) && preg_match("|^[\d]{1,11}$|", trim($_SESSION["iduser"]))) ? intval(trim($_SESSION["iduser"])) : false; 
if($id_user == false){
include('blocklog.php');exit();  
}else{
$res = mysql_fetch_assoc(mysql_query("SELECT `user_status` FROM `b_users` WHERE `id`='$id_user'"));   
$status = $res["user_status"];  
if($status != 'admin') {  
echo "<img src=\"images/alert.png\" align=\"middle\"> Вы не являетесь администратором проекта!Ожидайте включения сайта в рабочий режим!";exit(); 
}  
}
}
?>