<?
require_once '../core/system.php';
echo only_reg();
$header = 'Покупка питомца';
require_once '../core/head.php';
?>
<?
{
?>
<?php
if($err) echo "<div class='xar'>" , $err , "</div>";
if(isset($_POST['ok'])){
    if(isset($_POST['idpets'])){
        $pets = mysql_query("SELECT * FROM pets WHERE id='".$_POST['idpets']."'") or die(mysql_error());
        $pets_row = mysql_fetch_array($pets);
        if(abs($user['gold']) < $pets_row['price']){
            echo "<div class='menu'><center>Извини,но у тебя не хватает золота!</center></div>";
        }else{
            $query = mysql_query("SELECT COUNT(id_pets) FROM mypets WHERE id_user='".$user['id']."' AND id_pets='".$_POST['idpets']."'") or die(mysql_error());
                if(mysql_result($query, 0) > 0){
                    echo "<div class='menu'><center><span class='red'>Этого питомца ты уже купил !</span></center></div>";

                }else{
                        $okcar1 = mysql_query("INSERT INTO mypets(id_pets,id_user,pets,petsname,silapets,healthpets,vinoslpets) VALUES('".$_POST['idpets']."','".$user['id']."','".$pets_row['pets']."','".$pets_row['petsname']."','".$pets_row['silapets']."','".$pets_row['healthpets']."','".$pets_row['vinoslpets']."')") or die(mysql_error());
                        if($okcar1 == true){
                        $resmon = abs($user['gold']) - $pets_row['price'];
                        mysql_query("UPDATE `user` SET gold='".$resmon."',pets='".$pets_row['pets']."',petsname='".$pets_row['petsname']."',silapets='".$pets_row['silapets']."',healthpets='".$pets_row['healthpets']."',vinoslpets='".$pets_row['vinoslpets']."',petschek='1' WHERE id='".$user['id']."'") or die(mysql_error());
                        $_SESSION['pets'] = "pets";
                        echo "<center><span class='yellow'> <img src='/images/icon/pit.png'> Питомец успешно куплен</span></center>";
echo" <div class='player menuList'><li><a href='/pets/index.php'><img src='/images/icon/user.png'>Мой питомец</a></li></div><div class='line'></div>";
                    include '../core/foot.php';
                        exit();
                }
                }
        }
    }
}
$pets = mysql_query("SELECT * FROM pets WHERE `level` <= '".$user['level']."'") or die(mysql_error());
$pets_row = mysql_fetch_array($pets);
do{
echo "<div class='block_zero player'>";
        printf("<img src='%s' alt='%s' height='80' style='margin-right:5px;float:left;'/>
         <img src='/images/icon/pit.png' alt='пет'/> <b><span class='yellow'>%s</b><br/>
         <img src='/images/icon/gold.png' alt='Цена'/> Цена: %s <br/>
         <img src='/images/icon/str.png' alt='str'/> Сила: %s <br>
         <img src='/images/icon/vit.png' alt='vit'/> Здоровье: %s <br>
         <img src='/images/icon/mana.png' alt='mana'/> Выносливость: %s <br>

        <form action='' method='post'>
            <input type='hidden' name='idpets' value='".$pets_row['id']."' />
            <center><span class='btn'><span class='end'><input class='label' type='submit'' name='ok' value='Купить'>Купить</span></span></center>
        </form>
        <div class='dot-line'></div>
        </div></div>
        ",$pets_row['pets'],$pets_row['petsname'],$pets_row['petsname'],$pets_row['price'],$pets_row['silapets'],$pets_row['healthpets'],$pets_row['vinoslpets']);
}while($pets_row = mysql_fetch_array($pets));
}

echo "<div class='menuList player'>";
echo "<li><a href='/pets/'><img src='/images/icon/arrow.png'>К питомцу</a></li>";
echo "</div>";
include '../core/foot.php';
?>