Location: PHPKode > projects > Babylon 5: Upheaval > b5-upheaval/php_functions/manage_planets.php
<!--    

	Copyright 2007 Martin Remisch

	This file is part of "Babylon 5: Upheaval".

    "Babylon 5: Upheaval" is free software: you can redistribute it and/or 
    modify it under the terms of the GNU General Public License as published 
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "Babylon 5: Upheaval" is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with "Babylon 5: Upheaval".  If not, see <http://www.gnu.org/licenses/>.

 -->

<?php

		session_start();
		error_reporting(E_ALL);

		include('../db_include.inc');	

		mysql_connect(HOST,USER,PASS)or die(mysql_error());
		mysql_select_db(DATABASE) or die(mysql_error());

		function parse_time($to_parse)
		{

			$gesamt = NULL;
			$d  = floor($to_parse / 1440)."T ";
			$h  = floor(($to_parse / 60)-($d	*24))."h ";
			$mi = ($to_parse % 60)."m";

			$zeit_angabe = array($d,$h,$mi);
	
			for ($i=0; $i < count($zeit_angabe); $i++)
			{
				if (!preg_match('/^0/',$zeit_angabe[$i])) 
				{ 
					$gesamt= $gesamt.$zeit_angabe[$i]; 
				}
			}

			return $gesamt;

		}

		if(isset($_POST['planet']))
		{
			$_SESSION['planet'] = $_POST['planet'];
		}

		if(isset($_SESSION['planet']))
		{
			$planet = $_SESSION['planet'];
		}
		else
		{
			$planet = 1;
		}
	
		$name = $_SESSION['name'];

		$planeten_name 		 	   = "planeten_".$name;
		$bauten_namen			 	   = array('Gaserzeuger','Festelementminen','Bioreaktoren','Energiegeneratoren','Forschungsstationen');	
		$res_namen 				 	   = array('Credits','Gesinnung','Population','Bio','Mineral','Gas','Energie','Moral','Forschung');	
		$coulumn_names			 	   = mysql_query("SELECT * FROM ".$planeten_name);
		$planeten_auswahl 	 	   = mysql_query("SELECT id,name FROM ".$planeten_name);
		$info_select_aktiv_planet  = mysql_query("SELECT * FROM ".$planeten_name." WHERE id='".$planet."'");
		$info_select_counter_count = mysql_query("SELECT * FROM ".$planeten_name." WHERE id='".$planet."'");
		$counter_count 				= mysql_fetch_array($info_select_counter_count,MYSQL_NUM);
		$end_count = 1;
		$distanz   = 1;

		for ($p=16;$p <= count($counter_count);$p+=3)
		{
				
			if ($counter_count[$p] != -1) { $end_count++; }
				
		} 

		echo "<html>\n";

		echo "<head>\n";
		echo	"<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n";
		echo 	"<link rel=\"stylesheet\" type=\"text/css\" href=\"../format.css\">\n";
		echo  "<script type=\"text/javascript\" src=\"../skripte/countdownpro.js\" defer=\"defer\"></script>\n";


		for ($x=1; $x <= $end_count;$x++)
		{
			echo  "<meta scheme=\"countdown$x\" name=\"event_msg\" content=\"beendet\">\n";
  			echo  "<meta scheme=\"countdown$x\" name=\"d_hidezero\" content=\"1\">";
  			echo  "<meta scheme=\"countdown$x\" name=\"h_hidezero\" content=\"1\">";
  			echo  "<meta scheme=\"countdown$x\" name=\"m_hidezero\" content=\"1\">";
			echo  "<meta style=\"visibility: hidden;\" scheme=\"countdown$x\" name=\"servertime\" content=\"".date("Y-m-d H:i:s")." GMT+02:00\">\n";				
		}

		echo  "</head>\n";

		echo  "<ul id=\"Navigation\">\n";
		echo		"Navigation\n";
		echo		"<a href=\"sternenkarte.php\">Sternenkarte</a>\n";
		echo		"<a href=\"display_own_planets.php\">Planeten</a>\n";
		echo		"<a href=\"manage_planets.php\">Baumenü</a>\n";
		echo  "</ul>\n";


		echo "<div style=\"width:20%; float:left;\">\n";

		echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">\n";
		echo "<table style=\"table-layout:fixed;\">\n";
		echo "<th>Sprung</th><th>Name</th>\n";
		
		while($planet_aktuell = mysql_fetch_array($planeten_auswahl))
		{

			if ($planet_aktuell['id'] == $planet)
			{
				echo "<tr><td><input type=\"radio\" name=\"planet\" value=\"".$planet_aktuell['id']."\" checked></td>\n";
			}
			else
			{
				echo "<tr><td><input type=\"radio\" name=\"planet\" value=\"".$planet_aktuell['id']."\"></td>\n";
			}

			echo "<td>$planet_aktuell[name]</td></tr>\n";

		}	

		echo "</table>";
		echo "<input type=\"submit\" value=\"Ok\" />";
		echo "</form>";
		echo "</div>";

		echo "<div style=\"width:79.8%; height:90%; border-width:1px; border-style:solid; float:right;\">";

//Ausgabe der vorhandenen Resourcen

		$row = mysql_fetch_array($info_select_aktiv_planet,MYSQL_NUM);

		echo "<h3 style=\"color:black; font-weight:bold;\">$row[12] verfügt über:</h3>";

		echo "<table style=\"table-layout:auto;\"><tr>";

		for($i=0;$i <= 8;$i++)			//Resourcennamen
		{
			echo "<th>$res_namen[$i]</th>\n";
		}

		echo "</tr>";

		for($i=3;$i < 12;$i++)			//Resourcen
		{
			echo "<td><img src=\"../bilder/legende/".$res_namen[$i-3].".png\"></img> $row[$i]</td>\n";
		}

		echo "</table>";

//Ausgabe der vorhandenen Gebäude

		echo "<h3 style=\"color:black; font-weight:bold;\">Baumenü:</h3>\n";
		
		$count = 0;
		$stufen_count = 14;
		
		for ($d=0; $d < count($bauten_namen); $d++)
		{

			$version = 1;
			$start   = 1;

			for($i=$stufen_count;$i < count($row); $i+=15)
			{	

				$code = '';

				if ($row[$i+1] != 0)
				{

					echo "\n<table style=\"empty-cells:hide; margin-bottom:15px; table-layout:fixed;\">\n";
	
					echo "<tr>\n";
					echo "<th style=\"width:200px; text-align: center; color:black; font-size: 1.2em; background-color:moccasin;\">$bauten_namen[$d]</th>\n";
					echo "<th style=\"width:80;\">Vorhanden</th>\n";
					echo "<th>Kosten</th>\n";
					echo "<th style=\"width:100px;\">Bauzeit</td>\n";
					echo "<th>Status</th>\n";
					echo "</tr>\n";

					$bauzeit = mysql_result(mysql_query("SELECT zeit FROM buildings WHERE name='$bauten_namen[$d]' AND version='$version'"),0);

					$erg 		= mysql_result(mysql_query("SELECT kosten FROM buildings WHERE name='$bauten_namen[$d]'"),0);
					$kosten  = explode("/",$erg);
					
					for ($k=6; $k <= 9; $k++)
					{

						$farbcode = 'green';
						
						if ($row[$k] < $kosten[$k-6])
						{
							$farbcode = "red";
						}
						
						$code = $code."<img src=\"../bilder/legende/".$res_namen[$k-3].".png\"></img><span style=\"color:$farbcode;\"> ".$kosten[$k-6]."&nbsp &nbsp</span>";
						
					}

					echo "<tr>\n";
					echo "<td style=\"border-style:solid;border-width:1px;\">Version ".$version."</td>\n";
					echo "<td style=\"border-style:solid;border-width:1px;\">$row[$i]</td>\n";
					echo "<td style=\"black; border-style:solid;border-width:1px;\">$code</td>\n";
					echo "<td style=\"border-style:solid;border-width:1px;\">".parse_time($bauzeit*5)."</td>\n";
					echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">\n";

					if(isset($_POST[$i+2]))
					{
						$b_time = strtotime("+".($bauzeit*5)." minutes", time());
						mysql_query("UPDATE ".$planeten_name." SET ".mysql_field_name($coulumn_names,$i+2)."='".$b_time."' WHERE id='".$planet."' AND ".mysql_field_name($coulumn_names,$i+2)."='-1'");
						mysql_query("UPDATE ".$planeten_name." SET bio='".($row[6]-$kosten[0])."', mineral='".($row[7]-$kosten[1])."', gas='".($row[8]-$kosten[2])."', energy='".($row[9]-$kosten[3])."' WHERE id='".$planet."'");
						unset($_POST[$i+2]);
					}

					unset($row);
					$sql 	 = "SELECT * FROM ".$planeten_name." WHERE id='".$planet."'";
					$query = mysql_query($sql);
					$row   = mysql_fetch_array($query,MYSQL_NUM);

					$query	 = mysql_query("SELECT kosten FROM buildings WHERE name='$bauten_namen[$d]'");
					$erg 		 = mysql_result($query,0);
					$kosten   = explode("/",$erg);
					$farbcode = 'green';
	
					for ($k=6; $k <= 9; $k++)
					{

						if ($row[$k] < $kosten[$k-6])
						{
							$farbcode = "red";
						}
					
					}

					if($row[$i+2] != -1)
					{
						
						echo "<td><span id=\"countdown$distanz\">".(date("Y-m-d H:i:s", $row[$i+2]))." GMT+02:00</span></td>\n";
						$distanz++;
					}
					elseif ($farbcode == 'green')
					{
						echo "<td><input type=\"submit\" name=\"".($i+2)."\" value=\"bauen\" /></td>\n";
					}	
					else
					{
						echo "<td>nicht genug Resourcen</td>\n";						
					}
					
					echo "</tr>\n";

				}

				$version++;
			}
			
			$stufen_count+=3;
			echo "</form>\n";
			echo "</table>\n";

		}

?>
		</form>
	</div>

</html>
Return current item: Babylon 5: Upheaval