<?php 
require('includes/header.php');  
?>	

<style>
.select2-container--default .select2-results__option[aria-disabled=true] {
    display: none;
}
</style>
<link href="//www.amcharts.com/lib/3/plugins/export/export.css" rel="stylesheet" type="text/css" />
<!--begin::Content-->
<div class="content d-flex flex-column flex-column-fluid" id="kt_content">
	<!--begin::Subheader-->
	<div class="subheader py-2 py-lg-4 subheader-solid" id="kt_subheader">
		<div class="container-fluid d-flex align-items-center justify-content-between flex-wrap flex-sm-nowrap">
			<!--begin::Info-->
			<div class="d-flex align-items-center flex-wrap mr-2">
				<!--begin::Page Title-->
				<h5 class="text-dark font-weight-bold mt-2 mb-2 mr-5">LAPORAN SEMAKAN STATUS PORTAL</h5>
				<!--end::Page Title-->
				<!--begin::Actions-->
				<div class="subheader-separator subheader-separator-ver mt-2 mb-2 mr-4 bg-gray-200"></div>
			</div>
			<!--end::Info-->
		</div>
	</div>
	<!--end::Subheader-->
	<!--begin::Entry-->
	<div class="d-flex flex-column-fluid">
		<!--begin::Container-->
		<div class="container">
			<div class="accordion accordion-solid accordion-panel accordion-svg-toggle" id="accordionExample8">
				<div class="card">
					<div class="card-header" id="headingThree8">
						<div class="card-title" data-toggle="" data-target="#collapseThree8">
							<div class="card-label">													
								<span class="svg-icon svg-icon-primary menu-icon">
									<?=$Tapisanhome_svg?>
								</span>Tapisan</div>
							<span class="svg-icon">
								<?=$Tapisan_svg?>
							</span>
						</div>
					</div>
					<div id="collapseThree8" class="" data-parent="#accordionExample8">
						<div class="card-body"><br>
							<form id="tapisan_form">
							<?php								
								$myArray = [];
								$myArray[] = array(1, 'PEMOHON WUJUD');
								$myArray[] = array(2, 'PEMOHON TIDAK WUJUD/BARU');
								createDropDown_Array('Jenis', $myArray, 'exist_sc', '0', 'Semua', 6, 3, 12, $readonly);		
								
								$mySQL = "SELECT id_program AS id, desk_program as name FROM i_program WHERE aktif = 1 ORDER BY susunan";	
								createDropDown_sql($PDO, 'Program', $mySQL, 'id_program', 0, 'Semua Program', 6, 3, 12, $readonly,'');
																
								echo '<div class="form-group m-form__group row col-md-12" id="tahun_semak_div">';
								echo '<label class="col-form-label col-md-3" id="tahun">Tahun</label>';
								createThn_simple('tahun_semak', date('Y'), false, 3, 0, 10, 0);
								echo '</div>';				
								
							?>
							</form>
							<div style="text-align:center">
								<input type="hidden" id="cetakInput">
								<input type="hidden" id="cetakInputValue">
								<button type="button" class="btn btn-primary mr-5" id="janaBtn">Jana Laporan</button>
								<button type="button" class="btn btn-primary mr-5" id="cetakStaBtn" style="display:none">Cetak Laporan</button>
							</div>
						</div>
					</div>
				</div>
			</div>				
			<div class="row" id="resultRow" style="display:none">
				<div class="col-lg-12">
					<!--begin::List Widget 11-->
					<div class="card card-custom card-stretch gutter-b">
						<!--begin::Header-->
						<div class="card-header border-0">
							<br>
						</div>
						<!--end::Header-->
						<!--begin::Body-->
						<div class="card-body pt-0">
							<div id="resultDiv"></div>
						</div>
						<!--end::Body-->
					</div>
					<!--end::List Widget 11-->
				</div>
			</div>
		</div>
		<!--end::Container-->
	</div>
	<!--end::Entry-->
</div>
<!--end::Content-->
					
<?php 
require('includes/footer.php');

$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);
?>

<script>

$(document).ready(function(){
	
	$('#exist_sc').change(function() {
		if($('#exist_sc').val() == 1)
		{
			$('#id_program_div').show();
		}
		else
		{
			$('#id_program_div').hide();
			$('#id_program_sc').val(0);
			$('#id_program_sc').trigger('change');
		}
	});
	$('#exist_sc').trigger('change');

	$('#ajax-modal').on('shown.bs.modal', function () {  // this is to clear modal cache each time modal load
	 $(this).removeData('bs.modal');
	}); 
	
	//print function
	$('#printExcel, #printPdf').click(function() {
		printFunc($('#table_name').val(), $(this).attr("value"), "normalPrint.php", $('#script_base_name').val(), $('#table_title').val(), $('#table_header').val());
	});	
	
	$('#janaBtn').click(function() {
		$('#resultRow').show();
		$('#janaBtn').html("LOADING...");
		$('#janaBtn').addClass('disabled');
		$('#resultDiv').html("Sedang Jana Laporan ...");
		var param = $('#tapisan_form').serialize();
		
		$.ajax({
		   type: "POST",
		   url: "la_semak-check.php",
		   data: param,
		   success: function(res){
				$('#resultDiv').html(res);
				$('#janaBtn').html("Jana Laporan");
				$('#janaBtn').removeClass('disabled');
				
			    var cetakInput = 'Laporan Semakan Status Portal';
				cetakInput += '|BRE|' + $("#exist_sc option:selected").text();
				cetakInput += '|BRE|' + $("#id_program option:selected").text();
				cetakInput += '|BRE|' + $("#tahun_semak_year option:selected").text();
				
			    var cetakInputValue = 'Laporan Semakan Status Portal';
				cetakInputValue += '|BRE|' + $("#exist_sc").val();
				cetakInputValue += '|BRE|' + $("#id_program").val();
				cetakInputValue += '|BRE|' + $("#tahun_semak_year").val();
				
			    $('#cetakInput').val(cetakInput);
			    $('#cetakInputValue').val(cetakInputValue);
				$('#cetakStaBtn').show();	
		   }
		});
	});
	
	$('#cetakStaBtn').click(function(){
		var allTable = document.getElementsByClassName("statTable");
		console.log(allTable);
		if(allTable.length > 0)
		{
			var dataObject = [];
			//dataObject['title'] = $('#' + allTable[0].id + '_title').html();
			dataObject['kriteria'] = $('#cetakInput').val();
			dataObject['allTable'] = '';
			for(var i=0; i < allTable.length; i+=1)
			{
				var tableId = allTable[i].id;
				//alert(tableId);
				var table = $("#" + tableId);
				var data = [];
				data.push($("#" + tableId + '_title').html());
				table.find('tr').each(function (rowIndex, r) 
				{
					var cols = [];
					$(this).find('th,td').each(function (colIndex, c) {
					cols.push(c.textContent);
					});
					data.push(cols.join('|'));
					//alert(cols);
				});
				dataObject[tableId] = data.join('|BRE|');
				dataObject['allTable'] += tableId + ',';
				//alert(data.join('<BR>'));
			}
			console.log(dataObject);
			post($('#script_base_name').val() + '-print.php', dataObject);
		}
		else
		{
			alert("Sila Jana Statistik dahulu sebelum cetak");
		}
	});
});
</script>