<?
/* Питомцы by wap_masterok */
/* Специально для teowap.ru */  

include_once '../system/common.php';

include_once '../system/functions.php';

include_once '../system/user.php';


if(!$user) {

  header('location: /');

exit;

}

$title = 'Питомец';
include '../system/h.php';

$buy = isset($_REQUEST['buy']) ? abs(intval($_REQUEST['buy'])) : false;

if($buy){

 $s = mysql_query('SELECT * FROM `pit_mag` WHERE `id` = "'.$buy.'"');
 $s = mysql_fetch_array($s);

mysql_query("INSERT INTO `pit` SET `user_id`='".$user['id']."' , `pit_id`='".$buy."'");
mysql_query("UPDATE `users` SET `pit_id` = '".$buy."',`g` = `g`- 600 WHERE `id` = '$user[id]' LIMIT 1");

header('location: /pit/');
}


if(isset($_GET['buy'])){





$sql = mysql_query("SELECT * FROM `pit_mag` ORDER BY `id` DESC");

	  	  while ($row = mysql_fetch_assoc($sql))
        {

echo " <div class='content'><img src='/pit/pet.png".$row['img']."' alt='*'/> <br /><div class='list'> ".$row['name']." <img src='/images/icon/gold.png' alt='*'/> ".$row['cena']." <br /> <li><a href='?buy=".$row['id']."' style='display: block;' class='menu_link'>Купить</a></li></div></div>";



        }


include_once '../system/f.php';
exit;
}



 $sack = mysql_query('SELECT * FROM `pit` WHERE `user_id` = "'.$user['id'].'"');
 $sack = mysql_fetch_array($sack);


 $p = mysql_query('SELECT * FROM `pit_mag` WHERE `id` = "'.$user['pit_id'].'"');
 $p = mysql_fetch_array($p);

 if(!$sack){

 echo "<div class='menu_link2'> У вас нет питомца <a href='?buy' style='display: block;' class='menu_link'>Купить</a></div>";


 }else{


echo " <div class='content'><img src='/pit/pet.png".$sack['img']."' alt='*'/> <br /><div class='list'> ".$sack['name']." <img src='/images/icon/str.png' alt='*'/> + ".$sack['sila']." | <img src='/images/icon/vit.png' alt='*'/> + ".$sack['heart']." | <img src='/images/icon/agi.png' alt='*'/> + ".$sack['ud']." | <img src='/images/icon/def.png' alt='*'/> + ".$sack['bron']." | <img src='/images/icon/mana.png' alt='*'/> + ".$sack['mana']." <br />
 Уровень: ".$sack['level']."<br /> <li><a href='tren.php?id=".$sack['id']."' style='display: block;' class='menu_link'>Тренировать</a></li></div></div>";


 }



include_once '../system/f.php';
?>