<?php
require_once('conf/dbc.php');
require_once('conf/session_start.php');
require_once('conf/ban.php');
$page_title = 'Борода';
require_once('conf/head.php');
require_once('conf/top.php');

echo'<center><p class="name">Борода</p></center>
    <p><img src="img/ico/boroda.png"/></p>
    <p class="net"> -Смотрите - выбирайте...</p>';
switch($_GET[type]){
default:
$query_us = "Select * from detectors order by det_id desc";
      $result_us = mysqli_query($dbc, $query_us) or die ('Ошибка передачи запроса к БД');
	  while ($row = mysqli_fetch_array($result_us)) {
     
	  echo'<div class="r6"><p><a href="detector.php?type=1&thing='.$row[det_id].'" class="menu"><img src="img/detectors/'.$row[screen].'" width="12" height="12" />'.$row[name].'</a></p></div>';
}
break;
case '1':

$user_id=abs(intval($_SESSION['id']));
$user=$dbc->query("Select * from users  where id = '$user_id' limit 1")->fetch_assoc();
$thing_id = abs(intval($_GET['thing']));
  $query_c = "Select * from detectors where det_id = '$thing_id' limit 1";
  $result_c = mysqli_query($dbc, $query_c) or die ('Ошибка передачи запроса к БД');
  $det = mysqli_fetch_array($result_c);
if ($det == 0) {
  ?>
  <script type="text/javascript">
  document.location.href = "detector.php";
  </script>
  <?php
  exit();
}
?>
 <?php if(!empty($_GET['err'])) {?>
   <?php if ($_GET['err']==1) {echo '<p style="border-top: dashed #444e4f 1px;"></p><span class="red">У вас не хватает хабара</span>';}?>
   <?php if ($_GET['err']==2) {echo '<p style="border-top: dashed #444e4f 1px;"></p><span class="red">У вас не хватает рублей</span>';}?>
   <?php } 
  ?>
<p><a href="detector.php" class="prof"><img src="img/ico/left.png" /> Назад к Бороде</a></p>
    <p>[<img src="img/ico/money.png" width="12" height="12"/> <span class="white"><?php echo $user['money'];?></span>] [<img src="img/ico/materials.png" width="12" height="12"/> <span class="white"><?php echo $user['habar'];?></span>]</p>
  <div style="border-style: double; border-width: 1px;">
 <div class="stats">
<center><p class="podmenu" style="border-top:1px solid #444e4f; background-color:#1c252f;"><?php echo $det['name'];?></p>
	<p><img src="img/detectors/<?php echo $det['screen'];?>" width="65" height="75" /></p></center>
	<p><b>Характеристики:</b></p> 
	<p><span class="net">Шанс нахождения артефакта: <?php echo $det['sh_nahod'];?>%</span><br />
	<p><span class="net">Шанс попадания в аномалию: <?php echo $det['anom'];?>%</span><br />
	<p><span class="net">Шанс удачной попытки достать: <?php echo $det['sh_dost'];?>%</span><br />
 	<p><span class="net">Прогресс при попытке достать: <?php echo $det['progress'];?>%</span><br />
</div>
	  <p class="zx"></p>
<a href="detector.php?thing=<?php echo $thing_id;?>&type=2" class="prof" onclick="return confirm ('Уверены?')">[Купить за <img src="img/ico/materials.png" width="12" height="12"/> <span class="white"><?php echo $det['price_hab'];?></span>]</a><a href="detector.php?thing=<?php echo $thing_id;?>&type=3" class="prof" onclick="return confirm ('Уверены?')">[Купить за <img src="img/ico/money.png" width="12" height="12"/> <span class="white"><?php echo $det['price'];?></span>]</a></p></div>
	  <?php
break;
case'2':
$user_id=abs(intval($_SESSION['id']));
$user=$dbc->query("Select * from users  where id = '$user_id' limit 1")->fetch_assoc();
$thing_id = abs(intval($_GET['thing']));
  $query_c = "Select * from detectors where det_id = '$thing_id' limit 1";
  $result_c = mysqli_query($dbc, $query_c) or die ('Ошибка передачи запроса к БД');
  $det = mysqli_fetch_array($result_c);
  $name = $det['name'];
  $lvl_need = $det['lvl_need'];
 $sh_dost = $det['sh_dost'];
 $anom = $det['anom'];
 $progress = $det['progress'];
 $screen = $det['screen'];
 $sh_nahod = $det['sh_nahod'];
 $price_hab = $det['price_hab'];
if ($price_hab > $user[habar]) {header('location: /detector.php?type=1&thing='.$det['det_id'].'&err=1');
exit();}

  $query = "insert into my_detector (`user_id`, `place`, `lvl_need`, `name`, `sh_nahod`, `anom`, `sh_dost`, `progress`,`screen`) values ('$user_id', '0', '$lvl_need', '$name', '$sh_nahod', '$anom','$sh_dost','$progress','$screen')";
  $result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД');
 $query_up = "update users set habar=habar -'$price_hab' where id = '$user_id' limit 1";
  $result_up = mysqli_query($dbc, $query_up) or die ('Ошибка передачи запроса к БД');
 ?>
  <script type="text/javascript">
    document.location.href = "my_det.php?thing=<?php echo "$thing_id";?>&err=4";
    </script>
  <?php
}
require_once('conf/navig.php');
require_once('conf/foot.php');
?>
</div>
</body>
</html>