<?
if($ku['zkl']<9)
{
echo "<div class='content'>";
echo '<div class="block">';
echo"Доступ с 80 уровня</div></div>";
echo "<img src='/images/smiles/zayac.gif'> Заводы доступны только для игроков у которых есть 10 ключей. и с 80 ур.";
echo '</div>';
include_once 'inc/foot.php';
exit;
}
if($ku['level']<79)
{
echo '<div class="block">';
echo '<img src="/images/smiles/zayac.gif"> Заводы доступны с 80 уровня.';
echo '</div>';
include_once 'inc/foot.php';
exit;
}
include_once 'inc/new_zavod.php';
include_once 'inc/obmen.php';
include_once 'inc/obmen_all.php';
include_once 'inc/sellz.php';
include_once 'inc/sellz_all.php';
include_once 'inc/level2.php';
include_once 'inc/level2_all.php';
include_once 'inc/sell_zavod.php';
include_once 'inc/buy_zavod.php';
include_once 'inc/GreyAll/buy_zavod.php';
include_once 'inc/GreyAll/sell_zavod.php';

if(isset($_SESSION['err']))
{
echo err_game("Не хватает табака на складе");
unset($_SESSION['err']);
}
if(isset($_GET['off']))
{
mysql_query("UPDATE `kolhoz_user` SET `kompact` = '1' WHERE `id` = '$ku[id]'");
header("Location:/?myzavod");
exit;
}
echo "<div class='event'><h1>Заводы</h1></div>";
echo "<div class='content'>";
echo "<div class='block'>";
echo "<a href='?myzavod&buy_zavod_all'>Купить все</a><br>";
echo "<a href='?myzavod&sell_all_t'>Продать все</a><br>";

if($ku['scarecrow_time']>$time)echo "<li><img width='16' height='16' src='images/icons/scarecrow.png' alt='o'> <a class='epic' href='?shop=scarecrow'>Охрана</a><span class='minor'> на <span>".time_left($ku['scarecrow_time']-$time)."</span></span></li>";
if($ku['time_shmel']>$time)echo "<li><img width='16' height='16' alt='o' src='images/icons/heli1n.png'> <a class='epic' href='?shop=helicopter&1'>Шмель</a><span class='minor'> на <span>".time_left($ku['time_shmel']-$time)."</span></span></li>";
if($ku['time_yastreb']>$time)echo "<li><img width='16' height='16' alt='o' src='images/icons/heli2n.png'> <a class='epic' href='?shop=helicopter&2'>Ястреб</a><span class='minor'> на <span>".time_left($ku['time_yastreb']-$time)."</span></span></li>";
if($ku['time_drakon']>$time)echo "<li><img width='16' height='16' alt='o' src='images/icons/heli3n.png'> <a class='epic' href='?shop=helicopter&3'></a><span class='minor'> на <span>".time_left($ku['time_drakon']-$time)."</span></span></li>";
echo "<li class='pt'>";
if($ku['obmen']<1)
{
$q=mysql_query("SELECT * FROM `kolhoz_zavod` WHERE `id_user` = '$ku[id]' AND `id_pet` != '0'");
$count_gol=0;
while($post=mysql_fetch_array($q))
{
$max_time=$time+$post['level']*(3600*4);
$mezh_time=$max_time-$post['time'];
if($mezh_time>=4*3600)$count_gol++;
}
if($count_gol!=0)echo "<div><img width='16' height='16' src='images/icons/money.png' alt='o'> <a href='?myzavod&obmen_all'>Обменять все</a></div>";
}

if($ku['sellz']>0 && !isset($_GET['moderate']))
{
$q=mysql_query("SELECT * FROM `kolhoz_zavod` WHERE `id_user` = '$ku[id]' AND `id_pet` != '0'");
$money2=0;
while($post=mysql_fetch_array($q))
{
$zav=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_zav` WHERE `id` = '$post[id_pet]'"));
$d_money=floor($post['time_money2']/(4*3600));
if($d_money>0)
{
$nt=$post['time_money2']-($d_money*14400);
$count=1;
$count_sellz_act=0;
$count_vet_act=0;
if(isset($sellz_act))$count_sellz_act=($count/100)*$sellz_act;
if(isset($vet_act))$count_vet_act=($count/100)*$vet_ps_m;
$count=$count_sellz_act+$count_vet_act+$count;

$money=($count*$zav['money'])*$d_money;
$money2=$money2+$money;
}
}
if($money2>0)echo "<div><img width='16' height='16' src='images/icons/harvest.png' alt='o'> <a href='?myzavod&sellz_all'>Продать все</a> за <span><img width='16' height='16' src='images/icons/money.png' alt='o'> <span
class='title'>$money2</span></span></div>";
}
echo "</li>";
echo "<div class='ptm'><ul>";
$q=mysql_query("SELECT * FROM `kolhoz_zavod` WHERE `id_user` = '$ku[id]'");
while($post=mysql_fetch_array($q))
{
$zav=mysql_fetch_array(mysql_query("SELECT * FROM `kolhoz_zav` WHERE `id` = '$post[id_pet]'"));
echo "<li><img width='48' height='48' src='".($post['id_pet']==0?"images/nozavod.png":"images/zavod/$zav[id].png")."' alt='o' class='portrait'>";
echo "<div>";
if($post['id_pet']==0)
{
echo " <a href='?myzavod&buy=$post[id]'>Купить завод</a>";
}
else
{
if(!isset($_GET['moderate']))
{
echo "<span class='title'>".hsc($zav['name'])."</span>";
if($post['time']>$time)echo "<span class='small minor'> (Будет производиться ".time_left($post['time']-$time).")</span>";
}
if(isset($_GET['moderate']))
{
echo "<li> <a href='?myzavod&sell=$post[id]'>Продать завод</a> за <span><img width='16' height='16' src='images/icons/money.png' alt='o'> <span
class='title'>".($zav['cena']/2)."</span></span></li>";
if($post['level']<20)
{
$post['next_level']=$post['level']+1;
$money_all_levels=0;
for($kp=$post['next_level'];$kp<=20;$kp++)
{
$money_all_levels=$money_all_levels+$kp;
}
echo "<li><img alt='' width='16' height='16' src='images/icons/up.png'> <a href='?myzavod&level2=$post[id]'>Увеличить производ.</a> за <span><img
width='16' height='16' src='images/icons/money.png' alt='o'> <span class='title'>$post[next_level] тыс.</span></span>
<span class='small minor'>(с $post[level] до $post[next_level])</span>
<br> <img alt='' width='16' height='16' src='images/icons/up.png'> <a href='?myzavod&level2_all=$post[id]'>Увеличить производ.</a> за <span><img
width='16' height='16' src='images/icons/money.png' alt='o'> <span class='title'>$money_all_levels тыс.</span></span>
<span class='small minor'>(с $post[level] до 20)</span></li>";
}
}
else
{
echo "<div>";
$d_money=floor($post['time_money2']/(4*3600));
if($d_money>0)
{
$nt=$post['time_money2']-($d_money*14400);
$count=1;
$count_sellz_act=0;
$count_vet_act=0;
if(isset($sellz_act))$count_sellz_act=($count/100)*$sellz_act;
if(isset($vet_act))$count_vet_act=($count/100)*$vet_ps_m;
$count=$count_sellz_act+$count_vet_act+$count;

$money=($count*$zav['money'])*$d_money;
echo " <a class='' href='?myzavod&sellz=$post[id]'>Продать</a> ( <span><img width='16' height='16' src='images/icons/money.png' alt='o'> <span
class='title'>$money</span> )</span>";
}
else
{
$max_time=$time+$post['level']*(3600*4);
$mezh_time=$max_time-$post['time'];
if($mezh_time>=4*3600)echo " <img src='images/icons/money.png'> <a class='' href='?myzavod&obmen=$post[id]'><span>Обменять</span></a>";
}
}
}
echo "<div style='clear:both'></div></li>";
}
if(mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_zavod` WHERE `id_user` = '$ku[id]'"),0)<20)echo "<br><li><img width='48' height='48' src='images/nozavod.png' alt='o' class='portrait'><div><span class='title'>Новый завод</span></div><div> <a href='?myzavod&new_zavod'>Купить</a>
за <span class='title'><img width='16' height='16' src='images/euro.png' alt='o'> <span>250 евро</span></div><div style='clear:both'></div></li>";
echo "</ul></div>";
echo "<div class='ptm'><img width='16' height='16' src='images/icons/refresh.png' alt='o'> <a href='?myzavod&refresh=".rand(99999,99999999)."'>Обновить</a> | <img alt='o' width='16' height='16' src='images/icons/moderate.png'> <a href='?myzavod&moderate'>Управление</a></li>";
echo '</ul></div></div>';
include_once 'inc/foot.php';
?>