<?php
define('PROTECTOR', 1);


include('files/db.php');
include('files/auth.php');
include('files/func.php');
$textl='Ломбард';
going();
include('files/core.php');
include('files/head.php');
include('files/zag.php');
$d = time();
switch($_GET['mod']){
//-----
default:
echo"<a href=\"lambard.php?mod=item\">Сдать вещи</a><br/>";
echo"<a href=\"lambard.php?mod=res\">Сдать ресурсы</a></br> $div";
echo'<a href="javascript:history.go(-1)">Назад</a>';break;
//-----
case 'item':
echo'<div class="main"><div class="block_zero center">Хотите продать вооружение?</div><div class="mini-line"></div>';
echo'<div class="block_zero"><a href="inventar.php?"><img src="image/icon/bag.png" alt="*"> Нет, я передумал</a></div><div class="mini-line"></div></div>';
$req = mysql_query("SELECT * FROM `weapon` WHERE `usr` = '$log' AND `image` = 'not'");
$avto=mysql_num_rows($req);
if(empty($_GET['id'])){
if($avto>=1){
$am=0;
While($mag = mysql_fetch_array($req)){
$cena=round($mag['cena']*1);
//-----
if($udata['lvl']>$mag['nlvl']){
$font="#AAAAAA";
$pic="downlvl.png";
}
if($udata['lvl']>=$mag['nlvl'] AND $udata['lvl']<=$mag['nlvl']+5){
$font="#9c9";
$pic="ok.png";
}
if($udata['lvl']<$mag['nlvl']){
$font="#c66";
$pic="error.png";
}
$wep = mysql_query("SELECT * FROM `weapon` WHERE `image` = 'yes' AND `usr` = '$log' AND `tip` = '$mag[tip]'") OR die (mysql_error());
$wep = mysql_fetch_array($wep);
$stat = $wep['hp']+$wep['mp']+$wep['krit']+$wep['ukrit']+$wep['sila']+$wep['lovk']+$wep['prot'];
$statmag = $mag['hp']+$mag['mp']+$mag['krit']+$mag['ukrit']+$mag['sila']+$mag['lovk']+$mag['prot'];
if($stat==$statmag){
$tex=" Надета такая же вещь!";
}
if($statmag-$stat>0){
$sta=$statmag-$stat;
$tex="<font color='#71cc71'> Лучше +$sta</font>";
}
if($statmag-$stat<0){
$sta=$statmag-$stat;
$tex="<font color='#FF6633'> Хуже $sta</font>";
}
$am=$am+$mag['cena'];
if(!empty($mag['img'])){
$patch="art/$mag[img]";
}else{
$patch="weapon/$mag[kompl]/$mag[tip].png";
}
switch($mag['tip']){
case 'weapon':
$tip='Оружие';
break;
case 'body':
$tip='Доспехи';
break;
case 'golova':
$tip='Шлем';
break;
case 'nogi':
$tip='Сапоги';
break;
case 'shit':
$tip='Щит';
break;
}
echo'<div class="main"><div class="block_zero"><img class="float-left" src="image/'.$patch.'" width="50" height="50" style="margin-left:10px; margin-right:10px;" alt="*"><span style="color: '.$font.';"><img src="image/icon/'.$pic.'" alt="*"> '.$tip.' '.$mag['name'].'</span><br><small><img src="image/icon/level.png" alt="*"> '.$mag['nlvl'].' ур. '.$tex.'<br>Прочность: '.$mag['proch'].'/10</small><div class="separ"></div><center><a class="btn" href="lambard.php?mod=item&id='.$mag['id'].'"><span class="end"><span class="label">Продать за <img src="image/icon/money.png" alt="*"> '.$cena.'</span></span></a></center>';
echo'</div><div class="dot-line"></div></div>';
}
}else{
echo'<div class="main"><div class="block_zero center">Сумка пуста</div></div>';
}
}else{
$req = mysql_query("SELECT * FROM `weapon` WHERE `usr` = '$log' AND `image` = 'not' AND `id` = '$_GET[id]'");
$avto=mysql_num_rows($req);
if($avto==1){
$item = mysql_fetch_array($req);
$cena=round($item['cena']*1);
//-----
$udata['money']=$udata['money']+$cena; //-----
mysql_query("UPDATE `users` SET `money` = '$udata[money]' WHERE `usr` = '$log'");
mysql_query("DELETE FROM `weapon` WHERE `usr` = '$log' AND `image` = 'not' AND `id` = '$_GET[id]'");
echo'Вы продали '.$tip.' '.$item['name'].' за <img src="image/icon/money.png" alt="*"> '.$cena.'<br></div></div>';
header('Location: lambard.php?mod=item');exit;
}else{
echo'<div class="main"><div class="block_zero center">Сумка пуста</div></div>';
}
}

break;
//-----
case 'res':
echo"<font color='#ffc22b'> • Ресурсы можно продать по 55% от магазинной стоимости<br> Цены указана за 1 единицу ресурса</font>$div";
$req = mysql_query("SELECT * FROM `res` WHERE `usr` = '$log' AND `kol` > '0' ORDER BY `cena` DESC");
////////////////////////////
$avto=mysql_num_rows($req);
if(empty($_GET[id])){
if($avto>=1){
While($mag = mysql_fetch_array($req))
{
$cena=round($mag[cena]/1.8);
echo"<a href=\"lambard.php?mod=res&id=$mag[id]\">$mag[name]</a> (<b>$mag[kol]</b> штук <img src='pic/bazar.gif' alt='*'/> $cena )<br/>";
}}else{echo"Нет ресурсов!<br/>";}}else{
if(empty($_POST[num])){
echo "<form action=\"lambard.php?mod=res&id=$_GET[id]\" method=\"post\">";
echo '<b>Сколько:</b><br/>';
echo '<input name="num"/><br/>';
echo '<input type="submit" value="Продолжить"/></form>';}else{
if($_POST[num]<1){echo"Ошибка!";
@include('files/down.php');exit;}
$req = mysql_query("SELECT * FROM `res` WHERE `usr` = '$log' and `id`='$_GET[id]'");
//////////////////////////////
$avto=mysql_num_rows($req);
if($avto==1){
$res = mysql_fetch_array($req);
/////////////////////
if($res[kol]-$_POST[num]<=0){
mysql_query("UPDATE `res` SET `kol` = '0' WHERE `usr` = '$log' and `id`='$_GET[id]'");
$nkol=$res[kol];
}else{
$res[kol]=$res[kol]-$_POST[num];
mysql_query("UPDATE `res` SET `kol` = '$res[kol]' WHERE `usr` = '$log' and `id`='$_GET[id]'");
$nkol=$_POST[num];
}
///////////////////////
$cena=round($res[cena]/1.8);
////////////////////////
$udata[money]=round($udata[money]+$cena*$nkol);
$cena=round($cena*$nkol);
/////////////////////
mysql_query("UPDATE `users` SET `money` = '$udata[money]' WHERE `usr` = '$log'");
//////////////////////////////////////
echo"<img src='pic/yes.png' alt='*'/> $res[name]($nkol штук) продано за $cena монет!<br/>";
}else{
echo"Нет ресурсов!<br/>";
}
}
}
echo"$div<a href=\"lambard.php?mod=res\">Назад</a><br><a href=\"lambard.php?\">В ломбард</a>";
break;


}
include('files/down.php');
?>