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

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

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

	////////////////////////////////////////////////////////////////
	// OPTIONS
	$filter['rank']	= $options['WEAPONS_MIN_KILLS'] ? "`kills`>=$options[WEAPONS_MIN_KILLS]" : "";
	if(isset($_COOKIE['ZITROSTATS']['WEAPONS_LIMIT_PLAYERS']))
		$options['WEAPONS_LIMIT_PLAYERS'] =
			min(max(1,intval($_COOKIE['ZITROSTATS']['WEAPONS_LIMIT_PLAYERS'])),$options['WEAPONS_LIMIT_PLAYERS_MAX']);

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

		////////////////////////////////////////////////////////////////
		// OUTPUT DETAILS
		if($weapon = $sql->fetcharray($sql->query("
			SELECT
				`kills`,
				`last`
			FROM `$options[SQL_TABPREFIX]weapons`
			WHERE `weapon`='".$sql->escape($name)."'
			LIMIT 1
			"))) {
			$weapon['killer'] = $weapon['kills'] ? pop($sql->fetchrow($sql->query("
				SELECT COUNT(*)
				FROM `$options[SQL_TABPREFIX]playerkillweapons`
				WHERE `weapon`='".$sql->escape($name)."'
				"))) : 0;
			$weapon['victims'] = $weapon['kills'] ? pop($sql->fetchrow($sql->query("
				SELECT COUNT(*)
				FROM `$options[SQL_TABPREFIX]playerdeathweapons`
				WHERE `weapon`='".$sql->escape($name)."'
				"))) : 0;
			$weapon['rank'] = $weapon['kills']>=$options['WEAPONS_MIN_KILLS'] ? pop($sql->fetchrow($sql->query("
				SELECT
					COUNT(*)+1
				FROM `$options[SQL_TABPREFIX]weapons`
				WHERE `kills`>$weapon[kills]
				".($filter['rank'] ? "AND $filter[rank]" : "")."
				"))) : 0;
			$stats = $sql->fetcharray($sql->query("
				SELECT
					MAX(`kills`) as `maxkills`,
					SUM(`kills`) as `sumkills`,
					COUNT(*) as `weapons`
				FROM `$options[SQL_TABPREFIX]weapons`
				".($filter['rank'] ? "WHERE $filter[rank]" : "")."
				"));
			$i = 0;
			$out['details'] =
				out_table(
					out_table_caption("Infobox").
					out_table_row(
						out_table_cell(0,1,1,"Weapon",H).
						out_table_cell(0,2,1,"<img src=\"images/weapons/".htmlentities($name).".gif\" alt=\"Weapon: ".htmlentities($name)."\" /><br /><span class=\"larger\">".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,$weapon['rank'] ?
							"<span class=\"larger\">$weapon[rank]</span> / <span class=\"smaller\">$stats[weapons]</span>" :
							"---<br />".
							"<span class=\"smaller\">".($options['WEAPONS_MIN_KILLS']>$weapon['kills'] ? ($options['WEAPONS_MIN_KILLS']-$weapon['kills'])." more Kill".($options['WEAPONS_MIN_KILLS']-$weapon['kills']==1?"":"s"):"")." needed</span>",
							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,$weapon['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",$weapon['kills']/$stats['maxkills']*100))."</span> % of max<br />".str_replace(".","<span class=\"smaller\">.",sprintf("%.3f",$weapon['kills']/$stats['sumkills']*100))."</span> % of all",C),
						$i&1 ? "light" : "dark"):
						"").
					out_table_row(
						out_table_cell(0,1,1,"Popularity",H).
						out_table_cell(0,2,1,"$weapon[killer] Killer<br /><span class=\"smaller\">$weapon[victims] Victim".($weapon['victims']==1?"":"s")."</span>",C),
						++$i&1 ? "light" : "dark").
					out_table_row(
						out_table_cell(0,1,1,"Last Action",H).
						out_table_cell(0,2,1,$weapon['last']=='0000-00-00 00:00:00' ? "---" : "<span class=\"smaller\">".str_replace(" ","</span><br />",$weapon['last']),C),
						++$i&1 ? "light" : "dark")
					).
				out_history(array('weapon'=>$name),"Weapon's History")."<br />\n";

			////////////////////////////////////////////////////////////////
			// OUTPUT LINKS
			$result = $sql->query("
				SELECT
					`weapon`
				FROM `$options[SQL_TABPREFIX]weapons`
				".($filter['rank'] ? "WHERE $filter[rank]" : "")."
				ORDER BY
					`kills` DESC,
					`weapon` ASC
				");
			$out['links'] = array();
			if($sql->numrows($result)) {
				while(list($other) = $sql->fetchrow($result)) {
					$out['links'][] =
						($other!=$name ?
							"<a href=\"?inc=weapon&amp;name=".urlencode($other)."\">".htmlentities($other)."</a>" :
							htmlentities($other)
							);
				}
			}
			$out['links'] =
				"<span class=\"smaller\">".
				implode(" | ",$out['links']).
				"</span><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,"Weapon's Players",H).
						out_table_cell(0,1,1,"<input type=\"text\" name=\"players\" size=\"2\" maxlength=\"2\" value=\"$options[WEAPONS_LIMIT_PLAYERS]\"/>",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 KILLER LIST
			$result = $sql->query("
				SELECT
					`player`,
					`kills`,
					`last`
				FROM `$options[SQL_TABPREFIX]playerkillweapons`
				WHERE `weapon`='".$sql->escape($name)."'
				ORDER BY
					`kills` DESC,
					`player` ASC
				".($options['WEAPONS_LIMIT_PLAYERS'] ? "LIMIT 0,$options[WEAPONS_LIMIT_PLAYERS]" : "")."
				");
			if($sql->numrows($result)) {
				$out['killer'] = '';
				$i = $max = $last = 0;
				$rank = 1;
				$rest = $weapon['kills'];
				while($player = $sql->fetcharray($result)) {
					if($i==0) $max = $last = $player['kills'];
					if($player['kills']<$last) {
						$rank = $i+1;
						$last = $player['kills'];
					}
					$rest -= $player['kills'];
					$out['killer'] .= out_table_row(
						out_table_cell(0,1,1,$rank,C).
						out_table_cells_player(0,1,$player['player']).
						out_table_cells_bar(1,1,$player['kills'],0,$max,"kills").
						out_table_cell(0,1,1,out_history(array('type'=>'kills','weapon'=>$name,'player'=>$player['player']),$player['last']=='0000-00-00 00:00:00' ? "---" : "<span class=\"smaller\">$player[last]</span>"),C),
						++$i&1 ? "light" : "dark");
				}
				if(($i=$weapon['killer']-$i)>0) {
					$out['killer'] .= out_table_row(
						out_table_cell(0,6,1,"<span class=\"smaller\">and $rest Kill".($rest==1?"":"s")." by $i other Player".($i==1?"":"s")."</span>",C),
						$options['WEAPONS_LIMIT_PLAYERS']&1 ? "dark" : "light");
				}
			} else {
				$out['killer'] = out_table_row(
					out_table_cell(0,6,1,"<span class=\"smaller\">no Players listed here</span>",C),
					"light");
			}
			$out['killer'] = out_table(
				out_table_caption("Killer").
				out_table_head(
					out_table_row(
						out_table_cell(0,1,1,"#").
						out_table_cell(0,2,1,"Player").
						out_table_cell(1,2,1,"Kills").
						out_table_cell(0,1,1,"Last Kill")
						)
					).
					out_table_body($out['killer'])
				);

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

			////////////////////////////////////////////////////////////////
			// OUTPUT
			$navi[] = "<a href=\"?inc=weapons\">Weapons</a>";
			$navi[] = "<a href=\"?inc=player&amp;name=".urlencode($name)."\">".htmlentities($name)."</a>";
			$links[] = "<link rel=\"up\" href=\"?inc=weapons\" />";
			$out =
				"<h1>Weapon Profile: ".htmlentities($name)."</h1>\n".
				"<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n".
				"	<tr>\n".
				"		<td align=\"center\" valign=\"top\" style=\"width:170px\">\n".
				out_indent($out['details'],3).
				"			<br />\n".
				"			<br />\n".
				"			<br />\n".
				out_indent($out['links'],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:400px\">\n".
				out_indent($out['killer'],3).
				"		</td>\n".
				"		<td class=\"line\">\n".
				"		</td>\n".
				"		<td align=\"center\" valign=\"top\" style=\"width:400px\">\n".
				out_indent($out['victims'],3).
				"		</td>\n".
				"	</tr>\n".
				"</table>\n";

		} else {
			$out =
				"Error:<br />\n".
				"Weapon '".htmlentities($name)."' not found in Database!\n";
		}
	} else {
		$out =
			"Error:<br />\n".
			"No Weapon Name given!\n";
	}

?>
Return current item: Zitro-Stats