<?php 
class M_register extends CI_Model{	
    
    function __construct() {
        parent::__construct();
    }
    
    function user_nik(){
        return $this->session->userdata('sess_nik');
    }
    
    function cek_email($data){
        $sql = "SELECT * FROM tb_user WHERE email = '$data[email]' AND is_deleted = 0 ";
        return $this->db->query($sql);
    }
    function add_user($data){
        $sql = "INSERT INTO `tb_user`   (`kode_user`,`username`, `email`, `tlp`, `unit_misioner`, `password`, `created_at`,`sebagai`) 
                                VALUES  ('$data[kode_user]','$data[username]','$data[email]','$data[tlp]','$data[unit_misioner]','$data[password]',NOW(),'1')";
        return $this->db->query($sql);
    }
    function cek_regist($kode_user){
        $sql = "SELECT id_user FROM tb_user WHERE kode_user = '$kode_user' AND valid = '0'";
        return $this->db->query($sql);
    }
    function ambil_email($kode_user){
        $sql = "SELECT email FROM tb_user WHERE kode_user = '$kode_user'";
        return $this->db->query($sql);
    }
    function ambil_tlp($kode_user){
        $sql = "SELECT tlp FROM tb_user WHERE kode_user = '$kode_user'";
        return $this->db->query($sql);
    }
    function terima($kode_user){
        $sql = "UPDATE `tb_user` SET `valid`='1' WHERE kode_user = '$kode_user'";
        return $this->db->query($sql);
    }
    function tolak($kode_user){
        $sql = "UPDATE `tb_user` SET `valid`='2' WHERE kode_user = '$kode_user'";
        return $this->db->query($sql);
    }
    function ambil_email_admin($data){
        $sql = "SELECT email FROM tb_user WHERE sebagai = '2' AND is_deleted = 0";
        return $this->db->query($sql);
    }
    function ambil_tlp_admin($data){
        $sql = "SELECT tlp FROM tb_user WHERE sebagai = '2' AND is_deleted = 0";
        return $this->db->query($sql);
    }
}