<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Bukutamu extends CI_Controller {
	
	public function __construct()
    {
        parent::__construct();
		$this->load->model('login');
		$this->load->model('bukutamu_m', 'bukutamu');
    }

	
	public function index()
	{
		$a=$this->session->userdata('username');
		$this->login->cek_login_siswa($a);
		$d['i_judul'] = "Bukutamu ".$this->config->item('nama_aplikasi_full');
        
        
        $config['total_rows'] = $this->bukutamu->hal($this->session->userdata('hak'));
		$config['per_page'] = 10;
		$config['uri_segment'] = 3;
		$config['full_tag_open'] = '<table id="simple-table" class="table-striped table-bordered table-hover"><thead><tr>';
		$config['full_tag_close'] = '</tr></thead></table>';
		$config['prev_link'] = '<th width="20" align="center">&lt;</th>';
		$config['prev_tag_open'] = '<th width="20" align="center">';
		$config['prev_tag_close'] = '</th>';
		$config['next_link'] = '<th width="20" align="center">&gt;</th>';
		$config['next_tag_open'] = '<th width="20" align="center">';
		$config['next_tag_close'] = '</th>';
		$config['cur_tag_open'] = '<th width=20" align="center"><a href="#" class="pi-active">';
		$config['cur_tag_close'] = '</a></th>';
		$config['num_tag_open'] = '<th width="20" align="center">';
		$config['num_tag_close'] = '</th>';
		 
		$config['first_tag_open'] = '<td width="20" align="center">';
		$config['first_tag_close'] = '</td>';
		$config['last_tag_open'] = '<td width="20" align="center">';
		$config['last_tag_close'] = '</td>';
		 
		$config['first_link'] = '<td width="20" align="center">&lt;&lt;</td>';
		$config['last_link'] = '<td width="20" align="center">&gt;&gt;</td>';
		$config['base_url'] = base_url()."index.php/bukutamu/index/";
		$this->pagination->initialize($config);
		
		
		
		$hal = $this->uri->segment(3);
		 if($hal==""){
			 $hal=0;
		}
           
        
		$d['page'] = $this->pagination->create_links();
		$d['no'] = $hal;
        
        $d['blog'] = $this->bukutamu->bukutamu_semua("", $this->session->userdata('hak'), "limit $hal, $config[per_page]");
        
        
		$this->load->view("theme/header", $d);
		$this->load->view('bukutamu/at_tampil',$d);
		$this->load->view("theme/footer");
	}
	
	
	 public function tambah($aksi=null, $id=null)
	{
	   $a=$this->session->userdata('username');
		$this->login->cek_login_siswa($a);
		
		
        
        
       
        
        $d['id'] = $id;
        
        if($aksi=="edit" and $id!=""){
			$d['i_judul'] = "Bukutamu";
            $d['nama']=balik2("at_bukutamu", "nama", "id", $id, "tenan_id", $this->session->userdata('hak'));
            $d['hp']=balik2("at_bukutamu", "hp", "id", $id, "tenan_id", $this->session->userdata('hak'));
            $d['alamat']=balik2("at_bukutamu", "alamat", "id", $id, "tenan_id", $this->session->userdata('hak'));
            $d['email']=balik2("at_bukutamu", "email", "id", $id, "tenan_id", $this->session->userdata('hak'));
            $d['isi']=balik2("at_bukutamu", "isi", "id", $id, "tenan_id", $this->session->userdata('hak'));
            $d['balas']=balik2("at_bukutamu", "balas", "id", $id, "tenan_id", $this->session->userdata('hak'));
        }
        elseif($aksi=="" and $id==""){
			$d['i_judul'] = "Tambah Bukutamu";
            $d['nama']="";
            $d['hp']="";
            $d['alamat']="";
            $d['email']="";
            $d['isi']="";
            $d['balas']="";
            
        }
        
		$this->load->view("theme/header", $d);
		$this->load->view('bukutamu/at_tambah',$d);
		$this->load->view("theme/footer");
	}
    
    public function simpan()
	{
	   $a=$this->session->userdata('username');
		$this->login->cek_login_siswa($a);
		
	   $id = $this->input->post('id');
       $nama = $this->input->post('nama');
       $hp = $this->input->post('hp');
       $alamat = $this->input->post('alamat');
       $email = $this->input->post('email');
       $isi = $this->input->post('isi');
	   $balas = $this->input->post('balas');
       
       
       if($id==""){
        $this->bukutamu->simpan($nama, $hp, $alamat, $email, $isi, $balas);
        echo"<html><head><meta http-equiv='refresh' content='0;url=".base_url()."index.php/bukutamu'></head><body></body></html>";
       }
       if($id!=""){
        $this->bukutamu->editsimpan($id, $nama, $hp, $alamat, $email, $isi, $balas);
        echo"<html><head><meta http-equiv='refresh' content='0;url=".base_url()."index.php/bukutamu'></head><body></body></html>";
       }
       
       
       
    }
    
    public function hapus($id=null)
	{
		$a=$this->session->userdata('username');
		$this->login->cek_login_siswa($a);
        $tipe=balik("at_bukutamu", "tenan_id", "id", $id);
        $this->bukutamu->hapus($id, $this->session->userdata('hak'));
        
		echo "<script>alert('Data berhasil dihapus')</script>";
		echo"<html><head><meta http-equiv='refresh' content='0;url=".base_url()."index.php/bukutamu'></head><body></body></html>";
	}
	
	
	
	
	
	
	
}
