<?php

	require_once '../includes/start.php';
	require_once '../includes/function.php';
	require_once '../includes/header1.php';
	if($level==0 OR $ban!=0)

{

		echo "<title>Доступ закрыт!!!</title>";
	 	echo "<script type=\"text/javascript\">createPopup().show( 0, 0, 0, 0, 0 );</script>";
	 	echo "<body oncontextmenu=\"return false;\"><body onselectstart='return false' oncopy='return false'><body onselectstart=\"return false\" oncopy=\"return false\"><body onload=\"digitalWatch()\">";
		echo '<div class="blok3"><img src="/images/errors.png" width="200px"/></div><div class="blok3"><b>Вы не авторизованный или заблокированный пользователь!!!</b><br/><a href="/?sign_in=1"><font color="#4EEE94"><b>Авторизуйтесь</font></a></b> или <a href="/reg.php"><font color="#4EEE94"><b>Зарегистрируйтесь</b></font></a></div>';

}else{

	$PAGINGS = mysql_query("SELECT * FROM `planet` WHERE `peo`!=0 ORDER BY `id` DESC");
	if($PAGINGS > 0)
	{
		while($row = mysql_fetch_array($PAGINGS))
		{	
			$q = mysql_query("SELECT * FROM `users` WHERE `id`='".check(htmlspecialchars(stripslashes(addslashes(strip_tags(mysql_real_escape_string(trim($row['uid'])))))))."'");
			$f = mysql_fetch_array($q);
			if($f['prov']>=$row['peo']*0.5){
			if($row['peo']<(1750*$row['maxpeo']) AND $row['peo']>=50000 AND $f['rasa']==1)$p=intval($row['peo']/40);
			if($row['peo']<(1750*$row['maxpeo']) AND $row['peo']<50000 AND $f['rasa']==1)$p=intval($row['peo']/13.3);
			if($row['peo']>=(1750*$row['maxpeo']) AND $f['rasa']==1)$p=rand(2,5);
			
			if($row['peo']<(1500*$row['maxpeo']) AND $row['peo']>=25000 AND $f['rasa']==2)$p=intval($row['peo']/50);
			if($row['peo']<(1500*$row['maxpeo']) AND $row['peo']<25000 AND $f['rasa']==2)$p=intval($row['peo']/16.6);
			if($row['peo']>=(1500*$row['maxpeo']) AND $f['rasa']==2)$p=rand(1,4);
			
			if($row['peo']<(2000*$row['maxpeo']) AND $row['peo']>=75000 AND $f['rasa']==3)$p=intval($row['peo']/30);
			if($row['peo']<(2000*$row['maxpeo']) AND $row['peo']<75000 AND $f['rasa']==3)$p=intval($row['peo']/10);
			if($row['peo']>=(2000*$row['maxpeo']) AND $f['rasa']==3)$p=rand(3,6);
			$e=$f['prov']-$row['peo']*0.5;
			mysql_query("UPDATE `users` SET `prov`=$e WHERE `id`='".$row['uid']."';");
			mysql_query("UPDATE `planet` SET `peo`=peo+$p WHERE `id`='".$row['id']."';");			
			mysql_query("INSERT INTO `doklad` SET `uid`='".$row['uid']."', `time`='" . time() . "', `type`=1, `text`='Прирост населения на планете <b>".$row['name']."</b> + ".$p." ед.!';");			
			}else{
			$p=intval($row['peo']-$f['prov']*2);
			$e=0;
			mysql_query("UPDATE `users` SET `prov`=$e WHERE `id`='".$row['uid']."';");
			mysql_query("UPDATE `planet` SET `peo`=peo-$p WHERE `id`='".$row['id']."';");	
			mysql_query("INSERT INTO `doklad` SET `uid`='".$row['uid']."', `time`='" . time() . "', `type`=1, `text`='На планете <b>".$row['name']."</b> от голода погибло ".$p." населения!';");}		
	}}
		
		

	$PAGINGS1 = mysql_query("SELECT * FROM `planet` WHERE `peo`=0 AND `repeo`=0 ORDER BY `id` DESC");
	if($PAGINGS1 > 0)
	{
		while($row1 = mysql_fetch_array($PAGINGS1))
		{	
				if($row1['rasa']==1)$npeople=1000;
				if($row1['rasa']==2)$npeople=750;
				if($row1['rasa']==3)$npeople=1250;
		
		
			mysql_query("UPDATE `planet` SET `peo`='".$npeople."', `repeo`=1 WHERE `id`='".$row1['id']."';");			
			mysql_query("INSERT INTO `doklad` SET `uid`='".$row1['uid']."', `time`='" . time() . "', `type`=1, `text`='На планету <b>".$row1['name']."</b> прибыло ".$npeople." населения! Внимательно следите за приростом населения так как теперь если оно закончится новые колонисты уже не прибудут';");			
	}}

		}
	echo '<div class="razd"></div>';
	echo '<center><div class="blok2"><a href="../"><b>На Главную</b></a></div></center>';
	echo '<div class="razd"></div>';
	require_once '../includes/footer.php';
?>