<?php
require_once('conf/dbc.php');
require_once('conf/session_start.php');
require_once('conf/ban.php');
$page_title = 'Арена';
require_once('conf/head.php');
if ((isset($_SESSION['id'])) and (isset($_SESSION['nick'])))  {
  require_once('conf/top.php');
}
if ((!isset($_SESSION['id'])) and (!isset($_SESSION['nick'])))  {
header('Location: /index.php');
}
//<!--Переменные-->//
$id = abs(intval($_SESSION['id'])); //ID user
$nick = filter($_SESSION['nick']); //Nick User
$type = abs(intval($_GET['type'])); //Type
$type = mysqli_real_escape_string($dbc, trim($type));	
//////////////////////////////////////
$user_q = "SELECT * FROM users WHERE id = $id LIMIT 1";
$user_r = mysqli_query($dbc, $user_q) or die('ERROR: 1');
$user = mysqli_fetch_array($user_r);
$lvl1 = $user['lvl'];
$hp1 = $user['hp'];
$bronya1 = $user['bronya'];
$mhp = $user['max_hp'];
$dmg11 = $user['yron_p'];
$dmg12 = $user['yron_w'];
$av1 = $user['avatar'];
$lvldo=($user['lvl']-1);
$habar = $user['habar'];
$timearena = $user['timearena'];
if((time()-$timearena) < 1800) {header('location: arena.php');}
if($lvl1 < 5){
echo '<br/><center><p class="name">Дуэли</p></center>Арена доступна с 5 уровня';
require_once('conf/navig.php');
require_once('conf/foot.php');
exit();
}
echo '<p class="podmenu"></p>';
if($type == 1) {
if($user[habar]>=1500) {
$dbc->query("update users set habar =habar -1500 where id = '$id' limit 1");}
else{header('location: arena.php?err=4');}
$op_q = "SELECT * FROM users where id != $id and lvl =$lvldo ORDER BY RAND() DESC LIMIT 1";
$op_r = mysqli_query($dbc, $op_q) or die ('Errror 2 Arena Oponent');
while($op = mysqli_fetch_array($op_r))
{
$nick_2 = $op['nick'];
$id_2 = $op['id'];
$avatar_2 = $op['avatar'];
$lvl_2 = $op['lvl'];
$status_a_2 = $op['status_a'];
$hp_2 = $op['hp'];
$bronya_2 = $op['bronya'];
$dmg_2_1 = $op['yron_p'];
$dmg_2_2 = $op['yron_w'];
$opid = $op['id'];
echo '<table border="2px solid black">';
//Ники
echo'<br/><center><p class="name2">Дуэли</p></center>';
echo'<p style="border-top: dashed #444e4f 1px;"> </p>';
echo '<center><b>'.$nick.'</b> против <b><a href="profile.php?id='.$id_2.'">'.$nick_2.'</b></a></center></p>';
echo'<p style="border-top: dashed #444e4f 1px;"> </p>
<center></p></center>
<p class="white" style="background: #303030;">Хочет сказать тебе: <span class="bonus">'.$status_a_2.'</span></p>';


//Аватар
echo '
<div style="float: left;">
<img src="/img/avatars/'.$av1.'"  width="65" height="65"><br/>
<img src="img/ico/lvl.gif"/>'.$lvl1.'<br/>
<img src="img/ico/life.png"/>'.$hp1.'<br/>
<img src="img/ico/shield.png"/>'.$bronya1.'<br/>
<img src="img/ico/to4nost.png"/>'.$dmg11.'||'.$dmg12.'<br/>
</div>
<div style="float: right;">
<img src="/img/avatars/'.$avatar_2.'"  width="65" height="65"><br/>
<img src="img/ico/lvl.gif"/>'.$lvl_2.'<br/>
<img src="img/ico/life.png"/>'.$hp_2.'<br/>
<img src="img/ico/shield.png"/>'.$bronya_2.'<br/>
<img src="img/ico/to4nost.png"/>'.$dmg_2_1.'||'.$dmg_2_2.'<br/>';
echo '</table>';
echo '<div style="clear:left; background: #303030;">
<p class="podmenu" style="border-top:1px solid #444e4f; background-color:#1c252f;"></p>
<table>
<tr>
<td style="width:33%;padding-right:4px;">
<div style="position:relative;">
<a class="simple-but border gray mb1" href="arena_a.php?attack='.$opid.'"><span><span>Напасть</span></span></a>

</div>
</td>
<td style="width:33%;padding-left:4px;">
<div style="position:relative;">
<a class="simple-but gray border mb1" href="arena1.php?type=1"><span><span>Следующий</span></span></a>

</div>
</td>
</tr>
</table>
<div class="foot"><a href="arena.php" class="foot"><img src="img/ico/arena.png" width="12" height="12"/>Дуэли</a></div>
</div>';
}
} //LVL < LVL User
if($type == 2) {
if($user[habar]>=1500) {
$dbc->query("update users set habar =habar -1500 where id = '$id' limit 1");}
else{header('location: arena.php?err=4');}
echo'<center><p class="name2">Арена</p></center>';

$op_q2 = "SELECT * FROM users where id != $id and lvl = $lvl1 ORDER BY RAND() DESC LIMIT 1";
$op_r2 = mysqli_query($dbc, $op_q2) or die ('Errror 2 Arena Oponent');
while($op2 = mysqli_fetch_array($op_r2))
{
$nick_2 = $op2['nick'];
$id_2 = $op2['id'];
$avatar_2 = $op2['avatar'];
$lvl_2 = $op2['lvl'];
$status_a_2 = $op2['status_a'];
$hp_2 = $op2['hp'];
$bronya_2 = $op2['bronya'];
$dmg_2_1 = $op2['yron_p'];
$dmg_2_2 = $op2['yron_w'];
$opid = $op2['id'];
echo '<table border="2px solid black">';
//Ники
echo'<p style="border-top: dashed #444e4f 1px;"> </p>';
echo '<center><b>'.$nick.'</b> против <b><a href="profile.php?id='.$id_2.'">'.$nick_2.'</b></a></center></p>';
echo'<p style="border-top: dashed #444e4f 1px;"> </p>
<center></p></center>
<p class="white" style="background: #303030;">Хочет сказать тебе: <span class="bonus">'.$status_a_2.'</span></p>

';
//Аватар
echo '
<div style="float: left;">
<img src="/img/avatars/'.$av1.'"  width="65" height="65"><br/>
<img src="img/ico/lvl.gif"/>'.$lvl1.'<br/>
<img src="img/ico/life.png"/>'.$hp1.'<br/>
<img src="img/ico/shield.png"/>'.$bronya1.'<br/>
<img src="img/ico/to4nost.png"/>'.$dmg11.'||'.$dmg12.'<br/>
</div>
<div style="float: right;">
<img src="/img/avatars/'.$avatar_2.'"  width="65" height="65"><br/>
<img src="img/ico/lvl.gif"/>'.$lvl_2.'<br/>
<img src="img/ico/life.png"/>'.$hp_2.'<br/>
<img src="img/ico/shield.png"/>'.$bronya_2.'<br/>
<img src="img/ico/to4nost.png"/>'.$dmg_2_1.'||'.$dmg_2_2.'<br/>';
echo '</table>';
echo '<div style="clear:left; background: #303030;">
<p class="podmenu" style="border-top:1px solid #444e4f; background-color:#1c252f;"></p>
<table>
<tr>
<td style="width:33%;padding-right:4px;">
<div style="position:relative;">
<a class="simple-but border gray mb1" href="arena_a.php?attack='.$opid.'"><span><span>Напасть</span></span></a>

</div>
</td>
<td style="width:33%;padding-left:4px;">
<div style="position:relative;">
<a class="simple-but gray border mb1" href="arena1.php?type=2"><span><span>Следующий</span></span></a>

</div>
</td>
</tr>
</table>
<div class="foot"><a href="arena.php" class="foot"><img src="img/ico/arena.png" width="12" height="12"/>Дуэли</a></div>
</div>';
}
} //LVL = LVL User
if($type == 3) {
if($user[habar]>=1500) {
$dbc->query("update users set habar =habar -1500 where id = '$id' limit 1");}
else{header('location: arena.php?err=4');}
echo'<br/><center><p class="name2">Дуэли</p></center>';
$op_q3 = "SELECT * FROM users where id != $id and lvl =$lvl1+1 ORDER BY RAND() DESC LIMIT 1";
$op_r3 = mysqli_query($dbc, $op_q3) or die ('Errror 2 Arena Oponent');
while($op3 = mysqli_fetch_array($op_r3))
{
$nick_2 = $op3['nick'];
$id_2 = $op3['id'];
$status_a_2 = $op3['status_a'];
$avatar_2 = $op3['avatar'];
$lvl_2 = $op3['lvl'];
$bronya_2 = $op3['bronya'];
$hp_2 = $op3['hp'];
$dmg_2_1 = $op3['yron_p'];
$dmg_2_2 = $op3['yron_w'];
$opid = $op3['id'];
echo '<table border="2px solid black">';
//Ники
echo'<p style="border-top: dashed #444e4f 1px;"> </p>';
echo '<center><b>'.$nick.'</b> против <b><a href="profile.php?id='.$id_2.'">'.$nick_2.'</b></a></center></p>';
echo'<p style="border-top: dashed #444e4f 1px;"> </p>
<center></p></center>
<p class="white" style="background: #303030;">Хочет сказать тебе: <span class="bonus">'.$status_a_2.'</span></p>
';
//Аватар
echo '
<div style="float: left;">
<img src="/img/avatars/'.$av1.'"  width="65" height="65"><br/>
<img src="img/ico/lvl.gif"/>'.$lvl1.'<br/>
<img src="img/ico/life.png"/>'.$hp1.'<br/>
<img src="img/ico/shield.png"/>'.$bronya1.'<br/>
<img src="img/ico/to4nost.png"/>'.$dmg11.'||'.$dmg12.'<br/>
</div>
<div style="float: right;">
<img src="/img/avatars/'.$avatar_2.'"  width="65" height="65"><br/>
<img src="img/ico/lvl.gif"/>'.$lvl_2.'<br/>
<img src="img/ico/life.png"/>'.$hp_2.'<br/>
<img src="img/ico/shield.png"/>'.$bronya_2.'<br/>
<img src="img/ico/to4nost.png"/>'.$dmg_2_1.'||'.$dmg_2_2.'<br/>';
echo '</table>';
echo '<div style="clear:left; background: #303030;">
<p class="podmenu" style="border-top:1px solid #444e4f; background-color:#1c252f;"></p>
<table>
<tr>
<td style="width:33%;padding-right:4px;">
<div style="position:relative;">
<a class="simple-but border gray mb1" href="arena_a.php?attack='.$opid.'"><span><span>Напасть</span></span></a>

</div>
</td>
<td style="width:33%;padding-left:4px;">
<div style="position:relative;">
<a class="simple-but gray border mb1" href="arena1.php?type=3"><span><span>Следующий</span></span></a>

</div>
</td>
</tr>
</table>
<div class="foot"><a href="arena.php" class="foot"><img src="img/ico/arena.png" width="12" height="12"/>Дуэли</a></div>
</div>';
}
} //LVL > LVL User
//////////////////////////////////////
if ((isset($_SESSION['id'])) and (isset($_SESSION['nick'])))  {
  require_once('conf/navig.php');
}
require_once('conf/foot.php');
?>
</body>
</html>