<?
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><br/>";
echo"<a href=\"lambard.php?mod=shems\">Продать схемы</a><br/>";
echo'<a href="almaz.php">Торговец Драгоценностями</a><br/>';
echo'<a href="almaz2.php">Скупщик алмазов</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 'shems':
if ($_GET[page] == "" || $_GET[page] < 0 || $_GET[page] == "0") 
{
$_GET[page] = 0;
}
$next = $_GET[page] + 1;
$back = $_GET[page] - 1;
$num = $_GET[page] * 5;
if($_GET[page] == "0")
{$i = 1;}
else{$i = ($_GET[page]*5)+1;}
$viso = mysql_num_rows(mysql_query("SELECT usr FROM  shems"));
$puslap = floor($viso/5);
$times = date("H:i");



$req = mysql_query("SELECT * FROM `shems` WHERE `usr` = '$log'  ORDER BY id DESC LIMIT $num,5");
////////////////////////////
$avto=mysql_num_rows($req);
if(empty($_GET[id])){
if($avto>=1){
While($mag = mysql_fetch_array($req))
{
if($mag['unknow']=='0'){$mag['name']='Схема скрыта';}

$cena=round($mag[cena]/3);
echo"<a href=\"lambard.php?mod=shems&id=$mag[id]\">$mag[name]</a> ($mag[kol] штук, цена за 1, $cena монет)<br/>";
}

if ($_GET[page] > 0)
{
echo "<a href=\"lambard.php?mod=shems&page=$back\">< Назад</a>";
}

if($_GET[page] < $puslap || $_GET[page] == "" || $_GET[page] == 0)
{echo "<a href=\"lambard.php?mod=shems&page=$next\"> Далее ></a>";}



}else{
echo"Нет cхем!<br/>";
if ($_GET[page] > 0)
{
echo "<a href=\"lambard.php?mod=shems&page=$back\">< Назад</a>";
}


}
}else{
if(empty($_POST[num])){

echo" <form action=\"lambard.php?mod=shems&id=".mysql_real_escape_string($_GET[id])."\" method=\"post\">";
echo 'Сколько?<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 `shems` WHERE `usr` = '$log' and `id`='".mysql_real_escape_string($_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 `shems` WHERE usr='$log' and `id`='".mysql_real_escape_string($_GET['id'])."'");
$nkol=$res[kol];
}else{
$res[kol]=$res[kol]-$_POST[num];
mysql_query("UPDATE `shems` SET `kol` = '$res[kol]' WHERE `usr` = '$log' and `id`='".mysql_real_escape_string($_GET['id'])."'");
$nkol=$_POST[num];
}
///////////////////////
$cena=round($res[cena]/3);
////////////////////////
$udata[money]=round($udata[money]+$cena*$nkol);
$cena=round($cena*$nkol);
/////////////////////
mysql_query("UPDATE `users` SET `money` = '$udata[money]' WHERE `usr` = '$log'");
//////////////////////////////////////
echo"Схема: [$nkol штук] продана за $cena монет!<br/>";
}else{
echo"Нет схем!<br/>";
}
}
}
echo "<br/><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');
?>