<?php
echo '<link rel="stylesheet" type="text/css" href="style.css"/>
<body>
<div class="head">'.$date.'-[<a href="./game.php">'.$user['country'].'</a>] </div>';
$round_main_img = rand(1,6);
echo '<div class="info"><center><img src="./img_main/'.$round_main_img.'.png" alt=*></center>';
echo '<center><img src="./images/iron.png">'.$user['iron'].', <img src="./images/wood.png">'.$user['lumber'].', <img src="./images/stone.png">'.$user['stone'].', <img src="./images/grain.png">'.$user['grain'].', <img src="./images/money2.png">'.$user['money'].' '.$igolds.$user['gold'].'</div></center>';


$count_hours_country = intval(($time-$user['time_reg'])/60/60);
$isset_ach = mysql_result(mysql_query("SELECT count(`id`) FROM `achieve` WHERE `num`='7' AND `user`='$id'"),0);
				if ($isset_ach == '0')
					{
					mysql_query("INSERT INTO `achieve` SET `num`='7',`count`='$count_hours_country',`user`='$id';");
					} else 
						  {
						  $a_time = mysql_fetch_array(mysql_query("SELECT * FROM `achieve` WHERE `num`='7' AND `user`='$id'"));
						  if ($a_time['count'] < $count_hours_country)
							{
						  mysql_query("UPDATE `achieve` SET `count`='$count_hours_country' WHERE `num`='7' AND `user`='$id'");
							}
						  }



echo '<a class="razd" href="faq.php">Помощь, FAQ</a>';
echo '<a class="razd" href="./map.php">Карта мира</a>';
echo '<a class="razd" href="news.php">Новости';
if($user['news'] > 0)
{
	echo ' (<font color="red">Новых <b>'.$user['news'].'</b></font>)';
}
echo '</a>';

if($user['rank'] == "Админ")
{
	echo '<a class="razd" href="adm.php">Админка</a>';
}
if($user['rank'] == "Модер" OR $user['rank']=='Админ')
{
	echo '<a class="razd" href="modpan.php">Модерка</a>';
}
if($user['marat_end'] > $time)
{
echo '<div class="info"><u>Неприкосновенность</u><br />Осталось ';
time_end($user['marat_end']);
echo '</div>';
}
$wars=mysql_query("SELECT * FROM wars WHERE id_attacker='$id'");
$invasions=mysql_query("SELECT * FROM wars WHERE id_cover='$id'");

$ally_sql = mysql_query("SELECT * FROM `ally` WHERE `id_user`='$id' OR `id_ally`='$id' AND `accept`='1'");
while($res_ally = mysql_fetch_assoc($ally_sql))
	{
	if ($res_ally['id_user']==$id) $ally_id = $res_ally['id_ally'];
	if ($res_ally['id_ally']==$id) $ally_id = $res_ally['id_user'];
	$invasions_ally=mysql_query("SELECT * FROM wars WHERE id_cover='$ally_id'");
	$count_invasions_ally=mysql_num_rows($invasions_ally);
	$login_ally_inv = mysql_fetch_array(mysql_query("SELECT `country` FROM `users` WHERE `id`='$ally_id'"));
	//Война союзника
	if($count_invasions_ally > 0)
			{
			echo '<img src="./images/Q_vipers_nest.png" alt=*  style="float:left; padding:8px">';
			echo '
			<div class="info">Вторжения к: '.$login_ally_inv['country'].'<br />';
			$i=1;
			while($invasion_ally=mysql_fetch_array($invasions_ally))
			{
				$attacker=mysql_fetch_array(mysql_query("SELECT country FROM users WHERE id='$invasion_ally[id_attacker]'"));
				echo '<a href="invasions.php?wid='.$invasion_ally['id'].'">'.$attacker[0].'</a>';
			if($i != $count_invasions_ally)
			{
			echo '|';
			}
			else
			{
			echo '</div>';
			}
			$i++;
			}
			echo ' <div style="clear: center"></div></div>';
			}
	
	
	}
$count_wars=mysql_num_rows($wars);
$count_invasions=mysql_num_rows($invasions);
if($count_wars > 0)
{

$i=1;

echo '<img src="./images/Q_vandal.png" alt=*  style="float:left; padding:8px">';
echo '
<div class="info">Войны:<br />';
			


while($war=mysql_fetch_array($wars))
{
	$defender=mysql_fetch_array(mysql_query("SELECT country FROM users WHERE id='$war[id_cover]'"));
	echo '<a href="war.php?a=view&amp;id_war='.$war['id'].'">'.$defender[0].'</a>';
if($i != $count_wars)
{
echo '|';
}
else
{
echo '</div>';
}
$i++;
}
echo ' <div style="clear: center"></div></div>';
}
if($count_invasions > 0)
{
echo '<img src="./images/Q_vipers_nest.png" alt=*  style="float:left; padding:8px">';
echo '
<div class="info">Вторжения:<br />';
$i=1;
while($invasion=mysql_fetch_array($invasions))
{
	$attacker=mysql_fetch_array(mysql_query("SELECT country FROM users WHERE id='$invasion[id_attacker]'"));
	echo '<a href="invasions.php?wid='.$invasion['id'].'">'.$attacker[0].'</a>';
if($i != $count_invasions)
{
echo '|';
}
else
{
echo '</div>';
}
$i++;
}
echo ' <div style="clear: center"></div></div>';
}
if ($user['last_gift']=='1')
	{
	echo '<img src="./images/Category_icons_banquet_normal.png" alt=*  style="float:left; padding:8px">';
	if (intval($_GET['gift'])=='1')
		{
		
		$isset_ach = mysql_result(mysql_query("SELECT count(`id`) FROM `achieve` WHERE `num`='14' AND `user`='$id'"),0);
				if ($isset_ach == '0')
					{
					mysql_query("INSERT INTO `achieve` SET `num`='14',`count`='1',`user`='$id';");
					} else 
						  {
						  mysql_query("UPDATE `achieve` SET `count`=count+'1' WHERE `num`='14' AND `user`='$id'");
						  }
		
		
		
		mysql_query("UPDATE `users` SET `money`=money+'500',
										`iron`=iron+'100',
										`grain`=grain+'100',
										`lumber`=lumber+'100',
										`stone`=stone+'100',
										`last_gift`='0' WHERE `id`='$id'");
		echo '
		<div class="money">Вы получили: <b>100</b> ед. каждого ресурса +<b>500</b> денег<br /> <a href="./game.php">Закрыть</a>';
		} else {
	echo '
	<div class="money">Ежедневный подарок<br /><a href="?gift=1">Получить</a>';
				}
	echo ' <div style="clear: center"></div></div>';
	}

?>
