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

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

	////////////////////////////////////////////////////////////////
	// OPTIONS
	$filter['rank']		= $options['WEAPONS_MIN_KILLS'] ? "`kills`>=$options[WEAPONS_MIN_KILLS]" : "";
	$filter['name']		= @$_GET['name'];
	$filter['kills']	= @$_GET['kills']=='' ? $options['WEAPONS_MIN_KILLS'] : intval(@$_GET['kills']);
	$filter['sort']		= @$_GET['sort'] && in_array($_GET['sort'],array('weapon','last')) ? $_GET['sort'] : 'kills';
	$filter['user'] =
		($filter['name'] ? "LCASE(`weapon`) LIKE '%".str_replace(array('%','_'),array('\%','\_'),strtolower($sql->escape($filter['name'])))."%'" : "").
		($filter['kills'] ? ($filter['name'] ? " AND " : "")."`kills`>=$filter[kills]" : "");

	////////////////////////////////////////////////////////////////
	// OUTPUT FILTER
	$i = 0;
	$out['filter'] =
		"<form method=\"get\" action=\"\">\n".
		out_table(
			out_table_caption("Filter Options").
			out_table_row(
				out_table_cell(0,1,1,"Name",H).
				out_table_cell(0,1,1,"<input type=\"text\" name=\"name\" size=\"15\" maxlength=\"14\" value=\"".htmlentities($filter['name'])."\"/>",L),
				++$i&1 ? "light" : "dark").
			out_table_row(
				out_table_cell(0,1,1,"Kills",H).
				out_table_cell(0,1,1,"<input type=\"text\" name=\"kills\" size=\"5\" maxlength=\"5\" value=\"$filter[kills]\"/> or more",L),
				++$i&1 ? "light" : "dark").
			out_table_row(
				out_table_cell(0,1,1,"Order",H).
				out_table_cell(0,1,1,"<select name=\"sort\" size=\"1\">".
					"<option value=\"weapon\"".($filter['sort']=='weapon'?" selected=\"selected\"":"").">Weapon</option>".
					"<option value=\"kills\"".($filter['sort']=='kills'?" selected=\"selected\"":"").">Kills</option>".
					"<option value=\"last\"".($filter['sort']=='last'?" selected=\"selected\"":"").">Last Action</option>".
					"</select>",L),
				++$i&1 ? "light" : "dark")
			).
		"<div>\n".
		"	<input type=\"hidden\" name=\"inc\" value=\"$include\"/>\n".
		"	<input class=\"button\" type=\"submit\" value=\"Filter\"/>\n".
		"</div>\n".
		"</form>\n";

	////////////////////////////////////////////////////////////////
	// OUTPUT INFO
	$out['info'] =
		"Weapons' Ranks depend on the Kills all Players made with it together.<br />\n".
		($options['WEAPONS_MIN_KILLS'] ? "<br />\nA Weapon needs at least $options[WEAPONS_MIN_KILLS] Kill".($options['WEAPONS_MIN_KILLS']==1?"":"s")." to be ranked. Weapons with less Kills can be seen when changing the Filter Options above.<br />\n" : "");

	////////////////////////////////////////////////////////////////
	// OUTPUT LIST
	$stats = $sql->fetcharray($sql->query("
		SELECT
			MAX(`kills`) as `maxkills`,
			SUM(`kills`) as `kills`,
			COUNT(*) as `weapons`
		FROM `$options[SQL_TABPREFIX]weapons`
		".($filter['user'] ? "WHERE $filter[user]" : "")."
		"));
	$result = $sql->query("
		SELECT
			`weapon`,
			`kills`,
			`last`
		FROM `$options[SQL_TABPREFIX]weapons`
		".($filter['user'] ? "WHERE $filter[user]" : "")."
		ORDER BY
			`$filter[sort]` ".($filter['sort']=='weapon'?"ASC":"DESC").",
			`kills` DESC,
			`weapon` ASC
		");
	if($sql->numrows($result)) {
		$out['list'] = '';
		$i = 0;
		$last = $rank = $ranked = 0;
		while($weapon = $sql->fetcharray($result)) {
			// CALCULATE RANK:
			// IF NOT RANKED
			if($weapon['kills']<$options['WEAPONS_MIN_KILLS']) {
				$rank = 0;
			// IF RANKED AND LIST SORTED BY KILLS AND EVERY RANKED IS IN LIST
			} elseif($filter['sort']=='kills' && $filter['kills']<=$options['WEAPONS_MIN_KILLS'] && !$filter['name']) {
				// IF NO WEAPON RANKED BEFORE ON THIS PAGE
				if(!$ranked) {
					$last = $weapon['kills'];
					// NUMBER OF RANKED WEAPONS WITH MORE POINTS TO GET RANK OF CURRENT WEAPON
					$ranked = $rank = pop($sql->fetchrow($sql->query("
						SELECT COUNT(*)+1
						FROM `$options[SQL_TABPREFIX]weapons`
						WHERE `kills`>$weapon[kills]
						".($filter['rank'] ? "AND $filter[rank]" : "")."
						")));
				// IF RANK CAN BE CALCULATED FROM PREVIOUS RANKS
				} else {
					$rank = $ranked ++;
					if($weapon['kills']<$last) {
						$rank = $ranked;
						$last = $weapon['kills'];
					}
				}
			// IF RANKED BUT NOT SORTED BY KILLS: ASK DATABASE FOR RANK
			} else {
				$rank = pop($sql->fetchrow($sql->query("
					SELECT COUNT(*)+1
					FROM `$options[SQL_TABPREFIX]weapons`
					WHERE `kills`>$weapon[kills]
					".($filter['rank'] ? "AND $filter[rank]" : "")."
					")));
			}
			$out['list'] .= out_table_row(
				out_table_cell(0,1,1,$rank ? $rank : '---',C).
				out_table_cells_weapon($filter['sort']=='weapon'?1:0,1,$weapon['weapon']).
				out_table_cells_bar($filter['sort']=='kills'?1:0,1,$weapon['kills'],0,$stats['maxkills'],"kills").
				out_table_cell($filter['sort']=='last'?1:0,1,1,$weapon['kills'] ? out_history(array('weapon'=>$weapon['weapon']),$weapon['last']) : "---",C),
				++$i&1 ? "light" : "dark");
		}
		$out['list'] = out_table_foot(
			out_table_row(
				out_table_cell(0,6,1,"$stats[weapons] Weapon".($stats['weapons']==1?"":"s")." used for ".($stats['kills'])." Kill".($stats['kills']==1?"":"s")." (".round($stats['kills']/$stats['weapons'])." Kills per Weapon)",C)
				)
			).
			out_table_body($out['list']);
	} else {
		$out['list'] = out_table_body(
			out_table_row(
				out_table_cell(0,6,1,"<span class=\"smaller\">no Weapons listed here</span>",C),
				"light")
			);
	}
	$out['list'] = out_table(
		out_table_head(
			out_table_row(
				out_table_cell(0,1,1,"Rank").
				out_table_cell($filter['sort']=='weapon'?1:0,2,1,"Weapon").
				out_table_cell($filter['sort']=='kills'?1:0,2,1,"Kills").
				out_table_cell($filter['sort']=='last'?1:0,1,1,"Last Action")
				)
			).
			$out['list']
		);

	////////////////////////////////////////////////////////////////
	// OUTPUT
	$navi[] = "<a href=\"?inc=weapons\">Weapons</a>";
	$links[] = "<link rel=\"up\" href=\"?inc=index\" />";
	$out =
		"<h1>Weapon Rankings</h1>\n".
		"<table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n".
		"	<tr>\n".
		"		<td align=\"center\" valign=\"top\" style=\"width:170px\">\n".
		out_indent($out['filter'],3).
		"			<br />\n".
		"			<br />\n".
		"			<br />\n".
		out_indent($out['info'],3).
		"		</td>\n".
		"		<td class=\"line\">\n".
		"		</td>\n".
		"		<td align=\"center\" valign=\"top\" style=\"width:450px\">\n".
		out_indent($out['list'],3).
		"		</td>\n".
		"	</tr>\n".
		"</table>\n";

?>
Return current item: Zitro-Stats