<?php  
session_start();
include "../config/conn.php";

$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");

echo '<markers>';
while ($row = mysql_fetch_array($result)){
if($row['icon']=="siaga4" || $row['icon']=="normal"){ 
		  	$img="PDAOnlineS4.png";
			$sts="PDAOnlineS4";
} else if($row['icon']=="siaga3"){ 
		  	$img="PDAOnlineS3.png";
			$sts="PDAOnlineS3";
} else if($row['icon']=="siaga2"){ 
		  	$img="PDAOnlineS2.png";
			$sts="PDAOnlineS2";
} else if($row['icon']=="siaga1"){ 
		  	$img="PDAOnlineS1.png";
			$sts="PDAOnlineS1";
} else if($row['icon']=="cerah"){ 
		  	$img="cerah.png";
			$sts="cerah";
} else if($row['icon']=="ringan"){ 
		  	$img="ringan.png";
			$sts="ringan";
} else if($row['icon']=="lebat"){ 
		  	$img="lebat.png";
			$sts="lebat";
} else if($row['icon']=="sangat lebat"){ 
		  	$img="sangatlebat.png";
			$sts="sangatlebat";
} else {
		  	$img="iconalarmDanger.png";
			$sts="Offline";
} 

$namaLokasi = trim(parseToXML($row['nama_lokasi']));
$namaLokasiString = ucfirst($namaLokasi);

 echo '<marker ';
 echo 'nama_lokasi="' . $namaLokasi . '" ';
 echo 'nama_lokasi_2="' . $namaLokasiString . '" ';
 echo 'lat="' . trim($row['lat']) . '" ';
 echo 'lng="' . trim($row['lng']) . '" ';
 echo 'id_tipe="' . trim($row['id_tipe']) . '" ';
 echo 'ReceivedDate="' . date('d/m/y',strtotime(trim($row['ReceivedDate']))) . '" ';
 echo 'ReceivedTime="' . date('H:i',strtotime(trim($row['ReceivedTime']))) . '" ';
 echo 'img="' . trim($img) . '" ';
 echo 'sts="' . trim($sts) . '" ';
 echo 'icon="' . trim($row['icon']) . '" ';
 echo 'WLevel="' . number_format(trim($row['WLevel']),0) . ' cm" ';
 echo 'Rain="' . number_format(trim($row['Rain']),0) . ' mm" ';
 echo 'foto_lokasi="' . trim($row['foto_lokasi']) . '" ';
 echo 'nama_pengamat="' . trim($row['nama_pengamat']) . '" ';
 echo 'nama_alat="' . trim($row['nama_alat']) . '" ';
 echo 'nama_das="' . trim($row['nama_das']) . '" ';
 echo 'ws="' . trim($row['ws']) . '" ';
 echo '/>';
}

echo '</markers>';

?>