
<?php
include 'core/system.php';

head('Аватар');

reg();
$total = $dbc->query("SELECT * FROM `avatars` where `ava` !='".$user['avatar']."'");






while($inf=$total->fetch_assoc()){

?>


<div class="lblue-panel">
<div class="panel-inner-2">

<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<td valign="top"><img src=/img/avatar/<?=$user['sex']?>/<?=$inf['ava']?>.png style="border-radius:2px"></td>

<td valign="top" style="padding-left:4px;">&nbsp;Цена: <?=$inf['gold']?><img src=/img/money/money.png><br/>


<a href="/avatar.php?id=<?=$inf['id']?><??>&amp;buy" class="gr-btn center"><span>Купить</span></a>




</td></tbody></table><div class="hr"></div>












</div>
</div>







<?
			  if(isset($_GET['buy']) and !empty($_GET['id'])){               

$pet_id = int($_GET['id']);
 
$pet = $dbc->query("SELECT * FROM `avatars` WHERE `ava`='".$pet_id."'")->fetch_assoc();





if(!$pet){
	header("Location: avatar.php");

exit; }


if($pet['ava']==$user['avatar']){
	header("Location: avatar.php");
exit; }


if($user['gold']<$pet['gold']){ $_SESSION['message']='Недостаточно Золота';
	header("Location: avatar.php"); 
exit; }


$dbc->query("UPDATE `users` SET `gold`=`gold`-'".$pet['gold']."', `avatar`='".$pet['ava']."' WHERE `id`='".$user['id']."'");


header('location: my.php?');exit;




}
}

 echo '
<div class="lblue-panel">
<div class="panel-inner-2">
Также ты можешь получить <a href="/av_pv.php">личный уникальный аватар!</a>


</div></div>

';


foot();
