<?php
include './system/bd.php';
include './system/cook.php';
include ("./system/gzip.php");
if(isset($_SESSION['auth']) && $_SESSION['auth']==1){
include './system/head.php';

switch($_GET[mod]){
default:

echo"<div class='title'>Торговая площадь </div>";
echo' <div class="empty_block item_center">
<img src="/img/shop.png" alt="*"/> </div> ';

echo"<div class='block_link'>
<a href='?mod=items'> 
<img src='img/images/arrow.png'> Вещи</a></div>";

echo"<div class='line'></div>";
echo"<div class='block_link'>
<a href='hone.php'> 
<img src='img/images/arrow.png'> Заточка</a></div>";

echo"<div class='line'></div>";
echo"<div class='block_link'>
<a href='?mod='> 
<img src='img/images/arrow.png'> Еще</a></div>";
break;

case 'items':
echo'<img src="/pic/main/name.png" alt="*"/> ';
echo"Прикупи-ка уникальные себе вещички они тебе помогут...";

echo"<div class='block_link'>
<a href='?mod=1'>
<img src='img/images/arrow.png'> Адамантитовый Набор </a></div>";

echo"<div class='line'></div>";
echo"<div class='block_link'>
<a href='?mod=2'>
<img src='img/images/arrow.png'> Набор Импа</a></div>";

echo"<div class='line'></div>";
echo"<div class='block_link'>
<a href='set.php?id=1'>
<img src='img/images/arrow.png'> Комплект 1</a></div>";


echo"<div class='line'></div>";
echo"<div class='block_link'>
<a href='magazin.php'>
<img src='img/images/arrow.png'> Вернуться</a></div>";



break;
//
case '1':
echo"<div class='title'> Адамантитовый Набор </div>
<div class='empty_block'> ";
if($user[lvl] < 10){
echo ' <center>
Вещи доступны с 10-го уровня </center> </div>';
include './system/foot.php';
exit;
}
$cop=10;
$ca=mysql_result(mysql_query("SELECT COUNT(*) FROM `shop` WHERE `set`='1' "),0);
$cp=ceil($ca/$cop);
if(isset($_GET['page']) && is_numeric($_GET['page'])){
$page = $_GET['page'];
if($_GET['page']>$cp) $page=$cp;
if($_GET['page']<1)$page=1;
}else{
$page=1;
}
$start=$page*$cop-$cop;
$dlist = 'list1';
$req = mysql_query("SELECT * FROM `shop` WHERE `images`='1' ORDER BY gold DESC LIMIT $start,$cop");
////////////////////////////
if($user){
     switch($mag[quality]) {    
  case 0:
        $quality= Хлам;
        $hone = 5;
        $q = 0;
  break;   
  case 1:
        $quality= Обычный;
        $hone = 10;
        $q = 1;
  break;
  case 2:
       $quality= Необычный;
       $hone = 15;
       $q = 2;
 break;
 case 3:
      $quality= Редкий;
      $hone = 25;
      $q = 3;
 break;
 case 4:
      $quality= Эпический;
      $hone = 30;
      $q = 4;
  break;
 case 5:
     $quality= Легендарный;
     $hone = 40;
     $q = 5;
 break;
 case 6:
    $quality= Мифический;
    $hone = 50;
    $q = 6;
 break;
}}

$avto=mysql_num_rows($req);
if($avto>=1){
While($mag = mysql_fetch_array($req))
{
echo"
 <table>
                            <tbody><tr>
                    <td class='b40px'>
<img src='/img/items/$mag[tip]/$mag[images].png'>
</td><td>";                                                               

echo"<img src='../img/star/".$q.".png'>
<a href='magazin.php?mod=infa&id=$mag[id]'> $mag[name]</a>[0/$hone]";
echo"<br> $quality, $mag[lvl] уровень


</td> </tr>";
}
echo ' </tbody> </table> </div>
</div>';
}

echo"<div class='block_link'>
<a href='magazin.php?'> <img src='img/images/arrow.png'> Вернуться</a></div>";
break;
//
case '2':
echo"<div class='title'> Набор Импа </div>
<div class='empty_block'> ";
if($user[lvl] < 10){
echo ' <center>
Вещи доступны с 10-го уровня </center> </div>';
include './system/foot.php';
exit;
}
$cop=10;
$ca=mysql_result(mysql_query("SELECT COUNT(*) FROM `shop` WHERE `set`='2' "),0);
$cp=ceil($ca/$cop);
if(isset($_GET['page']) && is_numeric($_GET['page'])){
$page = $_GET['page'];
if($_GET['page']>$cp) $page=$cp;
if($_GET['page']<1)$page=1;
}else{
$page=1;
}
$start=$page*$cop-$cop;
$dlist = 'list1';
$req = mysql_query("SELECT * FROM `shop` WHERE `images`='2' ORDER BY gold DESC LIMIT $start,$cop");
////////////////////////////
if($user){
     switch($mag[quality]) {    
  case 0:
        $quality= Хлам;
        $hone = 5;
        $q = 0;
  break;   
  case 1:
        $quality= Обычный;
        $hone = 10;
        $q = 1;
  break;
  case 2:
       $quality= Необычный;
       $hone = 15;
       $q = 2;
 break;
 case 3:
      $quality= Редкий;
      $hone = 25;
      $q = 3;
 break;
 case 4:
      $quality= Эпический;
      $hone = 30;
      $q = 4;
  break;
 case 5:
     $quality= Легендарный;
     $hone = 40;
     $q = 5;
 break;
 case 6:
    $quality= Мифический;
    $hone = 50;
    $q = 6;
 break;
}}

$avto=mysql_num_rows($req);
if($avto>=1){
While($mag = mysql_fetch_array($req))
{
echo"
 <table>
                            <tbody><tr>
                    <td class='b40px'>
<img src='/img/items/$mag[tip]/$mag[images].png'>
</td><td>";                                                               

echo"<img src='../img/star/".$q.".png'>
<a href='magazin.php?mod=infa&id=$mag[id]'> $mag[name]</a>[0/$hone]";
echo"<br> $quality, $mag[lvl] уровень


</td> </tr>";
}
echo ' </tbody> </table> </div>
</div>';
}
echo"<div class='block_link'>
<a href='magazin.php?'> <img src='img/images/arrow.png'> Вернуться</a></div>";
break; 
///
                  ////////////
case 'purchase':
$req = mysql_query("SELECT * FROM `shop` WHERE `id`='".mysql_real_escape_string($_GET['id'])."'");
$avto=mysql_num_rows($req);
if($avto==0){
header ("Location: ?mod=1");
exit;
}
$mag= mysql_fetch_array($req);

if($user){
     switch($mag[quality]) {    
  case 0:
        $quality= Хлам;
        $hone = 5;
        $q = 0;
  break;   
  case 1:
        $quality= Обычный;
        $hone = 10;
        $q = 1;
  break;
  case 2:
       $quality= Необычный;
       $hone = 15;
       $q = 2;
 break;
 case 3:
      $quality= Редкий;
      $hone = 25;
      $q = 3;
 break;
 case 4:
      $quality= Эпический;
      $hone = 30;
      $q = 4;
  break;
 case 5:
     $quality= Легендарный;
     $hone = 40;
     $q = 5;
 break;
 case 6:
    $quality= Мифический;
    $hone = 50;
    $q = 6;
 break;
}}


if($mag[tip] == head){
$tip=Голова;}
if($mag[tip] == shoulder){
$tip=Наплечник;}
if($mag[tip] == body){
$tip=Тело;}
if($mag[tip] == weapon){
$tip=Оружие;}
if($mag[tip] == shield){
$tip=Щит;}

if($mag[nev] == 0){
$new=личный;}
if($mag[nev] == 1){
$new=новый;}

echo" <div class='title'> Магазин </div>";
echo" <div class='empty_block'>
    <table>
        <tbody><tr>
            <td class='b40px'>
<img src='/img/items/$mag[tip]/$mag[images].png'> </td>
            <td> <small>
<span class='c1'> 
<img src='/img/star/$q.png'>
 $mag[name] </span> [0/$hone]<br>
<span class='c1'> 
$quality, $new</span>
<span class='c1'> </br>
$tip, $mag[lvl] уровень </span>
</small></td>
        </tr>
    </tbody></table>
</div>";


echo' <div class="block item_center">
Вы действительно хотите купить вещь: за '.number_format($mag[gold]).' <img src=\'img/icon/gold.png\'>?<br/>';
echo"<div class='link_center'>
<a href='magazin.php?mod=purchase_ok&id=$mag[id]'>Да</a> </div>";
echo" <div class='link_center_h'>
<a href='magazin.php?mod=shmot'>Нет</a> </div> </div>";



break;
case 'purchase_ok':
$req = mysql_query("SELECT * FROM `shop` WHERE `id`='".mysql_real_escape_string($_GET['id'])."'");
$avto=mysql_num_rows($req);
if($avto==0){
header ("Location: ?mod=1");
exit;
}


$req = mysql_query("SELECT * FROM `shop` WHERE `id`='".mysql_real_escape_string($_GET['id'])."'");
////////////////////////////
$avto=mysql_num_rows($req);
if($avto>=1){
While($mag = mysql_fetch_array($req))
if($mag[gold]>$user[gold]){
echo'<img src="/pic/main/nou.png" alt="*"/> У тебя маловато <img src="/pic/main/fermany.png" alt="*"/> золота.<br/>';
echo'<div class="ssl">';
echo"<a href=\"?mod=1\">&nbsp <img src=\"pic/main/rotate.png\"> Вернуться</a></div>";
include 'inc/nogi.php';
exit;
}

$req = mysql_query("SELECT * FROM `shop` WHERE `id`='".mysql_real_escape_string($_GET['id'])."'");
////////////////////////////
$avto=mysql_num_rows($req);
if($avto>=1){
$mag = mysql_fetch_array($req);

mysql_query("INSERT INTO `item` SET
`user` = '$user[id]',
`name` = '$mag[name]',
`quality` = '$mag[quality]',
`tip` = '$mag[tip]',
`lvl` = '$mag[lvl]',
`hp` = '$mag[hp]',
`attack` = '$mag[attack]',
`def` = '$mag[def]',
`wearing` = 'no',
`silver` = '$mag[silver]',
`exp` = '$mag[exp]',
`images` = '$mag[images]'");

mysql_query("UPDATE `user` SET `gold`=`gold`- '$mag[gold]' 
WHERE `id`='$user[id]' LIMIT 1");

echo" <div class='title'> Магазин </div>";
echo"<div class='empty_block'> Вы успешно купили <a>$mag[name]</a> </div> ";

echo'<div class="block_link">
<a href="?">
<img src="img/images/arrow.png"> Вернуться</a></div>';
}}







break;
case 'infa':
$req = mysql_query("SELECT * FROM `shop` WHERE `id`='".mysql_real_escape_string($_GET['id'])."'");
////////////////////////////
$avto=mysql_num_rows($req);
if($avto==0){
header ("Location: magazin.php?mod=razdel_obuc");
include 'inc/nogi.php';
exit;
}


////////////////////////////

$m = mysql_fetch_array($req);

if($user){
     switch($mag[quality]) {    
  case 0:
          $quality= Хлам;
          $hone = 5;
  break;   
  case 1:
          $quality= Обычный;
          $hone = 10;
  break;
  case 2:
       $quality= Необычный;
       $hone = 15;
 break;
 case 3:
      $quality= Редкий;
      $hone = 25;
 break;
 case 4:
      $quality= Эпический;
      $hone = 30;
  break;
 case 5:
     $quality= Легендарный;
     $hone = 40;
 break;
 case 6:
    $quality= Мифический;
    $hone = 50;
 break;
}}



if($mag[nev] == 0){
$new=Личный;}
if($mag[nev] == 1){
$new=Новый;}

if($m[tip] == head){
$tip=Голова;}
if($m[tip] == shoulder){
$tip=Наплечник;}
if($m[tip] == body){
$tip=Тело;}
if($m[tip] == weapon){
$tip=Оружие;}
if($m[tip] == shield){
$tip=Щит;}

$req = mysql_query("SELECT * FROM `shop` WHERE `id`='".mysql_real_escape_string($_GET['id'])."'");


$avto=mysql_num_rows($req);
if($avto>=1){While($mag = mysql_fetch_array($req))


echo"<div class='title'> $mag[name] </div>

<div class='empty_block'>
    <table>
        <tbody><tr>
            <td class='b40px'>
<img src='/img/items/$mag[tip]/$mag[images].png'> </td>
            <td> <small>
<span class='c1'>Уровень заточки </span> [0/$hone]<br>
<span class='c1'> 
$quality , $new </span><br>
<span class='c1'> 
$tip, $mag[lvl] уровень </span>
</small></td>
        </tr>
    </tbody></table>
</div>
<div class='block'> <small>
<img src='img/icon/attack.png'>
Атака: <span class='c1'> $mag[attack] </span>
<br>
<img src='img/icon/def.png'>
Защита: <span class='c1'> $mag[def]</span>
<br>
<img src='img/icon/hp.png'>
Здоровья: <span class='c1'>  
$mag[hp] </span>
<br>
<img src='img/icon/silver.png'> Бонус к серебру: <span class='c1'> $mag[silver]% </span>
</br>
<img src='img/icon/exp.png'>
Бонус к серебру: <span class='c1'> $mag[exp]% </span>
</small>
<div class='link_center'> <a href=\"?mod=purchase&id=$mag[id]\"> 15 </a> </div>
</div>";


 
}
echo'<div class="block_link">
<a href="?mod=1"> 
<img src="img/images/arrow.png"> Вернуться</a></div>';



break;




}
}else{
header ("Location: index.php"); exit;
}
include 'system/foot.php';
?>
