<?
/*
//||||||||||||||||||||||||||||||||||||||||||||||||\\
\\*          SUPER HERO MOD WEB STATS 3.0         //
//                                                \\
\\  Written By ShadowLeader aka 123 (Tim Hansen)  //
//                                                \\
\\              http://SH-MOD.TK                  //
//          Email: shadowleader@jubii.dk          \\
\\          MSN: shadowleader11@hotmail.com       //
//                                                \\
\\   You are allowed to edit anything in these    //
//     files, as long as these lines remain.      \\
\\                                                //
//   If you have any trouble with the system,     \\
\\       go to www.SH-MOD.TK to get help.         //
//                                                \\
\\   Thanks to:                                   //
//   AlleyKat - Help with Template system         \\
\\   MajesticM00se - A little code                //
//   Vittu - Finding bugs                         \\
\\||||||||||||||||||||||||||||||||||||||||||||||||//
*/

require "include/header.php";

dbconn(true);

stdhead("Home");
/////////START/////////
?>
<?
	if(!isset($_GET['page']))
	{$page = 1;
	}else
	{$page = $_GET['page'];
	}
	$min = (($page * $max) - $max);
	
	$sort = $_GET[sort];
	if($sort == "name"){ 
	$result = mysql_query("SELECT SH_KEY, PLAYER_NAME, LAST_PLAY_DATE, XP, SKILL_COUNT FROM sh_savexp ORDER BY PLAYER_NAME LIMIT $min, $max") or die(mysql_error());
	}elseif($sort == "skill"){
	$result = mysql_query("SELECT SH_KEY, PLAYER_NAME, LAST_PLAY_DATE, XP, SKILL_COUNT FROM sh_savexp ORDER BY SKILL_COUNT DESC LIMIT $min, $max") or die(mysql_error());
	}elseif($sort == "xp"){
	$result = mysql_query("SELECT SH_KEY, PLAYER_NAME, LAST_PLAY_DATE, XP, SKILL_COUNT FROM sh_savexp ORDER BY XP DESC LIMIT $min, $max") or die(mysql_error());
	}else{
	$result = mysql_query("SELECT SH_KEY, PLAYER_NAME, LAST_PLAY_DATE, XP, SKILL_COUNT FROM sh_savexp ORDER BY XP DESC LIMIT $min, $max") or die(mysql_error());
	}
	$numbers = mysql_num_rows($result);
	if($numbers >= "1"){
	$players = mysql_query("SELECT SH_KEY FROM sh_savexp") or die(mysql_error());
	$totalplayers = mysql_num_rows($players); 
	echo"<table class=\"borders\" cellpadding=\"0\" cellspacing=\"2\" width=100%>
	<tr>
    <td width=\"250\" valign=\"top\"><b><a href=\"".$_SERVER['PHP_SELF']."?sort=name&page=$page\">Player</a></b> ($totalplayers players)</td>
    <td width=\"250\" valign=\"top\"><b><a href=\"".$_SERVER['PHP_SELF']."?sort=skill\">User Level</a></b></td>
	<td width=\"250\" valign=\"top\"><b><a href=\"".$_SERVER['PHP_SELF']."?sort=xp\">XP</a></b> ($maxxp max)</td></tr>";
	
	while($row = mysql_fetch_array($result)) 
	{
	echo"<tr>
    <td width=\"250\" valign=\"top\"><a href=\"sh_user.php?id=$row[SH_KEY]\">$row[PLAYER_NAME]</a></td>
    <td width=\"250\" valign=\"top\">$row[SKILL_COUNT]</td>
	<td width=\"250\" valign=\"top\">$row[XP]</td>
    <tr>
	";}
	$result2 = mysql_query("SELECT SH_KEY, PLAYER_NAME, LAST_PLAY_DATE, XP, SKILL_COUNT FROM sh_savexp") or die(mysql_error());
	$total_results = mysql_num_rows($result2);

	$total_pages = ceil($total_results / $max);

	echo "<tr><td colspan=\"3\" align=\"center\" width=\"100%\">";

	if($page > 1)
	{
	$prev = ($page - 1);
	echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">&lt;&lt;Previous</a>&nbsp;";
	}
	for($page_no = 1; $page_no <= $total_pages; $page_no++)
	{
	if(($page) == $page_no)
	{
	echo "<b>$page_no</b>&nbsp;";
	}else{
	echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$page_no\">$page_no</a>&nbsp;";
	}
	}

	if($page < $total_pages)
	{
	$next = ($page + 1); 
	echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next&gt;&gt;</a>&nbsp;";
	}
	echo"</td></tr></table><br>";
	}else{
	echo"<table class=\"borders\" cellpadding=\"0\" cellspacing=\"2\" width=100%>
	<tr>
    <td width=\"250\" valign=\"top\">No players were found</td></tr></table>";
	}
	echo"<table class=\"borders\" cellpadding=\"0\" cellspacing=\"2\" width=100%>
	<tr>
    <td width=\"735\" align=\"center\" valign=\"top\"><b>Users by level:</b><br>";
	$starttal = 0;
	$nummer = $levels+1;

	$taeller = $starttal;

	while ( $taeller < $nummer )
	{
	echo "<a href='sh_list.php?id=".$taeller."'>".$taeller."</a>";
	if($taeller == $nummer-1){
	echo"";
	}elseif($taeller == 25){
	echo"<br>";
	}elseif($taeller == 50){
	echo"<br>";
	}elseif($taeller == 75){
	echo"<br>";
	}else{
	echo"-";
	}
	$taeller = $taeller+1;
	}
	echo"</td></tr></table>";
?>
<?
/////////END/////////
stdfoot();
?>