<?php
header('Content-type: text/html; charset=utf-8');
function cutzero($value) {
    return preg_replace("/(\.\d+?)0+$/", "$1", $value)*1;
}

function getRankingCollection()
{

global $lang;

	$i = 0;
$query = '';
$query2 = '';
$query3 = '';
	$full[$i]['name'] = $lang['TopScore'];
	$full[$i]['data'] = getTopScore();
	$full[$i]['data2'] = getTopScore2();
	$i++;
	$full[$i]['name'] = $lang['TopTeamwork'];
	$full[$i]['data'] = getTopTeamwork();
	$full[$i]['data2'] = getTopTeamwork2();
	$i++;
	$full[$i]['name'] = $lang['TopSPM'];
	$full[$i]['data'] = getTopSPM();
	$full[$i]['data2'] = getTopSPM2();
	$i++;
/*	$full[$i]['name'] = 'Лучшие по реальным очкам/минуту';
	$full[$i]['data'] = getTopRSPM();
	$full[$i]['data2'] = getTopRSPM2();
	$i++;
	$full[$i]['name'] = 'Лучшие по боевым очкам/минуту';
	$full[$i]['data'] = getTopSSPM();
	$full[$i]['data2'] = getTopSSPM2();
	$i++;
	$full[$i]['name'] = 'Лучшие салаги (<100 часов) по очкам/минуту';
	$full[$i]['data'] = getTopNoobs();
	$full[$i]['data2'] = getTopNoobs2();
	$i++;
	$full[$i]['name'] = 'Золотые бойцы (золото/раунды)%';
	$full[$i]['data'] = getTopGMPR();
	$full[$i]['data2'] = getTopGMPR2();
	$i++;
	$full[$i]['name'] = 'Пурпурные бойцы :)';
	$full[$i]['data'] = getTopPurpur();
	$full[$i]['data2'] = getTopPurpur2();
	$i++;
	$full[$i]['name'] = 'Лучшие по точкам<br>(защита, захват, помощь)';
	$full[$i]['data'] = getTopFlagwork();
	$full[$i]['data2'] = getTopFlagwork2();
	$i++;
	$full[$i]['name'] = 'Лучшие по захвату точек';
	$full[$i]['data'] = getTopCaptures();
	$full[$i]['data2'] = getTopCaptures2();
	$i++;
	$full[$i]['name'] = 'Лучшие по защите точек';
	$full[$i]['data'] = getTopDefends();
	$full[$i]['data2'] = getTopDefends2();
	$i++;
	$full[$i]['name'] = 'Лучшие убийцы :)';
	$full[$i]['data'] = getTopKills();
	$full[$i]['data2'] = getTopKills2();
	$i++;
	$full[$i]['name'] = 'Почетные доноры подсосников :)';
	$full[$i]['data'] = getTopAssists();
	$full[$i]['data2'] = getTopAssists2();
	$i++;*/
	$full[$i]['name'] = $lang['TopKDR'];
	$full[$i]['data'] = getTopKDR();
	$full[$i]['data2'] = getTopKDR2();
	$i++;
	$full[$i]['name'] = $lang['TopCMDScore'];
	$full[$i]['data'] = getTopCMDScore();
	$full[$i]['data2'] = getTopCMDScore2();
	$i++;
	$full[$i]['name'] = $lang['TopCMD'];
	$full[$i]['data'] = getTopCMD();
	$full[$i]['data2'] = getTopCMD2();
	$i++;
/*	$full[$i]['name'] = 'Самые опытные офицеры (часов)';
	$full[$i]['data'] = getTopOfficers();
	$full[$i]['data2'] = getTopOfficers2();
	$i++;
	$full[$i]['name'] = 'Лучшие медики<br>(оживление и лечение)';
	$full[$i]['data'] = getTopSani();
	$full[$i]['data2'] = getTopSani2();
	$i++;
	$full[$i]['name'] = 'Лучшие взрывники<br />(С4+клемы+мины)';
	$full[$i]['data'] = getTopExpl();
	$full[$i]['data2'] = getTopExpl2();
	$i++;
	$full[$i]['name'] = 'Лучшие кидалы<br />(heal+ammo+repair)';
	$full[$i]['data'] = getTopHAR();
	$full[$i]['data2'] = getTopHAR2();
	$i++;*/
	$full[$i]['name'] = $lang['TopKnife'];
	$full[$i]['data'] = getTopKnife();
	$full[$i]['data2'] = getTopKnife2();
	$i++;
	$full[$i]['name'] = $lang['TopSnip'];
	$full[$i]['data'] = getTopSnip();
	$full[$i]['data2'] = getTopSnip2();
	$i++;
/*	$full[$i]['name'] = 'Лучшие антитанки****<br>(>25 часов)';
	$full[$i]['data'] = getTopAT();
	$full[$i]['data2'] = getTopAT2();
	$i++;*/
	$full[$i]['name'] = $lang['TopWLR'];
	$full[$i]['data'] = getTopWLR();
	$full[$i]['data2'] = getTopWLR2();
	$i++;
/*	$full[$i]['name'] = 'Лучший летчик<br>(KD + KPM)';
	$full[$i]['data'] = getTopAviator();
	$full[$i]['data2'] = getTopAviator2();
	$i++;
	$full[$i]['name'] = 'Лучший вертолетчик<br>(KD + KPM)';
	$full[$i]['data'] = getTopHeli();
	$full[$i]['data2'] = getTopHeli2();
	$i++;
	$full[$i]['name'] = 'Лучший на ПВО<br>(KD + KPM)';
	$full[$i]['data'] = getTopAA();
	$full[$i]['data2'] = getTopAA2();
	$i++;
	$full[$i]['name'] = 'Лучший танкист<br>(KD + KPM)';
	$full[$i]['data'] = getTopArmor();
	$full[$i]['data2'] = getTopArmor2();*/
	return $full;
}

//---------- Top Players ----------//
function getTopTen()
{
	include(ROOT . DS . 'queries'. DS .'getTopTen.php'); // imports the correct sql statement
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$data = array();

	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$data[$idx] = $row;
		$idx++;
	}
	((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
	return $data;
}
//---------- Top Players ----------//
//---------- Top Players - modifecation ----------//
function getTop()
{
	include(ROOT . DS . 'queries'. DS .'getTop.php'); // imports the correct sql statement
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$data = array();

	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$data[$idx] = $row;
		$idx++;
	}
	((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
	return $data;
}
//---------- Top Players - modifecation ----------//

function getTopNP()
{
	include(ROOT . DS . 'queries'. DS .'getTopNP.php'); // imports the correct sql statement
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$totalc = mysqli_num_rows($result);
	
	$limit            = $_GET['limit']; 
	$type             = $_GET['type']; 
	$page             = $_GET['page']; 
	
	//set default if: $limit is empty, non numerical, less than 50, greater than 150 
	if((!$limit)  || (is_numeric($limit) == false) || ($limit < 50) || ($limit > 150)) { 
	     $limit = 50; //default 
	 } 
	//set default if: $page is empty, non numerical, less than zero, greater than total available 
	if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $totalc)) { 
	     $page = 1; //default 
	}
	
	//calcuate total pages 
	$totalpages = ceil($totalc / $limit);
	$set_limit = $page * $limit - ($limit);
	
	//query
	$query = $query . ' limit '.$set_limit.', '.$limit.';';
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$data = array();

	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$row['num'] = ($idx + $set_limit);
		$row['pgs'] = $totalpages;
		$data[$idx] = $row;
		$idx++;
	}
	((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
	return $data;
}
/*----------------------------*/
function getTopScore()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopScore.php'); // imports the correct sql statement
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$data = array();

	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['score'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
	return $data;
}

function getTopScore2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopScore.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysqli_query($GLOBALS["___mysqli_ston"], $query2) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $result2 = mysqli_query($GLOBALS["___mysqli_ston"], $query3) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $idx = 0;
       	while ($row = mysqli_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		    $data2[$idx]['id'] = $row['id'];
		    $data2[$idx]['name'] = $row['name'];
		    $data2[$idx]['rank'] = $row['rank'];
		    $data2[$idx]['value'] = $row['score'];
            $data2[$idx]['num'] = $row['num'];
		    $data2[$idx]['country'] = $row['country'];
        }
        }
        ((mysqli_free_result($result2) || (is_object($result2) && (get_class($result2) == "mysqli_result"))) ? true : false);
    }
	return $data2;
}

function getTopTeamwork()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopTeamwork.php'); // imports the correct sql statement
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$data = array();

	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['teamwork'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
	return $data;
}

function getTopTeamwork2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopTeamwork.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysqli_query($GLOBALS["___mysqli_ston"], $query2) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $result2 = mysqli_query($GLOBALS["___mysqli_ston"], $query3) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $idx = 0;
       	while ($row = mysqli_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['teamwork'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        ((mysqli_free_result($result2) || (is_object($result2) && (get_class($result2) == "mysqli_result"))) ? true : false);
    }
	return $data2;
}

function getTopSPM()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopSPM.php'); // imports the correct sql statement
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$data = array();

	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['spm'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
	return $data;
}

function getTopSPM2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopSPM.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysqli_query($GLOBALS["___mysqli_ston"], $query2) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $result2 = mysqli_query($GLOBALS["___mysqli_ston"], $query3) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $idx = 0;
       	while ($row = mysqli_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
    		$data2[$idx]['id'] = $row['id'];
    		$data2[$idx]['name'] = $row['name'];
    		$data2[$idx]['rank'] = $row['rank'];
    		$data2[$idx]['value'] = $row['spm'];
    		$data2[$idx]['num'] = $row['num'];
    		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        ((mysqli_free_result($result2) || (is_object($result2) && (get_class($result2) == "mysqli_result"))) ? true : false);
    }
	return $data2;
}

/*
function getTopRSPM()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopRSPM.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['spm'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopRSPM2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopRSPM.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
    		$data2[$idx]['id'] = $row['id'];
    		$data2[$idx]['name'] = $row['name'];
    		$data2[$idx]['rank'] = $row['rank'];
    		$data2[$idx]['value'] = $row['spm'];
    		$data2[$idx]['num'] = $row['num'];
    		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopSSPM()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopSSPM.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['spm'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopSSPM2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopSSPM.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
    		$data2[$idx]['id'] = $row['id'];
    		$data2[$idx]['name'] = $row['name'];
    		$data2[$idx]['rank'] = $row['rank'];
    		$data2[$idx]['value'] = $row['spm'];
    		$data2[$idx]['num'] = $row['num'];
    		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopNoobs()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopNoobs.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['spm'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopNoobs2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopNoobs.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
    		$data2[$idx]['id'] = $row['id'];
    		$data2[$idx]['name'] = $row['name'];
    		$data2[$idx]['rank'] = $row['rank'];
    		$data2[$idx]['value'] = $row['spm'];
    		$data2[$idx]['num'] = $row['num'];
    		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopGMPR()
{
	include(ROOT . DS . 'queries'. DS .'getTopGMPR.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['gmpr'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopGMPR2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getTopGMPR.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['gmpr'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopPurpur()
{
	include(ROOT . DS . 'queries'. DS .'getTopPurpur.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['purpurs'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopPurpur2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getTopPurpur.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['purpurs'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopFlagwork()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopFlagwork.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['flagwork'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopFlagwork2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopFlagwork.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['flagwork'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopCaptures()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopCaptures.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['captures'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopCaptures2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopCaptures.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['captures'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopDefends()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopDefends.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['defends'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopDefends2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopDefends.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['defends'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopKills()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopKills.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['kills'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopKills2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopKills.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['kills'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopAssists()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopAssists.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['assists'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopAssists2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopAssists.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['assists'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}
*/

function getTopKDR()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopKDR.php'); // imports the correct sql statement
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$data = array();

	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['kdr'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
	return $data;
}

function getTopKDR2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopKDR.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysqli_query($GLOBALS["___mysqli_ston"], $query2) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $result2 = mysqli_query($GLOBALS["___mysqli_ston"], $query3) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $idx = 0;
       	while ($row = mysqli_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['kdr'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        ((mysqli_free_result($result2) || (is_object($result2) && (get_class($result2) == "mysqli_result"))) ? true : false);
    }
	return $data2;
}

function getTopCMDScore()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopCmdScore.php'); // imports the correct sql statement
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$data = array();

	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['cmdscore'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
	return $data;
}

function getTopCMDScore2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopCmdScore.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysqli_query($GLOBALS["___mysqli_ston"], $query2) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $result2 = mysqli_query($GLOBALS["___mysqli_ston"], $query3) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $idx = 0;
       	while ($row = mysqli_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['cmdscore'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        ((mysqli_free_result($result2) || (is_object($result2) && (get_class($result2) == "mysqli_result"))) ? true : false);
    }
	return $data2;
}

function getTopCMD()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopCMD.php'); // imports the correct sql statement
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$data = array();

	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['cmd'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
	return $data;
}


function getTopCMD2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopCMD.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysqli_query($GLOBALS["___mysqli_ston"], $query2) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $result2 = mysqli_query($GLOBALS["___mysqli_ston"], $query3) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $idx = 0;
       	while ($row = mysqli_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['cmd'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        ((mysqli_free_result($result2) || (is_object($result2) && (get_class($result2) == "mysqli_result"))) ? true : false);
    }
	return $data2;
}

/*
function getTopOfficers()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopOfficers.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['off'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}


function getTopOfficers2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopOfficers.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['off'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopSani()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopSani.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['sani'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopSani2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopSani.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['sani'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopExpl()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopExpl.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['pid'];
		$data[$idx]['name'] = $row['pname'];
		$data[$idx]['rank'] = $row['prank'];
		$data[$idx]['value'] = $row['expl'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopExpl2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopExpl.php'); // imports the correct sql statement
	$data2 = array();
    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['pid'] == $crid) {
		$data2[$idx]['id'] = $row['[pid'];
		$data2[$idx]['name'] = $row['pname'];
		$data2[$idx]['rank'] = $row['prank'];
		$data2[$idx]['value'] = $row['expl'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopHAR()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopHAR.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['pid'];
		$data[$idx]['name'] = $row['pname'];
		$data[$idx]['rank'] = $row['prank'];
		$data[$idx]['value'] = $row['har'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopHAR2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopHAR.php'); // imports the correct sql statement
	$data2 = array();
    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['pid'] == $crid) {
		$data2[$idx]['id'] = $row['[pid'];
		$data2[$idx]['name'] = $row['pname'];
		$data2[$idx]['rank'] = $row['prank'];
		$data2[$idx]['value'] = $row['har'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}
*/

function getTopKnife()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopKnifes.php'); // imports the correct sql statement
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$data = array();

	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['topk'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
	return $data;
}

function getTopKnife2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopKnifes.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysqli_query($GLOBALS["___mysqli_ston"], $query2) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $result2 = mysqli_query($GLOBALS["___mysqli_ston"], $query3) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $idx = 0;
       	while ($row = mysqli_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['topk'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        ((mysqli_free_result($result2) || (is_object($result2) && (get_class($result2) == "mysqli_result"))) ? true : false);
    }
	return $data2;
}

function getTopSnip()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopSnip.php'); // imports the correct sql statement
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$data = array();

	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['pid'];
		$data[$idx]['name'] = $row['pname'];
		$data[$idx]['rank'] = $row['prank'];
		$data[$idx]['value'] = $row['kd'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
	return $data;
}

function getTopSnip2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopSnip.php'); // imports the correct sql statement
	$data2 = array();
    if ($compare) {
    mysqli_query($GLOBALS["___mysqli_ston"], $query2) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $result2 = mysqli_query($GLOBALS["___mysqli_ston"], $query3) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $idx = 0;
       	while ($row = mysqli_fetch_assoc($result2)) {
        if ($row['pid'] == $crid) {
		$data2[$idx]['id'] = $row['pid'];
		$data2[$idx]['name'] = $row['pname'];
		$data2[$idx]['rank'] = $row['prank'];
		$data2[$idx]['value'] = $row['kd'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        ((mysqli_free_result($result2) || (is_object($result2) && (get_class($result2) == "mysqli_result"))) ? true : false);
    }
	return $data2;
}

/*
function getTopAT()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopAT.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['pid'];
		$data[$idx]['name'] = $row['pname'];
		$data[$idx]['rank'] = $row['prank'];
		$data[$idx]['value'] = $row['kd'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopAT2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopAT.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['pid'] == $crid) {
		$data2[$idx]['id'] = $row['pid'];
		$data2[$idx]['name'] = $row['pname'];
		$data2[$idx]['rank'] = $row['prank'];
		$data2[$idx]['value'] = $row['kd'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}
*/

function getTopWLR()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopWLR.php'); // imports the correct sql statement
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
	$data = array();

	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['wlr'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
	return $data;
}

function getTopWLR2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopWLR.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysqli_query($GLOBALS["___mysqli_ston"], $query2) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $result2 = mysqli_query($GLOBALS["___mysqli_ston"], $query3) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));
        $idx = 0;
       	while ($row = mysqli_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['wlr'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        ((mysqli_free_result($result2) || (is_object($result2) && (get_class($result2) == "mysqli_result"))) ? true : false);
    }
	return $data2;
}

/*
function getTopAviator()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopAviator.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['pid'];
		$data[$idx]['name'] = $row['pname'];
		$data[$idx]['rank'] = $row['prank'];
		$data[$idx]['value'] = $row['kd'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopAviator2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopAviator.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['pid'] == $crid) {
		$data2[$idx]['id'] = $row['pid'];
		$data2[$idx]['name'] = $row['pname'];
		$data2[$idx]['rank'] = $row['prank'];
		$data2[$idx]['value'] = $row['kd'];
        $data2[$idx]['num'] = $row['num'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopHeli()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopHeli.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['pid'];
		$data[$idx]['name'] = $row['pname'];
		$data[$idx]['rank'] = $row['prank'];
		$data[$idx]['value'] = $row['kd'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopHeli2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopHeli.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['pid'] == $crid) {
		$data2[$idx]['id'] = $row['pid'];
		$data2[$idx]['name'] = $row['pname'];
		$data2[$idx]['rank'] = $row['prank'];
		$data2[$idx]['value'] = $row['kd'];
        $data2[$idx]['num'] = $row['num'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopAA()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopAA.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['pid'];
		$data[$idx]['name'] = $row['pname'];
		$data[$idx]['rank'] = $row['prank'];
		$data[$idx]['value'] = $row['kd'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopAA2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopAA.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['pid'] == $crid) {
		$data2[$idx]['id'] = $row['pid'];
		$data2[$idx]['name'] = $row['pname'];
		$data2[$idx]['rank'] = $row['prank'];
		$data2[$idx]['value'] = $row['kd'];
        $data2[$idx]['num'] = $row['num'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}

function getTopArmor()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopArmor.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['pid'];
		$data[$idx]['name'] = $row['pname'];
		$data[$idx]['rank'] = $row['prank'];
		$data[$idx]['value'] = $row['kd'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopArmor2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopArmor.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['pid'] == $crid) {
		$data2[$idx]['id'] = $row['pid'];
		$data2[$idx]['name'] = $row['pname'];
		$data2[$idx]['rank'] = $row['prank'];
		$data2[$idx]['value'] = $row['kd'];
        $data2[$idx]['num'] = $row['num'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}
*/

/*--------Other---------*/
/*
function getTopRndScore()
{
	include(ROOT . DS . 'queries'. DS .'getRankingTopRndScore.php'); // imports the correct sql statement
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	$data = array();

	$idx = 0;
	while ($row = mysql_fetch_assoc($result)) {
		$data[$idx]['id'] = $row['id'];
		$data[$idx]['name'] = $row['name'];
		$data[$idx]['rank'] = $row['rank'];
		$data[$idx]['value'] = $row['rndscore'];
		$data[$idx]['country'] = $row['country'];
		$idx++;
	}
	mysql_free_result($result);
	return $data;
}

function getTopRndScore2()
{
GLOBAL $compare, $crid;
	include(ROOT . DS . 'queries'. DS .'getRankingTopRndScore.php'); // imports the correct sql statement
	$data2 = array();

    if ($compare) {
    mysql_query($query2) or die('Query failed: ' . mysql_error());
        $result2 = mysql_query($query3) or die('Query failed: ' . mysql_error());
        $idx = 0;
       	while ($row = mysql_fetch_assoc($result2)) {
        if ($row['id'] == $crid) {
		$data2[$idx]['id'] = $row['id'];
		$data2[$idx]['name'] = $row['name'];
		$data2[$idx]['rank'] = $row['rank'];
		$data2[$idx]['value'] = $row['rndscore'];
        $data2[$idx]['num'] = $row['num'];
		$data2[$idx]['country'] = $row['country'];
	    }
	    }
        mysql_free_result($result2);
    }
	return $data2;
}
*/

/*
| --------------------------------------------------------------
| Next Ranks Functions
| --------------------------------------------------------------
*/
/*function getNextRankInfo($PID)
{
	// Get player data
	$player = getPlayerDataFromPID($PID);
	
	// Read the lines from the ranks list,a dn assign a key to each rank
	$lines  = file( ROOT . DS . 'queries'. DS .'ranks.list' );
	foreach($lines as $key => $value)
	{
		$rank[$key] = $value;
	}
	unset($lines);
	
	// Read the lines from the ranks points list to assign needed points for each rank
	$lines  = file( ROOT . DS . 'queries'. DS .'rank_points.list' );
	foreach($lines as $key => $value)
	{
		$points[$key] = $value;
	}
	unset($lines);
	
	// Lets get our SPM, very important
	$SPM = round(($player['score'] / intToMins($player['time'])), 1);
	
	// Init a return array
	$return = array();
	
	// Include the requirements for special ranks, and get the next 3
	include(ROOT . DS . 'queries'. DS .'nextRankReqs.php' );
	foreach(getNextRanks($PID, $player['rank'], 3) as $id)
	{
		// Next rank
		$return[] = array(
			'rank' => $id,
			'title' => $rank[$id], 
			'rank_points' => $points[$id],
			'points_needed' => $points[$id] - $player['score'],
			'percent' => @round(($player['score'] / $points[$id]) * 100, 2),
			'days' => getNextRankDayCount($player['joined'], $player['lastonline'], $player['score'], $points[$id]),
			'time_straight' => getNextRankTime($player['score'], $points[$id], $SPM)
		);
	}
	
	// Make sure our percents are not over 100!
	foreach($return as $key => $value)
	{
		if($value['percent'] > 100) $return[$key]['percent'] = 100;
	}
	return $return;
}

function getNextRankTime($score, $points_needed, $spm)
{
	
	$temp = ($points_needed - $score) / ($spm  / 60);
	if($temp < 0) return "0 Seconds";
	
	// Convert into a fancy little time
	$temp = intToTime($temp, 0, 0, 0);
	
	// Explode the time
	$time = explode(':', $temp);
	
	// Hour corrections
	$return = '';
	if($time[0] > 0)
	{
		$return .= ($time[0] > 1) ? $time[0] .' Hours, and ' : $time[0] .' Hour, and ';
	}
	if($time[1] > 0)
	{
		$return .= ($time[1] > 1) ? $time[1] .' Minutes ' : $time[1] .' Minute ';
	}
	
	return $return;
}

function getNextRankDayCount($joined, $last, $score, $points_needed)
{
	$temp = $last - $joined;
	$days = round(($temp / 86400), 0);
	
	// Score Per Day
	$spd = @round(($score / $days), 0);
	
	// Get how many points you need
	$needs = $points_needed - $score;
	$total = @round(($needs / $spd), 0);
	return ($total > 0) ? $total : 0;	
}*/
?>