Файл: item.php
Строк: 113
<?php
require_once ('system/func.php');
auth(); // Закроем от не авторизованных
# Настройки #
$id = abs(intval($_GET['id']));
if($id)$item = mysql_fetch_assoc(mysql_query("SELECT * FROM `inv` WHERE `id` = '".$id."'"));
# Ошибки #
if(!$item){
$_SESSION['msg'] == 'Такой вещи не существует';
header('Location: /inv');
exit();
}
$title = $item['name'];
require_once ('system/header.php');
## Тип вещи ##
switch($item['tip']){
case 'golova':
$tip = 'Голова';
break;
case 'plechi':
$tip = 'Плечи';
break;
case 'tors':
$tip = 'Торс';
break;
case 'perchatki':
$tip = 'Перчатки';
break;
case 'lev':
$tip = 'Левая рука';
break;
case 'prav':
$tip = 'Правая рука';
break;
case 'nogi':
$tip = 'ноги';
break;
case 'obuv':
$tip = 'Обувь';
break;
}
## Качество ##
switch($item['skill']){
case '0':
$kachestvo = 'Простое';
$cena = 10;
break;
case '1':
$kachestvo = 'Обычное';
$cena = 100;
break;
case 10:
$kachestvo = 'Редкое';
$cena = 150;
break;
case 26:
$kachestvo = 'Эпическое';
$cena = 500;
break;
case 48:
$kachestvo = 'Легендарное';
$cena = 2500;
break;
case 100:
$kachestvo = 'Божественное';
$cena = 50000;
break;
}
if(isset($_GET['items_ok'])){
$items = mysql_fetch_assoc(mysql_query("SELECT * FROM `item` WHERE `id` = '".num($_GET['items_ok'])."'"));
if($items['tip'] != $item['tip'] and $items['skill'] != $item['skill'] and $items['name'] == $item['name']){
$_SESSION['msg'] = "При смене вещи произошла ошибка";
header("Location: ?items");
exit();
}
if($user['gold'] < ceil($items['cena']*50/100)){
$_SESSION['msg'] = "Не хватает ".ico('icons','gold.png')." ".(ceil($items['cena']*50/100)-$user['gold'])." золота";
header("Location: ?items");
exit();
}
mysql_query("update `inv` set `name` = '$items[name]', `item` = '$items[item]' where (`id` = '".$item['id']."')");
mysql_query("update `users` set `gold` = '".($user['gold']-ceil($items['cena']*50/100))."' where (`id` = '".$myID."')");
$_SESSION['msg'] = "Вещь успешно изменена";
header("Location: ?");
exit();
}
if(isset($_GET['items']) and $item[id_user] == $myID){
$q = mysql_query("SELECT * FROM `item` WHERE `tip` = '$item[tip]' AND `skill` = '$item[skill]' AND `name` != '$item[name]' ORDER BY `id` ASC");
echo "<div class='block'>";
while($post = mysql_fetch_assoc($q)) {
echo "<div class='oh'><img src='/images/items/$post[tip]/$post[item].png' style='margin-right:3px;margin-top:-2px;'></div><a>$post[name]</a>";
echo "<div style='clear:both'></div>";
echo "<hr><a href='?items_ok=$post[id]' class='link center'>Выбрать вещь за ".ico('icons','gold.png')." ".ceil($post['cena']*50/100)."</a>";
}
echo "</div>";
echo "<a href='?' class='link'>Вернуться назад</a>";
require_once ('system/footer.php');
break;
}
if(isset($_GET['snar']) and $myID == $item['id_user']){
$inv = mysql_result(mysql_query("SELECT COUNT(*) FROM `inv` WHERE `odeta` = 'net' AND `id_user` = '$myID'"),0);
if($inv == 20){
$_SESSION['msg'] = "Вы не смогли поднять вещь, ваша сумка переполнена";
header("Location: ?$random");
exit();
}
$item_snar = mysql_query("SELECT * FROM `inv` WHERE `id_user` = '".$myID."' AND `tip` = '".$item['tip']."' AND `odeta` = 'da'");
$item_snar = mysql_fetch_array($item_snar);
if(isset($item_snar)){
mysql_query("update `users` set
`str` = '".(($user['str']-$item_snar['str'])+$item['str'])."',
`def` = '".(($user['def']-$item_snar['def'])+$item['def'])."',
`max_health` = '".(($user['max_health']-$item_snar['health'])+$item['health'])."'
where (`id` = '".$myID."')");
## Перенос заточки ##
#####################
mysql_query("update `inv` set `odeta` = 'net' where (`id` = '".$item_snar['id']."')");
mysql_query("update `inv` set `odeta` = 'da' where (`id` = '".$item['id']."')");
}else{
mysql_query("update `inv` set `odeta` = 'da' where (`id` = '".$item['id']."')");
/*
mysql_query("update `users` set
`str` = '".($user['str']+$item['str'])."',
`def` = '".($user['def']+$item['def'])."',
`max_health` = '".($user['max_health']+$item['health'])."'
where (`id` = '".$myID."')");
*/
}
$_SESSION['msg'] = 'Вещь успешно одета';
header('Location: /inv');
exit();
}
if(isset($_GET['inv']) and $myID == $item['id_user']){
mysql_query("update `inv` set `odeta` = 'net' where (`id` = '".$item['id']."')");
mysql_query("update `users` set
`str` = '".($user['str']-$item['str'])."',
`def` = '".($user['def']-$item['def'])."',
`max_health` = '".($user['max_health']-$item['health'])."'
where (`id` = '".$myID."')");
$_SESSION['msg'] = 'Вещь успешно снята';
header('Location: /snar/');
exit();
}
if(isset($_GET['exit']) and $myID == $item['id_user'] and $item['odeta'] == 'net'){
mysql_query("DELETE FROM `inv` where (`id` = '".$item['id']."')");
mysql_query("update `users` set `crystals` = '".($user['crystals']+$cena)."' where (`id` = '".$myID."')");
$_SESSION['msg'] = 'Вещь успешно продана';
header('Location: /inv');
exit();
}
echo "<div class='block'>";
echo "<div class='oh'><img src='/images/items/$item[tip]/$item[item].png' width='50px';style='margin-right:3px;margin-top:-10px;'></div><img src='/images/snop/$item[skill].png' width='16px'> $item[name] - $kachestvo<br>";
$item_snars = mysql_query("SELECT * FROM `inv` WHERE `id_user` = '".$myID."' AND `tip` = '".$item['tip']."' AND `odeta` = 'da'");
$item_snars = mysql_fetch_array($item_snars);
$param_1 = $item_snars['str']+$item_snars['def']+$item_snars['health'];
$param_2 = $item['str']+$item['def']+$item['health'];
if($param_1 > $param_2){
echo "-".($param_1-$param_2)." к параметрам";
}elseif($param_1 < $param_2){
echo "+".($param_2-$param_1)." к параметрам";
}
echo "<div style='clear:both;'></div></div>";
echo "<div class='block center'>";
echo ico('icons', 'str.png')." $item[str] ";
echo ico('icons', 'def.png')." $item[def] ";
echo ico('icons', 'health.png')." $item[health]<br>";
if($myID == $item['id_user']){
if($item['odeta'] == 'net'){
echo "$separ";
echo "<a href='?snar' class='btn2'>Надеть вещь</a><br>";
echo "<a href='?exit' class='btn2'>Продать за ".ico('icons', 'crystal.png')." $cena кристаллов</a><br>";
}else{
echo "$separ";
echo "<a href='?inv' class='btn2'>Снять вещь</a><br>";
}
if($item['skill'] > 0)echo "<a href='?items' class='btn2'>Изменить вид вещи</a>";
}
echo "</div>";
require_once ('system/footer.php');
?>