<?php
// header('Content-type: application/json');
include '../config/database.php';
function _command(){
	$conn = _connectDB();
	$sql = "SELECT * FROM monitor";
	$result = $conn->query($sql);
	$res = [];
	if ($result->num_rows > 0) {
	    while($row = $result->fetch_assoc()) {
			array_push($res,$row);
	    }
	}
	return $res;
}


$data = [];
foreach(_command() as $key => $val){
	//$res = $val['Code'] .' '. $val['Version'] .' = '. $val['Status'] ;
	//array_push($data,$res);
	array_push($data,$val);
	// $data = [];
	// $data['name'] = base64_decode($val['line_name']);
	// $data['product'] = $val['line_product'];
	// $data['person'] = base64_decode($val['line_person']);
}



function _getTime(){
	$current = date("Y-m-d H:i:s");  
	return $current;
}

// $now = date("Y-m-d H:i:s"); 
// if (_getTime() >= $now){
//  echo "true";
// }else{
//   echo "FAlse";
// }

// Array
// (
//     [Code] => HUAYLIKE
//     [Version] => V1
//     [Status] => RUN
//     [Timeout] => 2020-09-18 13:38:30
//     [Comment] => 
// )

?>

<!DOCTYPE html>
<html>
<head>
	<title>MONITOR</title>
	<link rel="stylesheet" type="text/css" href="assets/Semantic-UI-CSS/semantic.min.css">
	<script src="https://code.jquery.com/jquery-3.1.1.min.js"  integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="  crossorigin="anonymous"></script>
	<script src="assets/Semantic-UI-CSS/semantic.min.js"></script>
</head>
<body>
	<br><br>
	<div class="ui container">



		<div class="ui three column grid">



		<?php foreach ($data as $key => $val){ ?>
			<?php 
				if($val['Status'] == 'RUN'){
					$color = 'green';
				}else if($val['Status'] == 'OFFLINE'){
					$color = 'red';
				}
			?>

		  <div class="column">
		    <div class="ui fluid card">
		      <div class="image">
		        <img src="assets/icon/<?php echo $val['Code']; ?>.jpg">
		      </div>
		      <div class="content">
		        <a class="header"><?php echo substr($val['Code'],0,7).' ['.$val['Version'].']'; ?> <span style="float:right;color:<?php echo $color; ?>"><?php echo $val['Status']; ?></span></a>
		      </div>
		    <div class="content">
		      <!-- <a class="header">INFO</a> -->
		      <div class="meta">
		        <span class="date">อัพเดท : <?php echo $val['Timeout']; ?></span>
		      </div>
		      <div class="meta">
		        <span class="date">อยู่ <b><?php echo $val['Total']; ?></b> กลุ่ม | SPEED : <?php echo $val['Speed']; ?></span>
		      </div>		      
		    </div>
		    </div>
		  </div>


		  <?php } ?>



		</div>









	</div>


</body>
</html>

