<?
require_once 'core/system.php';


head('Покупка Питомцa');


if( !isset($_GET["id"]))
$_GET["id"]=0;
	$pet_id = int($_GET['id']);
if(isset($_GET['buy']) and !empty($_GET['id'])){
$pet_buy = $dbc->query("SELECT * FROM `pets_tj` WHERE `id` = '$pet_id'")->fetch_assoc(); 

if(!$pet_buy){


header('Location: spet.php?');exit;}
if($pet_buy['lite']!='iEpic'){ header("location:index.php");exit;}
$prov = $dbc->query("SELECT * FROM `user_pets` WHERE `id_user` =  '$user[id]' "); $dev = $prov->num_rows; if($dev>0){

$_SESSION['err'] = 'У вас уже есть питомец!';
header('Location: spet.php?');exit;}
elseif($user['gold'] < $pet_buy['g']){$_SESSION['err'] = 'У вас не достаточно золота!';


header('Location: spet.php?');exit;}
else{ 

$dbc->query("INSERT INTO `user_pets` SET 

`id_user` = '$user[id]', 
`id_pets` = '$pet_buy[id]', 
`name` = '$pet_buy[name]',
`str` = '$pet_buy[str]',
`vit` = '$pet_buy[vit]',
`def` = '$pet_buy[def]',
`img` = '$pet_buy[img]',
`level` = '1',
`arena_battle` = '10'

, `lite`  ='iEpic'") or die(mysql_error());


$dbc->query("UPDATE `users` SET 

`gold` = `gold` - '$pet_buy[g]', 



`s_pet` =  '1'
 WHERE `id` = '$user[id]'") or die(mysql_error()); 

header('Location: my.php'); 
exit;
} 
} 

$pets  = $dbc->query("SELECT * FROM `pets_tj` WHERE `lite`='iEpic'  ORDER BY `id` DESC LIMIT 20"); 













?><center><img src="img/at/pitomnik.jpg"></center><?



echo "<table cellpadding='0'  cellspacing='0'>";
 while($cor = $pets->fetch_assoc()){
?><div class="lblue-panel panel-inner-2">
<div class="el-img"><img alt="" src="<?=$cor['img']?>" class="i100 pet_brd"/></div>
<span class="iEpic"><big><?=$cor['name']?></big></span>

<div class="el-descr"><div class="mb5">
<span class="c-sel ml5">
<img src="img/stat/hp.png" alt=".">Здоровье: <span><?=$cor['vit']?></span></br>
<img src="img/stat/AKulak.png" alt=".">Сила: <span><?=$cor['str']?></span></br>
<img src="images/icons/armor.png" alt=".">Броня: <span><?=$cor['def']?></span></br>
</span>

</div>
</div>
</br><a href="spet.php?id=<?=$cor['id']?>&amp;buy" class="btn mt3">Приобрести за <span><nobr><img src="img/money/money.png"></span><?=$cor['g']?></nobr></span>

</a></div><?
 }
  
  
  
  
foot();
?>