<?php

include 'system/bd.php';
include 'system/cook.php';
include ("system/gzip.php");
include ("system/head1.php");



if(isset($_SESSION['auth']) && $_SESSION['auth']==1){
header ("Location: main.php?");
exit;
} 
switch($_GET[mod]){
default:

echo "<div class='title'>";
echo 'Эпоха сражений</font></div>';
echo'<center>
<div class="empty_block item_center bottom"><img src="/img/logo.png"> </div></center>';

/////////рега///////
echo' 
<div class="link_center"> ';


if (isset($_GET['go']) && $_GET['go']=='reg'){

$faq = mysql_query("SELECT * FROM `config`");
$conf = mysql_fetch_array($faq);


$to = mysql_insert_id();
$newpassword =uniqid("F"); 
$newpas=substr($newpassword,8);
$new=$newpas;

$password = $newpas;



$login = mysql_real_escape_string(trim($login));
$password = mysql_real_escape_string(trim($password));

$newpassword =uniqid("F"); 
$newpas=substr($newpassword,3);
$new=$newpas;
$dater = time();
if(!$err){
mysql_query("INSERT INTO `user` SET
`login` = '$dater',
`password` = '$password',
`secret` = '$new',
`save` = '1',
`sex` = 'man',
`rasa` = 'war',
`storona` = 'dark',
`lvl` = '1',
`prava` = '0',
`gold` = '".$conf[gold]."',
`silver` = '".$conf[silver]."',
`hp` = '".$conf[hp]."',
`hpfull` = '".$conf[hpfull]."',
`mp` = '100',
`mpfull` = '1000',
`attack` = '".$conf[attack]."',
`def` = '".$conf[def]."',
`exp` = '0',
`spells` = '1',
`regenerator` = '$dater'");

$_SESSION['id'] = mysql_insert_id();
$_SESSION['login']=$login;
$_SESSION['password'] = $password;
$_SESSION['auth']=1;
header ("Location: start.php");
$dater = time();
$text = "успешная регистрация";
$to = mysql_insert_id();

mysql_query("INSERT INTO `mail` SET `user` = '2', `to` = '$to', `time` = '$dater', `read` = '0', `msg` = '$text'");

exit;

}else{
	 foreach($err as $valhelp){
		echo ''.$valhelp.' </b>';	}
}
}

$req = mysql_query("SELECT * FROM `config` WHERE `registratoins` = 'of' ");
////////////////////////////
if (mysql_num_rows($req)==1){
echo ' 
<div class="link_center">
<a href="?mod=reg_off"> Начать игру </a></div>';
}else{

echo '
<form action="?go=reg&ref='.intval($_GET['ref']).'" method="post" class="">
<center>
<input type="submit"   value="Начать игру" class="button"/>
</center>
</form>';
 echo' </div> </div> ';

///////////

}

$kolic = mysql_query("SELECT COUNT(`id`) FROM `user`;");
$kols = mysql_result($kolic, 0);

echo "<div class='foot'>";
$faq = mysql_query("SELECT * FROM `config`");
$base = mysql_fetch_array($faq);
echo '<center>

</div></center>';



echo' 
<div class="block item_center">';


echo ' <div class="red">';
if (('chat_clear') && isset($_GET['act']) && $_GET['act']=='clear1')
{echo "<center><b>Ошибка авторизации!</b></center>";}

if (('chat_clear') && isset($_GET['act']) && $_GET['act']=='clear2')
{echo "  <center> Ошибка авторизации!</center>";}
echo '</div>';

echo'
<form method="post" action="auth.php">';

echo "<center>Имя персонажа<br/>";
echo '<input name="login" value="'.htmlspecialchars(mysql_real_escape_string($_POST['login'])).'"/><br/>';

echo "Пароль<br/>";
echo '<input name="password" type="password"  value="'.htmlspecialchars(mysql_real_escape_string($_POST['password'])).'"/><br/></div>';

echo '<center>
<input class="button" type="submit" value="Войти"/></center></form>
<div class="link_center">
<a href="restore_password.php">Забыли пароль</a></div>
</center>';
break;

case 'reg_off':
echo "<div class='title'>";
echo ' Регистрация игры закрыта </font></div>';

echo'
<div class="empty_block item_center bottom"><img src="/img/logo.png"> </div>';

echo' 
<div class="link_center item_center"> 
приносим свои извинения
</div>';

echo"
<div class='block_link'> <a href=\"index.php\"> <img src='/img/foot/index.png'>  На главную</a></div> ";

break;
}

include ("system/foot.php");

?>
