<?php 

class M_user extends CI_Model{	

    

    function __construct() {

        parent::__construct();

    }

    

    function kode_user(){
        return $this->session->userdata("kode_user");
    }

    

    function data_user($data){

        if ($data["valid"] == "semua") {

            $valid = "";

        }else{

            $valid = "u.valid='".$data["valid"]."' AND";

        }

        $sql = "SELECT u.*,um.nama nama_um FROM tb_user u

                LEFT JOIN tb_unit_misioner um ON um.id_unit_misioner = u.unit_misioner

                WHERE $valid u.sebagai=1 AND u.is_deleted = 0 ";

        return $this->db->query($sql);

    }

    function ambil_email($data){

        $sql = "SELECT p.email FROM tb_user as p 

                WHERE p.id_user = '$data[id_user]'";

        return $this->db->query($sql);

    }
    function ambil_tlp($data){

        $sql = "SELECT p.tlp FROM tb_user as p 

                WHERE p.id_user = '$data[id_user]'";

        return $this->db->query($sql);

    }

    function tolak_user($data){
        $kode_user = $this->kode_user();

        $sql = "UPDATE `tb_user` SET `valid`='2',`valid_oleh`='$kode_user' WHERE id_user = '$data[id_user]'";

        return $this->db->query($sql);

    }

    function terima_user($data){
        $kode_user = $this->kode_user();
        $sql = "UPDATE `tb_user` SET `valid`='1',`valid_oleh`='$kode_user' WHERE id_user = '$data[id_user]'";

        return $this->db->query($sql);

    }

    function hapus_user($data){

        $sql = "UPDATE `tb_user` SET `is_deleted`='1' WHERE id_user = '$data[id_user]'";

        return $this->db->query($sql);

    }
    function ambil_valid_oleh($data){
        $sql = "SELECT p.username FROM tb_user as p 
                WHERE p.kode_user = '$data[kode_user]'";
        return $this->db->query($sql);
    }

}