<?
define('PROTECTOR', 1);

$headmod = 'lambard';//фикс. места

$textl='Ломбард';
include('files/path.php');
include($path.'files/db.php');
include($path.'files/auth.php');
include($path.'files/func.php');
going();
zasad();
ryd();
place_okr();
place_zamok();
place_tower();
include($path.'files/core.php');
include($path.'files/head.php');
include($path.'files/zag.php');

switch($_GET[mod]){

default:
echo"<a href=\"lambard.php?mod=item\">Продать вещи</a><br/>";
echo"<a href=\"lambard.php?mod=res\">Продать ресурсы</a>";
break;
case 'item':
$req = mysql_query("SELECT * FROM `item` WHERE `usr` = '$log' and `image`='not'");
////////////////////////////
$avto=mysql_num_rows($req);
if(empty($_GET[id])){
if($avto>=1){
While($mag = mysql_fetch_array($req))
{
$cena=round($mag[cena]/4);
echo"<a href=\"lambard.php?mod=item&amp;id=$mag[id]\">$mag[name]</a> (Цена $cena монет)<br/>";
}
}else{
echo"Нет вещей<br/>";
}
}else{
$req = mysql_query("SELECT * FROM `item` 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]/4);
$udata[money]=$udata[money]+$cena;

mysql_query("UPDATE `users` SET `money` = '$udata[money]' WHERE `usr` = '$log'");

mysql_query("DELETE FROM `item` WHERE usr='$log' and `image`='not' and `id`='$_GET[id]'");
        
echo"Вещь $item[name] продана за $cena монет!<br/>";
}else{
echo"Нет такой вещи<br/>";
}
}
echo"<a href=\"lambard.php?\">Назад</a>";
break;
case 'res':
$req = mysql_query("SELECT * FROM `res` WHERE `usr` = '$log'");
////////////////////////////
$avto=mysql_num_rows($req);
if(empty($_GET[id])){
if($avto>=1){
While($mag = mysql_fetch_array($req))
{
$cena=round($mag[cena]/4);
echo"<a href=\"lambard.php?mod=res&amp;id=$mag[id]\">$mag[name]</a> ($mag[kol] штук, цена за 1 $cena монет)<br/>";
}
}else{
echo"Нет ресурсов!<br/>";
}
}else{
if(empty($_POST[num])){
echo "<form action=\"lambard.php?mod=res&amp;id=$_GET[id]\" method=\"post\">";
echo '<b>Сколько:</b><br/>';
echo '<input name="num"/><br/>';
echo '<input type="submit" value="Продолжить"/></form>';
}else{
if($_POST[num]<=0){
echo"Ошибка!";
include($path.'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("DELETE FROM `res` 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]/4);
////////////////////////
$udata[money]=round($udata[money]+$cena*$nkol);
$cena=round($cena*$nkol);
/////////////////////
mysql_query("UPDATE `users` SET `money` = '$udata[money]' WHERE `usr` = '$log'");
//////////////////////////////////////
echo"$res[name]($nkol штук) продано за $cena монет!<br/>";
}else{
echo"Нет ресурсов!<br/>";
}
}
}
echo"<a href=\"lambard.php?\">Назад</a>";
break;
}
include($path.'files/down.php');
?>