<?
include_once '../sys/inc/start.php';
include_once '../sys/inc/compress.php';
include_once '../sys/inc/sess.php';
include_once '../sys/inc/home.php';
include_once '../sys/inc/settings.php';
include_once '../sys/inc/db_connect.php';
include_once '../sys/inc/ipua.php';
include_once '../sys/inc/fnc.php';
include_once '../sys/inc/user.php';


$set['title']='База'; // заголовок страницы

include_once '../sys/inc/thead.php';
title();
echo '<link rel="stylesheet" href="style.css" type="text/css" />';
include_once 'function.php';

if(mysql_result(mysql_query("SELECT COUNT(*) FROM `tanks_buildings` WHERE `id_user`='".$user['id']."'"),0)==0) {

mysql_query("INSERT INTO `tanks_buildings` (`id_user`,`name`,`time`,`count`,`text`,`images`) VALUES('".$user['id']."','Шахта','0','0','Производит ресурсы','Mine.jpg')");
mysql_query("INSERT INTO `tanks_buildings` (`id_user`,`name`,`time`,`count`,`text`,`images`) VALUES('".$user['id']."','Полигон','0','0','Производит усиление танка','Polygon.jpg')");
mysql_query("INSERT INTO `tanks_buildings` (`id_user`,`name`,`time`,`count`,`text`,`images`) VALUES('".$user['id']."','Оружейная','0','0','Производит снаряды, ремкомплекты','Armory.jpg')");

echo '<div class="trnt-block">
  <div class="wrap1">
    <div class="wrap2">
      <div class="wrap3">
        <div class="wrap4">
          <div class="wrap5">
            <div class="wrap6">
              <div class="wrap7">
                <div class="wrap8">
                  <div class="wrap-content-mini">
                    <div class="mt5 mb5 small bold gray1 cntr">Ваша база успешно создана</div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>';
}
function sictime($timediff){

$oneMinute=60;
$oneHour=60*60;
$oneDay=60*60*24;
$dayfield=floor($timediff/$oneDay);
$hourfield=floor(($timediff-$dayfield*$oneDay)/$oneHour);
$minutefield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour)/$oneMinute);
$secondfield=floor(($timediff-$dayfield*$oneDay-$hourfield*$oneHour-$minutefield*$oneMinute));
$time_1="$hourfield ч. $minutefield м. $secondfield c";
return $time_1;
}

if($_GET['batt_tanks'] == 'tanks') {

if(isset($_GET['id'])) { $id_tank = $_GET['id'];}
$barte = mysql_fetch_array(mysql_query("SELECT * FROM `tanks_buildings` WHERE `id` = '$id_tank'"));
$newtime = time()+60*60*12;
mysql_query("UPDATE `tanks_buildings` SET `count`=`count`+'1',`time`='".$newtime."' WHERE `id` = '$id_tank' AND `id_user`='".$user['id']."'");
header('Refresh: 1; url=angar.php');
echo 'Улучшения успешно активировано';

}
$buildings = mysql_query("SELECT * FROM `tanks_buildings` WHERE `id_user`='".$user['id']."'");
while($building = mysql_fetch_array($buildings)) {

$betl = mysql_fetch_array(mysql_query("SELECT * FROM `tanks_buildings` WHERE `id` = '$building[id]'"));
if($betl['time'] < time()){
echo '<div class="trnt-block">
  <div class="wrap1">
    <div class="wrap2">
      <div class="wrap3">
        <div class="wrap4">
          <div class="wrap5">
            <div class="wrap6">
              <div class="wrap7">
                <div class="wrap8">
                  <div class="wrap-content">
                    <div class="mb5 inbl w100">
                      <div class="thumb fl">
                        <img src="images/building/'.$building['images'].'" alt="">
                        <span class="mask2"> </span>
                      </div>
                      <div class="ml58 small white sh_b bold">
                        <span class="green2">'.$building['name'].' + '.$building['count'].'</span>
                        <br>
                        '.$building['text'].'
                        <br>
                      </div>
                      <div class="clrb"></div>
                    </div>
                    <div class="bot">
                      <table>
                        <tbody>
                          <tr>
                            <td style="width:50%;padding-right:1px;">
                              <div style="position:relative;">
                                <a class="simple-but border" href="?batt_tanks=tanks&id='.$building['id'].'">
                                  <span>
                                    <span>Улучшить</span>
                                  </span>
                                </a>
                                <span class="digit esmall">
                                  <span class="l"> </span>
                                  <span class="m">+</span>
                                  <span class="r"> </span>
                                </span>
                              </div>
                            </td>
                          </tr>
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>';
}else {
echo '<div class="trnt-block">
  <div class="wrap1">
    <div class="wrap2">
      <div class="wrap3">
        <div class="wrap4">
          <div class="wrap5">
            <div class="wrap6">
              <div class="wrap7">
                <div class="wrap8">
                  <div class="wrap-content">
                    <div class="mb5 inbl w100">
					                      <div class="thumb fl">
                        <img src="images/building/'.$building['images'].'" alt="">
                        <span class="mask2"> </span>
                      </div>
                      <div class="ml58 small white sh_b bold">
                        <br>
                        
                        Идет улучшение подождите: '.sictime($betl['time']-time()).'
                        
                        <br>
                      </div>
                      <div class="clrb"></div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>';

}
}


include_once '../sys/inc/tfoot.php';
?>
