<?
include './system/common.php';
include './system/functions.php';
include './system/user.php';
if(!$user) exit(header('location: /menu'));
$id = _string(_num($_GET['id']));
if($id){
$u_pet = mysql_query('SELECT * FROM `pets_user` WHERE `id` = "'.$id.'"');
$u_pet = mysql_fetch_array($u_pet);
if(!$u_pet)exit(header('location: /menu'));}
$title = 'Сменить кличку';
include './system/h.php';
$id = _string(_num($_GET['id']));
$name = _string($_POST['name']);
if(isset($_GET['yes'])){
$cost = 600;
if($cost > $user['d']){
$_SESSION['not']= '<div class="header center block"><span class="red"><img src="/images/icons/cross.png"> Вам не хватает ещё <img src=\'/images/icons/donate.png\' alt=\'\'/> '.($cost - $user['d']).'</span></div><div class="dotted"></div>';
header('Location: /pet/setting/name/'.$id.'/');
exit;
}elseif(strlen($name)<3 OR strlen($name)>16){
$_SESSION['err']='<div class="block center header"><span class="red">Ошибка </span><div>Кличка должна быть от 3 до 16 символов</div></div><div class="dotted"></div>';
header('Location: /pet/setting/name/'.$id.'/');
exit;
}else{
$_SESSION['err']='<div class="block center header"><span class="green">Готово! </span><div>Вы успешно сменили кличку питомцу!</div></div><div class="dotted"></div>';
mysql_query("UPDATE `users` SET `d` = `d` - '{$cost}' WHERE `id` = '{$user["id"]}'");
mysql_query('UPDATE `pets_user` SET `name` = \''._string($_POST['name']).'\' WHERE `id` = '.$id.' LIMIT 1');
header('Location: /pet/setting/name/'.$id.'/');
exit;
}}?>
<form action='/pet/setting/name/<?=$id?>/yes' method='post'>
<div class="content">
<div class="header center block"><a href="/pet?id=<?=$u_pet['id']?>"><u><?=$u_pet['name']?></u></a>/ <?=$title?>
</div>
<div class="line"></div><div class="block"> Цена смены клички: 600<img src="/images/icons/donate.png" width="16" height="16"> </div><div class="dotted"></div>
<div class="block">
<?
if($petsu['id'] == $u_pet['id']) {
?> <input style='width:97%; height:30px' type='text' name='name' placeholder="Введите новую кличку..." value='<?=$cl['name']?>'/>
<span class="m3 btn_start middle"><span class="btn_end">
<button type="submit" class="btn">Сохранить</button></span>
</span>
<div>
</div></div><div class="clear"></div></div>
<?}else{
header('Location: /profile');
exit;}?>
</form>
<?
include './system/f.php';
?>