<?
define('PROTECTOR', 1);

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

$textl='Магазин';
@include('files/db.php');
@include('files/auth.php');
@include('files/func.php');
going();
place_tower();
@include('files/core.php');
@include('files/head.php');
@include('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 `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('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 `id`='$_GET[id]'");
$avto=mysql_num_rows($req);
if($avto==0){
echo'Ошибка, такой вещи нет!';
@include('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]*$_POST[kol]);

if($nmoney<0){
echo'Нехватает монет!';
@include('files/down.php');
exit;}
if(empty($_POST[kol])){echo'
<form action="shopelexirs.php?mod=sell&id='.$_GET[id].'" method="post"><b>Сколько?</b><br/><input name="kol"/><br/><input type="submit" value="Продолжить"/></form>';}else{
$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` = '$_POST[kol]',
        `cena` = '$mag[cena]'");
        
}else{
$nk=$res[kol]+$_POST[kol];
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'");
$cena=$mag[cena]*$_POST[kol];
echo"
Вещь $mag[name] куплена и помещена в инвентарь!<br/>
Монет потрачено: $cena<br/>
Монет осталось: $nmoney<br/>
";}
echo"<a href=\"shopelexirs.php?\">Назад</a>";

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