<?
if(isset($_GET['sell_all']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_market` WHERE `id_user` = '$ku[id]'"),0)!=0)
{
$q=mysql_query("SELECT * FROM `kolhoz_market` WHERE `id_user` = '$ku[id]'");
$cm=0;
while($post=mysql_fetch_array($q))
{
$plant2=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant2` WHERE `id` = '$post[id_plant2]'"));
$m=floor(($plant2['money']/$plant2['count'])*$post['count']);
$cm=$cm+$m;
}
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$cm)."' WHERE `id` = '$ku[id]'");
mysql_query("DELETE FROM `kolhoz_market` WHERE `id_user` = '$ku[id]'");
mysql_query("UPDATE `kolhoz_user` SET `umoney2` = '$cm' WHERE `id` = '$ku[id]'");
if(isset($mc) && $mc['nalog2']>0)
{
$nrubies=floor(($cm/100)*$mc['nalog2']);
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$cm-$nrubies)."' WHERE `id` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_collective_cash` SET `id_user` = '$ku[id]', `id_collective` = '$mc[id]', `count` = '$nrubies', `type` = 'money', `time` = '$time'");
mysql_query("UPDATE `kolhoz_collective` SET `money` = '".($mc['money']+$nrubies)."' WHERE `id` = '$mc[id]'");
}
header("Location:?market&".passgen());
exit;
}
if(isset($_GET['sell']) && intval($_GET['sell'])!=NULL && mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_market` WHERE `id_user` = '$ku[id]' AND `id` = '".intval($_GET['sell'])."'"),0)!=0)
{
$pw=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_market` WHERE `id_user` = '$ku[id]' AND `id` = '".intval($_GET['sell'])."'"),0);
$plant2=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_plant2` WHERE `id` = '$pw[id_plant2]'"));
$m=floor(($plant2['money']/$plant2['count'])*$pw['count']);
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$m)."' WHERE `id` = '$ku[id]'");
mysql_query("DELETE FROM `kolhoz_market` WHERE `id` = '$pw[id]'");
mysql_query("UPDATE `kolhoz_user` SET `umoney2` = '$m' WHERE `id` = '$ku[id]'");
if(isset($mc) && $mc['nalog2']>0)
{
$nrubies=floor(($m/100)*$mc['nalog2']);
mysql_query("UPDATE `kolhoz_user` SET `money` = '".($ku['money']+$m-$nrubies)."' WHERE `id` = '$ku[id]'");
mysql_query("INSERT INTO `kolhoz_collective_cash` SET `id_user` = '$ku[id]', `id_collective` = '$mc[id]', `count` = '$nrubies', `type` = 'money', `time` = '$time'");
mysql_query("UPDATE `kolhoz_collective` SET `money` = '".($mc['money']+$nrubies)."' WHERE `id` = '$mc[id]'");
}
header("Location:?market&".passgen());
exit;
}
echo "<div class='input_button'><center>Заготовки</center></div>";
echo "<div class='block'>";
echo '<div class="div_hr2"></div>';
echo "<div class='content'>";
$q=mysql_query("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_query("SELECT * FROM `kolhoz_plant2` WHERE `id` = '$post[id_plant2]'"));
$m=floor(($plant2['money']/$plant2['count'])*$post['count']);
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/money.png' alt='o'><span>$m</span>
</div></li>";
$cm=$cm+$m;
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_market` WHERE `id_user` = '$ku[id]'"),0)!=0)echo "<li><img alt='*' width='16' height='16' src='images/icons/money.png'> <a href='?market&sell_all'>Продать оптом</a> за <img width='16' height='16' src='images/icons/money.png' alt='o'><span>$cm</span></li>";
echo "</ul></div>";
include_once 'inc/foot.php';
?>