<?
define('PROTECTOR', 1);

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

$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=\"shopelexirs.php?mod=elexirs\">Отдел элексиров</a>";
break;

case 'elexirs':
$req = mysql_query("SELECT * FROM `shopelexirs` WHERE `city` = '$udata[city]' and `tip`='elexir'");
////////////////////////////
$avto=mysql_num_rows($req);

While($mag = mysql_fetch_array($req))
{
echo"<a href=\"shopelexirs.php?mod=info&amp;id=$mag[id]\">$mag[name]</a> ($mag[cena] монет) [<a href=\"shopelexirs.php?mod=sell&amp;id=$mag[id]\">купить</a>]<br/>";
}
echo"<a href=\"shopelexirs.php?\">Назад</a>";
break;
case 'info':
$req = mysql_query("SELECT * FROM `shopelexirs` WHERE `city` = '$udata[city]' and `id`='$_GET[id]'");

$avto=mysql_num_rows($req);
if($avto==0){
echo'Ошибка!';
include($path.'files/down.php');
exit;
}
$mag = mysql_fetch_array($req);
switch($mag[what]){
case 'hp':
$tip='жизнь';
break;
case 'mp':
$tip='ману';
break;
}
echo"<b>$mag[name]</b><br/>
Востанавливает: $tip<br/>
Едениц: $mag[give]<br/>
Цена: $mag[cena]<br/>
";
echo"<a href=\"shopelexirs.php?\">Назад</a>";
break;

case 'sell':
$req = mysql_query("SELECT * FROM `shopelexirs` WHERE `city` = '$udata[city]' and `id`='$_GET[id]'");

$avto=mysql_num_rows($req);
if($avto==0){
echo'Ошибка, такой вещи нет!';
include($path.'files/down.php');
exit;
}
$mag = mysql_fetch_array($req);

$req=mysql_query("SELECT * FROM domination WHERE id = '1'");
$dom = mysql_fetch_assoc($req);
if($dom['white']>$dom['black']){
$liders='white';
}elseif($dom['black']>$dom['white']){
$liders='black';
}else{
$liders='not';
}
if($udata['storona']==$liders){
$mag[cena]=round($mag[cena]-(($mag[cena]/100)*15));
}

$nmoney=$udata[money]-$mag[cena];

if($nmoney<0){
echo'Нехватает монет!';
include($path.'files/down.php');
exit;
}
$req1 = mysql_query("SELECT * FROM `res` WHERE `usr` = '$log' and `lat_name` = '$mag[lat_name]'");
$res = mysql_fetch_array($req1);
$avto1=mysql_num_rows($req1);
if($avto1==0){
mysql_query("INSERT INTO
        `res` SET
        `usr` = '$log',
        `name` = '$mag[name]',
        `lat_name` = '$mag[lat_name]',
        `tip` = '$mag[tip]',
        `what` = '$mag[what]',
        `give` = '$mag[give]',
        `kol` = '1',
        `cena` = '$mag[cena]'");
        
$req = mysql_query("SELECT * FROM `zamok` WHERE `city` = '$udata[city]' LIMIT 1");
////////////////////////////
$city = mysql_fetch_array($req);
if($city[clan]!='not' and $udata[clan]!=$city[clan]){
$req = mysql_query("SELECT * FROM `clan` WHERE `lider`='$city[clan]'");
////////////////////////////
$clan = mysql_fetch_array($req);
$clan[money]=$clan[money]+round(($mag[cena]/100)*2);

mysql_query("UPDATE `clan` SET `money` = '$clan[money]' WHERE `lider` = '$city[clan]'");
}

}else{
$nk=$res[kol]+1;
mysql_query("UPDATE `res` SET `kol` = '$nk' WHERE `usr` = '$log' and `lat_name` = '$mag[lat_name]'");
}
mysql_query("UPDATE users SET money = '$nmoney' WHERE usr = '$log'");

echo"
Вещь $mag[name] куплена и помещена в инвентарь!<br/>
Монет потрачено: $mag[cena]<br/>
Монет осталось: $nmoney<br/>
";
echo"<a href=\"shopelexirs.php?\">Назад</a>";

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