<?PHP
  $CPSeite = 20;
  $markierteZeile=0;
  if(isset($_GET['p'])) {
    if(!checkInt($_GET['p']) || !($_GET['p']>0)) $aSeite = 1;
    else $aSeite = $_GET['p'];
  }
  else { $aSeite = 1; }
   if(isset($_POST['suche']) && $_POST['suche']=='Cauta') {
    if(!empty($_POST['charakter'])) {
      $sqlCmd="SELECT id, name, level, exp, empire, guild_name, rang
      FROM (
      
        SELECT id, name, level, exp, empire, guild_name, @num := @num +1 AS rang
        FROM (
        
          SELECT player.id, player.name, player.level, player.exp, player_index.empire, guild.name AS guild_name, @num :=0
          FROM player.player
          LEFT JOIN player.player_index ON player_index.id = player.account_id
          LEFT JOIN player.guild_member ON guild_member.pid = player.id
          LEFT JOIN player.guild ON guild.id = guild_member.guild_id
          INNER JOIN account.account ON account.id=player.account_id
          WHERE player.name NOT LIKE '[%]%' AND account.status!='BLOCK'
          ORDER BY player.level DESC , player.exp DESC
          
        ) AS t1
        
      ) AS t2
      
      WHERE name LIKE '".mysql_real_escape_string($_POST['charakter'])."' LIMIT 1";
      $sqlQry=mysql_query($sqlCmd,$sqlServ);
      if(mysql_num_rows($sqlQry)>0) {
      
        $getRang = mysql_fetch_object($sqlQry);
        $aSeite = ceil($getRang->rang/$CPSeite);
        $markierteZeile = $getRang->rang;
      }
      
    }
    
  } 
  $sqlCmd = "SELECT COUNT(*) as summeChars  
  FROM player.player 
  LEFT JOIN player.player_index 
  ON player_index.id=player.account_id 
  LEFT JOIN player.guild_member 
  ON guild_member.pid=player.id 
  LEFT JOIN player.guild 
  ON guild.id=guild_member.guild_id
  INNER JOIN account.account 
  ON account.id=player.account_id
  WHERE player.name NOT LIKE '[%]%' AND account.status!='BLOCK'
  ORDER BY player.level DESC, player.exp DESC";
  
  $sqlQry = mysql_query($sqlCmd,$sqlServ);
  
  $getSum = mysql_fetch_object($sqlQry);
  $cSeite = calcPages($getSum->summeChars,$aSeite,$CPSeite);
  
?>
<div class="col-2">
    <div class="content content-last">
        <div class="content-bg">
				<div class="content banner">
			<div class="content-bg">
				<div class="content-bg-bottom">
									<!--<a id='various5' href="<?PHP echo $serverSettings['url']; ?>" target="_blank"></a>-->

				</div>
			</div>
		</div>
		            <div class="content-bg-bottom">
			<h2><?PHP echo $serverSettings['titel']; ?> - Lista de Personajes</h2>
                <div class="ranks-inner-content"><br />
                    <div class="ranks-dropdowns-box">
						<form   action="index.php?s=players" name="higscoreform" method="GET">
							
                            <div class="ranks-select-box">
								<label>Buscar:</label>
                                <div class="ranks-input">
<input type="text" maxlength="15"><br>

                                </div>
                            </div>
                            <div class="ranks-select-box-btn">
								<a class="small-btn" href="#" onclick="document.forms['higscoreform'].submit();return false;">Enviar</a>
                            </div>
                            <div class="clearfloat"></div>
                        </form>
                    </div>																																	
<?PHP
  $maxRange = 2;
  $maxStep = 1;
  if(($aSeite-$maxRange)>0) $sStart = $aSeite-$maxRange;
  else $sStart = 1;
  if(($aSeite+$maxRange)<=$cSeite[0]) $sEnde = $aSeite+$maxRange;
  else $sEnde = $cSeite[0];
  
  echo '<div class="ranks-nav prev prev-top">
  ';
  if(($aSeite-$maxStep)>0) echo '<a href="index.php?s=players&p='.($aSeite-$maxStep).'">Anteriores 20 personajes</a>';
  else echo '<a href="index.php?s=players&p=1"></a>';
  echo'</div>';
  echo' <div class="ranks-nav next next-top">';
  if(($aSeite+$maxStep)<=$cSeite[0]) echo ' <a href="index.php?s=players&p='.($aSeite+$maxStep).'">Siguientes 20 personajes</a>';
  else echo '<a href="index.php?s=players&p='.$cSeite[0].'"></a>'; 
  echo'</div>';
?>                
 <table border="0" cellpadding="0" cellspacing="0" >
                      <thead>
                       <tr>
						<th class="rank-th-1">Rang</th>
						<th class="rank-th-2">Nombre</th>
						<th class="rank-th-3">Nivel</th>
						<th class="rank-th-3">Reino</th>
						<th class="rank-th-4">EXP</th>
                       </tr>
                      </thead>
<?PHP
  $sqlCmd = "SELECT player.id,player.name,player.level,player.exp,player_index.empire,guild.name AS guild_name 
  FROM player.player 
  LEFT JOIN player.player_index 
  ON player_index.id=player.account_id 
  LEFT JOIN player.guild_member 
  ON guild_member.pid=player.id 
  LEFT JOIN player.guild 
  ON guild.id=guild_member.guild_id
  INNER JOIN account.account 
  ON account.id=player.account_id
  WHERE player.name NOT LIKE '[%]%' AND account.status!='BLOCK'
  ORDER BY player.level DESC, player.exp DESC 
  LIMIT ".$cSeite[1].",".$CPSeite;
  //echo $sqlCmd;
  $sqlQry = mysql_query($sqlCmd,$sqlServ);
  $x=$cSeite[1]+1;
  while($getPlayers = mysql_fetch_object($sqlQry)) {
				               $zF = ($x%2==0) ? "rank-td-2-1" : "rank-td-1-1";
							   $zF2 = ($x%2==0) ? "rank-td-2-2" : "rank-td-1-2";
							   $zF3 = ($x%2==0) ? "rank-td-2-3" : "rank-td-1-3";
							   $zF5 = ($x%2==0) ? "rank-td-2-5" : "rank-td-1-5";
							   $zF4 = ($x%2==0) ? "rank-td-2-4" : "rank-td-1-4";
    if(checkInt($markierteZeile) && $markierteZeile==$x) { $zF  = "first"; }
    echo "<tr>";
    echo "<td class=\"$zF\">".$x."</td>";
    echo "<td class=\"$zF2\"><!--<a class=\"agbok-rank\" href=\"index.php?s=player&char=".$getPlayers->name."\">-->".$getPlayers->name."</td>";
    echo "<td class=\"$zF3\">".$getPlayers->level."</td>";
	echo "<td class=\"$zF5\"><center>";if(!empty($getPlayers->empire)) {
    echo '<img src="img/kingdom/'.$getPlayers->empire.'_cls.jpg" height="10"/></center></td>';
    }
	echo "<td class=\"$zF4\">".$getPlayers->exp."</td>";
    echo "</tr>";
    $x++;
  }
?>
</table>
<?PHP
  $maxRange = 2;
  $maxStep = 1;
  if(($aSeite-$maxRange)>0) $sStart = $aSeite-$maxRange;
  else $sStart = 1;
  if(($aSeite+$maxRange)<=$cSeite[0]) $sEnde = $aSeite+$maxRange;
  else $sEnde = $cSeite[0];
  echo '<div class="ranks-nav prev">';
  if(($aSeite-$maxStep)>0) echo '<a href="index.php?s=players&p='.($aSeite-$maxStep).'">Anteriores 20 personajes</a>';
  else echo '<a href="index.php?s=players&p=1"></a>';
  echo'</div>';
  echo'<div class="ranks-nav next">';
  if(($aSeite+$maxStep)<=$cSeite[0]) echo ' <a href="index.php?s=players&p='.($aSeite+$maxStep).'">Siguientes 20 personajes</a>';
  else echo '<a href="index.php?s=players&p='.$cSeite[0].'"></a>';
  echo'</div>';
?>
<br class="clearfloat"/>
<div class="ranks-update-time"><br class="clearfloat"/>Actualizada: <?php
 $update_time = mktime(date("H"),date("i")-10,date("s"),date("m"),date("d"),date("Y"));
 echo "".date("D d F Y H:i:s", $update_time);
 ?> </div><br class="clearfloat"/>
<div class="box-foot"></div>
                </div>
            </div>
        </div>
</div></div>