<?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
  exit();
}
$page_title = 'Аукцион/Снаряжение';
require_once('conf/head.php');
require_once('conf/top.php');
?><br/>
<div id="main">
<div class="stats">
<center><p class="profile">Торговля</p></center>
</div>
<?php
$user_id = abs(intval($_SESSION['id']));
$query = "Select thing_id, type, inf_id, stat1, stat2, speed, sost, privat, need_lvl from things where user_id='$user_id' and place=3 limit 20";
$result = mysqli_query($dbc, $query) or die ('Ошибка передачи запроса к БД');
$total = mysqli_num_rows($result);
?>
<div class="stats">
<p class="net"> Вещей на аукционе<span class="bonus">[<?php echo "$total"; ?>]
<?php
$err = abs(intval($_GET['err']));
if (!empty($err)) {
  if ($err == 1) {
  ?>
  <div id="error">
  Тайник переполнен.
  </div>
  <?php
  }
  if ($err == 2) {
  ?>
  <div id="error">
  Одежда не для вашего уровня.
  </div>
  <?php
  }
  if ($err == 3) {
  ?>
  <div id="error">
  Рюкзак переполнен.
  </div>
  <?php
  }
}
if ($total == 0) {
?>
<div class="stats">
<p><p><p class="net">Вы еще не выставили на аукцион не одной вещи</p>
</div>
<?php
}
else {
  $query_st = "Select max_hp, bronya, yron_p, lvl, tochn_p, yron_w, tochn_w from users where id = '$user_id'";
  $result_st = mysqli_query($dbc, $query_st) or die ('Ошибка передачи запроса к БД');
  $row_st = mysqli_fetch_array($result_st);
  $stat1_cl = $row_st['max_hp'];
  $stat2_cl = $row_st['bronya'];
  $stat1_p = $row_st['yron_p'];
  $stat2_p = $row_st['tochn_p'];
  $stat1_w = $row_st['yron_w'];
  $stat2_w = $row_st['tochn_w'];
  while ($row = mysqli_fetch_array($result)) {
    $thing_id = $row['thing_id'];
    $type = $row['type'];
	$inf_id = $row['inf_id'];
	$stat1 = $row['stat1'];
	$stat2 = $row['stat2'];
	$speed = $row['speed'];
	$sost = $row['sost'];
	$privat = $row['privat'];
	$bonus = $row['bonus'];
	$need_lvl = $row['need_lvl'];


	if ($type == 1) {////////Одежда
	$query_inf = "Select name, screen,klass from clothes where clothes_id='$inf_id' limit 1";
    $result_inf = mysqli_query($dbc, $query_inf) or die ('Ошибка передачи запроса к БД');
	$row_inf = mysqli_fetch_array($result_inf);
	$screen = $row_inf['screen'];
	$name = $row_inf['name'];
	$klass = $row_inf['klass'];
	?>
	 <a href="thing_auc.php?thing=<?php echo "$thing_id";?>" style="text-decoration:none" ><div class="r2"><p class="button3"><span class="black"><?php echo "$name";?></p></span></center>
	</p><center><img src="img/clothes/<?php echo "$screen";?>" alt="<?php echo "$name";?>" width="70" height="70"/></center>
	
       </div></a>
	<?php
	}
	if ($type == 2) {////////Пистолеты
	$query_inf = "Select name, screen,klass from pistols where pistols_id='$inf_id' limit 1";
    $result_inf = mysqli_query($dbc, $query_inf) or die ('Ошибка передачи запроса к БД');
	$row_inf = mysqli_fetch_array($result_inf);
	$screen = $row_inf['screen'];
	$name = $row_inf['name'];
	$klass = $row_inf['klass'];
	?>
	 <a href="thing_auc.php?thing=<?php echo "$thing_id";?>" style="text-decoration:none" ><div class="r2"><p class="button3"><span class="black"><?php echo "$name";?></span></p></center>
	</p><center><img src="img/weapons/<?php echo "$screen";?>" alt="<?php echo "$name";?>" />
         </div></a>
	<?php
	}
	if ($type == 3) {////////Автоматы
	$query_inf = "Select name, screen,klass from weapons where weapons_id='$inf_id' limit 1";
    $result_inf = mysqli_query($dbc, $query_inf) or die ('Ошибка передачи запроса к БД');
	$row_inf = mysqli_fetch_array($result_inf);
	$screen = $row_inf['screen'];
	$name = $row_inf['name'];
	$klass = $row_inf['klass'];
    ?>
<a href="thing_auc.php?thing=<?php echo "$thing_id";?>" style="text-decoration:none" ><div class="r2"><p class="button3"><span class="black"><?php echo "$name";?></p></span>
</p><center><img src="img/weapons/<?php echo "$screen";?>" alt="<?php echo "$name";?>" width="145" height="50"/></center>
	</div></a>
    <?php
	}
if ($type == 4) {////////шлемы
	$query_inf = "Select name, screen,klass from shlem where shlem_id='$inf_id' limit 1";
    $result_inf = mysqli_query($dbc, $query_inf) or die ('Ошибка передачи запроса к БД');
	$row_inf = mysqli_fetch_array($result_inf);
	$screen = $row_inf['screen'];
	$name = $row_inf['name'];
	$klass = $row_inf['klass'];
	?>
	 <a href="thing_auc.php?thing=<?php echo "$thing_id";?>" style="text-decoration:none" ><div class="r2"><p class="button3"><span class="black"><?php echo "$name";?></p></span></center>
	</p><center><img src="img/shlem/<?php echo "$screen";?>" alt="<?php echo "$name";?>" width="55" height="55"/></center>
	
       </div></a>
	<?php
	}
  }
}
?>
</div>
<?php
require_once('conf/navig.php');
require_once('conf/foot.php');
mysqli_close($dbc);
?>

</body>
</html>