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

$indicator_Query = "SELECT A.*
				  FROM i_program A
				  WHERE A.id_program = ?";
$PDO_stmt = $PDO->prepare($indicator_Query);
$PDO_stmt->bindValue(1, $id_program, PDO::PARAM_INT);
$PDO_stmt->execute();
$program_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

if($flow_type == 1)
{
	$header_title = 'Penerimaan Dokumen';
	$table_info = 'Penerimaan dokumen dan lampiran permohonan';
}
else if($flow_type == 2)
{
	$header_title = 'Pengesahan Permohonan';
	$table_info = 'Semakan dan Pengesahan Permohonan';
}
else if($flow_type == 3)
{
	$header_title = 'Senarai Pemohon';
	$table_info = 'Senarai Keseluruhan Permohonan Program';	
}

?>	

<!--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"><?=$header_title?> : PROGRAM <?=$program_List['desk_program']?></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">
			<!--begin::Dashboard--> 
			<!--begin::Row-->
			<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 collapsed" data-toggle="collapse" 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="collapse" data-parent="#accordionExample8">					
						<div class="row">
							<div class="col-md-6">
								<div class="card-body"><br>
									<?php
										createDropDown($PDO, 'Parlimen', 'i_parlimen', 'parlimen_sc', $my_details->user_parlimen, 'Semua Parlimen', 8, 3, 12, $readonly);
										createDropDown($PDO, 'Daerah', 'i_daerah', 'daerah_sc', $my_details->user_daerah, 'Semua Daerah', 8, 3, 12, $readonly);
										createDropDown($PDO, 'DUN', 'i_dun', 'dun_sc', $my_details->user_dun, 'Semua DUN', 8, 3, 12, $readonly);
										//createDropDown($PDO, 'Bangsa', 'i_bangsa', 'bangsa_sc', '', 'Semua Bangsa', 8, 3, 12, $readonly);
										createDropDown($PDO, 'Poskod', 'i_poskod', 'poskod_sc', '', 'Semua Poskod', 8, 3, 12, $readonly);
									?>
								</div>
							</div>
							<div class="col-md-6">
								<div class="card-body"><br>
									<?php
										createDropDown($PDO, 'Cara Mohon', 'i_caramohon', 'caramohon_sc', '', 'Semua Cara Mohon', 8, 3, 12, $readonly);
										createDropDown($PDO, 'Cara Bayar', 'i_carabayar', 'carabayar_sc', '', 'Semua Cara Bayar', 8, 3, 12, $readonly);
										
										if($flow_type == 3)
										{
											$myArray = [];
											$myArray[] = array(1, 'BELUM DISAHKAN');
											$myArray[] = array(2, 'TELAH DISAHKAN');
											createDropDown_Array('Pengesahan EFT', $myArray, 'saheft_sc', '', 'Semua', 8, 3, 12, $readonly);
										}
									?>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>  
			<!--begin::Row-->
			<div class="row">
				<?php
					if($flow_type == 1)
					{
						$tbColumn = array();
						$tbColumn[] = array('Bil', 10);
						$tbColumn[] = array('Nama Pemohon', 30);
						$tbColumn[] = array('No KP', 20);
						$tbColumn[] = array('Tarikh Hantar', 20);
						$tbColumn[] = array('Cara Mohon', 20);
						$tbColumn[] = array('Tindakan', 0);
					}
					else if($flow_type == 2)
					{
						$tbColumn = array();
						$tbColumn[] = array('Bil', 10);
						$tbColumn[] = array('Nama Pemohon', 30);
						$tbColumn[] = array('No KP', 20);
						$tbColumn[] = array('Tarikh Hantar', 20);
						$tbColumn[] = array('Cara Mohon', 20);
						$tbColumn[] = array('Tindakan', 0);
						
						//column name, width(for pdf)
						$printOnlyTbColumn = array();
						$printOnlyTbColumn[] = array('Cara Bayar', 10);
						$printOnlyTbColumn[] = array('DUN', 10);
						$printOnlyTbColumn[] = array('Parlimen', 10);
					}
					else if($flow_type == 3)
					{
						$tbColumn = array();
						$tbColumn[] = array('Bil', 10);
						$tbColumn[] = array('Nama Pemohon', 30);
						$tbColumn[] = array('No KP', 20);
						$tbColumn[] = array('Tarikh Hantar', 20);
						$tbColumn[] = array('Cara Mohon', 20);
						$tbColumn[] = array('Cara Bayar', 20);
						$tbColumn[] = array('Tindakan', 0);
					}
					
					$userBtn = '';
					createTable('program_table', $tbColumn, $header_title.' : PROGRAM '.$program_List['desk_program'], $table_info, 1, $userBtn, 'ajax-modal', 12);
					
					echo '<input type="hidden" id="table_printonly_header" value=\''.json_encode($printOnlyTbColumn).'\'/>';
				?>
				
			</div>
			<!--end::Row-->
			<!--end::Dashboard-->
		</div>
		<!--end::Container-->
	</div>
	<!--end::Entry-->
</div>
<!--end::Content-->
					
<?php 
require('includes/footer.php');
?>


<script>
function paparBorang(pemohon, typeBorang)
{
	var dataOption = [];
	dataOption.readonly = 1;
	dataOption.pemohon = pemohon;
	
	post("p" + typeBorang + "_borang.php", dataOption);
}

function editBorang(pemohon, typeBorang)
{
	var dataOption = [];
	dataOption.readonly = 0;
	dataOption.pemohon = pemohon;
	
	post("p" + typeBorang + "_borang.php", dataOption);
}

var ajaxUrl = "general-list_ajax.php";
function getData()
{
	return {
		sqlOnly: 0,
		program: "<?=$id_program?>",
		flow_type: "<?=$flow_type?>",
		dun_sc: $('#dun_sc').val(),
		parlimen_sc: $('#parlimen_sc').val(),
		daerah_sc: $('#daerah_sc').val(),
		bangsa_sc: $('#bangsa_sc').val(),
		poskod_sc: $('#poskod_sc').val(),
		caramohon_sc: $('#caramohon_sc').val(),
		carabayar_sc: $('#carabayar_sc').val(),
		saheft_sc: $('#saheft_sc').val(),
	};
}

function reloadTable()
{
	reinitTable($('#table_name').val(), this.ajaxUrl, this.getData(), 3, 0);
}

$(document).ready(function(){  

	$('#ajax-modal').on('shown.bs.modal', function () {  // this is to clear modal cache each time modal load
	 $(this).removeData('bs.modal');
	}); 
	
	initTable($('#table_name').val(), ajaxUrl, getData(), 3, 0);
	
	//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(), getData(), $('#table_printonly_header').val());
	});
	
	$('#dun_sc,#parlimen_sc,#daerah_sc,#bangsa_sc,#caramohon_sc,#carabayar_sc,#saheft_sc,#poskod_sc').change(function(){
		reloadTable();
	});
});
</script>