Location: PHPKode > projects > Zitro-Stats > include/out_player.inc.php
<?php

	// ANTIHACK
	defined('INSTATS') AND defined('OUT') OR die();

	////////////////////////////////////////////////////////////////
	// COOKIES
	if(@$_POST['mode']=='display') {
		setcookie("ZITROSTATS[PLAYERS_LIMIT_WEAPONS]",@$_POST['weapons'],time()+intval($options['COOKIES_EXPIRE_TIME']));
		setcookie("ZITROSTATS[PLAYERS_LIMIT_OPPONENTS]",@$_POST['opponents'],time()+intval($options['COOKIES_EXPIRE_TIME']));
		header("Location: $_SERVER[REQUEST_URI]");
		die();
	}

	////////////////////////////////////////////////////////////////
	// OPTIONS
	$filter['rank']	= $options['PLAYERS_MIN_KILLS'] ? "`kills`>=$options[PLAYERS_MIN_KILLS]" : "";
	if(isset($_COOKIE['ZITROSTATS']['PLAYERS_LIMIT_WEAPONS']))
		$options['PLAYERS_LIMIT_WEAPONS'] =
			min(max(1,intval($_COOKIE['ZITROSTATS']['PLAYERS_LIMIT_WEAPONS'])),$options['PLAYERS_LIMIT_WEAPONS_MAX']);
	if(isset($_COOKIE['ZITROSTATS']['PLAYERS_LIMIT_OPPONENTS']))
		$options['PLAYERS_LIMIT_OPPONENTS'] =
			min(max(1,intval($_COOKIE['ZITROSTATS']['PLAYERS_LIMIT_OPPONENTS'])),$options['PLAYERS_LIMIT_OPPONENTS_MAX']);

	if($name = @$_GET['name']) {

		////////////////////////////////////////////////////////////////
		// OUTPUT DETAILS
		if(!$player = $sql->fetcharray($sql->query("
			SELECT
				`clan`,
				`points`,
				`kills`,
				`deaths`,
				`kills`/`deaths` as `ratio`,
				`selfkills`,
				`last`
			FROM `$options[SQL_TABPREFIX]players`
			WHERE `player`='".$sql->escape($name)."'
			LIMIT 1
			"))) {
			$player = array(
				'clan'		=> '',
				'points'	=> 1000,
				'kills'		=> 0,
				'deaths'	=> 0,
				'ratio'		=> NULL,
				'selfkills'	=> 0,
				'last'		=> '0000-00-00 00:00:00'
				);
		}
		$stats = $sql->fetcharray($sql->query("
			SELECT
				MIN(`points`) as `minpoints`,
				MAX(`points`) as `maxpoints`,
				MAX(`kills`) as `maxkills`,
				SUM(`kills`) as `sumkills`,
				MAX(`deaths`) as `maxdeaths`,
				SUM(`deaths`) as `sumdeaths`,
				MAX(`selfkills`) as `maxselfkills`,
				SUM(`selfkills`) as `sumselfkills`,
				COUNT(".($filter['rank']?"IF($filter[rank],1,NULL)":"*").") as `players`
			FROM `$options[SQL_TABPREFIX]players`
			"));
		$player['victims'] = $player['kills'] ? pop($sql->fetchrow($sql->query("
			SELECT COUNT(*)
			FROM `$options[SQL_TABPREFIX]playeropponents`
			WHERE `player`='".$sql->escape($name)."'
			"))) : 0;
		$player['offender'] = $player['kills'] ? pop($sql->fetchrow($sql->query("
			SELECT COUNT(*)
			FROM `$options[SQL_TABPREFIX]playeropponents`
			WHERE `opponent`='".$sql->escape($name)."'
			"))) : 0;
		$player['rank'] = $options['PLAYERS_MIN_KILLS'] && $player['kills']>=$options['PLAYERS_MIN_KILLS'] ? pop($sql->fetchrow($sql->query("
			SELECT
				COUNT(*)+1
			FROM `$options[SQL_TABPREFIX]players`
			WHERE `points`>$player[points]
			".($filter['rank'] ? "AND $filter[rank]" : "")."
			"))) : 0;
		$player['clanname'] = $player['clan'] ? @pop($sql->fetchrow($sql->query("
			SELECT
				`name`
			FROM `$options[SQL_TABPREFIX]clans`
			WHERE `clan`='".$sql->escape($player['clan'])."'
			LIMIT 1
			"))):
			'';
		$i = 0;
		$out['details'] =
			out_table(
				out_table_caption("Infobox").
				out_table_row(
					out_table_cell(0,1,1,"Player",H).
					out_table_cell(0,2,1,"<img src=\"images/player.gif\" alt=\"Player: ".htmlentities($name)."\" /><br /><span class=\"larger\">".str_replace(" ","&nbsp;",htmlentities($name))."</span>",C),
					++$i&1 ? "light" : "dark").
				out_table_row(
					out_table_cell(0,1,1,"Rank",H).
					out_table_cell(0,2,1,$player['rank'] ?
						"<span class=\"larger\">$player[rank]</span> / <span class=\"smaller\">$stats[players]</span>" :
						"---<br />".
						"<span class=\"smaller\">".($options['PLAYERS_MIN_KILLS']>$player['kills'] ? ($options['PLAYERS_MIN_KILLS']-$player['kills'])." more Kill".($options['PLAYERS_MIN_KILLS']-$player['kills']==1?"":"s"):"")." needed</span>",
						C),
					++$i&1 ? "light" : "dark").
				($player['clan'] ? out_table_row(
					out_table_cell(0,1,$player['clanname']?2:1,"Clan",H).
					out_table_cells_clan(0,1,$player['clan']),
					++$i&1 ? "light" : "dark").
					($player['clanname'] ? out_table_row(
						out_table_cell(0,2,1,"<span class=\"smaller\">".out_clanname($player['clanname'])."</span>",C),
						$i&1 ? "light" : "dark"):
						""):
					"").
				out_table_row(
					out_table_cell(0,1,$player['rank']>1?2:1,"Points",H).
					out_table_cells_bar(0,1,$player['points'],0,$stats['maxpoints'],"points"),
					++$i&1 ? "light" : "dark").
				($player['rank']>1 ? out_table_row(
					out_table_cell(0,2,1,($stats['maxpoints']-$player['points'])." below max",C),
					$i&1 ? "light" : "dark"):
					"").
				out_table_row(
					out_table_cell(0,1,$stats['maxkills']?2:1,"Kills",H).
					out_table_cells_bar(0,1,$player['kills'],0,$stats['maxkills'],"kills"),
					++$i&1 ? "light" : "dark").
				($stats['maxkills'] ? out_table_row(
					out_table_cell(0,2,1,str_replace(".","<span class=\"smaller\">.",sprintf("%.3f",$player['kills']/$stats['maxkills']*100))."</span> % of max<br />".str_replace(".","<span class=\"smaller\">.",sprintf("%.3f",$player['kills']/$stats['sumkills']*100))."</span> % of all",C),
					$i&1 ? "light" : "dark"):
					"").
				out_table_row(
					out_table_cell(0,1,$stats['maxdeaths']?2:1,"Deaths",H).
					out_table_cells_bar(0,1,$player['deaths'],0,$stats['maxdeaths'],"deaths"),
					++$i&1 ? "light" : "dark").
				($stats['maxdeaths'] ? out_table_row(
					out_table_cell(0,2,1,str_replace(".","<span class=\"smaller\">.",sprintf("%.3f",$player['deaths']/$stats['maxdeaths']*100))."</span> % of max<br />".str_replace(".","<span class=\"smaller\">.",sprintf("%.3f",$player['deaths']/$stats['sumdeaths']*100))."</span> % of all",C),
					$i&1 ? "light" : "dark"):
					"").
				out_table_row(
					out_table_cell(0,1,1,"K/D Ratio",H).
					out_table_cell(0,2,1,$player['ratio'] ? $player['ratio'] : "---",C),
					++$i&1 ? "light" : "dark").
				out_table_row(
					out_table_cell(0,1,$stats['maxselfkills']?2:1,"Selfkills",H).
					out_table_cells_bar(0,1,$player['selfkills'],0,$stats['maxselfkills'],"selfkills"),
					++$i&1 ? "light" : "dark").
				($stats['maxselfkills'] ? out_table_row(
					out_table_cell(0,2,1,str_replace(".","<span class=\"smaller\">.",sprintf("%.3f",$player['selfkills']/$stats['maxselfkills']*100))."</span> % of max<br />".str_replace(".","<span class=\"smaller\">.",sprintf("%.3f",$player['selfkills']/$stats['sumselfkills']*100))."</span> % of all",C),
					$i&1 ? "light" : "dark"):
					"").
				out_table_row(
					out_table_cell(0,1,1,"Last Action",H).
					out_table_cell(0,2,1,$player['last']=='0000-00-00 00:00:00' ? "---" : "<span class=\"smaller\">".str_replace(" ","</span><br />",$player['last']),C),
					++$i&1 ? "light" : "dark")
				).
			out_history(array('player'=>$name),"Player's History")."<br />\n";

		////////////////////////////////////////////////////////////////
		// OUTPUT DISPLAY
		$i = 0;
		$out['display'] =
			"<form method=\"post\" action=\"".htmlentities($_SERVER['REQUEST_URI'])."\">\n".
			out_table(
				out_table_caption("Display Options").
				out_table_row(
					out_table_cell(0,1,1,"Player's Weapons",H).
					out_table_cell(0,1,1,"<input type=\"text\" name=\"weapons\" size=\"2\" maxlength=\"2\" value=\"$options[PLAYERS_LIMIT_WEAPONS]\"/>",L),
					++$i&1 ? "light" : "dark").
				out_table_row(
					out_table_cell(0,1,1,"Player's Opponents",H).
					out_table_cell(0,1,1,"<input type=\"text\" name=\"opponents\" size=\"2\" maxlength=\"2\" value=\"$options[PLAYERS_LIMIT_OPPONENTS]\"/>",L),
					++$i&1 ? "light" : "dark")
				).
			"<div>\n".
			"	<input type=\"hidden\" name=\"mode\" value=\"display\" /><input class=\"button\" type=\"submit\" value=\"Save\"/>\n".
			"</div>\n".
			"</form>\n";

		////////////////////////////////////////////////////////////////
		// OUTPUT KILLWEAPONS
		$result = $sql->query("
			SELECT
				`weapon`,
				`kills`,
				`last`
			FROM `$options[SQL_TABPREFIX]playerkillweapons`
			WHERE `player`='".$sql->escape($name)."'
			ORDER BY
				`kills` DESC,
				`weapon` ASC
			");
		if($sql->numrows($result)) {
			$out['killweapons'] = '';
			$i = $max = $last = 0;
			$rank = 1;
			$rest = $player['kills'];
			while((!$options['PLAYERS_LIMIT_WEAPONS'] || $i<$options['PLAYERS_LIMIT_WEAPONS']) && ($weapon = $sql->fetcharray($result))) {
				if($i==0) $max = $last = $weapon['kills'];
				if($weapon['kills']<$last) {
					$rank = $i+1;
					$last = $weapon['kills'];
				}
				$rest -= $weapon['kills'];
				$out['killweapons'] .= out_table_row(
					out_table_cell(0,1,1,$rank,C).
					out_table_cells_weapon(0,1,$weapon['weapon']).
					out_table_cells_bar(1,1,$weapon['kills'],0,$max,"kills").
					out_table_cell(0,1,1,out_history(array('type'=>'kills','player'=>$name,'weapon'=>$weapon['weapon']),$weapon['last']=='0000-00-00 00:00:00' ? "---" : "<span class=\"smaller\">$weapon[last]</span>"),C),
					++$i&1 ? "light" : "dark");
			}
			if(($i=$sql->numrows($result)-$i)>0) {
				$out['killweapons'] .= out_table_row(
					out_table_cell(0,6,1,"<span class=\"smaller\">and $rest Kill".($rest==1?"":"s")." with $i other Weapon".($i==1?"":"s")."</span>",C),
					$options['PLAYERS_LIMIT_WEAPONS']&1 ? "dark" : "light");
			}
		} else {
			$out['killweapons'] = out_table_row(
				out_table_cell(0,6,1,"<span class=\"smaller\">no Weapons listed here</span>",C),
				"light");
		}
		$out['killweapons'] = out_table(
			out_table_caption("Kill Weapons").
			out_table_head(
				out_table_row(
					out_table_cell(0,1,1,"#").
					out_table_cell(0,2,1,"Weapon").
					out_table_cell(1,2,1,"Kills").
					out_table_cell(0,1,1,"Last Kill")
					)
				).
				out_table_body($out['killweapons'])
			);

		////////////////////////////////////////////////////////////////
		// OUTPUT DEATHWEAPONS
		$result = $sql->query("
			SELECT
				`weapon`,
				`deaths`,
				`last`
			FROM `$options[SQL_TABPREFIX]playerdeathweapons`
			WHERE `player`='".$sql->escape($name)."'
			ORDER BY
				`deaths` DESC,
				`weapon` ASC
			");
		if($sql->numrows($result)) {
			$out['deathweapons'] = '';
			$i = $max = $last = 0;
			$rank = 1;
			$rest = $player['deaths'];
			while((!$options['PLAYERS_LIMIT_WEAPONS'] || $i<$options['PLAYERS_LIMIT_WEAPONS']) && ($weapon = $sql->fetcharray($result))) {
				if($i==0) $max = $last = $weapon['deaths'];
				if($weapon['deaths']<$last) {
					$rank = $i+1;
					$last = $weapon['deaths'];
				}
				$rest -= $weapon['deaths'];
				$out['deathweapons'] .= out_table_row(
					out_table_cell(0,1,1,$rank,C).
					out_table_cells_weapon(0,1,$weapon['weapon']).
					out_table_cells_bar(1,1,$weapon['deaths'],0,$max,"deaths").
					out_table_cell(0,1,1,out_history(array('type'=>'kills','opponent'=>$name,'weapon'=>$weapon['weapon']),$weapon['last']=='0000-00-00 00:00:00' ? "---" : "<span class=\"smaller\">$weapon[last]</span>"),C),
					++$i&1 ? "light" : "dark");
			}
			if(($i=$sql->numrows($result)-$i)>0) {
				$out['deathweapons'] .= out_table_row(
					out_table_cell(0,6,1,"<span class=\"smaller\">and $rest Death".($rest==1?"":"s")." from $i other Weapon".($i==1?"":"s")."</span>",C),
					$options['PLAYERS_LIMIT_WEAPONS']&1 ? "dark" : "light");
			}
		} else {
			$out['deathweapons'] = out_table_row(
				out_table_cell(0,6,1,"<span class=\"smaller\">no Weapons listed here</span>",C),
				"light");
		}
		$out['deathweapons'] = out_table(
			out_table_caption("Death Weapons").
			out_table_head(
				out_table_row(
					out_table_cell(0,1,1,"#").
					out_table_cell(0,2,1,"Weapon").
					out_table_cell(1,2,1,"Deaths").
					out_table_cell(0,1,1,"Last Death")
					)
				).
				out_table_body($out['deathweapons'])
			);

		////////////////////////////////////////////////////////////////
		// OUTPUT KILLOPPONENTS
		$result = $sql->query("
			SELECT
				`opponent` as `player`,
				`kills`,
				`last`
			FROM `$options[SQL_TABPREFIX]playeropponents`
			WHERE `player`='".$sql->escape($name)."'
			ORDER BY
				`kills` DESC,
				`opponent` ASC
			".($options['PLAYERS_LIMIT_OPPONENTS']?"LIMIT 0,$options[PLAYERS_LIMIT_OPPONENTS]":"")."
			");
		if($sql->numrows($result)) {
			$out['killopponents'] = '';
			$i = $max = $last = 0;
			$rank = 1;
			$rest = $player['kills'];
			while($opponent = $sql->fetcharray($result)) {
				if($i==0) $max = $last = $opponent['kills'];
				if($opponent['kills']<$last) {
					$rank = $i+1;
					$last = $opponent['kills'];
				}
				$rest -= $opponent['kills'];
				$out['killopponents'] .= out_table_row(
					out_table_cell(0,1,1,$rank,C).
					out_table_cells_player(0,1,$opponent['player']).
					out_table_cells_bar(1,1,$opponent['kills'],0,$max,"kills").
					out_table_cell(0,1,1,out_history(array('type'=>'kills','player'=>$name,'opponent'=>$opponent['player']),$opponent['last']=='0000-00-00 00:00:00' ? "---" : "<span class=\"smaller\">$opponent[last]</span>"),C),
					++$i&1 ? "light" : "dark");
			}
			if(($i=$player['victims']-$i)>0) {
				$out['killopponents'] .= out_table_row(
					out_table_cell(0,6,1,"<span class=\"smaller\">and $rest Kill".($rest==1?"":"s")." by $i other Opponent".($i==1?"":"s")."</span>",C),
					$options['PLAYERS_LIMIT_OPPONENTS']&1 ? "dark" : "light");
			}
		} else {
			$out['killopponents'] = out_table_row(
				out_table_cell(0,6,1,"<span class=\"smaller\">no Players listed here</span>",C),
				"light");
		}
		$out['killopponents'] = out_table(
			out_table_caption("Victims").
			out_table_head(
				out_table_row(
					out_table_cell(0,1,1,"#").
					out_table_cell(0,2,1,"Opponent").
					out_table_cell(1,2,1,"Kills").
					out_table_cell(0,1,1,"Last Kill")
					)
				).
				out_table_body($out['killopponents'])
			);

		////////////////////////////////////////////////////////////////
		// OUTPUT DEATHOPPONENTS
		$result = $sql->query("
			SELECT
				`player`,
				`kills` as `deaths`,
				`last`
			FROM `$options[SQL_TABPREFIX]playeropponents`
			WHERE `opponent`='".$sql->escape($name)."'
			ORDER BY
				`deaths` DESC,
				`player` ASC
			".($options['PLAYERS_LIMIT_OPPONENTS']?"LIMIT 0,$options[PLAYERS_LIMIT_OPPONENTS]":"")."
			");
		if($sql->numrows($result)) {
			$out['deathopponents'] = '';
			$i = $max = $last = 0;
			$rank = 1;
			$rest = $player['deaths'];
			while($opponent = $sql->fetcharray($result)) {
				if($i==0) $max = $last = $opponent['deaths'];
				if($opponent['deaths']<$last) {
					$rank = $i+1;
					$last = $opponent['deaths'];
				}
				$rest -= $opponent['deaths'];
				$out['deathopponents'] .= out_table_row(
					out_table_cell(0,1,1,$rank,C).
					out_table_cells_player(0,1,$opponent['player']).
					out_table_cells_bar(1,1,$opponent['deaths'],0,$max,"deaths").
					out_table_cell(0,1,1,out_history(array('type'=>'kills','player'=>$opponent['player'],'opponent'=>$name),$opponent['last']=='0000-00-00 00:00:00' ? "---" : "<span class=\"smaller\">$opponent[last]</span>"),C),
					++$i&1 ? "light" : "dark");
			}
			if(($i=$player['offender']-$i)>0) {
				$out['deathopponents'] .= out_table_row(
					out_table_cell(0,6,1,"<span class=\"smaller\">and $rest Death".($rest==1?"":"s")." from $i other Opponent".($i==1?"":"s")."</span>",C),
					$options['PLAYERS_LIMIT_OPPONENTS']&1 ? "dark" : "light");
			}
		} else {
			$out['deathopponents'] = out_table_row(
				out_table_cell(0,6,1,"<span class=\"smaller\">no Players listed here</span>",C),
				"light");
		}
		$out['deathopponents'] = out_table(
			out_table_caption("Killer").
			out_table_head(
				out_table_row(
					out_table_cell(0,1,1,"#").
					out_table_cell(0,2,1,"Opponent").
					out_table_cell(1,2,1,"Deaths").
					out_table_cell(0,1,1,"Last Death")
					)
				).
				out_table_body($out['deathopponents'])
			);

		////////////////////////////////////////////////////////////////
		// OUTPUT
		$navi[] = "<a href=\"?inc=players\">Players</a>";
		$navi[] = "<a href=\"?inc=player&amp;name=".urlencode($name)."\">".htmlentities($name)."</a>";
		$links[] = "<link rel=\"up\" href=\"?inc=players\" />";
		$out =
			"<h1>Player Profile: ".str_replace(" ","&nbsp;",htmlentities($name))."</h1>\n".
			"<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n".
			"	<tr>\n".
			"		<td align=\"center\" valign=\"top\" style=\"width:190px\">\n".
			out_indent($out['details'],3).
			"			<br />\n".
			"			<br />\n".
			"			<br />\n".
			out_indent($out['display'],3).
			"		</td>\n".
			"		<td class=\"line\">\n".
			"		</td>\n".
			"		<td align=\"center\" valign=\"top\" style=\"width:340px\">\n".
			out_indent($out['killweapons'],3).
			out_indent($out['deathweapons'],3).
			"		</td>\n".
			"		<td class=\"line\">\n".
			"		</td>\n".
			"		<td align=\"center\" valign=\"top\" style=\"width:350px\">\n".
			out_indent($out['killopponents'],3).
			out_indent($out['deathopponents'],3).
			"		</td>\n".
			"	</tr>\n".
			"</table>\n";

	} else {
		$out =
			"Error:<br />\n".
			"No Player Name given!\n";
	}

?>
Return current item: Zitro-Stats