<?php
	
	$set      		= $this->db->query("SELECT * FROM pengaturan WHERE id='2' ")->row();
	$services 		= $this->db->query("SELECT * FROM ptsp_hubungi WHERE id = '1'")->result();
	
	
	$tahun_statistik= $this->input->get('tahun');
	if($tahun_statistik == ''){
		$thn_stt = date('Y');
		}else{
		$thn_stt = $tahun_statistik;
	}
	
	$statistik_1 = $this->db->query("SELECT A.*, (SELECT COUNT(id) FROM ptsp_pengunjung WHERE l_id=A.id AND STATUS='1' AND YEAR(waktu_hubungi)='$thn_stt') AS total FROM ptsp_layanan A WHERE id_jenis_layanan='1' LIMIT 0,3")->result();
	
	$statistik_2 = $this->db->query("SELECT A.*, (SELECT COUNT(id) FROM ptsp_pengunjung WHERE l_id=A.id AND STATUS='1' AND YEAR(waktu_hubungi)='$thn_stt') AS total FROM ptsp_layanan A WHERE id_jenis_layanan='1' LIMIT 3,9")->result();
	
	//ubah timezone menjadi jakarta
	date_default_timezone_set("Asia/Jakarta");
	
	//ambil jam dan menit
	$jam = date('H:i');
	
	//atur salam menggunakan IF
	if ($jam > '05:30' && $jam < '10:00') {
		$salam = 'pagi';
		} elseif ($jam >= '10:00' && $jam < '15:00') {
		$salam = 'siang';
		} elseif ($jam < '18:00') {
		$salam = 'sore';
		} else {
		$salam = 'malam';
	}
	
	//tampilkan pesan
	$salam = $salam;
	
	$nik  = set_value('nik');
	$hp   = set_value('hp');
	$email= set_value('email');
	$nama = set_value('nama');
	
	$nik_data 	= $this->session->userdata('nik');
	$nama_data 	= $this->session->userdata('nama');
	$jk_data 	= $this->session->userdata('jk');
	if($jk_data == 'L'){
		$yth = ' Bapak ';
		}else if($jk_data == 'P'){
		$yth = ' Ibu ';
		}else{
		$yth = '';
	}
	
	if($status_layanan == 'buka'){
		if($this->session->userdata('isLoginPenggunaPTSP') == 'TRUE'){
			$beranda_status = 'Keluar Sistem';
			$beranda_link   = site_url('logout');
			}else{
			$beranda_status = 'BUKA';
			$beranda_link   = site_url('login');
		}
		}else{
		if($this->session->userdata('isLoginPenggunaPTSP') == 'TRUE'){
			$beranda_status = 'Keluar Sistem';
			$beranda_link   = site_url('logout');
			}else{
			$beranda_status = 'TUTUP';
			$beranda_link   = site_url('login');
		}	
	}
	
?>
<!DOCTYPE html>
<html lang="en">
	
	<head>
		<meta charset="utf-8">
		<meta content="width=device-width, initial-scale=1.0" name="viewport">
		
		<title><?=$set->title;?></title>
		<meta content="" name="description">
		<meta content="" name="keywords">
		
		<!-- Favicons -->
		<link href="<?=base_url('one');?>/assets/img/favicon.png" rel="icon">
		<link href="<?=base_url('one');?>/assets/img/apple-touch-icon.png" rel="apple-touch-icon">
		
		<!-- Google Fonts -->
		<link href="<?=base_url('one');?>/https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Raleway:300,300i,400,400i,500,500i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
		
		<!-- Vendor CSS Files -->
		<link href="<?=base_url('one');?>/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
		<link href="<?=base_url('one');?>/assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
		<link href="<?=base_url('one');?>/assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
		<link href="<?=base_url('one');?>/assets/vendor/glightbox/css/glightbox.min.css" rel="stylesheet">
		<link href="<?=base_url('one');?>/assets/vendor/remixicon/remixicon.css" rel="stylesheet">
		<link href="<?=base_url('one');?>/assets/vendor/swiper/swiper-bundle.min.css" rel="stylesheet">
		
		<!-- Template Main CSS File -->
		<link href="<?=base_url('one');?>/assets/css/style.css" rel="stylesheet">
	</head>
	
	<body>
		
		<!-- ======= Header ======= -->
		<header id="header" class="fixed-top ">
			<div class="container-fluid">
				
				<div class="row justify-content-center">
					<div class="col-xl-9 d-flex align-items-center justify-content-lg-between">
						<h1 class="logo me-auto me-lg-0"><a href="<?=base_url();?>"><?=$set->title;?></a></h1>
						<!-- Uncomment below if you prefer to use an image logo -->
						<!-- <a href="<?=base_url('one');?>/index.html" class="logo me-auto me-lg-0"><img src="<?=base_url('one');?>/assets/img/logo.png" alt="" class="img-fluid"></a>-->
						
						<nav id="navbar" class="navbar order-last order-lg-0">
							<ul>
								<li><a class="nav-link scrollto" href="#hero">Home</a></li>
								<li><a class="nav-link scrollto" href="#about">About</a></li>
								<li><a class="nav-link scrollto" href="#services">Services</a></li>
								<li><a class="nav-link scrollto" href="#counts">Statistik</a></li>
								<li><a class="nav-link scrollto" href="#contact">Contact</a></li>
							</ul>
							<i class="bi bi-list mobile-nav-toggle"></i>
						</nav><!-- .navbar -->
						<?php if($status_layanan == 'buka'){ ?>
							<a href="<?=$beranda_link;?>" class="get-started-btn btn-success scrollto"><?=$beranda_status;?></a>
							<?php }else{?>
							<a href="<?=$beranda_link;?>" class="btn btn-danger scrollto"><?=$beranda_status;?></a> 
						<?php }?>
					</div>
				</div>
				
			</div>
		</header><!-- End Header -->
		
		
		<main id="main">
			<?php echo $contents; ?>	
			<!-- ======= About Us Section ======= -->
			<section id="about" class="about">
				<div class="container">
					
					<div class="section-title">
						<h2>TENTANG <?=$set->title;?></h2>
					</div>
					
					<div class="row content">
						<div class="col-lg-12">
							<p><?=$set->deskripsi_lengkap;?></p>
						</div>
					</div>
					
				</div>
			</section><!-- End About Us Section -->
			
			<!-- ======= Services Section ======= -->
			<section id="services" class="services">
				<div class="container">
					
					<div class="section-title">
						<h2>LAYANAN <?=$set->title;?></h2>
						<!-- p></p -->
					</div>
					
					<div class="row">
						<?php foreach($services as $srv){ ?>
							<div class="col-sm-12 align-items-stretch">
								<center>
									<div class="icon-box">
										<div class="icon" style="background-color:<?=$srv->warna;?>"><i class="<?=$srv->icon;?>"></i></div>
										<h4><?=$srv->nama_layanan;?></h4>
										<p><?=$srv->keterangan;?></p>
									</div>
								</center>
							</div>
						<?php } ?>
					</div>
					
				</div>
			</section><!-- End Services Section -->
			
			<!-- ======= Counts Section ======= -->
			<section id="counts" class="counts">
				<div class="container">
					
					<div class="text-center title">
						<h3>Statistik Permohonan Layanan</h3>
						<p>Data Permohonan pada Pelayanan Terpadu Satu Pintu</p>
					</div>
					<div class="row counters position-relative">
						<?php foreach($statistik_1 as $sp) {?>
							<div class="col-lg-4 text-center">
								<span data-purecounter-start="0" data-purecounter-end="<?=$sp->total;?>" data-purecounter-duration="1" class="purecounter"></span>
								<h3 style="color:white;"><?=$sp->layanan;?></h3>
								<p><?=$sp->keterangan;?></p>
							</div>
						<?php } ?>
						<?php foreach($statistik_2 as $sp) {?>
							<div class="col-lg-6 text-center">
								<span data-purecounter-start="0" data-purecounter-end="<?=$sp->total;?>" data-purecounter-duration="1" class="purecounter"></span>
								<h3 style="color:white;"><?=$sp->layanan;?></h3>
								<p><?=$sp->keterangan;?></p>
							</div>
						<?php } ?>
					</div>					
				</div>
			</section><!-- End Counts Section -->
			
			
			<!-- ======= Contact Section ======= -->
			<section id="contact" class="contact">
				<div class="container">
					
					<div class="section-title">
						<h2>CONTACT</h2>
						<p><b><?=$set->title;?></b> - <?=$set->deskripsi_singkat;?></p>
					</div>
				</div>
				
				<div class="container-fluid">
					<iframe style="border:0; width: 100%; height: 350px;" src="<?=$set->map;?>" frameborder="0" allowfullscreen></iframe>
				</div>
				
				<div class="container">
					
					<div class="row mt-5">
						
						<div class="col-lg-6">
							<div class="info">
								<div class="address">
									<i class="ri-map-pin-line"></i>
									<h4>Alamat:</h4>
									<p><?=$set->alamat;?></p>
								</div>
								
								<div class="email">
									<i class="ri-mail-line"></i>
									<h4>Email:</h4>
									<p><?=$set->email;?></p>
								</div>
								
								<div class="phone">
									<i class="ri-phone-line"></i>
									<h4>Telepon:</h4>
									<p><?=$set->telp;?></p>
								</div>
							</div>
							
						</div>
						
						<div class="col-lg-6 mt-5 mt-lg-0">
							<?php if($this->session->userdata('isLoginPenggunaPTSP') == FALSE){ ?>
								<center><b style="font-weight:bold;text-align:center;">Belum punya akun? Daftarkan dengan mengisi form dibawah ini</b></center><br/>
								<form action="<?=base_url('login/proses_daftar');?>" method="post"  class="">
									<div class="row">
										<div class="col-md-6 form-group">
											<input type="text" class="form-control form-control-user"
											placeholder="NIK (Nomor Induk Kependudukan)" name="nik" value="<?=$nik;?>"><center><?php echo form_error('nik') ?></center>
										</div>
										<div class="col-md-6 form-group mt-3 mt-md-0">
											<input type="text" class="form-control form-control-user"
											placeholder="Nomor HP / WA" name="hp" value="<?=$hp;?>"><center><?php echo form_error('hp') ?></center>
										</div>
									</div>
									<div class="form-group mt-3">
										<input type="email" class="form-control form-control-user"
										placeholder="Email" name="email" value="<?=$email;?>"><center><?php echo form_error('email') ?></center>
									</div>
									<div class="form-group mt-3">
										<input type="text" class="form-control form-control-user"
										placeholder="Nama Lengkap" name="nama" value="<?=$nama;?>"><center><?php echo form_error('nama') ?></center>
									</div>
									<div class="form-group mt-3">
										<input type="password" class="form-control form-control-user"
										placeholder="Password" name="password"
										required>
									</div>
									<br/>
									<div class="text-center"><button type="submit" class="btn btn-warning btn-user">Daftar Akun</button></div>
								</form>
								<?php }else{?>
								<center>
									<h4>Selamat <?=$salam.''.$yth.'<b>'.$nama_data.'</b>';?></h4>
									<h5>Terimakasih telah menggunakan layanan kami</h5>
									<h2><?=$set->title;?></h2>
									<h5><?=$set->deskripsi_singkat;?></h5>
									<hr/>untuk keluar dari sistem klik tombol dibawah ini</br>
									<a href="<?=base_url('logout');?>" class="btn btn-warning">KELUAR SISTEM</a>
								</center>
							<?php } ?>
						</div>
						
					</div>
				</div>
			</section><!-- End Contact Section -->	
			
		</main><!-- End #main -->
		
		<!-- ======= Footer ======= -->
		<footer id="footer">
			<div class="container">
				<h3><?=$set->title;?></h3>
				<p><?=$set->deskripsi_singkat;?></p>
				<div class="social-links">
					<a href="#" class="twitter"><i class="bx bxl-twitter"></i></a>
					<a href="#" class="facebook"><i class="bx bxl-facebook"></i></a>
					<a href="#" class="instagram"><i class="bx bxl-instagram"></i></a>
				</div>
				<div class="copyright">
					<?=$set->nama_satker;?> &copy; Copyright <strong><span>Direktorat Jenderal Badan Peradilan Agama</span></strong>
				</div>
				<!-- div class="credits">
				<!-- All the links in the footer should remain intact. -->
				<!-- You can delete the links only if you purchased the pro version. -->
				<!-- Licensing information: https://bootstrapmade.com/license/ -->
				<!-- Purchase the pro version with working PHP/AJAX contact form: https://bootstrapmade.com/knight-simple-one-page-bootstrap-template/>
					Designed by <a href="https://bootstrapmade.com/">BootstrapMade</a>
				<!-- /div -->
			</div>
		</footer><!-- End Footer -->
		
		<div id="preloader"></div>
		<a href="#" class="back-to-top d-flex align-items-center justify-content-center"><i class="bi bi-arrow-up-short"></i></a>
		
		
		<!-- Vendor JS Files -->
		<script src="<?=base_url('one');?>/assets/vendor/purecounter/purecounter.js"></script>
		<script src="<?=base_url('one');?>/assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
		<script src="<?=base_url('one');?>/assets/vendor/glightbox/js/glightbox.min.js"></script>
		<script src="<?=base_url('one');?>/assets/vendor/isotope-layout/isotope.pkgd.min.js"></script>
		<script src="<?=base_url('one');?>/assets/vendor/swiper/swiper-bundle.min.js"></script>
		<script src="<?=base_url('one');?>/assets/vendor/php-email-form/validate.js"></script>
		
		<!-- Template Main JS File -->
		<script src="<?=base_url('one');?>/assets/js/main.js"></script>
		
	</body>
	
</html>
