<?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 = mysql_query($query) or die('Query failed: ' . mysql_error());

	$mapname = array();
	$idx = 0;
	while ($row = mysql_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);	
}


?>