<?php
	$nebeneinander = 2;
	$counter = 0;
	$active_page = !empty($_GET['page']) ? $_GET['page'] : 1;
?>


<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="34%"><div id="s1">
      <br />
      <br />
      <br />
      <br />
      <br />
      <br />
<?php
	if ($_SESSION['user_eingeloggt'])
				{
				
				$get_money = mysql_query("SELECT gamecash FROM global_users WHERE gameuser = '".$_SESSION['username']."' LIMIT 1");
				$row_money = mysql_fetch_array($get_money);
				$aktmoney = $row_money['gamecash'];
				
				$redate = explode(" ",$_SESSION['since']);
				
				$formatted_cash = number_format($aktmoney, 0, '.', '.' );
?>
		<table width="70%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr>
          <td><strong>Logged in as <?php echo $_SESSION['username']; ?></td>
        </tr>
		</table>
		</strong><hr width="80%" size="1" />
		<table width="70%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr class="login">
          <td width="40%">Cash:</td>
          <td width="60%" align="right"><img src="gfx/content/g-pip12px.png" width="10" height="10" /> <?php echo $formatted_cash; ?></td>
        </tr>
        <tr class="login">
          <td>User since:</td>
          <td align="right"><?php echo $redate[0]." ".$redate[1]." ".$redate[2]; ?></td>
        </tr>
		</table>
		</strong><hr width="80%" size="1" />
		<table width="70%" border="0" align="center" cellpadding="0" cellspacing="0">
<?php 
		if($_SESSION['level'] > 7)
			{
?>
			<tr>
			<td>&nbsp;</td>
			<td align="right"><a href="./admin/">AdminPanel</a></td>  
			</tr>
<?php			
			}
?>	
        <tr>
		<td><a href="index.php?show=editprofile">Edit Profile</a></td>
         <td align="right"><a href="action.php?action=logout&site=<?php echo $_GET['show']; ?>">Logout</a></td>  
        </tr>
      </table><br><br>
<?php
				} else {
?>
      <form id="form1" name="form1" method="post" action="action.php?action=login&site=<?php echo $_GET['show']; ?>">
        <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td class="login">Username:</td>
          </tr>
          <tr>
            <td><label>
              <input name="loginname" type="text" class="input" id="username" size="35" />
            </label></td>
          </tr>
          <tr>
            <td class="login">Password:</td>
          </tr>
          <tr>
            <td><input name="loginpass" type="password" class="input" id="password" size="35" /></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
          </tr>
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tr>
				<td>&nbsp;&nbsp;
              <input type='submit' name='login' value='' class='login_bgImage' />
              </form> &nbsp;&nbsp;&nbsp;</td>
			<td>
			  <form id="form2" name="form2" method="post" action="index.php?show=forgotPW">
			  <input type='submit' name='login' value='' class='getpw_bgImage' /></form></td>
			</tr>
		</table></td>
          </tr>
        </table>
      <br>
<?php
				}
include('serverstatus.php');
?>
    </div></td>
    <td width="66%" align="left" valign="top"><table width="515" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="368" align="left" valign="top" background="gfx/content/ranking_bg.png">


		 <div id="show_ranking">
          <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="10%" align="center" bgcolor="#000000" class="mainnews"><strong>Rank</strong></td>
              <td width="29%" align="left" valign="top" bgcolor="#000000" class="mainnews"><strong>Playername</strong></td>
              <td width="17%" align="center" bgcolor="#000000" class="mainnews"><strong>Level</strong></td>
              <td width="19%" align="left" valign="top" bgcolor="#000000" class="mainnews"><strong>Experience</strong></td>
              <td width="25%" align="right" bgcolor="#000000" class="mainnews"><strong>Last Login</strong></td>
            </tr>
<?php
			$bg = "";
			$aktrank = 1;
			// Tabelle leeren
			$query = "TRUNCATE TABLE global_ranking";
			$ergebnis=mysql_query($query);		
			$selected = mssql_select_db('World00_Character', $mssqlhandle) or die ("Couldn't open database Account"); 
			$result=mssql_query('SELECT TOP 100 sID, nLevel, nExp, dLastLoginDate FROM tCharacter WHERE nAdminLevel = 0 AND bDeleted = 0 ORDER by nLevel DESC, nExp DESC');
			while($data = mssql_fetch_array($result))
				{
						
				$regquerymysql = "INSERT INTO global_ranking (rank, rankname, ranklevel, rankexp, ranklogindate) VALUES ('".$aktrank."', '".$data['sID']."', '".$data['nLevel']."', '".$data['nExp']."', '".$data['dLastLoginDate']."')";
				mysql_query($regquerymysql);
				$aktrank++;
				}
	
			$result=mysql_query("SELECT COUNT(rank) FROM global_ranking");

			list($entries)=mysql_fetch_row($result);
			$blaettern=new blaettern($active_page, $entries);
			$blaettern->setLinkHref('index.php?show=ranking&amp;page=');
			$blaettern->setDelimiter1(' ');
			$blaettern->setDelimiter3(', ');
			$blaettern->setLinkActiveMore(' style="font-size:13px;"');
			$blaettern->setLinkFirstLastText('Machst Du Seite 1', 'Machst Du Seite ganz hinten');
			$blaettern->setShowActiveLink('false');
			$blaettern->setShowFirstLast(false);
			$blaettern->setShowNextPrev(false);
			$blaettern->setEntriesPerPage(12);
			$start = ".$blaettern->getEntriesPerPage()." * ".$blaettern->getActivePage().";
			$stop = ".$blaettern->getEntriesPerPage().";
			$result=mysql_query('SELECT * FROM global_ranking LIMIT '.($blaettern->getEntriesPerPage() * $blaettern->getActivePage()).', '.$blaettern->getEntriesPerPage());
			while($data = mysql_fetch_array($result))
				{
							if ($bg == "")
							{
								$bg = "#464951";
							} else {
								$bg = "";
							}

			echo "	<tr>
						<td align='center' bgcolor='".$bg."' class='mainnews'>".$data['rank'].".</td>
						<td align='left' valign='top' bgcolor='".$bg."' class='mainnews'>".$data['rankname']."</td>
						<td align='center' bgcolor='".$bg."' class='mainnews'>".$data['ranklevel']."</td>
						<td align='left' valign='top' bgcolor='".$bg."' class='mainnews'>".$data['rankexp']."</td>
						<td align='right' bgcolor='".$bg."' class='mainnews'>".$data['ranklogindate']."</td>
					</tr>";
			$counter++;
				}
?>
            <tr>
              <td colspan="5" align="center">&nbsp;</td>
              </tr>
            <tr>
              <td colspan="5" align="center"><?php echo $blaettern->create(); ?></td>
              </tr>
          </table>
        </div>
		
        </td>
      </tr>
    </table></td>
  </tr>
</table>