<?php
/*********************************************
  CPG Dragonfly - DF_Arcade Your_Account Block
  ********************************************
  CPG Dragonfly is copyright © 2004 - 2005 by CPG Dev Team
  http://www.dragonflycms.com

  Dragonfly and DF_Arcade are released under the terms
  and conditions of the GNU GPL version 2 or any later version

  port of pnFlashGames - http://pnflashgames.com/
  Written by gerry@redgerry.com
  redgerry.com - Home of RG_Sports
  Revision Date: 16/10/2005 11:46
  Version Number 1.00

  UNDER NO CIRCUMSTANCES MAY THIS GPL CODE BE USED FOR ANY COMMERCIAL
  PURPOSES UNDER THE GUISE OF V.I.P. OR ANY OTHER DESCRIPTION
********************************************************/
if (!defined('CPG_NUKE')) { exit; }
require_once('language/'.$language.'/DF_Arcade.php');
// Last 10 scores
$result = $db->sql_query("SELECT user_id FROM ".$prefix."_users WHERE username='$username'");
list($auserid) = $db->sql_fetchrow($result);
$db->sql_freeresult($result);
$result = $db->sql_query("SELECT game_id, playerscore, DATE_FORMAT(date, '%l:%i%p %W %D %M %Y') AS 'nicedate' FROM ".$prefix."_rgarcade_hiscores WHERE uid='$auserid' ORDER BY date DESC LIMIT 0,10",false, __FILE__,__LINE__);
if ($db->sql_numrows($result)) {
	echo '<br />';
	OpenTable();
	echo "<table cellpadding=\"4\"><tr><td valign=\"top\">"
	."<div align=\"center\"><font class=\"title\">".$username."	&#146;s "._RGALTENHS."</font>";
	while (list($game_id, $playerscore, $nicedate) = $db->sql_fetchrow($result)) {
		$result2 = $db->sql_query("SELECT gname FROM ".$prefix."_rgarcade_games WHERE game_id='$game_id'");
		list($gname) = $db->sql_fetchrow($result2);
		$db->sql_freeresult($result2);
		echo "<a href=\"".getlink('DF_Arcade&amp;func=play&amp;game_id='.$game_id.'')."\">".$gname."</a> - <font class=\"title\">".$playerscore."</font><br/><font class=\"content\">$nicedate<font><hr />";
	}
	$db->sql_freeresult($result);
	echo "</div><div align=\"center\">";
	$a = 0;
	$b = 0;
	$c = 0;
	$opt = "";
	$result = $db->sql_query("SELECT game_id, gtype FROM ".$prefix."_rgarcade_games WHERE gtype<'3' ORDER BY game_id ASC");
	while (list($game_id, $gtype) = $db->sql_fetchrow($result)) {
		if ($gtype == 1){
			$opt = "DESC";
		} elseif ($gtype == 2){
			$opt == "ASC";
		}
		$d = 0;
		$result2 = $db->sql_query("SELECT uid FROM ".$prefix."_rgarcade_hiscores WHERE game_id='$game_id' ORDER BY playerscore $opt LIMIT 0,3");
		while (list($auid) = $db->sql_fetchrow($result2)) {
			$d++;
			if ($auid == $auserid){
				if ($d == 1){
					$a++;
				} elseif ($d == 2){
					$b++;
				} elseif ($d == 3){
					$c++;
				}
			}
		}
	}
	echo "<font class=\"title\">"._RGARH."<br />"
	."1st <b>$a</b>&nbsp;|&nbsp;2nd <b>$b</b>&nbsp;|&nbsp;3rd <b>$c</b></font></div></td>"
	."<td valign=\"top\">"
	."<div align=\"left\"><font class=\"title\">"._RGALTENHS."</font>";
	$result = $db->sql_query("SELECT game_id, uid, playerscore, DATE_FORMAT(date, '%l:%i%p %W %D %M %Y') AS 'nicedate' FROM ".$prefix."_rgarcade_hiscores ORDER BY date DESC LIMIT 0,10",false, __FILE__,__LINE__);
	while (list($game_id, $auid, $playerscore, $nicedate) = $db->sql_fetchrow($result)) {
		$pos = 0;
		$position = 0;
		$totplayers = 0;
		$result2 = $db->sql_query("SELECT gname, gtype, gimage FROM ".$prefix."_rgarcade_games where game_id='$game_id'");
		list($gname, $gtype, $gimage) = $db->sql_fetchrow($result2);
		if ($gtype == 1){
			$opt ="DESC";
		} else {
			$opt = "ASC";
		}
		$pos = 0;
		$result2 = $db->sql_query("SELECT uid FROM ".$prefix."_rgarcade_hiscores WHERE game_id='$game_id' ORDER BY playerscore $opt");
		while (list($scorerid) = $db->sql_fetchrow($result2)) {
			$pos++;
			if ($scorerid == $auid){
				$position = $pos;
			}
		}
		$totplayers = $pos;
		$result2 = $db->sql_query("SELECT username FROM ".$prefix."_users WHERE user_id='$auid'");
		list($ausername) = $db->sql_fetchrow($result2);
		$db->sql_freeresult($result2);
		echo "<font class=\"content\">$totplayers "._RGAPLAYERS.":<font> <a href=\"".getlink('DF_Arcade&amp;func=play&amp;game_id='.$game_id.'')."\">".$gname."</a> - <font class=\"content\"><b>".$playerscore."</b> (Ranking <b>".$position."</b>)</font> - <a href=\"".getlink('Your_Account&amp;profile='.$ausername.'')."\">".$ausername."</a><br/><font class=\"content\">$nicedate<font><hr />";
	}
	$db->sql_freeresult($result);
	echo "</td></tr></table>";
	CloseTable();
}
?>