Location: PHPKode > projects > ezStats for Crysis 3 > ezStats2_c3/index.php
<?php
	### Weiterleitung auf den Installer ###
	if (!file_exists('tmp/sql.php')) {
		header("Status: 301 Moved Permanently");
		header("Location:install/");
		exit; 
	}
	
	
	### Klassen laden ###
	if (true) {
		require 'tmp/sql.php';
		require 'classes/mysql.php';
		
		$sql = new MySQL(); if ($sql->debug) error_reporting (E_ALL|E_STRICT); else error_reporting (0);
		
		require 'plugins/phpQuery.php';
		require 'classes/settings.php';
		require 'classes/security.php';
		require 'classes/functions.php';
		require 'classes/template.php';
		require 'classes/player.php';
		require 'classes/stats.php';
		
		
		$func = new Functions();
		$secure = new Security();
		$settings = new Settings();
		$tpl = new Templates();
		$tpl->load_phrases("overview", true);
		$tpl->load_phrases("_c3_overview", true);
		$tp2 = new Templates();
		$tp2->load_phrases("_c3_admin", true);
		
	}
	
	
	### Allgemeine Variablen setzen ###
	if (true) {
		$func->counter();                                             // Counter starten
		$preset = $func->load_settings("settings");                   // Settings laden
		$ov = $func->load_settings("overview");                       // Settings laden
		date_default_timezone_set($preset["timezone"]);               // Zeitzone setzen
		$lastupdate = date("d.m.Y - H:i", $preset["lastcheckall"]);   // Variable für das letzte Update aller Spieler
		$columns = $func->load_settings("overview");                  // Spalten die in der Übersicht angezeigt werden können/sollen
	}
	
	
	### Tabellenkopf ###
	if (true) {
		$thead = phpQuery::newDocumentHTML("<thead><tr></tr></thead>");
		
		// Alle Spaltenheader erstellen, die im Leaderboard aktiviert wurden
		foreach ($columns as $name => $active) {
			if ($active) pq('tr')->append('<th>'.$tpl->phrase($name).'</th>');
		}
		
		// Sortierung umdrehen, wenn Spalte 1 "Position" enthält
		$sortList = pq('th')->eq(0)->text() == $tpl->phrase('position') ? "[[0,0]]" : "[[0,1]]";
	}
	
	
	### Tabellenkörper ###
	if (true) {
		$tbody = phpQuery::newDocumentHTML("<tbody></tbody>");
		$summary = Array();
		$i = 0;
		
		// Die IDs aller Spieler abrufen, die eine Spielzeit > 0 haben, nicht die ID 1 haben, sortiert nach den Punkten
		$sql->query('
			SELECT p.id
			FROM '.$sql->prefix.'player p
			LEFT JOIN '.$sql->prefix.'stats_general g
				ON p.id = g.id
			WHERE g.TimePlayed != 0
			AND p.id != 1
			ORDER BY g.xp DESC
		');
		
		// Alle Spieler durchlaufen und in als Zeile in die Tabelle speichern
		while ($row = $sql->fetchAssoc()) {
			$i++;
			$td = Array();
			$stats = new Stats($row['id']);
			
			
			if ($ov['position']) {      // Position im Leaderboard
				$result = $stats->format($i, Array('number', 0, '', 'position'));
				$td['position'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['position'])) $summary['position'] = Array();
				$summary['position'][] = '';
			}
			
			if ($ov['rank']) {          // Rank-Icon
				$result = $stats->get('player', 'rank', Array('rankicon'));
				$td['rank'] = phpQuery::newDocumentHTML('<td class="tcenter" sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['rank'])) $summary['rank'] = Array();
				$summary['rank'][] = NULL;
			}
			
			if ($ov['country']) {       // Country-Icon
				$result = $stats->get('player', 'country', Array('deficon', 'country'));
				$td['country'] = phpQuery::newDocumentHTML('<td class="tcenter" sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['country'])) $summary['country'] = Array();
				$summary['country'][] = NULL;
			}
			
			if ($ov['name']) {          // Spielername
				$name     = $stats->get('player', 'name');
				$nickname = $stats->get('player', 'nickname');
				$clantag  = $settings->get('clantag');
				
				if ($nickname) $name = $nickname;
				$tip = $tpl->phrase("open_detail_view"); eval ( "\$tip = \"$tip\";" );
				
				
				$path = ($preset['cms'] == "standalone") ? "" : $settings->get("path");
				$html = utf8_encode(htmlentities(
					'<h1>'.$clantag.$name.'</h1>
					<a class="fancyDetail" href="'.$path.'detail.php?pid='.$row['id'].'">'.$tpl->phrase("link_detail").'</a> | 
					<a href="'.$stats->get('player', 'url').'" target="_blank">crysis3s.com</a>
				'));
				$td['name'] = phpQuery::newDocumentHTML('<td class="tleft" sort="'.$name.'" menu="'.$html.'"><a href="#">'.$clantag.$name.'</a></td>');
				
				
				if (!isset($summary['name'])) $summary['name'] = Array();
				$summary['name'][] = NULL;
			}
			
			if ($ov['custom1']) {       // Custon-Wert 1
				$result = $stats->get('player', 'custom1');
				$td['custom1'] = phpQuery::newDocumentHTML('<td class="tleft" sort="'.$result.'">'.$result.'</td>');
				
				if (!isset($summary['custom1'])) $summary['custom1'] = Array();
				$summary['custom1'][] = NULL;
			}
			
			if ($ov['platform']) {      // Plattform-Icon
				$result = $stats->get('player', 'platform', Array('deficon', 'platform'));
				$td['platform'] = phpQuery::newDocumentHTML('<td class="tcenter" sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['platform'])) $summary['platform'] = Array();
				$summary['platform'][] = NULL;
			}
			
			if ($ov['score']) {         // Gesamt-Punkte
				$result = $stats->get('general', 'xp', Array('number', 0, "", "score"));
				$td['score'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['score'])) $summary['score'] = Array();
				$summary['score'][] = $result['raw'];
			}
			
			if ($ov['time']) {          // Spielzeit
				$result = $stats->get('general', 'TimePlayed', Array('time', 0, 'h'));
				$td['time'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['time'])) $summary['time'] = Array();
				$summary['time'][] = $result['raw'];
			}
			
			if ($ov['spm']) {           // Score per Minute
				$time =   $stats->get('general', 'TimePlayed') / 60;
				$result = $stats->get('general', 'xp', Array('ratio', $time, 0, '', 'spm'));
				$td['spm'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['spm'])) $summary['spm'] = Array();
				$summary['spm'][] = $result['raw'];
			}
			
			if ($ov['kills']) {         // Kills
				$result = $stats->get('general', 'kills', Array('number', 0, "", "kills"));
				$td['kills'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['kills'])) $summary['kills'] = Array();
				$summary['kills'][] = $result['raw'];
			}
			
			if ($ov['deaths']) {        // Deaths
				$result = $stats->get('general', 'deaths', Array('number', 0, "", "deaths"));
				$td['deaths'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['deaths'])) $summary['deaths'] = Array();
				$summary['deaths'][] = $result['raw'];
			}
			
			if ($ov['kdr']) {           // Kill-Death-Ratio
				$deaths = $stats->get('general', 'deaths');
				$result = $stats->get('general', 'kills', Array('ratio', $deaths, 2, '', 'kdr'));
				$td['kdr'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['kdr'])) $summary['kdr'] = Array();
				$summary['kdr'][] = $result['raw'];
			}
			
			if ($ov['lifeExpectancy']) {
				$result = $stats->get('general', 'lifeExpectancy', Array('time', "0", "s"));
				$td['lifeExpectancy'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$tp2->phrase("lifeExpectancy").': '.$result['format'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['lifeExpectancy'])) $summary['lifeExpectancy'] = Array();
				$summary['lifeExpectancy'][] = $result['raw'];
			}
			
			if ($ov['HeadShotKills']) {
				$result = $stats->get('general', 'HeadShotKills', Array('number', 0, "", "kills"));
				$td['HeadShotKills'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$tp2->phrase("HeadShotKills").': '.$result['format'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['HeadShotKills'])) $summary['HeadShotKills'] = Array();
				$summary['HeadShotKills'][] = $result['raw'];
			}
			
			if ($ov['hskratio']) {
				$shots =  $stats->get('general', 'kills');
				$result = $stats->get('general', 'HeadShotKills', Array('ratio', $shots, 0, '%'));
				$td['hskratio'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$tp2->phrase("hskratio").': '.$result['format'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['hskratio'])) $summary['hskratio'] = Array();
				$summary['hskratio'][] = $result['raw'];
			}
			
			if ($ov['KillsStreak']) {
				$result = $stats->get('general', 'KillsStreak', Array('number', 0));
				$td['KillsStreak'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$tp2->phrase("KillsStreak").': '.$result['format'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['KillsStreak'])) $summary['KillsStreak'] = Array();
				$summary['KillsStreak'][] = $result['raw'];
			}
			
			if ($ov['DeathsStreak']) {
				$result = $stats->get('general', 'DeathsStreak', Array('number', 0));
				$td['DeathsStreak'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$tp2->phrase("DeathsStreak").': '.$result['format'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['DeathsStreak'])) $summary['DeathsStreak'] = Array();
				$summary['DeathsStreak'][] = $result['raw'];
			}
			
			if ($ov['wins']) {          // Gewonnene Runden
				$result = $stats->get('general', 'gameswon', Array('number', 0, "", "wins"));
				$td['wins'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['wins'])) $summary['wins'] = Array();
				$summary['wins'][] = $result['raw'];
			}
			
			if ($ov['loss']) {          // Verlorene Runden
				$result = $stats->get('general', 'gameslost', Array('number', 0, "", "loss"));
				$td['loss'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['loss'])) $summary['loss'] = Array();
				$summary['loss'][] = $result['raw'];
			}
			
			if ($ov['draws']) {
				$result = $stats->get('general', 'gamesdrawn', Array('number', 0, ""));
				$td['draws'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$tp2->phrase("draws").': '.$result['format'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['draws'])) $summary['draws'] = Array();
				$summary['draws'][] = $result['raw'];
			}
			
			if ($ov['wlr']) {           // Win-Loss-Ratio
				$loss =   $stats->get('general', 'gameslost');
				$result = $stats->get('general', 'gameswon', Array('ratio', $loss, 2, '', 'wlr'));
				$td['wlr'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['wlr'])) $summary['wlr'] = Array();
				$summary['wlr'][] = $result['raw'];
			}
			
			if ($ov['shots']) {
				$result = $stats->get('general', 'wep_shots', Array('number', 0, ""));
				$td['shots'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$tp2->phrase("shots").': '.$result['format'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['shots'])) $summary['shots'] = Array();
				$summary['shots'][] = $result['raw'];
			}
			
			if ($ov['hits']) {
				$result = $stats->get('general', 'wep_hits', Array('number', 0, ""));
				$td['hits'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$tp2->phrase("hits").': '.$result['format'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['hits'])) $summary['hits'] = Array();
				$summary['hits'][] = $result['raw'];
			}
			
			if ($ov['acc']) {           // Accuracy
				$shots =  $stats->get('general', 'wep_shots');
				$result = $stats->get('general', 'wep_hits', Array('ratio', $shots, 0, '%', 'acc'));
				$td['acc'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['acc'])) $summary['acc'] = Array();
				$summary['acc'][] = $result['raw'];
			}
			
			if ($ov['dgt']) {           // Dogtags
				$result = $stats->get('general', 'DogtagsCollected',  Array('number', 0, "", "dgt"));
				$td['dgt'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$result['tip'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['dgt'])) $summary['dgt'] = Array();
				$summary['dgt'][] = $result['raw'];
			}
			
			if ($ov['mvp']) {
				$result = $stats->get('general', 'mvp', Array('number', 0, ""));
				$td['mvp'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$tp2->phrase("mvp").': '.$result['format'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['mvp'])) $summary['mvp'] = Array();
				$summary['mvp'][] = $result['raw'];
			}
			
			if ($ov['DamageDelt']) {
				$result = $stats->get('general', 'DamageDelt', Array('number', 0, "k"));
				$td['DamageDelt'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$tp2->phrase("DamageDelt").': '.$result['raw'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['DamageDelt'])) $summary['DamageDelt'] = Array();
				$summary['DamageDelt'][] = $result['raw'];
			}
			
			if ($ov['DamageTaken']) {
				$result = $stats->get('general', 'DamageTaken', Array('number', 0, "k"));
				$td['DamageTaken'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$tp2->phrase("DamageTaken").': '.$result['raw'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['DamageTaken'])) $summary['DamageTaken'] = Array();
				$summary['DamageTaken'][] = $result['raw'];
			}
			
			if ($ov['DamageRatio']) {
				$shots =  $stats->get('general', 'DamageTaken');
				$result = $stats->get('general', 'DamageDelt', Array('ratio', $shots, 2, ''));
				$td['DamageRatio'] = phpQuery::newDocumentHTML('<td sort="'.$result['sort'].'" info="'.$tp2->phrase("DamageRatio").': '.$result['format'].'">'.$result['format'].'</td>');
				
				if (!isset($summary['DamageRatio'])) $summary['DamageRatio'] = Array();
				$summary['DamageRatio'][] = $result['raw'];
			}
			
			// Zellen der gewünschten Reihenfolge nach in eine Zeile speichern
			$tr = phpQuery::newDocumentHTML('<tr></tr>');
			foreach ($ov as $name => $show) {
				if ($show AND isset($td[$name])) pq('tr')->append($td[$name]);
			}
			
			// Zeile an den Tabellenkörper anhängen
			phpQuery::selectDocument($tbody);
			pq('tbody')->append($tr);
		}
	}
	
	
	### Tabellenfuss ###
	if (true) {
		$tfoot = phpQuery::newDocumentHTML('<tfoot></tfoot>');
		$methods = Array('ov_averages', 'ov_median', 'ov_summary');
		
		if ($sql->count()) {
			foreach ($methods as $method) {
				if ($settings->get($method)) {
					$td = Array();
					
					if ($ov['position']) {      // Position im Leaderboard
						$td['position'] = phpQuery::newDocumentHTML('<td></td>');
					}
					
					if ($ov['rank']) {          // Rank-Icon
						$td['rank'] = phpQuery::newDocumentHTML('<td></td>');
					}

					if ($ov['platform']) {      // Plattform-Icon
						$td['platform'] = phpQuery::newDocumentHTML('<td></td>');
					}
					
					if ($ov['country']) {       // Country-Icon
						$td['country'] = phpQuery::newDocumentHTML('<td></td>');
					}
					
					if ($ov['name']) {          // Spielername
						$td['name'] = phpQuery::newDocumentHTML('<td>'.$tpl->phrase($method).': </td>');
					}

					if ($ov['custom1']) {       // Custon-Wert 1
						$td['custom1'] = phpQuery::newDocumentHTML('<td></td>');
					}
					
					if ($ov['score']) {         // Gesamt-Punkte
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['score']);
							$result = $stats->format($result, Array('number', 0, "", 'score'));
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['score']);
							$result = $stats->format($result, Array('number', 0, "", 'score'));
						}
						if ($method == 'ov_summary') {
							$result = array_sum($summary['score']);
							$result = $stats->format($result, Array('number', 0, "k", 'score'));
						}
						
						
						$td['score'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['time']) {          // Spielzeit
						if ($method == 'ov_averages') $result = $func->calculate_average($summary['time']);
						if ($method == 'ov_median')   $result = $func->calculate_median($summary['time']);
						if ($method == 'ov_summary')  $result = array_sum($summary['time']);
						
						$result = $stats->format($result, Array('time', 0, 'h'));
						$td['time'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['lifeExpectancy']) {
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['lifeExpectancy']);
							$result = $stats->format($result, Array('number', 0, 's'));
							$td['lifeExpectancy'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("lifeExpectancy").': '.$result['format'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['lifeExpectancy']);
							$result = $stats->format($result, Array('number', 0, 's'));
							$td['lifeExpectancy'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("lifeExpectancy").': '.$result['format'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_summary') {
							$td['lifeExpectancy'] = phpQuery::newDocumentHTML('<td></td>');
						}
					}
					
					if ($ov['HeadShotKills']) {
						if ($method == 'ov_averages') $result = $func->calculate_average($summary['HeadShotKills']);
						if ($method == 'ov_median')   $result = $func->calculate_median($summary['HeadShotKills']);
						if ($method == 'ov_summary')  $result = array_sum($summary['HeadShotKills']);
						
						$result = $stats->format($result, Array('number', 0));
						$td['HeadShotKills'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("HeadShotKills").': '.$result['format'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['hskratio']) {
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['hskratio']);
							$result = $stats->format($result, Array('number', 0, '%'));
							$td['hskratio'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("hskratio").': '.$result['format'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['hskratio']);
							$result = $stats->format($result, Array('number', 0, '%'));
							$td['hskratio'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("hskratio").': '.$result['format'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_summary') {
							$td['hskratio'] = phpQuery::newDocumentHTML('<td></td>');
						}
					}
					
					if ($ov['KillsStreak']) {
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['KillsStreak']);
							$result = $stats->format($result, Array('number', 0));
							$td['KillsStreak'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("KillsStreak").': '.$result['format'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['KillsStreak']);
							$result = $stats->format($result, Array('number', 0));
							$td['KillsStreak'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("KillsStreak").': '.$result['format'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_summary') {
							$td['KillsStreak'] = phpQuery::newDocumentHTML('<td></td>');
						}
					}
					
					if ($ov['DeathsStreak']) {
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['DeathsStreak']);
							$result = $stats->format($result, Array('number', 0));
							$td['DeathsStreak'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("DeathsStreak").': '.$result['format'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['DeathsStreak']);
							$result = $stats->format($result, Array('number', 0));
							$td['DeathsStreak'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("DeathsStreak").': '.$result['format'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_summary') {
							$td['DeathsStreak'] = phpQuery::newDocumentHTML('<td></td>');
						}
					}
					
					if ($ov['spm']) {           // Score per Minute
						if ($method == 'ov_averages') $result = $func->calculate_average($summary['spm']);
						if ($method == 'ov_median')   $result = $func->calculate_median($summary['spm']);
						if ($method == 'ov_summary')  $result = array_sum($summary['spm']);
						
						$result = $stats->format($result, Array('number', 0, '', 'spm'));
						$td['spm'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['kills']) {         // Kills
						if ($method == 'ov_averages') $result = $func->calculate_average($summary['kills']);
						if ($method == 'ov_median')   $result = $func->calculate_median($summary['kills']);
						if ($method == 'ov_summary')  $result = array_sum($summary['kills']);
						
						$result = $stats->format($result, Array('number', 0, "", "kills"));
						$td['kills'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['deaths']) {        // Deaths
						if ($method == 'ov_averages') $result = $func->calculate_average($summary['deaths']);
						if ($method == 'ov_median')   $result = $func->calculate_median($summary['deaths']);
						if ($method == 'ov_summary')  $result = array_sum($summary['deaths']);
						
						$result = $stats->format($result, Array('number', 0, "", "deaths"));
						$td['deaths'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['kdr']) {           // Kill-Death-Ratio
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['kdr']);
							$result = $stats->format($result, Array('number', 2, '', 'kdr'));
							$td['kdr'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['kdr']);
							$result = $stats->format($result, Array('number', 2, '', 'kdr'));
							$td['kdr'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_summary') {
							$td['kdr'] = phpQuery::newDocumentHTML('<td></td>');
						}
					}
					
					if ($ov['dgt']) {           // Dogtags
						if ($method == 'ov_averages') $result = $func->calculate_average($summary['dgt']);
						if ($method == 'ov_median')   $result = $func->calculate_median($summary['dgt']);
						if ($method == 'ov_summary')  $result = array_sum($summary['dgt']);
						
						$result = $stats->format($result, Array('number', 0, '', 'dgt'));
						$td['dgt'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['acc']) {           // Accuracy
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['acc']);
							$result = $stats->format($result, Array('number', 0, '%', 'acc'));
							$td['acc'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['acc']);
							$result = $stats->format($result, Array('number', 0, '%', 'acc'));
							$td['acc'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_summary') {
							$td['acc'] = phpQuery::newDocumentHTML('<td></td>');
						}
					}
					
					if ($ov['wins']) {          // Gewonnene Runden
						if ($method == 'ov_averages') $result = $func->calculate_average($summary['wins']);
						if ($method == 'ov_median')   $result = $func->calculate_median($summary['wins']);
						if ($method == 'ov_summary')  $result = array_sum($summary['wins']);
						
						$result = $stats->format($result, Array('number', 0, '', 'wins'));
						$td['wins'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['loss']) {          // Verlorene Runden
						if ($method == 'ov_averages') $result = $func->calculate_average($summary['loss']);
						if ($method == 'ov_median')   $result = $func->calculate_median($summary['loss']);
						if ($method == 'ov_summary')  $result = array_sum($summary['loss']);
						
						$result = $stats->format($result, Array('number', 0, '', 'loss'));
						$td['loss'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['draws']) {
						if ($method == 'ov_averages') $result = $func->calculate_average($summary['draws']);
						if ($method == 'ov_median')   $result = $func->calculate_median($summary['draws']);
						if ($method == 'ov_summary')  $result = array_sum($summary['draws']);
						
						$result = $stats->format($result, Array('number', 0));
						$td['draws'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("draws").': '.$result['format'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['wlr']) {           // Win-Loss-Ratio
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['wlr']);
							$result = $stats->format($result, Array('number', 2, '', 'wlr'));
							$td['wlr'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['wlr']);
							$result = $stats->format($result, Array('number', 2, '', 'wlr'));
							$td['wlr'] = phpQuery::newDocumentHTML('<td info="'.$result['tip'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_summary') {
							$td['wlr'] = phpQuery::newDocumentHTML('<td></td>');
						}
					}
					
					if ($ov['shots']) {
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['shots']);
							$result = $stats->format($result, Array('number', 0, ""));
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['shots']);
							$result = $stats->format($result, Array('number', 0, ""));
						}
						if ($method == 'ov_summary') {
							$result = array_sum($summary['shots']);
							$result = $stats->format($result, Array('number', 0, "k"));
						}
						
						
						$td['shots'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("shots").': '.$result['raw'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['hits']) {
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['hits']);
							$result = $stats->format($result, Array('number', 0, ""));
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['hits']);
							$result = $stats->format($result, Array('number', 0, ""));
						}
						if ($method == 'ov_summary') {
							$result = array_sum($summary['hits']);
							$result = $stats->format($result, Array('number', 0, "k"));
						}
						
						
						$td['hits'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("hits").': '.$result['raw'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['mvp']) {
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['mvp']);
							$result = $stats->format($result, Array('number', 0, ""));
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['mvp']);
							$result = $stats->format($result, Array('number', 0, ""));
						}
						if ($method == 'ov_summary') {
							$result = array_sum($summary['mvp']);
							$result = $stats->format($result, Array('number', 0, ""));
						}
						
						
						$td['mvp'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("mvp").': '.$result['format'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['DamageDelt']) {
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['DamageDelt']);
							$result = $stats->format($result, Array('number', 0, "k"));
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['DamageDelt']);
							$result = $stats->format($result, Array('number', 0, "k"));
						}
						if ($method == 'ov_summary') {
							$result = array_sum($summary['DamageDelt']);
							$result = $stats->format($result, Array('number', 0, "k"));
						}
						
						
						$td['DamageDelt'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("DamageDelt").': '.$result['format'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['DamageTaken']) {
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['DamageTaken']);
							$result = $stats->format($result, Array('number', 0, "k"));
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['DamageTaken']);
							$result = $stats->format($result, Array('number', 0, "k"));
						}
						if ($method == 'ov_summary') {
							$result = array_sum($summary['DamageTaken']);
							$result = $stats->format($result, Array('number', 0, "k"));
						}
						
						
						$td['DamageTaken'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("DamageTaken").': '.$result['format'].'">'.$result['format'].'</td>');
					}
					
					if ($ov['DamageRatio']) {
						if ($method == 'ov_averages') {
							$result = $func->calculate_average($summary['DamageRatio']);
							$result = $stats->format($result, Array('number', 2));
							$td['DamageRatio'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("DamageRatio").': '.$result['format'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_median') {
							$result = $func->calculate_median($summary['DamageRatio']);
							$result = $stats->format($result, Array('number', 2));
							$td['DamageRatio'] = phpQuery::newDocumentHTML('<td info="'.$tp2->phrase("DamageRatio").': '.$result['format'].'">'.$result['format'].'</td>');
						}
						if ($method == 'ov_summary') {
							$td['DamageRatio'] = phpQuery::newDocumentHTML('<td></td>');
						}
					}
					
					// Zellen der gewünschten Reihenfolge nach in eine Zeile speichern
					$tr = phpQuery::newDocumentHTML('<tr></tr>');
					foreach ($ov as $name => $show) {
						if ($show AND isset($td[$name])) pq('tr')->append($td[$name]);
					}
					
					// Zeile an den Tabellenfuss anhängen
					phpQuery::selectDocument($tfoot);
					pq('tfoot')->append($tr);
				}
			}
		}
	}
	
	
	### Seite erzeugen und ausgeben ###
	if (true) {
		if ($preset['cms'] == "standalone") {
			eval ("\$html = \"".$tpl->template("standalone")."\";");  $html = phpQuery::newDocumentHTML($html);
		} else {
			eval ("\$html = \"".$tpl->template("plugin")."\";");
			$html = str_replace('#PATH#', $preset['path'], $html);
			$html = phpQuery::newDocumentHTML($html);
		}
		
		pq('#ezOverview')->append($thead);
		pq('#ezOverview')->append($tfoot);
		pq('#ezOverview')->append($tbody);
		
		
		// Postprocessing
		if (!$preset['ov_brand'])            pq('#ezBrand')->remove(); // Werbung entfernen
		if (!$preset['ov_infobox'])          pq('#ezAside')->remove(); // Infobox entfernen
		if ($preset['language'] == "hebrew") pq('#ezStats')->attr('dir', 'rtl'); // Schriftrichtung ändern bei RTL-Sprachen
		if ($preset['selfadd'] == "1")       pq("#ezStats")->prepend('<a href="'.$preset["path"].'admin/index.php?selfadd" class="selfadd">'.$tpl->phrase("selfadd").'</a>'); // Selfadd: Link einblenden, mit dem Spieler sich selbst adden können
		
		
		// Ausgabe
		header('Content-Type:text/html; charset=UTF-8');
		echo $html;
	}
?>
Return current item: ezStats for Crysis 3