<title>Рынок</title>
<?
?>
<div class="event"><h1>Рынок</h1></div>
<?Error_Reporting (E_ALL & ~E_NOTICE);
echo "<div class='content'>";
echo "<div class='block'>";
if(isset($_GET['sell_all']) && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_market` WHERE `id_user` = '$ku[id]'"),0)!=0)
{
$q=mysql_querll("SELECT * FROM `kolhoz_market` WHERE `id_user` = '$ku[id]'");
$cm=0;
while($post=mysql_fetch_array($q))
{
$plant2=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_plant2` WHERE `id` = '$post[id_plant2]'"));
$m=floor(($plant2['rubies']/$plant2['count'])*$post['count']);
$d=1;
if($ku['double_res']>time()){
$d=2;
}
$cm=floor(($cm+$m)*$d);
}
mysql_querll("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']+$cm)."' WHERE `id` = '$ku[id]'");
mysql_querll("DELETE FROM `kolhoz_market` WHERE `id_user` = '$ku[id]'");
mysql_querll("UPDATE `kolhoz_user` SET `umoney2` = '$cm' WHERE `id` = '$ku[id]'");
if(isset($mc) && $mc['nalog2']>0)
{
$nrubies=floor(($cm/100)*$mc['nalog2']);
mysql_querll("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']+$cm-$nrubies)."' WHERE `id` = '$ku[id]'");
mysql_querll("INSERT INTO `kolhoz_collective_cash` SET `id_user` = '$ku[id]', `id_collective` = '$mc[id]', `count` = '$nrubies', `type` = 'rubies', `time` = '$time'");
mysql_querll("UPDATE `kolhoz_collective` SET `rubies` = '".($mc['rubies']+$nrubies)."' WHERE `id` = '$mc[id]'");
}
header("Location:?market&".passgen());
exit;
}
if(isset($_GET['sell']) && intval($_GET['sell'])!=NULL && mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_market` WHERE `id_user` = '$ku[id]' AND `id` = '".intval($_GET['sell'])."'"),0)!=0)
{
$pw=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_market` WHERE `id_user` = '$ku[id]' AND `id` = '".intval($_GET['sell'])."'"),0);
$plant2=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_plant2` WHERE `id` = '$pw[id_plant2]'"));
$d=1;
if($ku['double_res']>time()){
$d=2;
}
$m=floor((($plant2['rubies']/$plant2['count'])*$pw['count'])*$d);
mysql_querll("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']+$m)."' WHERE `id` = '$ku[id]'");
mysql_querll("DELETE FROM `kolhoz_market` WHERE `id` = '$pw[id]'");
mysql_querll("UPDATE `kolhoz_user` SET `umoney2` = '$m' WHERE `id` = '$ku[id]'");
if(isset($mc) && $mc['nalog2']>0)
{
$nrubies=floor(($m/100)*$mc['nalog2']);
mysql_querll("UPDATE `kolhoz_user` SET `rubies` = '".($ku['rubies']+$m-$nrubies)."' WHERE `id` = '$ku[id]'");
mysql_querll("INSERT INTO `kolhoz_collective_cash` SET `id_user` = '$ku[id]', `id_collective` = '$mc[id]', `count` = '$nrubies', `type` = 'rubies', `time` = '$time'");
mysql_querll("UPDATE `kolhoz_collective` SET `rubies` = '".($mc['rubies']+$nrubies)."' WHERE `id` = '$mc[id]'");
}
header("Location:?market&".passgen());
exit;
}
echo "<div><h3>Домашние заготовки</h3>";
echo "<ul class='ptm'>";
$q=mysql_querll("SELECT * FROM `kolhoz_market` WHERE `id_user` = '$ku[id]' AND `arena` = '0'");
if(mysql_num_rows($q)==0)echo "<li>Для продажи ничего нету</li>";
$cm=0;
while($post=mysql_fetch_array($q))
{
$plant2=mysql_fetch_array(mysql_querll("SELECT * FROM `kolhoz_plant2` WHERE `id` = '$post[id_plant2]'"));
$d=1;
if($ku['double_res']>time()){
$d=2;
}

$m=floor((($plant2['rubies']/$plant2['count'])*$post['count'])*$d);
echo "<li><div><img width='16' height='16' src='images/icons/recipes.png' alt='o'><span class='title'>".hsc($plant2['name'])."</span> (<span>$post[count]</span>): <a href='?market&tachka=$post[id]'></a> принесет прибыль</a> : <img width='16' height='16' src='images/icons/ruby.png' alt='o'><span>$m</span>
</div></li>";
$d=1;
if($ku['double_res']>time()){
$d=2;
}
$cm=floor(($cm+$m)*$d);
}
if(mysql_result(mysql_querll("SELECT COUNT(*) FROM `kolhoz_market` WHERE `id_user` = '$ku[id]'"),0)!=0)echo "<li><img alt='*' width='16' height='16' src='images/icons/ruby.png'> <a href='?market&sell_all'>Продать оптом</a> за <img width='16' height='16' src='images/icons/ruby.png' alt='o'><span>$cm</span></li>";
echo "</ul></div>";
include_once 'inc/foot.php';
?>