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

if($tipepos=="PDA") {
if ($idpos!=""){
$sql="SELECT DISTINCT ReceivedDate,jam_value AS ReceivedTime,UNIX_TIMESTAMP(CONCAT(ReceivedDate,'-',DATE_FORMAT(a.ReceivedTime,'%H:0'))) AS tgl,max(a.WLevel) AS WLevel, FORMAT(a.WLevel*100,0) AS klWLevel
FROM ".$_GET['idpos']." AS a
INNER JOIN m_jam AS b ON DATE_FORMAT(b.jam_value,'%H:0') = DATE_FORMAT(a.ReceivedTime,'%H:0')
WHERE 1=1 AND a.WLevel!=0 AND a.WLevel>=1 AND a.ReceivedDate='".$_GET['tgl']."' GROUP BY ReceivedDate,jam_value
ORDER BY a.ReceivedDate ASC,b.jam_value ASC";
$query = mysql_query($sql);

$i=0;
while($row=mysql_fetch_array($query)){
$i++;
echo "<tr>
      <td style='background-image:url(images/bgWarning.png); background-repeat:no-repeat; padding-left:17px;'>
	  <strong>&raquo;</strong>".date('d/m/Y',strtotime($row['ReceivedDate']))."</td>
      <td>".date('H:i',strtotime($row['ReceivedTime']))."</td>
      <td>".$row['Rain']." cm</td>
      <td>".$row['WLevel']." cm</td>
      <td>".$row['ML']." v</td>
      </tr>";
	} 
echo"</table>";
}

} else { 
if ($idpos!=""){
echo $sql="SELECT DISTINCT ReceivedDate,ReceivedTime,UNIX_TIMESTAMP(CONCAT(ReceivedDate,'-',DATE_FORMAT(a.ReceivedTime,'%H:0'))) AS tgl,Rain,WLevel
FROM ".$_GET['idpos']." AS a
WHERE 1=1 AND a.ReceivedDate='".$_GET['tgl']."' GROUP BY ReceivedDate,ReceivedTime
ORDER BY a.ReceivedDate ASC,a.ReceivedTime ASC";
$query = mysql_query($sql);

$i=0;
while($row=mysql_fetch_array($query)){
$i++;
echo "<tr>
      <td style='background-image:url(images/bgWarning.png); background-repeat:no-repeat; padding-left:17px;'>
	  <strong>&raquo;</strong>".date('d/m/Y',strtotime($row['ReceivedDate']))."</td>
      <td>".date('H:i',strtotime($row['ReceivedTime']))."</td>
      <td>".$row['Rain']." cm</td>
      <td>".$row['WLevel']." cm</td>
      <td>".$row['ML']." v</td>
      </tr>";
	} 
echo"</table>";
}
}
?>