<?php
header('Content-type: application/json');
include '../config/database.php';
function _status(){
	$conn = _connectDB();
	$sql = "SELECT SCode,Code,Version FROM monitor WHERE Status != 'EXIT' AND Counter > 5 ORDER BY Code ASC";
	$result = $conn->query($sql);
	$data = '';
	$total = 0;
	if ($result->num_rows > 0) {
	    $data = ":: Active BOT ::\n-------------";
	    while($row = $result->fetch_assoc()) {
	    	if($row['Code'] == 'HUAY'){
	    		$sql_c = "SELECT groupline.groupline_id FROM groupline WHERE (groupline_products='HUAYNORMAL' OR groupline_products='HUAYVIP' OR groupline_products='HUAYNORMALVIP') AND  groupline_access='active' AND groupline_version = '".$row['Version']."'";
				}else if($row['Code'] == 'MAWIN' || $row['Code'] == '1000LOTTO' || $row['Code'] == 'DEEWOW' || $row['Code'] == 'CALJET' || $row['Code'] == 'LOTTOVIP' || $row['Code'] == 'PARUAY999' || $row['Code'] == 'TANGTOOK' || $row['Code'] == 'MOO999' || $row['Code'] == 'LnwLOTTO' || $row['Code'] == 'STOCK_JET' || $row['Code'] == 'STOCK_MAWIN' || $row['Code'] == 'STOCK_PARUAY' || $row['Code'] == 'STOCK_HUAY' || $row['Code'] == 'STOCKDEEWOW' || $row['Code'] == 'STOCK' || $row['Code'] == 'CALHUAY' || $row['Code'] == 'CHOKE77' || $row['Code'] == 'NON111' || $row['Code'] == 'HOY111' || $row['Code'] == 'YIKEEVIP'){
		    		$sql_c = "SELECT groupline.groupline_id FROM groupline WHERE groupline_products='".$row['Code']."' AND  groupline_access='active' AND groupline_version = '".$row['Version']."'";
				}else{
		    		$sql_c = "SELECT groupline.groupline_id FROM groupline WHERE (groupline_products='HUAYNORMAL' OR groupline_products='HUAYVIP' OR groupline_products='HUAYNORMALVIP') AND  groupline_access='active' AND groupline_version = '".$row['Version']."'";
				}
	    	$result_c = $conn->query($sql_c);
			  $row_c = $result_c->num_rows;
	    	$data = $data."\n".$row['SCode'].':'.$row['Version'].'['.$row_c.']';
				$total =$total+$row_c;
	    }
	} else {
	    echo "";
	}
 $data=$data."\n"."[----TOTAL----]\n"."จำนวน ".$total." ตัว";
	return $data;
}
echo _status();
