<?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/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 `active` = '1' AND `id` = '".intval($_GET['id'])."' LIMIT 1"), 0)==0){
header("Location: index.php?".SID);
exit;
} 
$build = mysql_fetch_assoc(mysql_query("SELECT * FROM `build` WHERE `active` = '1' AND `id` = '".intval($_GET['id'])."' LIMIT 1"));
$build_user = mysql_fetch_assoc(mysql_query("SELECT * FROM `build_user` WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1"));


if(isset($_POST['summ'])){
mysql_query("INSERT INTO `build_shop` (`id_build`, `id_user`, `summ`, `type`) values('$build[id]', '$user[id]', '".intval($_POST['summ'])."', '".htmlspecialchars($_GET['type'])."')");    

if($_GET['type'] == 'kirpich'){
mysql_query("UPDATE `build_user` SET `kirpich` = '".($build_user['kirpich']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'ekskavator'){
mysql_query("UPDATE `build_user` SET `ekskavator` = '".($build_user['ekskavator']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'kraska_voda'){
mysql_query("UPDATE `build_user` SET `kraska_voda` = '".($build_user['kraska_voda']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'police'){
mysql_query("UPDATE `build_user` SET `police` = '".($build_user['police']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'sobaka'){
mysql_query("UPDATE `build_user` SET `sobaka` = '".($build_user['sobaka']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'ohrana'){
mysql_query("UPDATE `build_user` SET `ohrana` = '".($build_user['ohrana']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'zadelka'){
mysql_query("UPDATE `build_user` SET `zadelka` = '".($build_user['zadelka']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'zabor'){
mysql_query("UPDATE `build_user` SET `zabor` = '".($build_user['zabor']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'vzyatka'){
mysql_query("UPDATE `build_user` SET `vzyatka` = '".($build_user['vzyatka']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'vred'){
mysql_query("UPDATE `build_user` SET `vred` = '".($build_user['vred']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'vzyatka'){
mysql_query("UPDATE `build_user` SET `vzyatka` = '".($build_user['vzyatka']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'molotok'){
mysql_query("UPDATE `build_user` SET `molotok` = '".($build_user['molotok']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'kraska'){
mysql_query("UPDATE `build_user` SET `kraska` = '".($build_user['kraska']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'bomj'){
mysql_query("UPDATE `build_user` SET `bomj` = '".($build_user['bomj']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

if($_GET['type'] == 'fms'){
mysql_query("UPDATE `build_user` SET `fms` = '".($build_user['fms']-1)."' WHERE `id_user` = '$user[id]' AND `id_build` = '$build[id]' LIMIT 1");    
}

$_SESSION['message'] = 'Ваш товар успешно выставлен на продажу';
header("Location: index.php?".SID);
}

echo "<form method=\"post\" name=\"message\" action=\"summ.php?id=".intval($_GET['id'])."&type=".htmlspecialchars($_GET['type'])."\">\n";
echo "Укажите сумму товара (max: 10000):<br />\n<input name=\"summ\" size=\"16\" maxlength=\"10000\" value=\"\" type=\"text\" /><br />\n";
echo "<input value=\"Выставить на продажу\" type=\"submit\" />\n";
echo "</form>\n";
include_once '../sys/inc/tfoot.php';
?>