<?php
function getMapByID($id)
{
	$lines  = file(getcwd()."/queries/maps.list");
	$i = 0;
	while ($i<getMapCount())
	{
		if (strncasecmp( $lines[$i], "$id", strlen("$id") ) == 0)
			return substr($lines[$i], strlen("$id")+1);
		$i++;
	}
	$query = "SELECT * FROM mapinfo WHERE id = $id LIMIT 1;";
	$result = mysqli_query($GLOBALS["___mysqli_ston"], $query) or die('Query failed: ' . mysqli_error($GLOBALS["___mysqli_ston"]));

	$mapname = array();
	$idx = 0;
	while ($row = mysqli_fetch_assoc($result)) {
		$mapname[$idx] = $row;
		$idx++;
	}
	$mapname[0]['name'] = str_replace("_", " ", $mapname[0]['name']);
	$mapname[0]['name'] = preg_replace("/v(\d) (\d+)/i", "", $mapname[0]['name']);
	$mapname[0]['name'] = preg_replace("/(\d) (\d+)/i", "", $mapname[0]['name']);
	$mapname[0]['name'] = trim ($mapname[0]['name']);
	$mapname[0]['name'] = ucwords(strtolower($mapname[0]['name']));
	return $mapname[0]['name'];
}

function getMapCount()
{
	$lines  = file(getcwd()."/queries/maps.list");
	return count($lines);	
}


?>