<?php
echo "<div class='aut'>Купить постройки</div>\n";
if($q['r_l']=='0'){
echo "<div class='err'>Для покупки построек вам необходимы строители</div>\n";
}else{
  $kup=abs(intval($_GET['kup']));
  if($kup=='0'){
   $all_p=mysql_result(mysql_query("SELECT COUNT(*) FROM `empire_zdan`"),0);
  $k_page=k_page($all_p,$set['p_str']);
  $page=page($k_page);
  $start=$set['p_str']*$page-$set['p_str'];
  $my_p=mysql_query("SELECT * FROM `empire_zdan` ORDER BY `id` LIMIT $start,$set[p_str]");
while($arr=mysql_fetch_array($my_p)){
if($num==1){ 
echo "<div class='f1'>"; 
$num=0;}
else{ 
echo "<div class='f2'>"; 
$num=1;} 
echo "<img src='buildings.PNG'> <a href='?do=6&amp;kup=$arr[id]'>".output_text($arr['name'])."</a> ($arr[vek] век)";
echo "</div>\n";
}
if($k_page>'1')str('?do=6&amp;',$k_page,$page);
}else{
$all_p=mysql_result(mysql_query("SELECT COUNT(*) FROM `empire_zdan` WHERE `id`='$kup'"),0);
if($all_p!='0'){
$all_v=mysql_fetch_array(mysql_query("SELECT * FROM `empire_zdan` WHERE `id`='$kup'"));
$vek=$all_v['vek'];
$name=$all_v['name'];
$zoloto=$all_v['zoloto'];
$eda=$all_v['eda'];
$derevo=$all_v['derevo'];
$gelezo=$all_v['gelezo'];
$voin=$all_v['voin'];
$push=$all_v['push'];
$time_h=$all_v['time_h'];
$zoloto_abs=$all_v['zoloto_abs'];
$eda_abs=$all_v['eda_abs'];
$derevo_abs=$all_v['derevo_abs'];
$gelezo_abs=$all_v['gelezo_abs'];
echo "<div class='f1'><img src='buildings.png' alt='.'/> ".output_text($name)."</div>\n
<div class='aut'>Ресурсы</div>";
echo "<div class='f2'>Дерево: +".intval($derevo)."</div>\n";
echo "<div class='f1'>Золото: +".intval($zoloto)."</div>\n";
echo "<div class='f2'>Железо: +".intval($gelezo)."</div>\n";
echo "<div class='f1'>Еда: +".intval($eda)."</div>\n";
echo "<div class='f2'>Воины: +".intval($voin)."</div>\n";
echo "<div class='f1'>Пушки: +".intval($push)."</div>\n";
echo "<div class='aut'>Условия постройки</div>";
echo "<div class='f2'>Дерево: ".intval($derevo_abs)."</div>\n";
echo "<div class='f1'>Золото: ".intval($zoloto_abs)."</div>\n";
echo "<div class='f2'>Железо: ".intval($gelezo_abs)."</div>\n";
echo "<div class='f1'>Еда: ".intval($eda_abs)."</div>\n";
echo "<div class='f2'>Век: ".intval($vek)."</div>\n";

if(isset($_GET['ololo']) && $zoloto_abs<=$q['zoloto'] && $vek<=$q['vek'] && $derevo_abs<=$q['derevo'] && $gelezo_abs<=$q['gelezo'] && $eda_abs<=$q['eda'] && $vek<=$q['vek']){
$ntime=60*60*3;
$strtime=round($ntime/$q['r_l']);
  mysql_query("UPDATE `empire` SET `derevo`=`derevo`-$derevo_abs, `eda`=`eda`-$eda_abs, `zoloto`=`zoloto`-$zoloto_abs, `gelezo`=`gelezo`-$gelezo_abs WHERE `id_u`='".$user['id']."' LIMIT 1");
  mysql_query("INSERT INTO `empire_stroi`(`id_u`, `name`, `eda`, `derevo`, `gelezo`, `zoloto`, `time_h`, `voin`, `push`) VALUES('$user[id]', '$name', '$eda', '$derevo', '$gelezo', '$zoloto', '$ntime', '$voin', '$push')");
  header("Location:index.php?do=7");
  break;
}
 else
 {
   echo "<div class='glav'><a href='?do=6&amp;kup=$kup&amp;ololo'>Купить</a></div>\n";
 }
}
}
}
echo "<div class='aut'><a href='?do=0'>Назад</a></div>";
?>