<?
	define('PROTECTOR', 1);
	ob_start();
	$head = 'catacomb';//фикс. места
	
	$textl='Подземелья';
	
	
	@include('files/db.php');
	@include('files/auth.php');
	@include('files/func.php');
	@include('files/core.php');
	@include('files/head.php');
	@include('files/zag.php');
	if($udata[lvl]>=70){
		switch($_GET[mod]){
			default:
			echo'</div><div class="menu">
			<a href="?mod=add">Создать комнату</a> ('.$catacomb_rock.' камней подземелья)<br/>
			</div>
			<div class="menu">
			Комнаты:<br/>';
			$row = mysql_query("SELECT * FROM `catacomb_room` WHERE level = 0 ORDER by `id` DESC LIMIT 10");
			$avt=mysql_num_rows($row);
			while($cat = mysql_fetch_array($row)){
				$row2 = mysql_query("SELECT * FROM `catacomb_user` WHERE id_room = '$cat[id]'");
				$avt2=mysql_num_rows($row2);
				echo '<img src="pic/main/sword.png" alt=""/><a href="catacomb_room.php?id='.$cat[id].'">'.check($cat[name]).'</a> ['.$avt2.'/'.$cset_max_user.'] ';
				userr($cat[lider]);
				
				echo'<br/>';
			}
			
			if($avt>10){
				echo'Случайные:<br/>';
				$row = mysql_query("SELECT * FROM `catacomb_room` WHERE level = 0 ORDER by RAND() DESC LIMIT 10");
				$avt=mysql_num_rows($row);
				while($cat = mysql_fetch_array($row)){
					$row2 = mysql_query("SELECT * FROM `catacomb_user` WHERE id_room = '$cat[id]'");
				$avt2=mysql_num_rows($row2);
				echo '<img src="pic/main/sword.png" alt=""/><a href="catacomb_room.php?id='.$cat[id].'">'.check($cat[name]).'</a> ['.$avt2.'/8] ';
				userr($cat[lider]);
				
				echo'<br/>';
				}
				}
				
				if($avt){
				
				}else{
				echo'Нет свободных комнат';
				}
				break;
				case'add':
				if(empty($_POST[name])){
				
				echo "<form action=\"?mod=add\" method=\"POST\">";
				echo "Имя:<br/><input type=\"text\" size=\"20\" name=\"name\" maxlength=\"20\"/><br/><input type=\"submit\" value=\"Создать\" class=\"ibutton\"></div>";
				}else{
				if(strlen($_POST[name])<3 or strlen($_POST[name])>20){echo "Неверная длина имени!разрешено от 3 до 20 символов.<br/>";}
				elseif($udata[catacomb_rock]<$catacomb_rock){echo "Нехватает камней подземелья!<br/>";}
				elseif(!empty($_POST[name])){
				$input_text = mysql_escape_string(htmlspecialchars(strip_tags($_POST[name])));
				mysql_query("INSERT INTO catacomb_room SET name = '$input_text', lider = '$udata[id]'");
				$pi=mysql_insert_id();
				mysql_query("INSERT INTO catacomb_user SET id_room = '$pi', id = '$udata[id]', hp = '$udata[hpall]', uron = '$udata[sila]', lovk = '$udata[lovk]'");
				mysql_query("UPDATE users SET catacomb_rock = catacomb_rock - $catacomb_rock WHERE id = $udata[id]");
				header("Location: catacomb_room.php?id=$pi");
				
				}
				}
				break;
				}
				}else{
				echo'</div><div class="menu">
				Доступоно с 70 лвл!
				</div>';
				}
				
				@include('files/down.php');
				?>				