<?

include './system/common.php';
    
 include './system/functions.php';

 include './system/user.php';

if(!$user) exit(header('location: /'));
  $title = 'Магазин питомцев';
  include './system/h.php';
if($petsu) exit(header('location: /'));
?>
<div class="content"><div class="block center color3 s125"> Магазин питомцев</div>
<?
$_petsi = mysql_query("SELECT * FROM `pets_shop` ORDER BY `id` DESC");
while($shop=mysql_fetch_assoc($_petsi)){
$i++;
?>
            <div class="line"></div>        <div class="block">        
    <span>    <img class="left mr8" src="/images/pets/<?=$shop['id']?>.jpg" width="100" height="100" alt="">    </span>
                                <img src="/images/pets/pet_<?=$shop['id']?>.png" width="16" height="16" alt=""> <span><?=$shop['name']?></span>        <span class="white">
    
    <img src="/images/icons/level.png" width="16" height="16" alt=""> 1 ур.    </span>
    <div>
            
    <div>
    <img src="/images/icons/health.png" width="16" height="16" alt=""> Здоровье: 100    </div>
            
    <div>
    <img src="/images/icons/damage.png" width="16" height="16" alt=""> Сила: 100    </div>
            
    <div>
    <img src="/images/icons/armor.png" width="16" height="16" alt=""> Защита: 100    </div>
        </div>
<div class="clear"></div>
</div>

    <div class="dotted"></div>
                <div class="block center">
            <span class="btn_start"><span class="btn_end"><a class="btn" href="?cost=<?=$shop['id']?>">купить за     <img src="/images/icons/silver.png" width="16" height="16" alt=""> 90000   <img src="/images/icons/gold.png" width="16" height="16" alt=""> 1000</a></span> </span>        </div>
        <div class="dotted"></div>
<?
}?>
<ul class="block small">
    <li>Питомцы очень полезны, они помогают владельцу в сражениях</li>
    <li>После покупки питомца его можно прокачать</li>
    <li>Одновременно иметь можно только одного питомца</li>
</ul></div>
<?

$cost = _string(_num($_GET['cost']));
if($cost) {
	
 $shop = mysql_fetch_array(mysql_query('SELECT * FROM `pets_shop` WHERE `id` = \''.$cost.'\''));

if(1000 > $user['g']) $errors[] = 'Ошибка, не хватает <img src=\'/images/icon/g.png\' alt=\'*\'/> '.(1000 - $user['g']).'<div class=\'separator\'></div>';
if(90000> $user['s']) $errors[] = 'Ошибка, не хватает <img src=\'/images/icon/s.png\' alt=\'*\'/> '.(90000 - $user['s']).'<div class=\'separator\'></div>';
  if($errors) {
echo '<div class=\'content\' align=\'center\'>';
foreach($errors as $error) {
          echo $error.'<br/>';}
echo '</div>
<div class=\'line\'></div>';
}else{
mysql_query('INSERT INTO `pets_user` SET  `user` = "'.$user['id'].'",`name` = "'.$shop['name'].'",`vit` = "'.$shop['vit'].'",`str` = "'.$shop['str'].'",`def` = "'.$shop['def'].'",`lvl` =  "1",`pet` = "'.$shop['id'].'"');
$pet_ids = mysql_insert_id();
mysql_query('UPDATE `users` SET `s` = `s` - 90000,`g` = `g` - 1000 WHERE `id` = "'.$user['id'].'"');

exit(header('location: /pets/'.$pet_ids.''));
}}
include './system/f.php';
?>