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

$my_dun = $my_details->user_dun;
$my_parlimen = $my_details->user_parlimen;
$my_daerah = $my_details->user_daerah;

if(in_array($my_details->user_level, array(1,3,2,4,6,8,15,5,7,9,16)))
{
	$new_title = '';
	$listid_statusmohon = "";	
	$listid_program = "";	
	$listid_dun = "";	
	$listid_parlimen = "";	
	$listid_daerah = "";

	if(in_array($my_details->user_level, array(1,3)))
	{
		$new_title = 'PENERIMAAN DAN PENGESAHAN PERMOHONAN SECARA DALAM TALIAN';
		$listid_statusmohon = "A.id_statusmohon IN (2,3)";
		$listid_program = "AND A.id_program IN (1,2,4,7)";	
	}
	else if(in_array($my_details->user_level, array(2,4,6,8,15)))
	{
		$new_title = 'PENERIMAAN PERMOHONAN SECARA DALAM TALIAN';
		$listid_statusmohon = "A.id_statusmohon IN (2)";
		
		if(in_array($my_details->user_level, array(2,4)))	
		{
			$listid_program = "AND A.id_program IN (1,2)";	
			$listid_daerah = "AND B.id_daerah = $my_daerah";
		}
		else if(in_array($my_details->user_level, array(6)))
		{
			$listid_program = "AND A.id_program IN (1,2,7)";	
			$listid_dun = "AND A.id_dun = $my_dun";
		}
		else if(in_array($my_details->user_level, array(8)))
		{
			$listid_program = "AND A.id_program IN (4)";	
			$listid_daerah = "AND B.id_daerah = $my_daerah";		
		}
		else if(in_array($my_details->user_level, array(15)))
		{
			$listid_program = "AND A.id_program IN (1,2,7)";	
			$listid_parlimen = "AND B.id_parlimen = $my_parlimen";		
		}
	}
	else if(in_array($my_details->user_level, array(5,7,9,16)))
	{
		$new_title = 'PENGESAHAN PERMOHONAN SECARA DALAM TALIAN';
		$listid_statusmohon = "A.id_statusmohon IN (3)";
		
		if(in_array($my_details->user_level, array(5)))	
		{
			$listid_program = "AND A.id_program IN (1,2)";	
			$listid_daerah = "AND B.id_daerah = $my_daerah";
		}
		else if(in_array($my_details->user_level, array(7)))
		{
			$listid_program = "AND A.id_program IN (1,2,7)";	
			$listid_dun = "AND A.id_dun = $my_dun";
		}
		else if(in_array($my_details->user_level, array(9)))
		{
			$listid_program = "AND A.id_program IN (4)";	
			$listid_daerah = "AND B.id_daerah = $my_daerah";		
		}
		else if(in_array($my_details->user_level, array(16)))
		{
			$listid_program = "AND A.id_program IN (1,2,7)";	
			$listid_parlimen = "AND B.id_parlimen = $my_parlimen";		
		}	
	}

	$indicator_Query = "SELECT COUNT(A.id_pemohon) as bilnewapp
					  FROM m_pemohon A
					  LEFT JOIN i_dun B ON B.id_dun = A.id_dun
					  WHERE $listid_statusmohon
					  AND A.id_statushidup = 1
					  AND A.id_aktifmohon = 1
					  AND A.id_carahantar = 2 $listid_program $listid_dun $listid_daerah $listid_parlimen";
	$PDO_stmt = $PDO->prepare($indicator_Query); 
	$PDO_stmt->execute();
	$bilnewapp_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
}

if(in_array($my_details->user_level, array(1,3,2,5)))
{	
	$listid_program = "AND A.id_program IN (1,2,7)";
	$listid_daerah = "";
	
	if(in_array($my_details->user_level, array(2,5)))
	{	
		$listid_daerah = "AND B.id_daerah = $my_daerah";	
	}

	$indicator_Query = "SELECT COUNT(A.id_pemohon) as bilneweftapp
					  FROM m_pemohon A
					  LEFT JOIN i_dun B ON B.id_dun = A.id_dun
					  WHERE A.id_statushidup = 1
					  AND A.id_aktifmohon = 1
					  AND A.id_statusmohon = 4
					  AND (A.id_carabayar = 2 OR A.id_byrkepada = 2)
					  AND A.flag_saheft = 0
					  AND A.id_carahantar = 2 $listid_program $listid_daerah";
	$PDO_stmt = $PDO->prepare($indicator_Query); 
	$PDO_stmt->execute();
	$bilneweftapp_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
}

if(in_array($my_details->user_level, array(1,3,2,4,5)))
{
	$newae_title = '';
	$listaeid_statusmohon = "";	
	$listaeid_daerah = "";

	if(in_array($my_details->user_level, array(1,3)))
	{
		$newae_title = 'PENERIMAAN DAN PENGESAHAN PERMOHONAN SECARA DALAM TALIAN';
		$listaeid_statusmohon = "A.id_statusmohon IN (2,3)";
	}
	else if(in_array($my_details->user_level, array(2,4)))
	{
		$newae_title = 'PENERIMAAN PERMOHONAN SECARA DALAM TALIAN';
		$listaeid_statusmohon = "A.id_statusmohon IN (2)";
		$listaeid_daerah = "AND C.id_daerah = $my_daerah";
	}
	else if(in_array($my_details->user_level, array(5)))
	{
		$newae_title = 'PENGESAHAN PERMOHONAN SECARA DALAM TALIAN';
		$listaeid_statusmohon = "A.id_statusmohon IN (3)";
		$listaeid_daerah = "AND C.id_daerah = $my_daerah";
	}

	$indicator_Query = "SELECT COUNT(A.id_anakemas) as bilnewaeapp
					  FROM m_anakemas A
					  LEFT JOIN m_pemohon B ON B.id_pemohon = A.id_pemohon
					  LEFT JOIN i_dun C ON C.id_dun = B.id_dun
					  WHERE $listaeid_statusmohon
					  AND A.id_carahantar = 2 $listaeid_daerah";
	$PDO_stmt = $PDO->prepare($indicator_Query); 
	$PDO_stmt->execute();
	$bilnewaeapp_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
}

$indicator_Query = "SELECT COUNT(A.id_pemohon) as bilquery
				  FROM m_pemohon A
				  WHERE A.id_terima = ?
				  AND A.id_statusmohon = 2
				  AND A.ulasan_sah != ''";
$PDO_stmt = $PDO->prepare($indicator_Query); 
$PDO_stmt->bindValue(1, $my_details->usr_id, PDO::PARAM_INT);
$PDO_stmt->execute();
$bilquery_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$indicator_Query = "SELECT COUNT(A.id_anakemas) as bilqueryae
				  FROM m_anakemas A
				  WHERE A.id_terima = ?
				  AND A.id_statusmohon = 2
				  AND A.ulasan_sah != ''";
$PDO_stmt = $PDO->prepare($indicator_Query); 
$PDO_stmt->bindValue(1, $my_details->usr_id, PDO::PARAM_INT);
$PDO_stmt->execute();
$bilqueryae_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$indicator_Query = "SELECT COUNT(A.id_pemohon) as bilkhairat
				  FROM m_pemohon A
				  WHERE A.id_keyinmati = ?
				  AND A.id_sahmati = 1
				  AND A.flag_querymati = 1";
$PDO_stmt = $PDO->prepare($indicator_Query); 
$PDO_stmt->bindValue(1, $my_details->usr_id, PDO::PARAM_INT);
$PDO_stmt->execute();
$bilkhairat_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$indicator_Query = "SELECT COUNT(A.id_pengguna) as bil
				  FROM t_pengguna A
				  WHERE A.aktif = 4";
$PDO_stmt = $PDO->prepare($indicator_Query); 
$PDO_stmt->execute();
$countbaru_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

$hyperlink = '';
$value = 0;
if($countbaru_List['bil'] > 0)
{
	$hyperlink = '?type=4';
	$value = $countbaru_List['bil'];	
}

$indicator_Query = "SELECT COUNT(A.id_aduan) as bil
				  FROM m_aduan A
				  WHERE A.id_statusaduan = 1";
$PDO_stmt = $PDO->prepare($indicator_Query); 
$PDO_stmt->execute();
$aduan_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);

if($my_details->user_level != 1 && $my_details->user_level != 3)
{
	$indicator_Query = "SELECT COUNT(A.id_aduan) as bil
				  FROM m_aduan A
				  WHERE A.id_statusaduan = 1
				  AND A.id_assign = ?";
	$PDO_stmt = $PDO->prepare($indicator_Query); 
	$PDO_stmt->bindValue(1, $my_details->usr_id, PDO::PARAM_INT);
	$PDO_stmt->execute();
	$aduan_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);	
}

$hyperlink1 = '';
$value1 = 0;
if($aduan_List['bil'] > 0)
{
	$hyperlink1 = '?type=4';
	$value1 = $aduan_List['bil'];	
}
?>	

<!--begin::Content-->
<div class="content d-flex flex-column flex-column-fluid" id="kt_content">
	<!--begin::Entry-->
	<div class="d-flex flex-column-fluid">
		<!--begin::Container-->
		<div class="container">
			<?php
			if($bilnewapp_List['bilnewapp'] > 0)
			{
			?>
			<div class="accordion accordion-solid accordion-panel accordion-svg-toggle" id="p_accordionExample99">
				<div class="card">
					<div class="card-header" id="p_headingThree99">
						<div class="card-title collapsed" data-toggle="collapse" data-target="#p_collapseThree99">
							<div class="card-label">													
								<span class="svg-icon svg-icon-primary menu-icon">
									<?=$Tapisanhome_svg?>
								</span>Program Utama : TERDAPAT (<?=$bilnewapp_List['bilnewapp']?>) MEMERLUKAN <?=$new_title?></div>
							<span class="svg-icon">
								<?=$Tapisan_svg?>
							</span>
						</div>
					</div>
					<div id="p_collapseThree99" class="collapse" data-parent="#p_accordionExample99">					
						<div class="row">
							<div class="col-md-12">
								<div class="card-body">
									<?php
										$indicator_Query = "SELECT A.*, C.desk_program, D.desk_statusmohon
														  FROM m_pemohon A
														  LEFT JOIN i_dun B ON B.id_dun = A.id_dun
														  LEFT JOIN i_program C ON C.id_program = A.id_program
														  LEFT JOIN i_statusmohon D ON D.id_statusmohon = A.id_statusmohon
														  WHERE $listid_statusmohon
														  AND A.id_statushidup = 1
														  AND A.id_aktifmohon = 1
														  AND A.id_carahantar = 2 $listid_program $listid_dun $listid_daerah $listid_parlimen";
										$PDO_stmt = $PDO->prepare($indicator_Query);
										$PDO_stmt->execute();

										$query_List = array();
										while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
										{
											$query_List[] = $result;
										}
									?>										
										
									<div class="table-responsive">
									<table class="table table-separate table-head-custom table-checkable">
										<thead>
											<tr>
												<th>Bil</th>
												<th>Tindakan</th>
												<th>Nama Pemohon</th>
												<th>No KP Baru</th>
												<th>No Telefon</th>
												<th>Program</th>
												<th>Status Permohonan</th>
											</tr>
										</thead>
										<tbody>	
										<?php
											for($num = 0; $num < count($query_List); $num++)
											{		
												$id_program = $query_List[$num]['id_program'];
												
												$name_id_program = $id_program;
												if ($id_program < 10 && (!(substr($id_program, 0, 1) === '0')))
												{
													$name_id_program = '0'.$id_program;
												}	

												$tel_rumah = '';
												if($query_List[$num]['tel_rumah'] != '')
												{
													$tel_rumah = '/'.$query_List[$num]['tel_rumah'];													
												}
												
												$penerimaan = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-terima_tind.php?id='.$query_List[$num]['id_pemohon'].'&program='.$query_List[$num]['id_program'].'&pass=1\', \'#ajax-modal\')" title="Penerimaan Permohonan"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Check_svg.'</span></a>';
												
												$pengesahan = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-sah_tind.php?id='.$query_List[$num]['id_pemohon'].'&program='.$query_List[$num]['id_program'].'&pass=1\', \'#ajax-modal\')" title="Pengesahan Permohonan"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Check_svg.'</span></a>';
												
												if($query_List[$num]['id_statusmohon'] == 2)
												{
													$link_newapp = $penerimaan;
												}
												else
												{
													$link_newapp = '-';
													
													$indicator_Query = "SELECT A.*
																  FROM t_pengguna A
																  WHERE A.id_pengguna = ?";
													$PDO_stmt = $PDO->prepare($indicator_Query); 
													$PDO_stmt->bindValue(1, $query_List[$num]['id_terima'], PDO::PARAM_INT);
													$PDO_stmt->execute();
													$penggunaterima_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
													
													if($my_dun == $penggunaterima_List['id_dun'] || $my_parlimen == $penggunaterima_List['id_parlimen'] || $my_daerah == $penggunaterima_List['id_daerah'])
													{
														$link_newapp = $pengesahan;
													}
												}
												
												echo '<tr>';
													echo '<td>'.($num + 1).'.</td>';
													echo '<td>'.$link_newapp.'</td>';
													echo '<td><a href="javascript:;" onclick="loadMyModal(\'general-maklumat.php?id='.$query_List[$num]['id_pemohon'].'&program='.$query_List[$num]['id_program'].'\', \'#ajax-modal\')" title="Maklumat Pemohon">'.$query_List[$num]['nama_pemohon'].'</a></td>';
													echo '<td>'.$query_List[$num]['kpbaru_pemohon'].'</td>';
													echo '<td>'.$query_List[$num]['tel_hp'].''.$tel_rumah.'</td>';
													echo '<td>'.$query_List[$num]['desk_program'].'</td>';
													echo '<td>'.$query_List[$num]['desk_statusmohon'].'</td>';
												echo '</tr>';
											}
										?>
										</tbody>
									</table>
									</div>
									
								</div>
							</div>
						</div>
					</div>
				</div>
			</div><br> 			
			<?php
			}	

			if($bilneweftapp_List['bilneweftapp'] > 0)
			{
			?>
			<div class="accordion accordion-solid accordion-panel accordion-svg-toggle" id="p_accordionExample97">
				<div class="card">
					<div class="card-header" id="p_headingThree97">
						<div class="card-title collapsed" data-toggle="collapse" data-target="#p_collapseThree97">
							<div class="card-label">													
								<span class="svg-icon svg-icon-primary menu-icon">
									<?=$Tapisanhome_svg?>
								</span>Program Utama : TERDAPAT (<?=$bilneweftapp_List['bilneweftapp']?>) MEMERLUKAN PENGESAHAN EFT - PERMOHONAN DALAM TALIAN</div>
							<span class="svg-icon">
								<?=$Tapisan_svg?>
							</span>
						</div>
					</div>
					<div id="p_collapseThree97" class="collapse" data-parent="#p_accordionExample97">					
						<div class="row">
							<div class="col-md-12">
								<div class="card-body">
									<?php
										$indicator_Query = "SELECT A.*, C.desk_program, D.desk_bank
														  FROM m_pemohon A
														  LEFT JOIN i_dun B ON B.id_dun = A.id_dun
														  LEFT JOIN i_program C ON C.id_program = A.id_program
														  LEFT JOIN i_bank D ON D.id_bank = A.id_bank
														  WHERE A.id_statushidup = 1
														  AND A.id_aktifmohon = 1
														  AND A.id_statusmohon = 4
														  AND (A.id_carabayar = 2 OR A.id_byrkepada = 2)
														  AND A.flag_saheft = 0
														  AND A.id_carahantar = 2 $listid_program $listid_daerah";
										$PDO_stmt = $PDO->prepare($indicator_Query);
										$PDO_stmt->execute();

										$query_List = array();
										while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
										{
											$query_List[] = $result;
										}
									?>										
										
									<div class="table-responsive">
									<table class="table table-separate table-head-custom table-checkable">
										<thead>
											<tr>
												<th>Bil</th>
												<th>Tindakan</th>
												<th>Nama Pemohon</th>
												<th>No KP Baru</th>
												<th>No Telefon</th>
												<th>Program</th>
												<th>Bank</th>
												<th>No Akaun</th>
												<th>Status Permohonan</th>
											</tr>
										</thead>
										<tbody>	
										<?php
											for($num = 0; $num < count($query_List); $num++)
											{	
												$bank_pemohon = $query_List[$num]['desk_bank'];
												$akaun_pemohon = $query_List[$num]['no_akaun'];	

												if($query_List[$num]['id_byrkepada'] == 2)
												{
													$indicator_Query = "SELECT A.id_pemohon, A.nama_waris, A.id_bankwaris, A.no_akaunwaris, B.desk_bank
																	  FROM m_waris A
																	  LEFT JOIN i_bank B ON B.id_bank = A.id_bankwaris
																	  WHERE A.id_pemohon = ?
																	  AND A.status = 1";
													$PDO_stmt = $PDO->prepare($indicator_Query);
													$PDO_stmt->bindValue(1, $query_List[$num]['id_pemohon'], PDO::PARAM_STR);
													$PDO_stmt->execute();
													$waris_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
													
													$bank_pemohon = 'WARIS - '.$waris_List['nama_waris'].'<br>'.$waris_List['desk_bank'];
													$akaun_pemohon = $waris_List['no_akaunwaris'];														
												}
												
												$id_program = $query_List[$num]['id_program'];
												
												$name_id_program = $id_program;
												if ($id_program < 10 && (!(substr($id_program, 0, 1) === '0')))
												{
													$name_id_program = '0'.$id_program;
												}	

												$tel_rumah = '';
												if($query_List[$num]['tel_rumah'] != '')
												{
													$tel_rumah = '/'.$query_List[$num]['tel_rumah'];													
												}
												
												$pengesahaneft = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-sah_eft.php?id='.$query_List[$num]['id_pemohon'].'&program='.$query_List[$num]['id_program'].'&pass=1\', \'#ajax-modal\')" title="Pengesahan EFT"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Check_svg.'</span></a>';
												
												echo '<tr>';
													echo '<td>'.($num + 1).'.</td>';
													echo '<td>'.$pengesahaneft.'</td>';
													echo '<td><a href="javascript:;" onclick="loadMyModal(\'general-maklumat.php?id='.$query_List[$num]['id_pemohon'].'&program='.$query_List[$num]['id_program'].'\', \'#ajax-modal\')" title="Maklumat Pemohon">'.$query_List[$num]['nama_pemohon'].'</a></td>';
													echo '<td>'.$query_List[$num]['kpbaru_pemohon'].'</td>';
													echo '<td>'.$query_List[$num]['tel_hp'].''.$tel_rumah.'</td>';
													echo '<td>'.$query_List[$num]['desk_program'].'</td>';
													echo '<td>'.$bank_pemohon.'</td>';
													echo '<td>'.$akaun_pemohon.'</td>';
													echo '<td>DISAHKAN (PENGESAHAN EFT)</td>';
												echo '</tr>';
											}
										?>
										</tbody>
									</table>
									</div>
									
								</div>
							</div>
						</div>
					</div>
				</div>
			</div><br> 			
			<?php
			}				
			
			if($bilnewaeapp_List['bilnewaeapp'] > 0)
			{
			?>
			<div class="accordion accordion-solid accordion-panel accordion-svg-toggle" id="p_accordionExample98">
				<div class="card">
					<div class="card-header" id="p_headingThree98">
						<div class="card-title collapsed" data-toggle="collapse" data-target="#p_collapseThree98">
							<div class="card-label">													
								<span class="svg-icon svg-icon-primary menu-icon">
									<?=$Tapisanhome_svg?>
								</span>Program Anak Emas : TERDAPAT (<?=$bilnewaeapp_List['bilnewaeapp']?>) MEMERLUKAN <?=$newae_title?></div>
							<span class="svg-icon">
								<?=$Tapisan_svg?>
							</span>
						</div>
					</div>
					<div id="p_collapseThree98" class="collapse" data-parent="#p_accordionExample98">					
						<div class="row">
							<div class="col-md-12">
								<div class="card-body">
									<?php
										$indicator_Query = "SELECT A.*, B.nama_pemohon, B.tel_hp, B.tel_rumah, D.desk_statusmohon
														  FROM m_anakemas A
														  LEFT JOIN m_pemohon B ON B.id_pemohon = A.id_pemohon
														  LEFT JOIN i_dun C ON C.id_dun = B.id_dun
														  LEFT JOIN i_statusmohon D ON D.id_statusmohon = A.id_statusmohon
														  WHERE $listaeid_statusmohon
														  AND A.id_carahantar = 2 $listaeid_daerah";
										$PDO_stmt = $PDO->prepare($indicator_Query);
										$PDO_stmt->execute();

										$query_List = array();
										while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
										{
											$query_List[] = $result;
										}
									?>										
										
									<div class="table-responsive">
									<table class="table table-separate table-head-custom table-checkable">
										<thead>
											<tr>
												<th>Bil</th>
												<th>Tindakan</th>
												<th>Nama Anak Emas</th>
												<th>No KP Baru</th>
												<th>Nama Ibu/Bapa</th>
												<th>No Telefon</th>
												<th>Status Permohonan</th>
											</tr>
										</thead>
										<tbody>	
										<?php
											for($num = 0; $num < count($query_List); $num++)
											{		
												$id_program = $query_List[$num]['id_program'];
												
												$name_id_program = $id_program;
												if ($id_program < 10 && (!(substr($id_program, 0, 1) === '0')))
												{
													$name_id_program = '0'.$id_program;
												}	

												$tel_rumah = '';
												if($query_List[$num]['tel_rumah'] != '')
												{
													$tel_rumah = '/'.$query_List[$num]['tel_rumah'];													
												}
												
												$penerimaan = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-terima_tind_sub.php?id='.$query_List[$num]['id_anakemas'].'&program=5&pass=1\', \'#ajax-modal\')" title="Penerimaan Permohonan"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Check_svg.'</span></a>';
												
												$pengesahan = '<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-sah_tind_sub.php?id='.$query_List[$num]['id_anakemas'].'&program=5&pass=1\', \'#ajax-modal\')" title="Pengesahan Permohonan"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Check_svg.'</span></a>';
												
												if($query_List[$num]['id_statusmohon'] == 2)
												{
													$linkae_newapp = $penerimaan;
												}
												else
												{
													$linkae_newapp = '-';
													
													$indicator_Query = "SELECT A.*
																  FROM t_pengguna A
																  WHERE A.id_pengguna = ?";
													$PDO_stmt = $PDO->prepare($indicator_Query); 
													$PDO_stmt->bindValue(1, $query_List[$num]['id_terima'], PDO::PARAM_INT);
													$PDO_stmt->execute();
													$penggunaterima_List = $PDO_stmt->fetch(PDO::FETCH_ASSOC);
													
													if($my_daerah == $penggunaterima_List['id_daerah'])
													{
														$linkae_newapp = $pengesahan;
													}
												}
												
												echo '<tr>';
													echo '<td>'.($num + 1).'.</td>';
													echo '<td>'.$linkae_newapp.'</td>';
													echo '<td><a href="javascript:;" onclick="loadMyModal(\'general-maklumat_sub.php?id='.$query_List[$num]['id_anakemas'].'&program=5\', \'#ajax-modal\')" title="Maklumat Anak Emas">'.$query_List[$num]['nama_anakemas'].'</a></td>';
													echo '<td>'.$query_List[$num]['kpbaru_anakemas'].'</td>';
													echo '<td>'.$query_List[$num]['nama_pemohon'].'</td>';
													echo '<td>'.$query_List[$num]['tel_hp'].''.$tel_rumah.'</td>';
													echo '<td>'.$query_List[$num]['desk_statusmohon'].'</td>';
												echo '</tr>';
											}
										?>
										</tbody>
									</table>
									</div>
									
								</div>
							</div>
						</div>
					</div>
				</div>
			</div><br> 			
			<?php
			}
			
			if(in_array($my_details->user_level, array(1,2,3,4,6,15,8,18)) && $bilquery_List['bilquery'] > 0)
			{
			?>
			<div class="accordion accordion-solid accordion-panel accordion-svg-toggle" id="p_accordionExample8">
				<div class="card">
					<div class="card-header" id="p_headingThree8">
						<div class="card-title collapsed" data-toggle="collapse" data-target="#p_collapseThree8">
							<div class="card-label">													
								<span class="svg-icon svg-icon-primary menu-icon">
									<?=$Tapisanhome_svg?>
								</span>Program Utama : Perhatian! Terdapat (<?=$bilquery_List['bilquery']?>) permohonan baru perlu disemak semula</div>
							<span class="svg-icon">
								<?=$Tapisan_svg?>
							</span>
						</div>
					</div>
					<div id="p_collapseThree8" class="collapse" data-parent="#p_accordionExample8">					
						<div class="row">
							<div class="col-md-12">
								<div class="card-body">
									<?php
										$indicator_Query = "SELECT A.*, B.desk_program
														  FROM m_pemohon A
														  LEFT JOIN i_program B ON B.id_program = A.id_program
														  WHERE A.id_terima = ?
														  AND A.id_statusmohon = 2
														  AND A.ulasan_sah != ''";
										$PDO_stmt = $PDO->prepare($indicator_Query);
										$PDO_stmt->bindValue(1, $my_details->usr_id, PDO::PARAM_INT);
										$PDO_stmt->execute();

										$query_List = array();
										while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
										{
											$query_List[] = $result;
										}
									?>										
										
									<div class="table-responsive">
									<table class="table table-separate table-head-custom table-checkable">
										<thead>
											<tr>
												<th>Bil</th>
												<th>Tindakan</th>
												<th>Nama Pemohon</th>
												<th>No KP Baru</th>
												<th>Program</th>
												<th>No Telefon</th>
												<th>Ulasan Pengesah</th>
											</tr>
										</thead>
										<tbody>	
										<?php
											for($num = 0; $num < count($query_List); $num++)
											{		
												$id_program = $query_List[$num]['id_program'];
												
												$name_id_program = $id_program;
												if ($id_program < 10 && (!(substr($id_program, 0, 1) === '0')))
												{
													$name_id_program = '0'.$id_program;
												}	

												$tel_rumah = '';
												if($query_List[$num]['tel_rumah'] != '')
												{
													$tel_rumah = '/'.$query_List[$num]['tel_rumah'];													
												}
												
												echo '<tr>';
													echo '<td>'.($num + 1).'.</td>';
													echo '<td><a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" href="p'.$name_id_program.'_borang.php?pemohon='.$query_List[$num]['id_pemohon'].'" target="_blank" title="Kemaskini Borang Permohonan"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Edit_svg.'</span></a>
													<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-terima_tind.php?id='.$query_List[$num]['id_pemohon'].'&program='.$query_List[$num]['id_program'].'&pass=1\', \'#ajax-modal\')" title="Perakuan Semula"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Check_svg.'</span></a></td>';
													echo '<td><a href="javascript:;" onclick="loadMyModal(\'general-maklumat.php?id='.$query_List[$num]['id_pemohon'].'&program='.$query_List[$num]['id_program'].'\', \'#ajax-modal\')" title="Maklumat Pemohon">'.$query_List[$num]['nama_pemohon'].'</a></td>';
													echo '<td>'.$query_List[$num]['kpbaru_pemohon'].'</td>';
													echo '<td>'.$query_List[$num]['desk_program'].'</td>';
													echo '<td>'.$query_List[$num]['tel_hp'].''.$tel_rumah.'</td>';
													echo '<td>'.$query_List[$num]['ulasan_sah'].'</td>';
												echo '</tr>';
											}
										?>
										</tbody>
									</table>
									</div>
									
								</div>
							</div>
						</div>
					</div>
				</div>
			</div><br> 			
			<?php
			}
			
			if(in_array($my_details->user_level, array(1,2,3,4)) && $bilqueryae_List['bilqueryae'] > 0)
			{
			?>
			<div class="accordion accordion-solid accordion-panel accordion-svg-toggle" id="p_accordionExample9">
				<div class="card">
					<div class="card-header" id="p_headingThree9">
						<div class="card-title collapsed" data-toggle="collapse" data-target="#p_collapseThree9">
							<div class="card-label">													
								<span class="svg-icon svg-icon-primary menu-icon">
									<?=$Tapisanhome_svg?>
								</span>Anak Emas : Perhatian! Terdapat (<?=$bilqueryae_List['bilqueryae']?>) permohonan baru perlu disemak semula</div>
							<span class="svg-icon">
								<?=$Tapisan_svg?>
							</span>
						</div>
					</div>
					<div id="p_collapseThree9" class="collapse" data-parent="#p_accordionExample9">					
						<div class="row">
							<div class="col-md-12">
								<div class="card-body">
									<?php
										$indicator_Query = "SELECT A.*, B.nama_pemohon, B.tel_hp, B.tel_rumah
														  FROM m_anakemas A
														  LEFT JOIN m_pemohon B ON B.id_pemohon = A.id_pemohon
														  WHERE A.id_terima = ?
														  AND A.id_statusmohon = 2
														  AND A.ulasan_sah != ''";
										$PDO_stmt = $PDO->prepare($indicator_Query);
										$PDO_stmt->bindValue(1, $my_details->usr_id, PDO::PARAM_INT);
										$PDO_stmt->execute();

										$query_List = array();
										while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
										{
											$query_List[] = $result;
										}
									?>										
										
									<div class="table-responsive">
									<table class="table table-separate table-head-custom table-checkable">
										<thead>
											<tr>
												<th>Bil</th>
												<th>Tindakan</th>
												<th>Nama Anak Emas</th>
												<th>No KP Baru</th>
												<th>Nama Ibu/Bapa</th>
												<th>No Telefon</th>
												<th>Ulasan Pengesah</th>
											</tr>
										</thead>
										<tbody>	
										<?php
											for($num = 0; $num < count($query_List); $num++)
											{		
												$id_program = $query_List[$num]['id_program'];
												
												$name_id_program = $id_program;
												if ($id_program < 10 && (!(substr($id_program, 0, 1) === '0')))
												{
													$name_id_program = '0'.$id_program;
												}	

												$tel_rumah = '';
												if($query_List[$num]['tel_rumah'] != '')
												{
													$tel_rumah = '/'.$query_List[$num]['tel_rumah'];													
												}
												
												echo '<tr>';
													echo '<td>'.($num + 1).'.</td>';
													echo '<td><a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" href="p05_borang.php?type=1&pemohon='.$query_List[$num]['id_pemohon'].'" target="_blank" title="Kemaskini Borang Permohonan"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Edit_svg.'</span></a>
													<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-terima_tind_sub.php?id='.$query_List[$num]['id_anakemas'].'&program=5\', \'#ajax-modal\')" title="Perakuan Semula"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Check_svg.'</span></a></td>';
													echo '<td><a href="javascript:;" onclick="loadMyModal(\'general-maklumat_sub.php?id='.$query_List[$num]['id_anakemas'].'&program=5\', \'#ajax-modal\')" title="Maklumat Anak Emas">'.$query_List[$num]['nama_anakemas'].'</a></td>';
													echo '<td>'.$query_List[$num]['kpbaru_anakemas'].'</td>';
													echo '<td>'.$query_List[$num]['nama_pemohon'].'</td>';
													echo '<td>'.$query_List[$num]['tel_hp'].''.$tel_rumah.'</td>';
													echo '<td>'.$query_List[$num]['ulasan_sah'].'</td>';
												echo '</tr>';
											}
										?>
										</tbody>
									</table>
									</div>
									
								</div>
							</div>
						</div>
					</div>
				</div>
			</div><br> 			
			<?php
			}
			
			if(in_array($my_details->user_level, array(1,2,3,4)) && $bilkhairat_List['bilkhairat'] > 0)
			{
			?>
			<div class="accordion accordion-solid accordion-panel accordion-svg-toggle" id="p_accordionExample10">
				<div class="card">
					<div class="card-header" id="p_headingThree10">
						<div class="card-title collapsed" data-toggle="collapse" data-target="#p_collapseThree10">
							<div class="card-label">													
								<span class="svg-icon svg-icon-primary menu-icon">
									<?=$Tapisanhome_svg?>
								</span>Khairat : Perhatian! Terdapat (<?=$bilkhairat_List['bilkhairat']?>) permohonan khairat perlu disemak semula</div>
							<span class="svg-icon">
								<?=$Tapisan_svg?>
							</span>
						</div>
					</div>
					<div id="p_collapseThree10" class="collapse" data-parent="#p_accordionExample10">					
						<div class="row">
							<div class="col-md-12">
								<div class="card-body">
									<?php
										$indicator_Query = "SELECT A.*, B.desk_program
														  FROM m_pemohon A
														  LEFT JOIN i_program B ON B.id_program = A.id_program
														  WHERE A.id_keyinmati = ?
														  AND A.id_sahmati = 1
														  AND A.flag_querymati = 1";
										$PDO_stmt = $PDO->prepare($indicator_Query);
										$PDO_stmt->bindValue(1, $my_details->usr_id, PDO::PARAM_INT);
										$PDO_stmt->execute();

										$query_List = array();
										while($result = $PDO_stmt->fetch(PDO::FETCH_ASSOC))
										{
											$query_List[] = $result;
										}
									?>										
										
									<div class="table-responsive">
									<table class="table table-separate table-head-custom table-checkable">
										<thead>
											<tr>
												<th>Bil</th>
												<th>Tindakan</th>
												<th>Nama Pemohon</th>
												<th>No KP Baru</th>
												<th>Program</th>
												<th>No Telefon</th>
												<th>Ulasan Pengesah</th>
											</tr>
										</thead>
										<tbody>	
										<?php
											for($num = 0; $num < count($query_List); $num++)
											{		
												$id_program = $query_List[$num]['id_program'];
												
												$name_id_program = $id_program;
												if ($id_program < 10 && (!(substr($id_program, 0, 1) === '0')))
												{
													$name_id_program = '0'.$id_program;
												}	

												$tel_rumah = '';
												if($query_List[$num]['tel_rumah'] != '')
												{
													$tel_rumah = '/'.$query_List[$num]['tel_rumah'];													
												}
												
												echo '<tr>';
													echo '<td>'.($num + 1).'.</td>';
													echo '<td>
													<a class="btn btn-sm btn-default btn-text-primary btn-hover-primary btn-icon mr-2" onclick="loadMyModal(\'general-khairat.php?id='.$query_List[$num]['id_pemohon'].'&type=0&from=1\', \'#ajax-modal\')" title="Kemaskini"><span class="svg-icon svg-icon-primary svg-icon-2x">'.$Edit_svg.'</span></a></td>';
													echo '<td><a href="javascript:;" onclick="loadMyModal(\'general-maklumat.php?id='.$query_List[$num]['id_pemohon'].'&program='.$query_List[$num]['id_program'].'\', \'#ajax-modal\')" title="Maklumat Pemohon">'.$query_List[$num]['nama_pemohon'].'</a></td>';
													echo '<td>'.$query_List[$num]['kpbaru_pemohon'].'</td>';
													echo '<td>'.$query_List[$num]['desk_program'].'</td>';
													echo '<td>'.$query_List[$num]['tel_hp'].''.$tel_rumah.'</td>';
													echo '<td>'.$query_List[$num]['ulasan_sahmati'].'</td>';
												echo '</tr>';
											}
										?>
										</tbody>
									</table>
									</div>
									
								</div>
							</div>
						</div>
					</div>
				</div>
			</div><br> 			
			<?php
			}
			?>
			<!--begin::Dashboard--> 
			<div class="row">	
				<?php
				if($my_details->user_level != 17)
				{	
					if($my_details->user_level < 4)
					{	
					?>	
						<div class="col-lg-4">
							<!--begin::Callout-->
							<div class="card card-custom wave wave-animate-slow wave-primary card-stretch gutter-b">
								<div class="card-body">
									<div class="d-flex align-items-center p-5">
										<!--begin::Icon-->
										<div class="mr-6">
											<?=$Globe_svg?>
										</div>
										<!--end::Icon-->
										<!--begin::Content-->
										<div class="d-flex flex-column">
											<a href="in_pengguna.php<?=$hyperlink?>" class="text-dark text-hover-primary font-weight-bold font-size-h4 mb-3">Pengguna Jabatan</a>
											<div class="text-dark-75">Terdapat <?=$value?> permohonan baru</div>
										</div>
										<!--end::Content-->
									</div>
								</div>
							</div>
							<!--end::Callout-->
						</div>
					<?php
					}
					?>
					<div class="col-lg-4">
						<!--begin::Callout-->
						<div class="card card-custom wave wave-animate-slow wave-primary card-stretch gutter-b">
							<div class="card-body">
								<div class="d-flex align-items-center p-5">
									<!--begin::Icon-->
									<div class="mr-6">
										<?=$Globe_svg?>
									</div>
									<!--end::Icon-->
									<!--begin::Content-->
									<div class="d-flex flex-column">
										<a href="general-carian.php" class="text-dark text-hover-primary font-weight-bold font-size-h4 mb-3">Penerimaan/ Pengesahan Permohonan/ Pengesahan EFT (Carian)</a>
										<div class="text-dark-75">Semua Program Utama</div>
									</div>
									<!--end::Content-->
								</div>
							</div>
						</div>
						<!--end::Callout-->
					</div>
					<?php
					
					if(in_array($my_details->user_level, array(1,3,5)))
					{
					?>
					<div class="col-lg-4">
						<!--begin::Callout-->
						<div class="card card-custom wave wave-animate-slow wave-primary card-stretch gutter-b">
							<div class="card-body">
								<div class="d-flex align-items-center p-5">
									<!--begin::Icon-->
									<div class="mr-6">
										<?=$Globe_svg?>
									</div>
									<!--end::Icon-->
									<!--begin::Content-->
									<div class="d-flex flex-column">
										<a href="general-carian_kh.php" class="text-dark text-hover-primary font-weight-bold font-size-h4 mb-3">Pengesahan Permohonan Khairat</a>
										<div class="text-dark-75">Khairat Kematian Program Utama</div>
									</div>
									<!--end::Content-->
								</div>
							</div>
						</div>
						<!--end::Callout-->
					</div>
					<?php
					}
					
					if($my_details->user_level <= 5)
					{
					?>
					<div class="col-lg-4">
						<!--begin::Callout-->
						<div class="card card-custom wave wave-animate-slow wave-primary card-stretch gutter-b">
							<div class="card-body">
								<div class="d-flex align-items-center p-5">
									<!--begin::Icon-->
									<div class="mr-6">
										<?=$Globe_svg?>
									</div>
									<!--end::Icon-->
									<!--begin::Content-->
									<div class="d-flex flex-column">
										<a href="general-carian_ae.php" class="text-dark text-hover-primary font-weight-bold font-size-h4 mb-3">Penerimaan/ Pengesahan Permohonan (Carian)</a>
										<div class="text-dark-75">Program Anak Emas</div>
									</div>
									<!--end::Content-->
								</div>
							</div>
						</div>
						<!--end::Callout-->
					</div>
					<?php
					}
				}
				?>
				<div class="col-lg-4">
					<!--begin::Callout-->
					<div class="card card-custom wave wave-animate-slow wave-primary card-stretch gutter-b">
						<div class="card-body">
							<div class="d-flex align-items-center p-5">
								<!--begin::Icon-->
								<div class="mr-6">
									<?=$Globe_svg?>
								</div>
								<!--end::Icon-->
								<!--begin::Content-->
								<div class="d-flex flex-column">
									<a href="in_aduan.php" class="text-dark text-hover-primary font-weight-bold font-size-h4 mb-3">Aduan Aktif</a>
									<div class="text-dark-75">Terdapat <?=$value1?> aduan aktif</div>
								</div>
								<!--end::Content-->
							</div>
						</div>
					</div>
					<!--end::Callout-->
				</div>
			</div>		
			<?php
			if($my_details->user_level <= 5)
			{
			?>
				<div class="row">	
					<?php
					if($my_details->user_level <= 3)
					{	
					?>	
					<div class="col-lg-4">
						<div class="card card-custom wave wave-animate-slow wave-primary card-stretch gutter-b">
							<div class="card-body">
								<div class="d-flex align-items-center p-5">
									<div class="mr-6">
										<?=$money_svg?>
									</div>
									<div class="d-flex flex-column">
										<a href="general-frontbayar_ae.php" class="text-dark text-hover-primary font-weight-bold font-size-h4 mb-3">Pembayaran Pukal EFT Program Anak Emas</a>
										<div class="text-dark-75">Program Anak Emas</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="col-lg-4">
						<div class="card card-custom wave wave-animate-slow wave-primary card-stretch gutter-b">
							<div class="card-body">
								<div class="d-flex align-items-center p-5">
									<div class="mr-6">
										<?=$money_svg?>
									</div>
									<div class="d-flex flex-column">
										<a href="general-frontbayar_kh.php" class="text-dark text-hover-primary font-weight-bold font-size-h4 mb-3">Pembayaran Pukal EFT Khairat Kematian</a>
										<div class="text-dark-75">Khairat Kematian</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					<?php
					}
					?>	
					<div class="col-lg-4">
						<div class="card card-custom wave wave-animate-slow wave-primary card-stretch gutter-b">
							<div class="card-body">
								<div class="d-flex align-items-center p-5">
									<div class="mr-6">
										<?=$money_svg?>
									</div>
									<div class="d-flex flex-column">
										<a href="tu_senarai.php" class="text-dark text-hover-primary font-weight-bold font-size-h4 mb-3">Pembayaran Tunai Program Utama (QR Code)</a>
										<div class="text-dark-75">Semua program Utama</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>					
			<?php
			}
			?>
			<!--end::Row-->
			<!--begin::Row-->
			<!--<div class="row">
				<div class="col-lg-12">
					<div class="card card-custom card-stretch gutter-b">
						<div class="card-header border-0">
							<h3 class="card-title font-weight-bolder text-dark">Program Kebajikan Utama</h3>
						</div>
						<div class="card-body pt-0" id="jumlahDiv">
							
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-lg-12">
					<div class="card card-custom card-stretch gutter-b">
						<div class="card-header border-0">
							<h3 class="card-title font-weight-bolder text-dark">Program Anak Emas</h3>
						</div>
						<div class="card-body pt-0" id="anakEmasDiv">
							
						</div>
					</div>
				</div>
			</div>-->
		</div>
		<!--end::Container-->
	</div>
	<!--end::Entry-->
</div>
<!--end::Content-->
					
<?php 
createModal();
require('includes/footer.php');
?>	

<script>
/*function loadJumlah()
{
	$.ajax({
		type: "POST", 
		url: "index-ajax.php", 
		data: '',
		success: function(res){
			$('#jumlahDiv').html(res);
		} 
	});
}
function loadAE()
{
	$.ajax({
		type: "POST", 
		url: "index-ae_ajax.php", 
		data: '',
		success: function(res){
			$('#anakEmasDiv').html(res);
		} 
	});
}*/

$(document).ready(function(){
	
	$('#ajax-modal').on('shown.bs.modal', function () {  // this is to clear modal cache each time modal load
		$(this).removeData('bs.modal');
		//location.reload();
	}); 
	//loadJumlah();
	//loadAE();
	
});
</script>