<? require $_SERVER['DOCUMENT_ROOT'].'inc/functions.php'; ?>
<?
if (!empty($HTTP_SERVER_VARS['SERVER_SOFTWARE']) && strstr($HTTP_SERVER_VARS['SERVER_SOFTWARE'], 'Apache/2')) {
	header ('Cache-Control: no-cache, pre-check=0, post-check=0, max-age=0');
} else {
	header ('Cache-Control: private, pre-check=0, post-check=0, max-age=0');
}
header("Expires: ".gmdate("D, d M Y H:i:s", time())." GMT");
header ('Content-Type: text/xml; charset=UTF-8');
echo '<?xml version="1.0" encoding="UTF-8"?>';?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
	<url>
		<loc>http://velo2.ru/</loc>
	</url>
<?$str='';?>
<? $db->query("SELECT id, url, (SELECT count(mtb_ann.id) FROM mtb_ann, mtb_user WHERE mtb_user.id=mtb_ann.uid and mtb_user.region_id=mtb_regions.id) as total, (SELECT count(mtb_ann.id) FROM mtb_ann, mtb_user WHERE flag='1' and mtb_user.id=mtb_ann.uid and mtb_user.region_id=mtb_regions.id) as tsale, (SELECT count(mtb_ann.id) FROM mtb_ann, mtb_user WHERE flag='2' and mtb_user.id=mtb_ann.uid and mtb_user.region_id=mtb_regions.id) as tbuy, (SELECT count(mtb_ann.id) FROM mtb_ann, mtb_user WHERE flag='3' and mtb_user.id=mtb_ann.uid and mtb_user.region_id=mtb_regions.id) as tchange FROM mtb_regions");
while($db->next_record()){
	$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/</loc></url><url><loc>http://velo2.ru/'.$db->Record['url'].'/market/</loc></url>';

$dba->query("SELECT count(mtb_ann.id) as total, mtb_ann.mtb_component_type_id FROM mtb_ann, mtb_component_type, mtb_user WHERE mtb_ann.mtb_component_type_id=mtb_component_type.id and mtb_ann.uid=mtb_user.id and mtb_user.region_id='".$db->Record['id']."' GROUP BY mtb_component_type_id");
while($dba->next_record()){
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/?category='.$dba->Record['mtb_component_type_id'].'</loc></url>';
if ($dba->Record['total']>20) {
$counttotal=ceil($dba->Record['total']/20);
for ($k=2; $k<=$counttotal; $k++) {
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/page'.$k.'/?category='.$dba->Record['mtb_component_type_id'].'</loc></url>';
}}}

if ($db->Record['total']>20) {
$counttotal=ceil($db->Record['total']/20);
for ($k=2; $k<=$counttotal; $k++) {
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/page'.$k.'/</loc></url>';
}}

if ($db->Record['tsale']>0) {
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/sale/</loc></url>';

$dba->query("SELECT count(mtb_ann.id) as total, mtb_ann.mtb_component_type_id FROM mtb_ann, mtb_component_type, mtb_user WHERE flag='1' and mtb_ann.mtb_component_type_id=mtb_component_type.id and mtb_ann.uid=mtb_user.id and mtb_user.region_id='".$db->Record['id']."' GROUP BY mtb_component_type_id");
while($dba->next_record()){
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/sale/?category='.$dba->Record['mtb_component_type_id'].'</loc></url>';

if ($dba->Record['total']>20) {
$counttotal=ceil($dba->Record['total']/20);
for ($k=2; $k<=$counttotal; $k++) {
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/sale/page'.$k.'/?category='.$dba->Record['mtb_component_type_id'].'</loc></url>';
}}}

if ($db->Record['tsale']>20) {
$counttotal=ceil($db->Record['tsale']/20);
for ($k=2; $k<=$counttotal; $k++) {
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/sale/page'.$k.'/</loc></url>';
}}}

if ($db->Record['tbuy']>0) {
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/buy/</loc></url>';

$dba->query("SELECT count(mtb_ann.id) as total, mtb_ann.mtb_component_type_id FROM mtb_ann, mtb_component_type, mtb_user WHERE flag='2' and mtb_ann.mtb_component_type_id=mtb_component_type.id and mtb_ann.uid=mtb_user.id and mtb_user.region_id='".$db->Record['id']."' GROUP BY mtb_component_type_id");
while($dba->next_record()){
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/buy/?category='.$dba->Record['mtb_component_type_id'].'</loc></url>';

if ($dba->Record['total']>20) {
$counttotal=ceil($dba->Record['total']/20);
for ($k=2; $k<=$counttotal; $k++) {
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/buy/page'.$k.'/?category='.$dba->Record['mtb_component_type_id'].'</loc></url>';
}}}

if ($db->Record['tbuy']>20) {
$counttotal=ceil($db->Record['tbuy']/20);
for ($k=2; $k<=$counttotal; $k++) {
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/buy/page'.$k.'/</loc></url>';
}}}

if ($db->Record['tchange']>0) {
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/change/</loc></url>';

$dba->query("SELECT count(mtb_ann.id) as total, mtb_ann.mtb_component_type_id FROM mtb_ann, mtb_component_type, mtb_user WHERE flag='3' and mtb_ann.mtb_component_type_id=mtb_component_type.id and mtb_ann.uid=mtb_user.id and mtb_user.region_id='".$db->Record['id']."' GROUP BY mtb_component_type_id");
while($dba->next_record()){
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/change/?category='.$dba->Record['mtb_component_type_id'].'</loc></url>';

if ($dba->Record['total']>20) {
$counttotal=ceil($dba->Record['total']/20);
for ($k=2; $k<=$counttotal; $k++) {
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/change/page'.$k.'/?category='.$dba->Record['mtb_component_type_id'].'</loc></url>';
}}}

if ($db->Record['tchange']>20) {
$counttotal=ceil($db->Record['tchange']/20);
for ($k=2; $k<=$counttotal; $k++) {
$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/market/change/page'.$k.'/</loc></url>';
}}}

$str.='<url><loc>http://velo2.ru/'.$db->Record['url'].'/shops/</loc></url><url><loc>http://velo2.ru/'.$db->Record['url'].'/services/</loc></url>';
}

$db->query("SELECT id FROM mtb_ann");
while($db->next_record()){
$str.='<url><loc>http://velo2.ru/market/'.$db->Record['id'].'/</loc></url>';
}

$str.='<url><loc>http://velo2.ru/brands/</loc></url>';

for ($k=A; $k<Z; $k++) {
$str.='<url><loc>http://velo2.ru/brands/?show='.$k.'</loc></url>';
}
$str.='<url><loc>http://velo2.ru/brands/?show=%D5</loc></url><url><loc>http://velo2.ru/brands/?show=2</loc></url><url><loc>http://velo2.ru/brands/?show=3</loc></url><url><loc>http://velo2.ru/brands/?show=4</loc></url><url><loc>http://velo2.ru/brands/?show=6</loc></url>';

$db->query("SELECT id, title FROM mtb_brand WHERE id!='679' and id!='675' and id!='361' and id!='404' and id!='601'");
while($db->next_record()){
$tmpstr=preg_replace('/\&/i',"&amp;",$db->Record['title']);
$str.='<url><loc>http://velo2.ru/brands/'.makeurl($tmpstr).'/</loc></url>';
}
$str.='<url><loc>http://velo2.ru/brands/%D5%C2%C7/</loc></url>';

$db->query("SELECT id, login FROM mtb_user");
while($db->next_record()){
$str.='<url><loc>http://velo2.ru/user/'.makeurl($db->Record['login']).'/</loc></url>';
}

$db->query("SELECT mtb_shops.id, mtb_regions.url FROM mtb_shops, mtb_regions WHERE mtb_shops.region_id=mtb_regions.id");
while($db->next_record()){
$str.='<url><loc>http://velo2.ru/shops/'.$db->Record['id'].'/</loc></url>';
}

$db->query("SELECT mtb_services.id, mtb_regions.url FROM mtb_services, mtb_regions WHERE mtb_services.region_id=mtb_regions.id");
while($db->next_record()){
$str.='<url><loc>http://velo2.ru/services/'.$db->Record['id'].'/</loc></url>';
}
echo $str;
?>
</urlset>
