Source

Selador / profile.php

Full commit
<?php

/* profile.php - Front-end code for the profile 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/>.
 **/

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


// Acquire lock for village here!

// Handle past events
// $me->event_handler (true, $me->activevillageid, $gui);

// Then calculate ressources through checking income - this takes into account
// past events, because event_handler might have updated $secspassed
// $me->activevillage->do_income ();

$me->activevillage->update_stamp ();

// We include basic design parts here
require_once ("styles/php/base_design-".$_SESSION['theme'].".php");
echo '<div id="contentbox">';


if (isset($_REQUEST['u']))
{


	$uid = (int) $_REQUEST['u'];
	require_once("AuthDB.inc.php");
	$authdb = new AuthDB;
	$query = "select A.invitations, A.invited_by, B.user, B.uid from user A left join user B on (A.invited_by=B.uid) where A.uid=".$uid;
	if ($res = $authdb->query($query))
	{
		if (mysql_num_rows($res) == 1)
		{
			if ($row = mysql_fetch_array($res))
			{

				if (strlen($row['user']) > 2)
					$invited_by = '<a href="profile.php?u='.$row['uid'].'">'.$row['user'].'</a>';
				else
				{
					if ($row['invited_by'] != 0)
					{
						$invited_by = '(gel&ouml;schter Spieler)';
					}
					else
						$invited_by = "---";
				}
				$invited = (int)$row['invitations'];
			}
			else
			{
			}
		}
	}
	else
	{
	}
	$query = "select A.uid, A.user, A.hero_sex, A.level, round(A.score/1000) as score, A.aid, B.name as race, C.name as class, D.ranking, E.*, F.tag from user A join races B on (A.race=B.raceid) join classes C on (A.class=C.classid) left join ranking D on (A.uid=D.uid) left join profile E on (A.uid=E.userid) left join allies F on (A.aid=F.aid) where A.uid=".$uid;

	$result = $gamedb->query($query);

	if ($result)
	{
		if ($row = mysql_fetch_array($result))
		{
			mysql_free_result ($result);

			// We should also pass this on to the tutorial, if it is still going strong
			if (is_object ($tutorial))
			{
				if ($tutorial->active)
					$tutorial->is_in_profile ($row['user']);
			}

	//Benutzername des Spielers
			//echo '<div id="reiter">
			//		<table class="inhalt" width="100%"><tr><th><a class="aktiv" href="profile.php?f=1&u='.$_REQUEST['u'].'">Profil</a></th></tr></table><br><br></div>';

			if (!isset ($_REQUEST['f']))
				$f = 1;
			else
			{
				if ($_REQUEST['f'] == 1)
					$f = 1;
				if ($_REQUEST['f'] == 2)
					$f = 2;
			}


	    if ($f == 1)
			{
				echo '<div id="forschung">
				 <div id="seite-links"><br>
					<table class="border" >
						<tr>
							<th colspan="3" class="bold">Spieler  '.$row['user'].'</th></tr> ';

//Rang des Spielers
				echo '<tr ><td  >Rang:</td><td  >'.$row['ranking'].'</td>';
//Avatar	des Spielers
				if ("keine Angabe"==$row['picture'])
					echo '<td rowspan="7" ><img src="gfx/a/all.png"></td></tr>';
				else
					echo '<td rowspan="7" width="120px"><img src="'.$row['picture'].'" height=174px width="120px"></td></tr>';

//Punkte des Spielers
				echo '<tr ><td  >Punkte:</td><td  >'.$row['score'].'</td></tr>';
//Volk des Spielers
				echo '<tr  ><td  >Volk:</td><td  >'.$row['race'].'</td></tr>';
//Klasse des Spielers
				echo '<tr  ><td  >Klasse:</td><td >'.$row['class'].'</td></tr>';
//Allianz

				echo '<tr ><td  >Allianz:</td><td  ><a href="allianz.php?a='.$row['aid'].'">'.$row['tag'].'</a></td></tr>';

//Geschlecht des Helden
				if (1==$row['hero_sex'])
					echo '<tr ><td >Geschlecht d. Helden: </td><td id=\"rundrum\">M&auml;nnlich</td></tr>';
				if (2==$row['hero_sex'])
					echo '<tr ><td >Geschlecht d. Helden: </td><td >Weiblich</td></tr>';
				//else
				//	echo '<tr ><td >Geschlecht d. Helden: </td><td >Nichts</td></tr>';
//Level des Helden
				echo '<tr ><td >Level: </td><td >'.$row['level'].'</td></tr>';
				echo '</table>';
				

//Aktionen
				echo '<table class="border" >';
				echo '<tr ><th class="bold"  > Aktionen</th></tr> ';

			 	echo '<tr ><td >Diesem Spieler eine <a href="bote.php?r='.$row['user'].'&f=2">Nachricht schreiben</a></td></tr>';
				echo '</table>';

//Persoenliche Angaben
				echo '<table class="border" >';
				echo '<tr ><th class="bold" colspan="2"> Pers&ouml;nliche Angaben</th></tr> ';

//Geburtstag
				if (0 == $row['birthday'])
					echo '<tr ><td >Geburtstag: </td><td >keine Angabe</td></tr>';
				else
					echo '<tr ><td >Geburtstag: </td><td >'.$row['birthday'].'</td></tr>';
//Geschlecht
				if (1==$row['sex'])
					echo '<tr ><td >Geschlecht: </td><td >m&auml;nnlich</td></tr>';
				else
				{
					if (2==$row['sex'])
						echo '<tr ><td >Geschlecht </td><td >weiblich</td></tr>';
					else
						echo '<tr ><td >Geschlecht: </td><td >keine Angabe</td></tr>';
				}
//Realname
				if (""==$row['realname'])
					echo '<tr ><td >Realname: </td><td >keine Angabe</td></tr>';
				else
					echo '<tr ><td >Realname: </td><td >'. stripslashes ($row['realname']).'</td></tr>';
//Wohnort
				if (""==$row['city'])
					echo '<tr ><td >Wohnort: </td><td >keine Angabe</td></tr>';
				else
					echo '<tr ><td >Wohnort: </td><td >'.stripslashes ($row['city']).'</td></tr>';
//ICQNummer
				if (""==$row['icq'])
					echo '<tr ><td >ICQ-Nummer: </td><td >keine Angabe</td></tr>';
				else
					echo '<tr ><td >ICQ-Nummer: </td><td >'.$row['icq'].'</td></tr>';

				echo '</table>';
				
				echo '<table class="border" >';
				echo '<tr><th class="bold">Einladungen</th></tr>';
				echo '<tr ><td >'.$row['user'].'
				wurde eingeladen von: <b>'.$invited_by.'</b></td></tr>';
				echo '<tr ><td  ><b>'.(int)$invited.' Spieler</b> ';
				if ($invited == 1)
				{
					echo ' ist ';
				}
				else
				{
					echo ' sind ';
				}
				echo '
				&uuml;ber '.$row['user'].' zu Selador gekommen.</td></tr>';
				echo '</table></div>';

				echo '<div id="seite-rechts" ><br>';

		 		//we are generous, players can use bbcode for their description if they want
				//require_once("php/bbcode/configure_bbcode.php");	    
                //$descr = $bbcode->parse ($row['description']);
                //$descr = '<pre style="white-space:normal">'.stripslashes ($row['description']).'</pre>';
                
                require_once("php/bbcode/configure_bbcode.php");
 				$descr = $bbcode->parse (stripslashes ($row['description']));
				
				echo '<table class="border">';
				echo '<tr ><th class="bold">Beschreibung</th></tr>';

				echo '<tr height="100px "><td>'.stripslashes ($descr).'</td></tr></table>';
				
					$query_villages = "select name,x,y,villageid,outpost_of from village where uid=".$uid;

				if (($result_villages = $gamedb->query($query_villages)))
				{
					echo '<table class="border">';
					echo '<tr><th colspan="3" class="bold"  >St&auml;dte</th></tr>';


					while ($row_villages = mysql_fetch_array($result_villages))
					{
						if ($row_villages['outpost_of'])
							$outposts[$row_villages['outpost_of']][] = $row_villages;
						else
							$vill[$row_villages['villageid']] = $row_villages;
					}

					foreach ($vill as $this_vid => $this_vill)
					{
						$z = ($world->sizex * $this_vill['y']) + $this_vill['x'];
						echo "<tr><td><a href=\"land.php?z=".$z."\">".stripslashes ($this_vill['name'])."</a>(".$this_vill['x']."|".$this_vill['y'].")";
						echo '</td><td>
							<a href="welt.php?x='.$this_vill['x'].'&y='.$this_vill['y'].'&h=true"><img src="styles/'.$_SESSION['theme'].'/world.png" title="Auf Weltkarte anzeigen" alt="Auf Weltkarte anzeigen"></a>';
						if (!$me->sat_by && $row['uid'] != $me->uid)
							echo '<a href="einheiten.php?f=3&x='.$this_vill['x'].'&y='.$this_vill['y'].'"><img src="styles/'.$_SESSION['theme'].'/shield_go.png" title="Truppen schicken" alt="Truppen schicken"></a>';
						echo '<a href="handel.php?f=1&x='.$this_vill['x'].'&y='.$this_vill['y'].'"><img src="styles/'.$_SESSION['theme'].'/lorry_go.png" title="Beliefern" alt="Beliefern"></a>';
//http://localhost/selador/vollmilch/einheiten.php?f=3&sendtroops[6]=Unterst%C3%BCtzen&x=370&y=312&r=1
						echo "</td></tr>";
						if (isset ($outposts[$this_vid]))
						{
							foreach ($outposts[$this_vid] as $this_outvid => $this_out)
							{
								$z = ($world->sizex * $this_out['y']) + $this_out['x'];
								echo "<tr><td><a href=\"land.php?z=".$z."\"><img src=\"gfx/apeinrueck.gif\">&nbsp;".stripslashes ($this_out['name'])."</a>(".$this_out['x']."|".$this_out['y'].")";
								echo '</td>';
								echo '<td>
									<a href="welt.php?x='.$this_out['x'].'&y='.$this_out['y'].'&h=true"><img src="styles/'.$_SESSION['theme'].'/world.png" title="Auf Weltkarte anzeigen" alt="Auf Weltkarte anzeigen"></a>';
								if (!$me->sat_by && $row['uid'] != $me->uid)
								{

									echo '
										<a href="einheiten.php?f=3&x='.$this_out['x'].'&y='.$this_out['y'].'"><img src="styles/'.$_SESSION['theme'].'/shield_go.png" title="Truppen schicken" alt="Truppen schicken"></a>';
								}
								echo "</td></tr>";
							}
						}
					}
				}
				else
				{
					log_err("Fehler beim Auslesen von Profild&ouml;rfern: ".$query. ", ". mysql_error() );
				}

				echo '</table>';
			}

/*Freunde und Feinde ansehen....*/

			if($f == 2)
			{
				$type_titles = array (1=>"Reallife-Freunde", 2=>"Pers&ouml;nliche B&uuml;ndnisse", 3=>"Pers&ouml;nliche NAPs", 4=>"Handelsabkommen", 5=>"Feinde");

				define ("FRIENDS", 1);
				define ("PRIVBND", 2);
				define ("PRIVNAP", 3);
				define ("HANDELSABK", 4);
				define ("ENEMIES", 5);


				echo '<div id="forschung">
				<form action="einstellungen.php?f=3" method="POST" name="friends">
				<div id="seite-links">
				<table width="98%"  class="inhalt">';


	/*****************************************Darstellung existierender Freundschaften******************************************************/

				$query = "select A.*,B.user from friends A, user B where (A.uid1=".$_REQUEST['u']." and A.uid2=B.uid) or (A.uid2=".$_REQUEST['u']." and A.uid1=B.uid)";

				if (!($result = mysql_query($query)))
				{
					echo "Fehler beim Lesen der Freundschaften aus der Datenbank!";
					log_err("Fehler beim Auslesen von Profild&ouml;rfern: ".$query. ", ". mysql_error() );
				}
				else
				{
					if (mysql_num_rows($result))
					{
						while($row = mysql_fetch_assoc($result))
						{
							if ($_REQUEST['u'] == $row['uid1'])
								$friends[$row['type']][$row['uid2']] = $row['user'];
							else
								$friends[$row['type']][$row['uid1']] = $row['user'];
						}
					}

					for ($type = 1; $type <= 5; $type++)
					{
						echo "<tr><th>".$type_titles[$type]."</th></tr>";
						if (isset ($friends[$type]))
						{
							foreach ($friends[$type] as $this_uid => $this_name)
							{
								echo "<tr><td><a href=\"profile.php?u=".$this_uid."\">".$this_name."</a></td></tr>";
								//
							}
						}
						else
						{
							echo "<tr><td>Der Spieler hat nichts eingetragen.</td></tr>";
						}
					}
				}
				echo "</table></div></form>";
			}
		}
		else
			echo "Benutzer existiert nicht";
	}
	else
		log_err("Fehler beim Auslesen von Profil: ".$query. ", ". mysql_error() );

echo "</div></div></div>";
require_once("footer.php");
}
?>