<?php  
session_start();
include "../config/conn.php";
//koneksi1_buka();
$sql="select lat,lng,nama_lokasi,icon,id_tipe,ReceivedDate,ReceivedTime,WLevel,Rain,foto_lokasi from m_lokasi WHERE 1=1 AND status_lokasi=1 AND id_bbws=".$_SESSION['id_bbws']."";
$koordinat="";
date_default_timezone_set('Asia/Jakarta');
$tanggal= mktime(0,0,0,date('m'),date('d'),date('Y'));
$hariini = date("Y-m-d", $tanggal);

function parseToXML($htmlStr)
{
$xmlStr=str_replace('<','&lt;',$htmlStr);
$xmlStr=str_replace('>','&gt;',$xmlStr);
$xmlStr=str_replace('"','&quot;',$xmlStr);
$xmlStr=str_replace("'",'&#39;',$xmlStr);
$xmlStr=str_replace("&",'&amp;',$xmlStr);
return $xmlStr;
}

$result = mysql_query($sql);
if (!$result) {
 die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Memulai XML dengan mencetak parent marker
echo '<markers>';

// Melakukan pengulangan untuk setiap node dibawah parent marker
while ($row = mysql_fetch_array($result)){
if($hariini==$row['ReceivedDate'] && $row['id_tipe']=='PDA' && $row['icon']=="siaga4"){ 
		  	$img="PDAOnlineS4.png";
			$sts="PDAOnlineS4";
} else if($hariini==$row['ReceivedDate'] && $row['id_tipe']=='PDA' && $row['icon']=="siaga3"){ 
		  	$img="PDAOnlineS3.png";
			$sts="PDAOnlineS3";
} else if($hariini==$row['ReceivedDate'] && $row['id_tipe']=='PDA' && $row['icon']=="siaga2"){ 
		  	$img="PDAOnlineS2.png";
			$sts="PDAOnlineS2";
} else if($hariini==$row['ReceivedDate'] && $row['id_tipe']=='PDA' && $row['icon']=="siaga1"){ 
		  	$img="PDAOnlineS1.png";
			$sts="PDAOnlineS1";
} else if($hariini==$row['ReceivedDate'] && $row['id_tipe']=='PCH' && $row['icon']=="berawan"){ 
		  	$img="PCHOnlineS3.png";
			$sts="PCHOnlineS3";
} else if($hariini==$row['ReceivedDate'] && $row['id_tipe']=='PCH' && $row['icon']=="sedang"){ 
		  	$img="PCHOnlineS2.png";
			$sts="PCHOnlineS2";
} else if($hariini==$row['ReceivedDate'] && $row['id_tipe']=='PCH' && $row['icon']=="lebat"){ 
		  	$img="PCHOnlineS1.png";
			$sts="PCHOnlineS1";
} else {
		  	$img="iconalarmDanger.png";
			$sts="Offline";
} 

// Menambahkan kedalam XML
 echo '<marker ';
 echo 'nama_lokasi="' . parseToXML($row['nama_lokasi']) . '" ';
 echo 'lat="' . $row['lat'] . '" ';
 echo 'lng="' . $row['lng'] . '" ';
 echo 'id_tipe="' . $row['id_tipe'] . '" ';
 echo 'ReceivedDate="' . $row['ReceivedDate'] . '" ';
 echo 'ReceivedTime="' . $row['ReceivedTime'] . '" ';
 echo 'img="' . $img . '" ';
 echo 'sts="' . $sts . '" ';
 echo 'icon="' . $row['icon'] . '" ';
 echo 'WLevel="' . $row['WLevel'] . '" ';
 echo 'Rain="' . $row['Rain'] . '" ';
 echo 'foto_lokasi="' . $row['foto_lokasi'] . '" ';
 echo '/>';
}

// End XML
echo '</markers>';
//koneksi1_tutup();
?>