<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Tamu 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_tamu');	
			$this->load->model('m_bidang');	
			$this->load->model('m_kategori');	
			if($this->session->userdata('token') !=md5(md5(md5(date('Ymd').'tamu')))){
				redirect(base_url("home"));
			}			
			
		}
	
	function index(){	
		$tampil = $this->m_tamu->tampil();
		$data['tampil'] = $tampil;
		$data['alert'] = '';
		$data['pesan'] = '';		
		$data['judul'] = 'Dashboard';	
		$this->load->view('admin/tamu', $data);		
	}


	function alltamu(){	
		$tampil = $this->m_tamu->tampilall();
		$data['tampil'] = $tampil;
		$data['alert'] = '';
		$data['pesan'] = '';		
		$data['judul'] = 'Dashboard';
		$this->load->view('admin/tamu-all', $data);		
	}
	
	function edit(){	
		$a = array('\'', '/',';', '[', ']', '{', '}', '|', '^', '~',',');	
		$id = str_replace($a,"",$this->uri->segment(4));
		$data['cek'] ='edit';
		$data['kategori'] = $this->m_kategori->tampil();		
		$data['edit'] = $this->m_tamu->edit($id);
		$data['bidang'] = $this->m_bidang->tampil();
		$this->load->view('admin/tamu-add', $data);	
	} 
	
	public function getNewData() {
        // Lakukan pengambilan data tamu baru di sini
        $data = $this->m_tamu->getNewData();
        // Kembalikan data dalam format JSON
        header('Content-Type: application/json');
        echo json_encode($data);
    }	
	
	public function hapus()
	{
		$a = array('\'', '/',';', '[', ']', '{', '}', '|', '^', '~',',');	
		$id = str_replace($a,"",$this->uri->segment(4));
		$where = array(
						'idtamu' => $id
				);
		$this->m_tamu->hapus($where,'tamu');
		$tampil = $this->m_tamu->tampilall();
		$data['tampil'] = $tampil;
		$data['alert'] = 'success';
		$data['pesan'] = 'Berhasil di hapus';		
		$data['judul'] = 'Dashboard';
		$this->load->view('admin/tamu-all', $data);				
	}	
}

	
