<?php

class m_user extends CI_Model {

    private $table = "web_admin";

    function cek($username, $password) {
        $this->db->where("user", $username);
        $this->db->where("pass", md5($password));
        return $this->db->get("web_admin");
    }

    function semua() {
        return $this->db->get("web_admin");
    }

    function cekKode($kode) {
        $this->db->where("web_admin", $kode);
        return $this->db->get("web_admin");
    }

    function cekId($kode) {
        $this->db->where("id", $kode);
        return $this->db->get("web_admin");
    }
    
    function getLoginData($usr, $psw) {
        $u = mysql_real_escape_string($usr);
        $p = mysql_real_escape_string($psw);
        $q_cek_login = $this->db->get_where('web_admin', array('user' => $u, 'pass' => $p,'status_user' => 'Aktif'));
        if (count($q_cek_login->result()) > 0) {
            foreach ($q_cek_login->result() as $qck) {
                foreach ($q_cek_login->result() as $qad) {
                    $sess_data['logged_in'] = 'aingLoginWebYeuh';
                    $sess_data['id'] = $qad->id;
                    $sess_data['username'] = $qad->username;
                    $sess_data['nama'] = $qad->nama;
                    $sess_data['status'] = $qad->status;
                    $sess_data['status_user'] = $qad->status_user;
                    $this->session->set_userdata($sess_data);
                }
                redirect('dashboard');
            }
        } else {
            $this->session->set_flashdata('result_login', '<br>Username atau Password yang anda masukkan salah.');
            header('location:' . base_url() . 'login');
        }
    }

    function update($id, $info) {
        $this->db->where("id", $id);
        $this->db->update("user", $info);
    }

    function simpan($info) {
        $this->db->insert("user", $info);
    }

    function hapus($kode) {
        $this->db->where("id", $kode);
        $this->db->delete("user");
    }

}
