<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Home extends CI_Controller {
	 
	function __construct(){
	error_reporting(0);
		parent::__construct();		
			$this->load->library('session');
			$this->load->library('form_validation');
			$this->load->model('m_login');						
			$this->load->model('m_kategori');						
			$this->load->model('m_home');		
			$this->load->model('m_home');	
			$this->load->model('m_tamu');	
			$this->load->model('m_bidang');	
			$this->load->model('m_asalinstansi');			
		}
	
	function index(){	
		$kategori = $this->m_kategori->tampil();
		$asalinstansi = $this->m_asalinstansi->tampil();
		$data['kategori'] = $kategori;
		$data['asalinstansi'] = $asalinstansi;
		$data['alert'] = '';
		$data['pesan'] = '';		
		$data['judul'] = 'Dashboard';
		$this->load->view('home/utama', $data);		
	}

	function tamu()
	{
	if(isset($_POST['simpan'])){
	$a = array('\'', '/',';', '[', ']', '{', '}', '|', '^', '~',',',"'");
	//str_replace($a,"",str_replace($a,"",$this->security->xss_clean($this->input->post('username')));	
	$idkategori = str_replace($a,"",$this->security->xss_clean($this->input->post('idkategori')));		
	$nama = str_replace($a,"",$this->security->xss_clean($this->input->post('nama')));		
	$alamat = str_replace($a,"",$this->security->xss_clean($this->input->post('alamat')));		
	$asalinstansi = str_replace($a,"",$this->security->xss_clean($this->input->post('asalinstansi')));		
	//$asalinstansi_lain = str_replace($a,"",$this->security->xss_clean($this->input->post('asalinstansi_lain')));		
	$nohp = str_replace($a,"",$this->security->xss_clean($this->input->post('nohp')));		

	$data_save = array(
										'idkategori' => $idkategori,
										'nama' =>ucwords(strtolower($nama)),
										'alamat' => $alamat,
										'asalinstansi' => $asalinstansi,
										'nohp' => $nohp,
										'keterangan' =>  '-',
										'tanggal' => date('Y-m-d H:i:s'),
										'status' =>  '0',
										'file_name' => '-',
								);
	$this->m_home->in($data_save,'tamu');	
	$data['alert'] = 'success';
	$data['pesan'] = 'Berhasil. Silahkan menunggu panggilan.';		
	$data['judul'] = 'Dashboard';
	$kategori = $this->m_kategori->tampil();
	$asalinstansi1 = $this->m_asalinstansi->tampil();
	$data['kategori'] = $kategori;
	$data['asalinstansi'] = $asalinstansi1;	
	$this->load->view('home/utama', $data);	
	//$this->load->view('footjs');		 
	}
	}	
	

	function admin(){	
		$kategori = $this->m_kategori->tampil();
		$data['kategori'] = $kategori;
		$data['alert'] = '';
		$data['pesan'] = '';		
		$data['judul'] = 'Dashboard';
		$this->load->view('admin/login', $data);		
	}

	function cek()
	{
	if(isset($_POST['button'])){
	$a = array('\'', '/',';', '[', ']', '{', '}', '|', '^', '~',',',"'");
	$username = str_replace("'","",$this->security->xss_clean($this->input->post('username')));	
	$katasandi = str_replace("'","",$this->security->xss_clean($this->input->post('katasandi')));
	
	$cek = $this->m_login->ceklogin($username, $katasandi);
	if($cek==1){ 
		$a = $this->m_login->cekloginstatus($username, $katasandi);	
		$iduser = $a->iduser;
		$nama = $a->nama;
		$username = $a->username;
		//datasession

		$data_session = array(
		'iduser' => $iduser,
		'nama' => $nama,
		'token' =>md5(md5(md5(date('Ymd').'tamu'))),
		);

		$this->session->set_userdata($data_session);
		$data['alert'] = '';
		$data['pesan'] = '';		
		$data['judul'] = 'Dashboard';	
		$tampil = $this->m_tamu->tampil();
		$data['tampil'] = $tampil;
		$this->load->view('admin/tamu', $data);	
	}else{
		$data['alert'] = 'danger';
		$data['pesan'] = 'Ada kesalahan pada username / password Anda';		
		$data['judul'] = '';
		$this->load->view('admin/login', $data);		
	}	
		 
	}
	}	
	
}

	
