Source

Selador / portal.php

Full commit
<?php

/* portal.php - Front-end code for the portal page
 *
 * Copyright (C) 2006, 2007, 2008 Kevin Read, 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/>.
 **/

@header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
@header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
@header ("Content-Type: text/html; charset=utf-8");
require_once ("php/base/config.inc.php");

if (!isset ($f))
{
	if (isset ($_REQUEST['f']))
	{
		$f = (int)$_REQUEST['f'];
		if (($f < 1) || ($f > 4))
			$f = 1;
	}
	else
	{
		$f = 1;
		$_REQUEST['f'] = 1;
	}


	//if ($num_heroes == 0 && !$stopped_worlds && $f == 1)
	//		$f = 2;

}

if (!isset($f))
	$f = 1;


function draw_world_entry ($world, $what, $folder, $first_login=false)
{
	global $races_byid, $classes_byid;

	if ($folder == 1)
        {
		// Deine Helden
		if (($world['running'] == 0) || (!isset ($world['uid'])))
			// Don't show world if it's not running or if player has no hero
			return false;
        }
	elseif ($folder == 2)
        {
		// Aktuelle Welten
		if (($world['running'] == 0) || (isset ($world['uid'])))
			// Don't show world if it's not running or if player has a hero
			return false;
        }
	elseif ($folder == 3)
        {
		// Abgelaufene Welten
		if ($world['running'] != 0)
			// Don't show running worlds
			return false;
        }
	elseif ($folder == 4)
        {
		// Sitter-Welten
		if ($world['running'] == 0)
			// Don't show not running worlds
			return false;
        }

	//create title for  worldpic
	if (isset($world['uid']) && $what==1)
		$title=' Um diese Welt zu betreten, klicke  auf Welt betreten';
	if (!isset($world['uid']))
		$title = ' Um in dieser Welt mitzuspielen, klicke auf Helden erstellen ';

	//create "new" icon, if need be
	if ($world['time_running'] < 3600*24*7)
		$new = "<img style=\"position:absolute;left:25px;z-index:2;\" src=\"styles/sun/new.gif\">";
	else
		$new = '';

	//sitter worlds need special treatment for world title representation
	if ($what == 2)
		$worldtitle = $world['user']." in ".$world['title'];
	else
		$worldtitle = $world['title'];

	//display information when this world started
	if ($world['time_running'] < 0)
		$started = 'Diese Welt ist noch nicht gestartet';
	elseif ($world['time_running'] < 3600*24*7)
		$started ='Diese Welt hat gerade erst begonnen';
	else
	{
		$weeks = floor ($world['time_running'] / (3600*24*7));
		$started = 'Diese Welt l&auml;uft seit '.$weeks.' Wochen';
	}

	//display information when this world will end
	if ($world['time_running'] > 0)
	{
		if ($world['ttl'] > 3600*24*14)
			$end = ' und endet vorraussichtlich am '.$world['date_end'];
		else
		{
			if ($world['ttl'] >= 0)
				$end = ' und endet am '.$world['date_end'];
			else
				$end = ' und wurde am '.$world['date_end'].' gewertet';
		}
	}

	//display information about world speed
	if ($world['speed'] < 1.5)
		$speed = 'eher langsam';
	elseif ($world['speed'] < 2.0)
		$speed =  'normal';
	elseif ($world['speed'] < 3.0)
		$speed =  'eher schnell';
	elseif ($world['speed'] < 5.0)
		$speed =  'schnell';
	elseif ($world['speed'] < 16.0)
		$speed =  'sehr schnell';
	else
		$speed =  '&uuml;berirdisch schnell';

	//create button to enter world / create new hero
	$hidden = array();
	//user already has a hero in this world
	if (isset ($world['uid']))
	{
		$action = $world['url'].'land.php';
		$hidden['username'] = $_SESSION['authed_user'];
		$hidden['password'] = $_SESSION['pwh'];
		if ($what == 2)
		{
			$hidden['foruid'] = $world['uid'];
			$submittext = 'Jetzt sitten';
		}
		else
			$submittext = 'Welt betreten';
	}
	else
	{
		// No he hasn't, we'll offer to make him a hero in this world
		if ($world['registration_open'])
		{
			$action = $world['url'].'index.php';
			$hidden['username'] = $_SESSION['authed_user'];
			$hidden['password'] = $_SESSION['pwh'];
			$hidden['first_login'] = $first_login;

			$submittext = 'Held erstellen';
		}
		else
			$submittext = 'Momentan keine Registrierung m&ouml;glich.';
	}


	echo
		'
	<table class="border">
		<tr>
			<th class="bold" colspan="2">'.$worldtitle.'</th>
		</tr>
		<tr>
			<td rowspan="5"><img src="'.$world['smallpic'].'" title="'.$title.'" alt="'.$title.'"></td>
			<td class="iterate"><i>'.$world['subtitle'].$new.'</i></td>
		</tr>
		<tr>
			<td><b>Zeitraum: </b>'.$started.$end.'</td>
		</tr>
		<tr class="iterate">
			<td><b>Geschwindigkeit: </b>'.$speed.'</td>
		</tr>
		<tr>
			<td><form method="POST" action="'.$action.'">';
		foreach ($hidden as $name => $value)
		{
			echo '<input type="hidden" name="'.$name.'" value="'.$value.'">';
		}
	echo '
			<input type="submit" value="'.$submittext.'">
			</form>
			</td>
		</tr>
	</table>';
}

@session_start ();

if (!isset ($_SESSION['authed_user']))
{
	require_once ("index.php");
	die ();
}

$races_byid = array (1=>"Mensch", 4=>"Ork");
$races_pl_byid = array (1=>"Menschen", 4=>"Orks");
$classes_byid = array (1=>"Krieger", 2=>"Dieb", 3=>"Miner", 4=>"Händler");




if (!$_SESSION['email_ok'])
{
	require_once ("activate.php");
	die ();
}

// require_once("php/base/user.inc.php");
// require_once("php/base.php");
// require_once("php/event.php");

require_once("menue_portal.php");

require_once ("php/base/AuthDB.inc.php");

$authdb = new AuthDB ();

$uid = $_SESSION['authed_uid'];

if (isset ($_REQUEST['addmail']))
{
	$query = "update user set wants_mail=1 where uid=".$uid;

	if (!$authdb->query ($query))
	{
		$add_err = "Leider ist ein Datenbank-Fehler aufgetreten";
	}
	else
		$_SESSION['wants_mail'] = 1;
}

$my_worlds = $authdb->list_worlds ($uid);
$my_sitting_worlds = $authdb->list_sat_worlds ($uid);

$num_heroes = 0;
$new_worlds = false;
$stopped_worlds = false;
// Calculate the number of heroes this user has
foreach ($my_worlds as $this_world)
{
	if ($this_world['uid'])
	{
		$num_heroes++;
		if ($this_world['running'] == 0)
			$stopped_worlds = true;
	}
	else
	{
		if ($this_world['time_running'] < (3600*24*7))
			$new_worlds = true;
	}
}

if (!isset ($_SESSION['first_login']))
	$first_login = false;
else
	$first_login = true;

if ($num_heroes > 0)
	$first_login = false;


if ($first_login == true)
{
	$f = 2;
	$header = '<h2>Willkommen, '.$_SESSION['authed_user'].'</h2>';
	$content = '<br>Dies ist das <b>Selador-Portal</b>. Mehrere Welten stehen zur Auswahl, um mitzuspielen.<span id="ie6box"></span>';
}
else
{
	$header = '<h2>Willkommen zur&uuml;ck, '.$_SESSION['authed_user'].'</h2>';
	$content = '<span id="ie6box"></span>';
}


?>

<?php
if (!$first_login)
{
?>
<div id="leiste-links">
	<div id="outer">
		<div id="inner">
			<div id="townmenu">

	<b>Wenn euch unser Spiel gefällt, votet bitte für uns! <u>Ihr könnt jeden Tag voten</u></b><br>
	<p><center><div style="width:88px; height:31px; background-image:url(http://www.kostenlose-browsergames.de/images/bgbutton.gif); background-repeat:no-repeat; padding: 4px 1px 2px 2px; line-height:12px; text-align:left;">
	<a href="http://www.kostenlose-browsergames.de" target="_blank" style="font-family:Arial,sans-serif; font-size:11px; font-weight:bold; letter-spacing:0px; color:#ffffff; text-decoration:none;">kostenlose browsergames</a></div>
	</center></p>
	<p><center><a href='http://www.galaxy-news.de/charts/?op=vote&amp;game_id=2527' target='_blank'><img src='gfx/vote.gif' style='border:0;' alt='Die besten Browsergames in den Galaxy-News MMOG-Charts!'/></a></center></p>

	<?php
	if (!$_SESSION['wants_mail'])
	{
		echo '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
		echo '<br>M&ouml;chtest du den Newsletter abonnieren?<br><br>';
		echo '<center><input type="submit" name="addmail" value="Ja, bitte"></center></form>';
	}
	?>
	</div>
</div>
</div>
</div>
<?php
}
?>


<div id="contentbox">
<?php echo $header ?></h3>
<table class="border">
	<tr>
		<td class="start" colspan="5"><?php echo $content ?>
	</td>
	</tr>
	<tr>

<?php

switch ($f)
{
	case 4:
		if (count ($my_sitting_worlds))
		{
			foreach ($my_sitting_worlds as $world)
				draw_world_entry ($world, 2, $f);
		}
		else
			echo '<tr><th colspan="5">Du bist bei keinem Spieler als Sitter eingetragen.</th></tr>';
		break;
	case 1:
	case 2:
	case 3:
		foreach ($my_worlds as $world)
		{
			draw_world_entry ($world, 1, $f, $first_login);
		}
		break;
}



?>
	</table>
	</td>
	</tr>
</table>

</div>
<?php


if (isset ($forumiframe))
	echo $forumiframe;
?>

   <div id="footer">
		<table>
		<tr>
		<td><a href="regeln_portal.php" class="imp">Regeln</a>&nbsp;</td>
		<td><a href="impressum_portal.php" class="imp">Impressum</a>&nbsp;</td>
		<td><a href="http://forum.selador.de" class="imp" target="_blank">Forum</a></td>
		<td><a href="http://forum.selador.de/index.php?topic=4243.msg34802#msg34802" class="imp" target="_blank">Spenden</a></td>

  		</tr>
  		</table>
   </div>
</body>
</html>