<?php
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/adm_check.php';
include_once '../sys/inc/user.php';

$set['title']='Рынок';
include_once '../sys/inc/thead.php';
title();
aut();
include_once 'css.php';
 if (mysql_result(mysql_query("SELECT COUNT(*) FROM `build` WHERE `id` = '".intval($_GET['id'])."' LIMIT 1"), 0)==0){
header("Location: index.php?".SID);
exit;
}  

$k_post=mysql_result(mysql_query("SELECT COUNT(*) FROM `build_shop` WHERE `id_build` = '".intval($_GET['id'])."'"),0);
$k_page=k_page($k_post,$set['p_str']);
$page=page($k_page);
$start=$set['p_str']*$page-$set['p_str'];

if ($k_post == 0){echo "На рынке пока нет ничего";}

$q=mysql_query("SELECT * FROM `build_shop` WHERE `id_build` = '".intval($_GET['id'])."'");
while ($post = mysql_fetch_assoc($q))
{
$ank=mysql_fetch_assoc(mysql_query("SELECT * FROM `user` WHERE `id` = '$post[id_user]' LIMIT 1"));
$b_u=mysql_fetch_assoc(mysql_query("SELECT * FROM `build_user` WHERE `id_build` = '".intval($_GET['id'])."' AND `id_user` = '$user[id]' LIMIT 1"));


echo "<div class='nav2'>";

if ($post['type'] == 'kirpich'){

if(isset($_GET['kirpich'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `kirpich` = '".($b_u['kirpich']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1"); 
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}

echo "<img src = 'img/kirpich.png' style='max-width: 60px;'><br><b>Кирпич</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&kirpich' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'ekskavator'){
    
if(isset($_GET['ekskavator'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `ekskavator` = '".($b_u['ekskavator']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1"); 
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}    
    
echo "<img src = 'img/ekskavator.png' style='max-width: 60px;'><br><b>Экскаватор</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&ekskavator' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'kraska_voda'){
    
if(isset($_GET['kraska_voda'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `kraska_voda` = '".($b_u['kraska_voda']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1"); 
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}    
    
echo "<img src = 'img/kraska_voda.gif' style='max-width: 60px;'><br><b>Отмыватель краски</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&kraska_voda' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'police'){
    
if(isset($_GET['police'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `police` = '".($b_u['police']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1"); 
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}     
    
echo "<img src = 'img/police.png' style='max-width: 60px;'><br><b>Полицейский</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&police' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'sobaka'){
    
 if(isset($_GET['sobaka'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `sobaka` = '".($b_u['sobaka']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1"); 
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}   
    
echo "<img src = 'img/sobaka.png' style='max-width: 60px;'><br><b>Собака</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&sobaka' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'ohrana'){
    
if(isset($_GET['ohrana'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `ohrana` = '".($b_u['ohrana']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1"); 
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}     
    
echo "<img src = 'img/ohrana.png' style='max-width: 60px;'><br><b>Охранник</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&ohrana' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'zadelka'){
    
if(isset($_GET['zadelka'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `zadelka` = '".($b_u['zadelka']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1"); 
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}    
    
echo "<img src = 'img/zadelka.png' style='max-width: 60px;'><br><b>Набор для заделки</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&zadelka' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'zabor'){
    
if(isset($_GET['zabor'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `zabor` = '".($b_u['zabor']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}     
    
echo "<img src = 'img/zabor.png' style='max-width: 60px;'><br><b>Забор</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&zabor' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'vzyatka'){
    
if(isset($_GET['vzyatka'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `vzyatka` = '".($b_u['vzyatka']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1"); 
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}    
    
echo "<img src = 'img/vzyatka.png' style='max-width: 60px;'><br><b>Взятка</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&vzyatka' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'vred'){
    
if(isset($_GET['vred'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `vred` = '".($b_u['vred']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1"); 
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}     
    
echo "<img src = 'img/vred.png' style='max-width: 60px;'><br><b>Копальщик</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&vred' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'molotok'){
    
if(isset($_GET['molotok'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `molotok` = '".($b_u['molotok']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1"); 
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}     
    
echo "<img src = 'img/molotok.png' style='max-width: 60px;'><br><b>Молоток</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&molotok' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'kraska'){
    
if(isset($_GET['kraska'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `kraska` = '".($b_u['kraska']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1"); 
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}     
    
echo "<img src = 'img/kraska.gif' style='max-width: 60px;'><br><b>Краска</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&kraska' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'bomj'){
    
if(isset($_GET['bomj'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `bomj` = '".($b_u['bomj']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1");
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}    
    
echo "<img src = 'img/bomj.png' style='max-width: 60px;'><br><b>Бомж</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&bomj' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}

if ($post['type'] == 'fms'){
    
if(isset($_GET['fms'])){
if ($user['money'] < $post['summ']){
$_SESSION['message'] = 'У вас недостаточно монет'; 
header('location: index.php');
}else{
mysql_query("UPDATE `build_user` SET `fms` = '".($b_u['fms']+1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$post[id_build]' LIMIT 1");    
mysql_query("UPDATE `user` SET `money` = '".($ank['money']+$post['summ'])."' WHERE `id` = '$ank[id]' LIMIT 1");
mysql_query("UPDATE `user` SET `money` = '".($user['money']-$post['summ'])."' WHERE `id` = '$user[id]' LIMIT 1"); 
mysql_query("DELETE FROM `build_shop` WHERE `id` = '$post[id]'");
$_SESSION['message'] = 'Поздравляем с покупкой'; 
header('location: index.php');    
}
}     
    
echo "<img src = 'img/fms.gif' style='max-width: 60px;'><br><b>ФМСник</b><br>"; 
echo "Продавец: $ank[nick]<br>";
echo "Цена: $post[summ]<br>";
echo "<br><a href='?id=".intval($_GET['id'])."&fms' class='b_k'><font color='white'><b>КУПИТЬ</b></font></a><br><br>";
}
echo "</div>";
} 


if ($k_page>1)str('?id='.intval($_GET['id']).'&',$k_page,$page); // Вывод страниц


echo "<div class='foot'><a href='/build/'>Назад к стройке</div>";


include_once '../sys/inc/tfoot.php';

?>
