<?php

require '../system/start.php';
require '../system/functions.php';
unreg();
$str['mesto'] = 'Авторизация';
$str['block'] = $set['site'].' / Авторизация';
if(isset($_GET['act']) && $_GET['act'] == 'exit')
{
	setcookie('login', '', time()+3600*24*365, '/');
	setcookie('password', '', time()+3600*24*365, '/');
	session_destroy();
	header("Location: ../index.php");
	exit;
}
include '../style/'.$style.'/head.php';
echo '<div class="on">';
if(isset($_POST['login']) && !empty($_POST['login']) && !empty($_POST['password']))
{
	$login = protect($_POST['login'], 12);
	$password = protect(md5($_POST['password']));
	$check = mysql_result(mysql_query("select count(*) from `users` where `login` = '".$login."' and `password` = '".$password."'"),0);
	if($check == 0)
	{
		echo 'Неверный логин и/или пароль!</div>';
		include '../style/'.$style.'/foot.php';
		exit;
	} else
	{
		setcookie('login', $login, time()+3600*24*365, '/');
		setcookie('password', $password, time()+3600*24*365, '/');
		mysql_query("DELETE FROM `online` WHERE `ip` = '$ip' AND `ua` = '$ua' LIMIT 1");
		header("Location: ../p/$login");
		exit;
	}
}
if(isset($_GET['login']) && !empty($_GET['login']) && !empty($_GET['password']))
{
	$login = protect($_GET['login'], 12);
	$password = protect(md5($_GET['password']));
	$check = mysql_result(mysql_query("select count(*) from `users` where `login` = '".$login."' and `password` = '".$password."'"),0);
	if($check == 0)
	{
		echo 'Неверный логин и/или пароль!</div>';
		include '../style/'.$style.'/foot.php';
		exit;
	} else
	{
		setcookie('login', $login, time()+3600*24*365, '/');
		setcookie('password', $password, time()+3600*24*365, '/');
		mysql_query("DELETE FROM `online` WHERE `ip` = '$ip' AND `ua` = '$ua' LIMIT 1");
		header("Location: ../index2.php");
		exit;
	}
}
echo '<form action="sign.php" method="post"><div>
Логин:<br/>
<input name="login" type="text" value=""/><br/>
Пароль:<br/>
<input name="password" type="password" value=""/><br/>
<input type="submit" value="Войти!"/></div></form>
<img class="ico" src="/style/'.$style.'/ico/personal.gif" alt="" />
Автологин:<br/>
<input name="sign" type="text" value="'.$set['http'].'/pages/sign.php?login=ЛОГИН&amp;password=ПАРОЛЬ"/></div>';
include '../style/'.$style.'/foot.php';
?>