<?php

require_once('conf/dbc.php');
require_once('conf/session_start.php');
require_once('conf/ban.php');
if ((!isset($_SESSION['id'])) or (!isset($_SESSION['nick'])))  {
?>
<script type="text/javascript">
  document.location.href = "reg.php?err_login=1";
</script>
<?php
}
$page_title = 'Прилавок';
require_once('conf/head.php');
require_once('conf/top.php');
$type = abs(intval($_GET['type']));
$thing_id = abs(intval($_GET['thing']));
if (empty($thing_id) or empty($type)) {
  ?>
  <script type="text/javascript">
  document.location.href = "sales.php";
  </script>
  <?php
  exit();
}
if ($type <> 1) {
  ?>
  <script type="text/javascript">
  document.location.href = "salesman.php";
  </script>
  <?php
  exit();
}
if ($type == 1) {
  $query_c = "Select * from artefact where artefact_id = '$thing_id' limit 1";
  $result_c = mysqli_query($dbc, $query_c) or die ('Ошибка передачи запроса к БД');
  $row_cl = mysqli_fetch_array($result_c);
}
if ($row_cl == 0) {
  ?>
  <script type="text/javascript">
  document.location.href = "sales.php";
  </script>
  <?php
  exit();
}
?>
<div id="main">
  <div class="stats">
    <p class="podmenu">Прилавок</p>
  </div>
  <div class="stats">
    <p><img src="img/ico/left.png" /> <a href="sales.php">Назад к торговц</a>у</p>
  </div>
  <?php 
$user_id = abs(intval($_SESSION['id']));
  $query = "Select lvl,money, habar from users where id = '$user_id'";
  $result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД');
  $row = mysqli_fetch_array($result);
  $money = $row['money'];
  $habar = $row['habar'];
  $lvl = $row['lvl'];
  ?>
  <div class="stats">
    <p>[<img src="img/ico/money.png" width="12" height="12"/> <span class="white"><?php echo "$money"; ?></span>] [<img src="img/ico/materials.png" width="12" height="12"/> <span class="white"><?php echo "$habar"; ?></span>]</p>
  </div>
  <?php
$err = abs(intval($_GET['err']));
  if (!empty($err)) {?>
  <div id="error">
  <?php if ($err == 1) {echo 'У вас недостаточно средств';}?>
  </div>
  <?php
  }
  if ($row['lvl'] < $row_cl['lvl_need']) {
  ?>
  <div id="error">
  <p>Если вы купите эту вещь - вы не сможете её одеть пока не достигните <?php echo $row_cl['lvl_need'];?> уровня или выше</p>
  </div>
  <?php
  }
  ?>
  <div class="stats">
  <?php
  if ($type == 1) {
  ?>
  <table width="190" border="0" cellpadding="0" cellspacing="0">
      <tbody>
      <tr>
      <td width="54" valign="top"><img src="img/artefact/<?php echo $row_cl['screen'];?>" alt="Слот №1" /></td>
      <td width="136" valign="top">
	  <div class="clothes">
	    <p>
<?php
if ($row_cl['klass'] == 1) {?><img src="img/ico/class1.png" width="12" height="12"/><?php }
if ($row_cl['klass'] == 2) {?><img src="img/ico/class2.png" width="12" height="12"/><?php }
if ($row_cl['klass'] == 3) {?><img src="img/ico/class3.png" width="12" height="12"/><?php }
if ($row_cl['klass'] == 4) {?><img src="img/ico/class4.png" width="12" height="12"/><?php }
?><span class="white"><?php echo $row_cl['name'];?></span></p>
<p><span class="white"><?php echo $row_cl['lvl_need'];?></span> ур, новый</p>
<p>Броня: <font color="green">+ </font><span class="white"><?php echo $row_cl['bronya'];?></span> </p>
<p>Здор: <font color="green">+ </font><span class="white"><?php echo $row_cl['hp'];?></span> </p>
<p>Урон: <font color="green">+ </font><span class="white"><?php echo $row_cl['stats_yron'];?></span> </p>
<p>Точн: <font color="green">+ </font><span class="white"><?php echo $row_cl['stats_tochn'];?></span> </p>
      </div>
	  </td>
      </tr>
      </tbody>
      </table>
	  <div class="clothes">
	  <p>Состояние:  <span class="white">8/8</span></p>
	  </div>
<div class="zx"><?php if ($row_cl['price_hab'] >=0) {
?>[<a href="buy_art_thing.php?thing=<?php echo "$thing_id";?>&type=6&money=1">Купить за <img src="img/ico/materials.png" width="12" height="12"/> <span class="white"><?php echo $row_cl['price_hab'];?></span></a>] <br /><?php }  else {?><p class="clothes"><span class="bonus">[Mожно получить на <a href="monsters.php">рейде</a> или приобрести на <a href="auction.php">аукционе</a>]</span></p>
	  <?php }
	  if ($row_cl['price'] >=0) {
?>[<a href="buy_art_thing.php?thing=<?php echo "$thing_id";?>&type=6&money=2">Купить за <img src="img/ico/money.png" width="12" height="12"/> <span class="white"><?php echo $row_cl['price'];?></span></a>]<?php }
	  ?></p>
	  </div>
	  <?php
  }

require_once('conf/navig.php');
require_once('conf/foot.php');
mysqli_close($dbc);
?>

</body>
</html>