<?php if($this->session->userdata('level')=='1'){ ?>
	
	<div class="row">
		<div class="col-xl-12 table-responsive" style="min-height:400px;">
			<table class="table table-bordered table-sm table-hover table-condensed">
				<thead>
					<tr>
						<th width="50px" style="text-align:center;">No</th>
						<th>
							<div class="badge" style="font-size:12px;text-align:center;">IDENTITAS PENGUNJUNG</div>
						</th>
						<th>
							<div class="badge" style="font-size:12px;text-align:center;">ALAMAT & KONTAK</div>
						</th>
						<th>
							<div class="badge" style="font-size:12px;text-align:center;">JENIS LAYANAN</div>
						</th>
						<th>
							<div class="badge" style="font-size:12px;text-align:center;">PERIHAL BANTUAN</div>
						</th>
						<th>
							<div class="badge" style="font-size:12px;text-align:center;">WAKTU MENGHUBUNGI</div>
						</th>
						<th>
							<div class="badge" style="font-size:12px;text-align:center;">HUBUNGI PIHAK</div>
						</th>
					</tr>
				</thead>
				<tbody>
					<?php $start=1;foreach ($pengunjung as $pp) { 
						if($pp->bantuan == '1'){
							$bantuan = 'CHAT';
							}else if($pp->bantuan == '2'){
							$bantuan = 'VOICE CALL';
							}else if($pp->bantuan == '3'){
							$bantuan = 'VIDEO CALL';
							}else{
							$bantuan = 'BELUM PILIH';
						}
						
						$nohp = $pp->p_hp;
						if (!function_exists('hp'))
						{
							function hp($nohp) {
								// kadang ada penulisan no hp 0811 239 345
								$nohp = str_replace(" ","",$nohp);
								// kadang ada penulisan no hp (0274) 778787
								$nohp = str_replace("(","",$nohp);
								// kadang ada penulisan no hp (0274) 778787
								$nohp = str_replace(")","",$nohp);
								// kadang ada penulisan no hp 0811.239.345
								$nohp = str_replace(".","",$nohp);
								
								// cek apakah no hp mengandung karakter + dan 0-9
								if(!preg_match('/[^+0-9]/',trim($nohp))){
									// cek apakah no hp karakter 1-3 adalah +62
									if(substr(trim($nohp), 0, 3)=='62'){
										$hp = trim($nohp);
									}
									// cek apakah no hp karakter 1 adalah 0
									elseif(substr(trim($nohp), 0, 1)=='0'){
										$hp = '62'.substr(trim($nohp), 1);
									}
								}
								print $hp;
							}
							//hp($nohp);
						}
					?>
					<tr>
						<td align="center"><?php echo $start++ ?></td>
						<td>
							<?php echo $pp->p_nama ?>
						</td>
						<td style="font-size:10px;">
							<?php echo $pp->p_hp; ?>
						</td>
						<td>
							<b><?php echo $pp->l_nama_jenis_layanan ?></b><br/>
							<?php echo $pp->l_layanan ?>
						</td>
						<td><?php echo $pp->catatan ?></td>
						<td style="text-align:center;"><?php echo date('d-m-Y / H:i:s',strtotime($pp->waktu)) ?></td>
						<td align="center">
							<a href="https://api.whatsapp.com/send/?phone=<?=hp($nohp);?>&text=Kami%20Akan%20Segera%20Menghubungi%20Anda" class="btn btn-danger">HUBUNGI<br/><?php echo hp($nohp); ?></a>
						</td>
					</tr>
					<?php } ?>	
				</tbody>
			</table>
		</div>
	</div>
<?php } ?>


<input type="hidden" id="awal" value="<?php echo $jlhnotif;?>">
<input type="hidden" name="akhir" id="akhir" value="<?php echo $jlhnotif;?>">
<script>
	function data_awal(){
		$.ajax({
			type  : "POST",
			url   : "<?=base_url()?>dashboard/cari_data_akhir",
			dataType: "json",
			success : function(data){
				$('#awal').val(data.no_akhir);
			}
		});
	}
	
	function data_akhir(){
		$.ajax({
			type  : "POST",
			url   : "<?=base_url()?>dashboard/cari_data_akhir",
			dataType: "json",
			success : function(data){
				$('#akhir').val(data.no_akhir)
			}
		});
	}
	
	function cektotal()
	{
		var awal = document.getElementById('awal');
		var akhir = document.getElementById('akhir');
		if (awal.value == akhir.value){
			//no action          
			}else{
			window.location.reload();
		}
	}
	
	setInterval(function(){
		data_akhir();
		cektotal();
	}, 2000);
	
</script>						