Selador / laufzeitenrechner.php

 <?php
 //error_reporting(E_ALL);

/* laufzeitenrechner.php - Front-end code for "Laufzeitenrechner" page
 *
 * Copyright (C) 2006, 2007, 2008 Simone Schaefer
 *
 * This file is part of Selador, a browser-based fantasy strategy game
 *
 * This program is distributed under the terms of the GNU Affero General Public License.
 *
 *
 *   Selador is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   any later version.
 *
 *   Selador 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 Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with Selador.  If not, see <http://www.gnu.org/licenses/>.
 **/

// kread: Don't know if this works or if it is finished.
 ?>

<html>
<head><title>Selador Laufzeiten-Berechner</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>

<body>
<table>
<tr>
  <th><h3>Selador Laufzeiten-Berechner</h3></th></tr></table>


<?php
require_once("php/base/config.inc.php");
$db = mysql_pconnect ( "localhost", DB_USER, DB_PASS);
mysql_select_db(DB_NAME) or die("Auswahl der Datenbank fehlgeschlagen");
echo "<table><tr><td colspan=\"3\">";
echo "<h5>Bitte Koordinaten eingeben!</h5><br></td></tr>\n";
echo "<tr><td>Angreifer:</td>";
echo "<form action=\"laufzeitenrechner.php\" method=\"POST\">";
if (isset ($_REQUEST['xattacker']))
  echo "<td>x <input name=\"xattacker\" value=\"".$_REQUEST['xattacker']."\" size=\"3\"></td>\n";
else
  echo "<td>x <input name=\"xattacker\" size=\"3\"></td>\n";
if (isset ($_REQUEST['yattacker']))
	echo "<td>y <input name=\"yattacker\" value=\"".$_REQUEST['yattacker']."\" size=\"3\"></td>\n";
else
	echo "<td>y <input name=\"yattacker\" size=\"3\"></td>\n";

echo "<tr><td>Opfer:</td>\n";
if (isset ($_REQUEST['xvictim']))
	echo "<td>x <input name=\"xvictim\" value=\"".$_REQUEST['xvictim']."\" size=\"3\"></td>\n";
else
	echo "<td>x <input name=\"xvictim\" size=\"3\"></td>\n<td>";
if (isset ($_REQUEST['yvictim']))
	echo "<td>y <input name=\"yvictim\" value=\"".$_REQUEST['yvictim']."\" size=\"3\"></td>\n";
else
	echo "y <input name=\"yvictim\" size=\"3\"></td></tr>\n";

echo "<table><tr><th style=\"text-align:left\"><h5><br>Bitte angeben, was berechnet werden soll</h5></th></tr><tr>";
echo "<td><input type=\"radio\" name=\"typ\" value=\"start\">Wann kommt welche Einheit an, wenn ich um xxx Uhr loslaufe?</td></tr>\n";
echo "<tr><td><input type=\"radio\" name=\"typ\" value=\"ankunft\">Wann muss ich loslaufen, um um xxx Uhr dazusein?</td></tr>\n";
echo "<tr><td><input type=\"radio\" name=\"typ\" value=\"nichts\">Wie lange braucht welche Einheit?</td></tr>\n";
echo "</tr></table>";
if (isset($_POST['Berechne']))
{
	$day = $_POST['tag'];
	$month = $_POST['monat'];
	$year = $_POST['jahr'];
	$hour = $_POST['hh'];
	$minute = $_POST['mm'];
	$second = $_POST['ss'];
}
else
{
	$day = date("d");
	$month = date("m");
	$year = date("Y");
	$hour = date("H");
	$minute = date("i");
	$second = date("s");
}
echo "<table>
			<tr><th><h5><br>Bitte eingeben, wann die Einheiten loslaufen bzw ankommen sollen (keine Eingabe n&ouml;tig f&uuml;r \"Wie lange braucht welche Einheit?\")</h5></th></tr>
			<tr><td>
			<input type=\"text\" size=2 name=\"tag\" value=\"".$day."\">.\n
			<input type=\"text\" size=2 name=\"monat\" value=\"".$month."\">.\n
			<input type=\"text\" size=4 name=\"jahr\" value=\"".$year."\"> &nbsp;\n

			<input type=\"text\" size=2 name=\"hh\" value=\"".$hour."\">:\n
			<input type=\"text\" size=2 name=\"mm\" value=\"".$minute."\">:\n
			<input type=\"text\" size=2 name=\"ss\" value=\"".$second."\">\n
			</td></tr></table>";

echo "<tr><td><input type=\"submit\" name=\"Berechne\" value=\"Berechnen\"></td></tr></table>";

if (isset($_POST['Berechne']))
{

	if (isset ($_REQUEST['xattacker']) && isset ($_REQUEST['yattacker']) &&   isset ($_REQUEST['xvictim']) && isset ($_REQUEST['yattacker']) && ($_REQUEST['xattacker'] != "") && ($_REQUEST['yattacker'] != "") && ($_REQUEST['xvictim'] != "") && ($_REQUEST['yvictim'] != "") && isset($_POST['typ']))
	{

		/*evaluate the form data*/
		$xattacker = (int)$_REQUEST['xattacker'];
		$yattacker = (int)$_REQUEST['yattacker'];
		$xvictim = (int)$_REQUEST['xvictim'];
		$yvictim = (int)$_REQUEST['yvictim'];

		/*calculate the distance*/
		$distance_a = ($xvictim - $xattacker) * ($xvictim - $xattacker);
		$distance_b = ($yvictim - $yattacker) * ($yvictim - $yattacker);
		$distance = sqrt ($distance_a + $distance_b);

		echo "<table><tr><td colspan=\"5\"><h5><br>Entfernung. ".$distance." Felder</h5></td></tr>";
		echo "<tr><th>Speed</th>\n";
		echo "<th colspan=\"2\">Einheit</th>\n";
		echo "<th>Dauer</td>\n";
		echo "<th>Abschicken um/Ankunft um...</th></tr>";

	/*fuer Startzeit und Ankunftsberechnung */
		$hh = (int)$_REQUEST['hh'];
		$mm = (int)$_REQUEST['mm'];
		$ss = (int)$_REQUEST['ss'];
		$tag = (int)$_REQUEST['tag'];
		$monat = (int)$_REQUEST['monat'];
		$jahr = (int)$_REQUEST['jahr'];

		if ($_REQUEST['typ'] == "start")
		{
			 $query = "select unitid, raceid, speed, date_format(addtime(\"".$jahr."-".$monat."-".$tag." ";
			 $query .= $hh.":".$mm.":".$ss."\",(sec_to_time(".$distance."/speed*3600))), \"Ankunft am %d.%m.%Y um %H:%i:%S\") as duration, name from units where speed>0 order by speed";
		}
		if ($_REQUEST['typ'] == "ankunft")
		{
			$query = "select unitid, raceid, speed, date_format(subtime(\"".$jahr."-".$monat."-".$tag." ";
			$query .= $hh.":".$mm.":".$ss."\",(sec_to_time(".$distance."/speed*3600))), \"Abschicken am %d.%m.%Y um %H:%i:%S\") as duration, name from units where speed>0 order by speed";
		}
		if ($_REQUEST['typ'] == "nichts")
		{
			$query = "select unitid, raceid, speed,";
			$query .= "name from units where speed>0 order by speed";
		}
		$result = mysql_query($query) or die("Anfrage fehlgeschlagen: Fehler: " . mysql_error());

	/*Berechnung der Dauer*/

		while (($line = mysql_fetch_array($result, MYSQL_ASSOC)))
		{
			echo "<tr><td width=\"80px\">".$line['speed']."</td>";
			echo "<td><img src=\"gfx/u/".$line['unitid'].".gif\"></td>\n";
			echo "<td width=\"200px\">".$line['name']."</td>";

			$time = $distance / $line['speed'];

			$hours = (int) $time;
			$rest = $time - $hours;
			$minutes = (int) ($rest * 60);
			$rest2 = ($rest*60) - $minutes;
			$seconds = round ($rest2 * 60);

			$minutes += (int)($seconds/60);
			$seconds = ($seconds % 60);

			if ($hours < 10)
			$hours = "0".$hours;
			if ($minutes < 10)
			$minutes = "0".$minutes;
			if ($seconds < 10)
			$seconds = "0".$seconds;

				echo "<td width=\"120px\">".$hours.":".$minutes.":".$seconds."</td>";
	/*Berechnung der Ankunft, falls "Startzeit" ausgewählt wurde*/
			if ($_REQUEST['typ'] == "start")
			{
				/*$timestamp = gmmktime ( $hh, $mm, $ss, $monat, $tag, $jahr);
				$duration_in_seconds = (int) ($time * 3600);
				$arrival_in_seconds = $timestamp + $duration_in_seconds;
				$arrival = strftime ("Ankunft am %d.%m.%Y um %H:%M:%S ", $arrival_in_seconds);*/
				echo "<td>".$line['duration']."</td></tr>";
			}
			if ($_REQUEST['typ'] == "ankunft")
				echo "<td>".$line['duration']."</td></tr>";
			if ($_REQUEST['typ'] == "nichts")
				echo "<td>---</td></tr>";
			echo "<tr><td colspan=\"5\"><img src=\"styles/sun/line_thin.gif\" style=\"width:100%;height:1px\"></td></tr>";
		}
		mysql_free_result ($result);
	}
	else
	{
		echo "<br><br><b>Bitte f&uuml;lle alle Felder aus!</b><br>";
	}
}


?>

</body>
</html>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.