<?php
class Bukutamu_m extends CI_Model {
    

    function __construct()
    {        
        parent::__construct();
    }
	
	public function tampil($id)
    {
		$this->d_pas = $this->load->database('default', TRUE);
		$query = $this->d_pas->query("SELECT * FROM at_bukutamu where tenan_id='$id'");
        $b=$query->result();
		return $b;
    }
	
	public function hal($id)
    {
		$this->d_pas = $this->load->database('default', TRUE);
		$query = $this->d_pas->query("SELECT * FROM at_bukutamu where tenan_id='$id'");
        $b=$query->num_rows();
		return $b;
    }
	
	public function bukutamu_semua($cari, $tipe, $limit)
    {
		$this->d_pas = $this->load->database('default', TRUE);
        $query = $this->d_pas->query("SELECT * FROM at_bukutamu where tenan_id='$tipe' order by waktu DESC $limit");
        return $query->result();
		
    }
	
	public function simpan($nama, $hp, $alamat, $email, $isi, $balas)
    {
		$data = array(
        'nama' => $nama, 
        'hp' => $hp,
        'alamat' => $alamat, 
        'email' => $email,
        'isi' => $isi, 
        'balas' => $balas,
		'tenan_id' => $this->session->userdata('hak'),
		'waktu' => date('Y-m-d H:i:s')
		
        );
		$str = $this->db->insert_string('at_bukutamu', $data);
        mysql_query($str);
    }
	
	public function editsimpan($a, $nama, $hp, $alamat, $email, $isi, $balas)
    {
		$data = array(
        'nama' => $nama, 
        'hp' => $hp,
        'alamat' => $alamat, 
        'email' => $email,
        'isi' => $isi, 
        'balas' => $balas
        );

		$this->db->where('id', $a);
		$this->db->update('at_bukutamu', $data); 
    }
    
    	
	public function hapus($a, $b)
    {
		$this->db->where('id', $a);
		$this->db->where('tenan_id', $b);
		$this->db->delete('at_bukutamu'); 
    }

}