<?
if(isset($_GET['callHelicopter']))
{
if($_GET['callHelicopter']==1){$tn='time_shmel';$utn='shmel_time';$n=7;$trn='shmel';}
if($_GET['callHelicopter']==2){$tn='time_yastreb';$utn='hawk_time';$n=7;$trn='hawk';}
if($_GET['callHelicopter']==3){$tn='time_drakon';$utn='dragon_time';$n=7;$trn='dragon';}    
if($_GET['callHelicopter']==4){$tn='time_shark';$utn='grom_time';$n=9;$trn='grom';}
  $kh=mysql_result(mysql_query("SELECT COUNT(*) FROM `kolhoz_collective_user` WHERE `id_collective`='".$mc[id]."'"),0)/($n*$mc[$trn]);
  if($mc[$trn]>0 && $mcu[$utn]<time())
  {
    if($_GET['callHelicopter']!=4)mysql_query("UPDATE `kolhoz_user` SET `$tn`='".($ku[$tn]>time()?"".($ku[$tn]+3600)."":"".(time()+3600)."")."' WHERE `id`='$ku[id]'"); else mysql_query("UPDATE `kolhoz_user` SET `time_shmel`='".($ku['time_shmel']>$time?"".($ku['time_shmel']+3600)."":"".($time+3600)."")."', `time_yastreb`='".($ku['time_yastreb']>$time?"".($ku['time_yastreb']+3600)."":"".($time+3600)."")."', `time_drakon`='".($ku['time_drakon']>$time?"".($ku['time_drakon']+3600)."":"".($time+3600)."")."' WHERE `id`='$ku[id]'");
     mysql_query("UPDATE `kolhoz_collective_user` SET `$utn`='".(time()+$k*3600)."' WHERE `id_user`='$ku[id]'");
     if(isset($_GET['myfarm']))header("Location: /myfarm");
    else if(isset($_GET['mypetfarm']))header("Location: /mypetfarm");
    else if(isset($_GET['mycellar']))header("Location: /mycellar");
      else header("Location: /collective-$mc[id]/hangar");
    
  }
}
if(isset($_GET['callAll']) && ($_GET['callAll']=='myfarm' || $_GET['callAll']=='mypetfarm' || $_GET['callAll']=='mycellar'))
{
  if($kh['grom']>0 && $ku['grom_time']<time())
  {
    $k=$kh['users']/(9*$kh['grom']);
    mysql_query("UPDATE `users` SET `shmel`='".($ku['shmel']>time()?"".($ku['shmel']+3600)."":"".(time()+3600)."")."', `hawk`='".($ku['hawk']>time()?"".($ku['hawk']+3600)."":"".(time()+3600)."")."', `dragon`='".($ku['dragon']>time()?"".($ku['dragon']+3600)."":"".(time()+3600)."")."' WHERE `id`='$ku[id]'");
    mysql_query("UPDATE `collective_user` SET `grom_time`='".(time()+$k*3600)."' WHERE `id_user`='$ku[id]'");
  }
  else {
  if($kh['shmel']>0  && $ku['shmel_time']<time())
  {
  $k=$kh['users']/(7*$kh['shmel']);
    mysql_query("UPDATE `users` SET `shmel`='".($ku['shmel']>time()?"".($ku['shmel']+3600)."":"".(time()+3600)."")."' WHERE `id`='$ku[id]'");
    mysql_query("UPDATE `collective_user` SET `shmel_time`='".(time()+$k*3600)."' WHERE `id_user`='$ku[id]'");
  }
  if($kh['hawk']>0  && $ku['hawk_time']<time())
  {
  $k=$kh['users']/(7*$kh['hawk']);
    mysql_query("UPDATE `users` SET `hawk`='".($ku['hawk']>time()?"".($ku['hawk']+3600)."":"".(time()+3600)."")."' WHERE `id`='$ku[id]'");
    mysql_query("UPDATE `collective_user` SET `hawk_time`='".(time()+$k*3600)."' WHERE `id_user`='$ku[id]'");
  }
  if($kh['dragon']>0  && $ku['dragon_time']<time())
  {
  $k=$kh['users']/(7*$kh['dragon']);
    mysql_query("UPDATE `users` SET `dragon`='".($ku['dragon']>time()?"".($ku['dragon']+3600)."":"".(time()+3600)."")."' WHERE `id`='$ku[id]'");
    mysql_query("UPDATE `collective_user` SET `dragon_time`='".(time()+$k*3600)."' WHERE `id_user`='$ku[id]'");
  }
  }
   if($_GET['callAll']=='myfarm')header("Location: /myfarm");
    else if($_GET['callAll']=='mypetfarm')header("Location: /mypetfarm");
    else if($_GET['callAll']=='mycellar')header("Location: /mycellar");
    else header("Location: /collective/hangar/$kh[id]");
}
echo'
<div class="event"><h1><a href="/collective-'.$ct['id'].'">'.$ct['name'].'</a> / Ангар</h1></div>
<div class="content">

<div class="block">
<ul>
'.($ct['shmel']>0?'<li><span>
<img width="64" height="64" class="portrait" src="/images/bumblebee1.png" alt="Шмель" title="Шмель"/>
<ul>
<li><span class="epic"><span>Шмель</span>(<span class="title">'.$ct['shmel'].'</span>)</span></li>

<li>'.($ct['id']==$mc['id']?'
'.($mcu['shmel_time']<time()?'<a href="/collective-'.$mc['id'].'/hangar?callHelicopter=1">вызвать себе</a>':'Вызов будет доступен через <span>'.time_left($mcu['shmel_time']-time()).'</span>').'':null).'
</li>


</ul>
<div style="clear:both"></div>
</span></li>':null).'
'.($ct['hawk']>0?'<li><span>
<img width="64" height="64" class="portrait" src="/images/hawk1.png" alt="Ястреб" title="Ястреб"/>
<ul>
<li><span class="epic"><span>Ястреб</span>(<span class="title">'.$ct['hawk'].'</span>)</span></li>

<li>'.($ct['id']==$mc['id']?'
'.($mcu['hawk_time']<time()?'<a href="/collective-'.$mc['id'].'/hangar?callHelicopter=2">вызвать себе</a>':'Вызов будет доступен через <span>'.time_left($mcu['hawk_time']-time()).'</span>').'':null).'
</li>


</ul>
<div style="clear:both"></div>
</span></li>':null).'
'.($ct['dragon']>0?'<li><span>
<img width="64" height="64" class="portrait" src="/images/dragon1.png" alt="Дракон" title="Дракон"/>
<ul>
<li><span class="epic"><span>Дракон</span>(<span class="title">'.$ct['dragon'].'</span>)</span></li>

<li>'.($ct['id']==$mc['id']?'
'.($mcu['dragon_time']<time()?'<a href="/collective-'.$mc['id'].'/hangar?callHelicopter=3">вызвать себе</a>':'Вызов будет доступен через <span>'.time_left($mcu['dragon_time']-time()).'</span>').'':null).'
</li>


</ul>
<div style="clear:both"></div>
</span></li>':null).'
'.($ct['grom']>0?'<li><span>
<img width="64" height="64" class="portrait" src="/images/grom1.png" alt="Гром" title="Гром"/>
<ul>
<li><span class="epic"><span>Гром</span>(<span class="title">'.$ct['grom'].'</span>)</span></li>


<li>'.($ct['id']==$mc['id']?'
'.($mcu['grom_time']<time()?'<a href="/collective-'.$mc['id'].'/hangar?callHelicopter=4">вызвать себе</a>':'Вызов будет доступен через <span>'.time_left($mcu['grom_time']-time()).'</span>').'':null).'
</li>

</ul>

<div style="clear:both"></div>
':null).'</ul>
'.($ct['id']==$mc['id']?'
<ul>
<li><a href="/shop-helicopter/1">Купить "Шмель"</a></li>
<li><a href="/shop-helicopter/2">Купить "Ястреб"</a></li>
<li><a href="/shop-helicopter/3">Купить "Дракон"</a></li>
<li><a href="/shop-helicopter/4">Купить "Гром"</a></li>
</ul>
':null).'
<div class="minor pt">
Ангар - колхозная постройка для управления вертолётами.<br/>
Вертолёты летают на фермы к колхозникам и оставляют бонусы, увеличивающие результативность грядок и загонов фермера!<br/>
Подробности читайте в описании вертолётов.
</div>
</div>';
include_once 'inc/foot.php';
?>