<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
	
	class Beranda extends CI_Controller
	{
		public function __construct()
		{
			parent::__construct();
			$this->load->model('beranda/Beranda_model', 'home');
			$this->load->library('form_validation');
			//$this->load->library('Dompdf_gen','dompdf');
			//$this->load->model('login/M_login', 'login');
			//$this->auth->cek_auth(); //ngambil auth dari library
		}
		
		public function index()
		{	
			$layanan = $this->db->query("SELECT * FROM jam_layanan where id='1' ")->row();
			$jam     = date('H:i:s');
			$hari    = date('D');
			
			if($hari == 'Mon' OR $hari == 'Tue' OR $hari == 'Wed' OR $hari == 'Thu' OR $hari == 'Fri'){
				if($layanan->status=='1' AND ($jam>=$layanan->jam_mulai AND $jam<=$layanan->jam_selesai)){
					$status = 'buka';
					}else{
					$status = 'tutup';
				}
				}else{
				$status = 'tutup';
			}
			
			//$jam = date('H:i');
			
			//atur salam menggunakan IF
			if ($jam > '05:30:00' && $jam < '10:00:00') {
				$salam = 'pagi';
				} elseif ($jam >= '10:00:00' && $jam < '15:00:00') {
				$salam = 'siang';
				} elseif ($jam < '18:00:00') {
				$salam = 'sore';
				} else {
				$salam = 'malam';
			}
			
			
			$data = array(
			'set'			=> $this->db->query("SELECT * FROM pengaturan WHERE id='2' ")->row(),
            'judul_halaman' => 'Halaman Utama',
			'status_layanan'=> $status,
			'jam'	 	    => $jam,
			'jam_mulai'     => $layanan->jam_mulai,
			'jam_selesai'   => $layanan->jam_selesai,
			'salam'			=> $salam,
			);
			//print_r($data);
			$this->template->load('template_beranda', 'beranda/beranda_utama', $data);
		}
		
		public function open()
		{	
			$layanan = $this->db->query("SELECT * FROM jam_layanan where id='1' ")->row();
			$jam     = date('H:i:s');
			$hari    = date('D');
			
			if($hari == 'Mon' OR $hari == 'Tue' OR $hari == 'Wed' OR $hari == 'Thu' OR $hari == 'Fri'){
				if($layanan->status=='1' AND ($jam>=$layanan->jam_mulai AND $jam<=$layanan->jam_selesai)){
					$status = 'buka';
					}else{
					$status = 'tutup';
				}
				}else{
				$status = 'tutup';
			}
			
			if ($jam > '05:30:00' && $jam < '10:00:00') {
				$salam = 'pagi';
				} elseif ($jam >= '10:00:00' && $jam < '15:00:00') {
				$salam = 'siang';
				} elseif ($jam < '18:00:00') {
				$salam = 'sore';
				} else {
				$salam = 'malam';
			}
			
			$data = array(
			'set'			=> $this->db->query("SELECT * FROM pengaturan WHERE id='2' ")->row(),
            'judul_halaman' => 'Halaman Utama',
			'status_layanan'=> $status,
			'jam'	 	    => $jam,
			'jam_mulai'     => $layanan->jam_mulai,
			'jam_selesai'   => $layanan->jam_selesai,
			'salam'			=> $salam,
			);
			//print_r($data);
			$this->template->load('template_css', 'beranda/beranda_open', $data);
			//$this->load->view('beranda/beranda_open', $data);
		}
		
		public function close(){
			$layanan = $this->db->query("SELECT * FROM jam_layanan WHERE id='1' ")->row();
			$jam     = date('H:i:s');
			$hari    = date('D');
			
			if($hari == 'Mon' OR $hari == 'Tue' OR $hari == 'Wed' OR $hari == 'Thu' OR $hari == 'Fri'){
				if($layanan->status=='1' AND ($jam>=$layanan->jam_mulai AND $jam<=$layanan->jam_selesai)){
					$status = 'buka';
					}else{
					$status = 'tutup';
				}
				}else{
				$status = 'tutup';
			}
			
			if ($jam > '05:30:00' && $jam < '10:00:00') {
				$salam = 'pagi';
				} elseif ($jam >= '10:00:00' && $jam < '15:00:00') {
				$salam = 'siang';
				} elseif ($jam < '18:00:00') {
				$salam = 'sore';
				} else {
				$salam = 'malam';
			}
			
			$data = array(
			'set'			=> $this->db->query("SELECT * FROM pengaturan WHERE id='2' ")->row(),
            'judul_halaman' => 'Halaman Utama',
			'status_layanan'=> $status,
			'jam'	 	    => $jam,
			'jam_mulai'     => $layanan->jam_mulai,
			'jam_selesai'   => $layanan->jam_selesai,
			'info'			=> $layanan->info,
			'salam'			=> $salam,
			);
			//print_r($data);
			$this->template->load('template_login','beranda/beranda_close',$data);
		}
		
	} // end controller home										