<?
require'config.php';
$align='center';
$title='Авторизация';
head();

if (isset($_POST['nik'])) $us = $_POST['nik'];
else if (isset($_GET['nik'])) $us = $_GET['nik'];
else if (isset($_POST['id'])) $us = $_POST['id'];
else if (isset($_GET['id'])) $us = $_GET['id'];


if (isset($_POST['ps'])) $pass = $_POST['ps'];
else if (isset($_GET['ps'])) $pass = $_GET['ps'];


if (isset($us) && !ctype_digit($us) && isset($pass))
{
if ($_POST['trun']==1)$us = translit($us);
if ($db->sql_fetchfield($db->sql_query("SELECT COUNT(*) FROM `users` WHERE `ruser` = '".check(rus_to_k($us))."' AND `pass` = '".check(md5($pass))."' LIMIT 1"), 0)==1)
{
$user=$db->sql_fetchrow($db->sql_query("SELECT * FROM `users` WHERE `ruser` = '".check(rus_to_k($us))."' AND `pass` = '".check(md5($pass))."' LIMIT 1"));


$_SESSION['id']=$user['id'];
$_SESSION['ps']=$pass;


setcookie('id', $user['id'], time()+3600*24*365);
setcookie('ps', $pass, time()+3600*24*365);


header("Location: ".H."enter?id=$user[id]&ps=".$pass."&".SID);
echo '<a href="enter?id='.$user[id].'&amp;ps='.$pass.'&amp;ref='.$ref.'">Перейти в чат</a><br/>';

}
else header('Location: aut?'.SID);exit;
}
elseif (isset($us) && ctype_digit($us) && isset($pass))
{
if ($db->sql_fetchfield($db->sql_query("SELECT COUNT(*) FROM `users` WHERE `id` = '".intval($us)."' AND `pass` = '".check(md5($pass))."' LIMIT 1"), 0)==1)
{
$user=$db->sql_fetchrow($db->sql_query("SELECT * FROM `users` WHERE `id` = '".intval($us)."' AND `pass` = '".check(md5($pass))."' LIMIT 1"));


$_SESSION['id']=$user['id'];
$_SESSION['ps']=$pass;


setcookie('id', $user['id'], time()+3600*24*365);
setcookie('ps', $pass, time()+3600*24*365);


header("Location: ".H."enter?ver=$ver&id=$user[id]&ps=".$pass."");
echo '<a href="enter?ver='.$ver.'&amp;id='.$user['id'].'&amp;ps='.$pass.'&amp;ref='.$ref.'">Перейти в чат</a><br/>';

}
else header('Location: aut?'.SID);exit;
}


echo gb.'<a href="index">На главную</a>'.div;



?>