<?php

include_once ("includes/setup.inc.php");

//Header("Content-type: application/xml");
Header("Cache-Control: no-cache");

$num_errors = 0;

$exist_sc = fetch_postget_val("exist_sc", $_POST, $_GET);
$id_program = fetch_postget_val("id_program", $_POST, $_GET);
$tahun_semak_year = fetch_postget_val("tahun_semak_year", $_POST, $_GET);

$query = "SELECT MONTH(tkh_keyin) AS month_log, count(id_semaklog) AS total
				FROM s_semaklog
				WHERE tkh_keyin BETWEEN ? AND ?";

if($exist_sc > 0)
{
	$jenis = ($exist_sc==1)?'1':'0';
	$query .= " AND flag_exist = '".$jenis."'";		
}

if($id_program > 0)
{
	$query .= ' AND id_program = '.$id_program;				
}

$query .= " GROUP BY MONTH(tkh_keyin)";

$PDO_stmt = $PDO->prepare($query);

$PDO_stmt->bindValue(1, $tahun_semak_year.'-01-01 00:00:00', PDO::PARAM_STR);
$PDO_stmt->bindValue(2, $tahun_semak_year.'-12-31 23:59:59', PDO::PARAM_STR);
$PDO_stmt->execute();
$login_month = [];
while($res = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
{
	$login_month[$res['month_log']] += $res['total'];
}

$name = "statTable_all";
$title = "Laporan Semakan Status Portal";

echo '<h4><label id="'.$name.'_title">'.$title.'</label></h4>';
echo '<div class="table-responsive">';
echo '<table class="table table-striped table-bordered table-hover statTable" id="'.$name.'" name="'.$name.'" style="text-align:center">';
	echo '<thead>';
		echo '<tr>';
			echo '<td>Jumlah / Bulan</td>';
			for($num = 1; $num <= 12; $num++)
			{
				echo '<td>'.monthToMalayShort($num).'</td>';
			}
			echo '<td>Jumlah</td>';
		echo '</tr>';
	echo '</thead>';
	echo '<tbody>';
		echo '<tr style="font-weight:bold">';
			echo '<td>Jumlah Keseluruhan</td>';
			$jumlah = 0;
			for($num = 1; $num <= 12; $num++)
			{
				echo '<td>'.($login_month[$num]>0?$login_month[$num]:0).'</td>';
				$jumlah += $login_month[$num];
			}
			echo '<td>'.($jumlah).'</td>';
		echo '</tr>';
	echo '</tbody>';
	echo '</table>';
echo '</div>';

?>