<?php
session_start();
include_once "../inc/db_connect.php";
include_once "../inc/fnc.php";
header('Content-Type: text/html;charset=utf8');
$err = "";
if(isset($_POST['regok'])){unset($_SESSION['reg_ok']);}
if(!isset($_SESSION['user'])){
	header("Location: index.php?");
	exit();
}else{
	$data_user = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE nick='".$_SESSION['user']."'")) or die(mysql_error());
	if($data_user['status'] == "Гонщик" or $data_user['status'] == "VIP" or $data_user['status'] == "Помощник"){
		header("Location: ../index.php?");
		exit();
	}else{
	$user = $_SESSION['user'];
	$dateig = date("H:i:s");
	$data_userid = $data_user['id'];
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
echo '<html>';
echo '<head>';
	echo '<title>DagLowRaceClub</title>';
	echo '<meta http-equiv="Content-Type" content="text/html" charset="windows-1251" />';
	echo '<meta name="description" content="Мобильные онлайн гонки">';
	echo '<link rel="stylesheet" type="text/css" href="/style/default/mobile.css" />';
echo '</head>';
echo '<body>';
?>
<div class="title">Меню</div>
<?
echo '<div class="inform"><center>';
        echo '<div class="block"><a href="/index.php"><b>Гараж</b></a></div>';
        echo '<div class="block"><a href="/race.php"><b>Гонки</b></a></div>';
        echo '<div class="block"><a href="/bar.php"><b>Бар</b></a></div>';
		echo '<div class="block"><a href="/city.php"><b>Город</b></a></div>';
echo '</center></div>';
?>
<div class="title">Админка</div>
<?php
if($err) echo "<div class='err'>" , $err , "</div>";
if(isset($_GET["addavto"])){
	echo <<<addavto
	<div class='menu'>
		<form action='addcar.php' method='post'>
			Путь к машине: <br/><input type='text' name='car' value='car/'/><br/>
			Имя машины: <br/><input type='text' name='carname' /><br/>
			Скорость: <br/><input type='text' name='speed' size='4' maxlength='3' /><br/>
			Уровень: <br/><input type='text' name='level' size='3' maxlength='2' /><br/>
			Цена: <br/><input type='text' size='6' name='price' /><br/>
			<input type='submit' name='submit' class='btn' value='Добавить' />
		</form>
	</div>
addavto;
}
if(isset($_GET["cars"])){
	if(isset($_GET['editcar'])){
		$editcar = trim(strip_tags(htmlspecialchars((int)$_GET['editcar'])));
		$editcarrow = mysql_fetch_array(mysql_query("SELECT * FROM auto WHERE id='".$editcar."'")) or die(mysql_error());
		echo "<div class='menu'>
		<form action='updata_car.php' method='post'>
			Путь: <br/><input type='text' name='car' value='".$editcarrow['car']."' /><br/>
			<input type='hidden' name='id' value='".$editcarrow['id']."' />
			Имя: <br/><input type='text' name='carname' value='".$editcarrow['carname']."' /><br/>
			Скорость: <br/><input type='text' name='speed' value='".$editcarrow['speed']."' /><br/>
			Уровень: <br/><input type='text' name='level' value='".$editcarrow['level']."' /><br/>
			Цена: <br/><input type='text' name='price' value='".$editcarrow['price']."' /><br/>
			<input type='submit' name='submit' class='btn' value='Сохранить' /><br/>
			</form>
		</div>";
	}
	
	
	$cars = mysql_query("SELECT * FROM auto ORDER BY id ASC") or die(mysql_error());
	$cars_row = mysql_fetch_array($cars);
	echo "<div class='menu'>";
do{
$cars_name = $cars_row['carname'];
$cars_id = $cars_row['id'];
	echo <<<cars
		<a style="color:#fff;font-size:8pt;" href="index.php?cars&editcar=$cars_id">$cars_name</a><br/>
cars;
}while($cars_row = mysql_fetch_array($cars));
echo "</div>";
}
if(isset($_GET["addvis"])){
	echo <<<addvis
	<div class='menu'>
		<form action='addvis.php' method='post'>
			Путь к машине: <br/><input type='text' name='car' value='car/'/><br/>
			Имя машины: <br/><input type='text' name='carname' /><br/>
			Скорость: <br/><input type='text' name='speed' /><br/>
			Уровень: <br/><input type='text' name='level'  /><br/>
Золота: <br/><input type='text' size='6' name='price' /><br/>
Тур. очков: <br/><input type='text' size='6' name='price2' /><br/>
			Колличество: <br/><input type='text' size='6' name='ogran' /><br/>
			<input type='submit' name='submit' class='btn' value='Добавить' />
		</form>
	</div>
addvis;
}
if(isset($_GET["cars"])){
	if(isset($_GET['editcar'])){
		$editcar = trim(strip_tags(htmlspecialchars((int)$_GET['editvis'])));
		$editcarrow = mysql_fetch_array(mysql_query("SELECT * FROM vis WHERE id='".$editcar."'")) or die(mysql_error());
		echo "<div class='menu'>
		<form action='updata_car.php' method='post'>
			Путь: <br/><input type='text' name='car' value='".$editcarrow['car']."' /><br/>
			<input type='hidden' name='id' value='".$editcarrow['id']."' />
			Имя: <br/><input type='text' name='carname' value='".$editcarrow['carname']."' /><br/>
			Скорость: <br/><input type='text' name='speed' value='".$editcarrow['speed']."' /><br/>
			Уровень: <br/><input type='text' name='level' value='".$editcarrow['level']."' /><br/>
Золото: <br/><input type='text' name='price' value='".$editcarrow['price']."' /><br/>
Тур. очки: <br/><input type='text' name='price2' value='".$editcarrow['price2']."' /><br/>
			Колличество: <br/><input type='text' name='ogran' value='".$editcarrow['ogran']."' /><br/>
			<input type='submit' name='submit' class='btn' value='Сохранить' /><br/>
			</form>
		</div>";
}
	$cars = mysql_query("SELECT * FROM vis ORDER BY id ASC") or die(mysql_error());
	$cars_row = mysql_fetch_array($cars);
	echo "<div class='menu'>";
do{
$cars_name = $cars_row['carname'];
$cars_id = $cars_row['id'];
	echo <<<cars
		<a style="color:#fff;font-size:8pt;" href="index.php?cars&editvis=$cars_id">$cars_name</a><br/>
cars;
}while($cars_row = mysql_fetch_array($cars));
echo "</div>";
}
if(isset($_GET['del'])){
	$del = (int)$_GET['del'];
	mysql_query("DELETE FROM `news` WHERE id=$del") or die(mysql_error());
	echo "<meta http-equiv='refresh' content='0; URL=/index.php?'>";
	exit();
}
if(isset($_GET['addnews'])){
	echo "<div class='menu'>
			<form action='addnews.php' method='post'>
				Сообщение:<br/>
				<textarea name='news'></textarea><br/>
				<input type='submit' name='add' class='btn' value='Добавить' />
			</form>
		</div>";
}
if($data_user['status'] == "Создатель"){
if(isset($_GET['clearbar'])){
	mysql_query("DELETE FROM bar");
	echo "<meta http-equiv='refresh' content='0; URL=index.php?' />";
	exit();
}
if(isset($_GET['users'])){
if(isset($_GET['edit'])){
	$edit_id = (int)$_GET['edit'];
	$edit_user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE id='".$edit_id."'")) or die(mysql_error());
print "<div class='menu'>
	<form action='update_user.php' method='post'>
	<font color='#fff'>ID игрока: <b>".$edit_user['id']."</b></font><br/>
	<input type='hidden' name='id1' value='".$edit_user['id']."' />
	Ник:<br> <input type='text' name='nick1' value='".$edit_user['nick']."' /><br/>
	E-mail:<br> <input type='text' name='email1' value='".$edit_user['email']."' /><br/>
	Пароль:<br> <input type='text' name='pass1' value='".$edit_user['password']."' /><br/>
	Статус:<br> <select name='status1'><option value='Гонщик'>Гонщик</option><option value='Админ'>Админ</option><option value='Модератор'>Модератор</option><option value='VIP'>VIP</option></select><br/>
	Бензин:<br> <input type='text' name='fuel1' value='".$edit_user['fuel']."' /><br/>
	Скорость:<br> <input type='text' name='speed1' value='".$edit_user['speed']."' /><br/>
	Уровень:<br> <input type='text' name='level1' value='".$edit_user['level']."' /><br/>
	Баксы:<br> <input type='text' name='money1' value='".$edit_user['money']."' /><br/>
	Золото:<br> <input type='text' name='money12' value='".$edit_user['money2']."' /><br/>
	Опыт:<br> <input type='text' name='opit1' value='".$edit_user['opit']."' /><br/>
	Машина:<br> <input type='text' name='car1' value='".$edit_user['car']."' /><br/>
	Машина имя:<br> <input type='text' name='carname1' value='".$edit_user['carname']."' /><br/>
	Рейтинг:<br> <input type='text' name='raiting1' value='".$edit_user['raiting']."' /><br/>
	Аватар:<br> <input type='text' name='avatar1' value='".$edit_user['avatar']."' /><br/>
	IP:<br> <input type='text' disabled='disabled' name='ip1' value='".$edit_user['ip']."' /><br/>
	Дата регистрации:<br> <input disabled='disabled' type='text' name='date1' value='".$edit_user['date']."' /><br/>
	<input type='submit' name='submitsoz' class='btn' value='Сохранить'/>
	</form>
</div>
<div class='adminka_a'><a href='index.php?'>» В админку</a></div>
<p align='center' style='margin-top:3px;'>&copy; 2013</p>
</body>
</html>
";
exit();
}
	$igroki = mysql_query("SELECT * FROM users ORDER BY id ASC") or die(mysql_error());
	$row_ig = mysql_fetch_array($igroki);
	echo "<div class='menu'><p style='color:red;padding-bottom:4px;margin:0;'>Пользователи: </p>";
	do{
	$usersall = $row_ig['id'];
		printf("<b>ID:</b> <font color='yellow'>$usersall</font> <b>Игрок:</b> <a href='?users&edit=%s'>%s</a><br/>",$row_ig['id'],$row_ig['nick']);
	}while($row_ig = mysql_fetch_array($igroki));
	echo "</div><div class='adminka_a'><a href='index.php?'>» В админку</a></div>";
}else{
	echo <<<sozdatel
	<div class="menu">
	<a href="?users">» Игроки</a><br/>
	<a href="?addavto">» Добавить машину</a><br/>
	<a href="?addvis">» Добавить на выставку</a><br/>
	<a href="?cars">» Машины</a><br/>
	<a href="?turnir">» Анонс турниров</a><br/>
	<a href="?addnews">» Добавить новость</a><br/>
	<a href="?clearbar">» Очистить бар</a><br/>
	</div>
sozdatel;
}
}elseif($data_user['status'] == "Админ"){
if(isset($_GET['clearbar'])){
	mysql_query("DELETE FROM `bar`") or die(mysql_error());
	echo "<meta http-equiv='refresh' content='0; URL=index.php?' />";
	exit();
}
if(isset($_GET["cars"])){
	echo "<meta http-equiv='refresh' content='0; URL=index.php?' />";
	exit();
}
if(isset($_GET["addavto"])){
	echo "<meta http-equiv='refresh' content='0; URL=index.php?' />";
	exit();
}if(isset($_GET["addnews"])){
	echo "<meta http-equiv='refresh' content='0; URL=index.php?' />";
	exit();
}if(isset($_GET["turnir"])){
	echo "<meta http-equiv='refresh' content='0; URL=index.php?' />";
	exit();
}
if(isset($_GET['users'])){
if(isset($_GET['edit'])){
	$edit_id = (int)$_GET['edit'];
	$edit_user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE id='".$edit_id."'")) or die(mysql_error());
print "<div class='menu'>
	<form action='update_user.php' method='post'>
	<font color='#fff'>ID игрока: <b>".$edit_user['id']."</b></font><br/>
	<input type='hidden' name='id3' value='".$edit_user['id']."' />
	Ник: <input type='text' disabled='disabled' name='nick3' value='".$edit_user['nick']."' /><br/>
	E-mail: <input type='text' disabled='disabled' name='email3' value='".$edit_user['email']."' /><br/>
	Статус: <select name='status3'><option value='VIP'>VIP</option><option value='Гонщик'>Гонщик</option></select><br/>
	Бензин: <input type='text' disabled='disabled' name='fuel3' value='".$edit_user['fuel']."' /><br/>
	Скорость: <input type='text' disabled='disabled' name='speed3' value='".$edit_user['speed']."' /><br/>
	Уровень: <input type='text' disabled='disabled' name='level3' value='".$edit_user['level']."' /><br/>
	Баксы: <input type='text' disabled='disabled' name='money3' value='".$edit_user['money']."' /><br/>
	Рейтинг: <input type='text' disabled='disabled' name='raiting3' value='".$edit_user['raiting']."' /><br/>
	<input type='submit' name='submitadm' class='btn' value='Сохранить'/>
	</form>
</div>
<div class='adminka_a'><a href='index.php?'>» В админку</a></div>
<p align='center' style='margin-top:3px;'>&copy; 2013</p>
</body>
</html>
";
exit();
}
	$igroki = mysql_query("SELECT * FROM users ORDER BY id ASC") or die(mysql_error());
	$row_ig = mysql_fetch_array($igroki);
	echo "<div class='menu'><p style='color:red;padding-bottom:4px;margin:0;'>Пользователи: </p>";
	do{
	$usersall = $row_ig['id'];
		printf("<b>ID:</b> <font color='yellow'>$usersall</font> <b>Игрок:</b> <a href='?users&edit=%s'>%s</a><br/>",$row_ig['id'],$row_ig['nick']);
	}while($row_ig = mysql_fetch_array($igroki));
	echo "</div><div class='adminka_a'><a href='index.php?'>» В админку</a></div>";
}else{
	echo <<<admin
	<div class="menu">
	<a href="?users">» Игроки</a><br/>
	<a href="?clearbar">» Очистить бар</a><br/>
	</div>
admin;
}
}elseif($data_user['status'] == "Модератор"){
if(isset($_GET['clearbar'])){
	echo "<meta http-equiv='refresh' content='0; URL=index.php?' />";
	exit();
}if(isset($_GET['cars'])){
	echo "<meta http-equiv='refresh' content='0; URL=index.php?' />";
	exit();
}if(isset($_GET['addnews'])){
	echo "<meta http-equiv='refresh' content='0; URL=index.php?' />";
	exit();
}if(isset($_GET['turnir'])){
	echo "<meta http-equiv='refresh' content='0; URL=index.php?' />";
	exit();
}if(isset($_GET['addavto'])){
	echo "<meta http-equiv='refresh' content='0; URL=index.php?' />";
	exit();
}
if(isset($_GET['users'])){
if(isset($_GET['edit'])){
	$edit_id = (int)$_GET['edit'];
		if($edit_id == 1){
		echo "<meta http-equiv='refresh' content='0; URL=index.php?users' />";
		exit();
	}else{
	$edit_user = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE id='".$edit_id."'")) or die(mysql_error());
print "<div class='menu'>
	<form action='update_user.php' method='post'>
	<font color='#fff'>ID игрока: <b>".$edit_user['id']."</b></font><br/>
	<input type='hidden' name='id4' value='".$edit_user['id']."' />
	Ник: <input type='text' disabled='disabled' name='nick4' value='".$edit_user['nick']."' /><br/>
	<input type='submit' name='submitmod' class='btn' value='Сохранить'/>
	</form>
</div>
<div class='adminka_a'><a href='index.php?'>» В админку</a></div>
<p align='center' style='margin-top:3px;'>&copy; 2013</p>
</body>
</html>
";
exit();
}
}
	$igroki = mysql_query("SELECT * FROM `users` ORDER BY `id` ASC") or die(mysql_error());
	$row_ig = mysql_fetch_array($igroki);
	echo "<div class='menu'><p style='color:red;padding-bottom:4px;margin:0;'>Пользователи: </p>";
	do{
	$usersall = $row_ig['id'];
		printf("<b>ID:</b> <font color='yellow'>$usersall</font> <b>Игрок:</b> <a href='?users&edit=%s'>%s</a><br/>",$row_ig['id'],$row_ig['nick']);
	}while($row_ig = mysql_fetch_array($igroki));
	echo "</div><div class='adminka_a'><a href='index.php?'>» В админку</a></div>";
}else{
	echo <<<moder
	<div class="menu">
	» <a href="?users">Игроки</a><br/>
	</div>
moder;
}
}else{
	echo "<meta http-equiv='refresh' content='0; URL=../index.php' />";
	exit();
}
?>
<div class='title'>&copy; DagLowRaceClub <?=date("Y")?>
</body>
</html>
<?
}
}
?>