<?php
session_start();
$ibbws = $_GET['ibbws'];
include "../config/conn.php";

$filter1 = " AND status_lokasi=1 AND lat IS NOT NULL AND lat <> '' AND lat <> '0' ";
if(isset($_GET['mod'])){
	switch ($_GET['mod']) {
		case 'rt':
			$sql = "SELECT * 
					FROM m_lokasi 
					WHERE 
						1=1 AND 
						id_tipe LIKE '%PDA%' AND 
						WLevel > siaga4 ".$filter1." 
					UNION
					SELECT * 
					FROM m_lokasi 
					WHERE 
						1=1 AND 
						id_tipe LIKE '%PCH%' AND 
						Rain > siaga4 ".$filter1."  ";
			$query = mysql_query($sql);

			$rt = '';
			$i = 0;
			while($row = mysql_fetch_object($query)){
				if($row->id_tipe == 'PDA'){
					if($row->WLevel >= $row->siaga1){
						$rt .= ' <span style="color:#b22300; font-weight:bold;">Siaga I</span> : '.$row->nama_alat.' ('.number_format(($row->WLevel / 100),2,',','.').'m) ; &nbsp;&nbsp; ';
					}else if($row->WLevel >= $row->siaga2){
						$rt .= ' <span style="color:#ff6d00; font-weight:bold;">Siaga II</span> : '.$row->nama_alat.' ('.number_format(($row->WLevel / 100),2,',','.').'m) ; &nbsp;&nbsp; ';
					}else if($row->WLevel >= $row->siaga3){
						$rt .= ' <span style="color:#ffab00; font-weight:bold;">Siaga III</span> : '.$row->nama_alat.' ('.number_format(($row->WLevel / 100),2,',','.').'m) ; &nbsp;&nbsp; ';
					}else if($row->WLevel >= $row->siaga4){
						$rt .= ' <span style="color:#2ac4ae; font-weight:bold;">Siaga IV</span> : '.$row->nama_alat.' ('.number_format(($row->WLevel / 100),2,',','.').'m) ; &nbsp;&nbsp; ';
					}

				}else if($row->id_tipe == 'PCH'){
					if($row->Rain >= $row->siaga1){
						$rt .= ' <span style="background-color:#b22300; font-weight:bold;">Siaga I</span> : '.$row->nama_alat.' ('.$Rain.'mm) ; &nbsp;&nbsp; ';
					}else if($row->Rain >= $row->siaga2){
						$rt .= ' <span style="color:#ff6d00; font-weight:bold;">Siaga II</span> : '.$row->nama_alat.' ('.$Rain.'mm) ; &nbsp;&nbsp; ';						
					}else if($row->Rain >= $row->siaga3){
						$rt .= ' <span style="color:#ffab00; font-weight:bold;">Siaga III</span> : '.$row->nama_alat.' ('.$Rain.'mm) ; &nbsp;&nbsp; ';						
					}else if($row->Rain >= $row->siaga4){
						$rt .= ' <span style="color:#2ac4ae; font-weight:bold;">Siaga IV</span> : '.$row->nama_alat.' ('.$Rain.'mm) ; &nbsp;&nbsp; ';
					}
				}else{
					//$rt .= ' <span style="color:#2ac4ae; font-weight:bold;">Siaga IV</span> : '.$row->nama_alat.' ('.$Rain.'mm) ; &nbsp;&nbsp; ';

				}
				$i++;
			}
			echo $rt.' '.$rt.' '.$rt.' '.$rt.' '.$rt.' '.$rt.' '.$rt.' '.$rt.' '.$rt;

			break;
		
		default:
			echo json_encode(false);
			break;
	}

}else{
	echo json_encode(false);
}

?>