<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class M_login extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }

    function insert($data)
    {
        $this->db->insert('pengguna', $data);
    }

    function update($id, $data)
    {
        $this->db->where('id', $id);
        $this->db->update('pengguna', $data);
    }

    function setting()
    {
        return $this->db->query("SELECT * FROM pengaturan WHERE id = '2' ")->row();
    }

    function sys_pengguna($username, $password)
    {
        return $this->db->query("SELECT nik,email,hp,password FROM pengguna WHERE (nik = '$username' OR hp='$username' OR email='$username') and password = '$password' AND status <> '0' ")->row();
    }

    function cek_pengguna($username = "", $password = "")
    {
        return $this->db->query("SELECT * FROM pengguna WHERE (nik = '$username' OR hp='$username' OR email='$username') AND password = '$password' ")->row();
    }

    function pengguna($id)
    {
        $this->db->select('*');
        $this->db->from('pengguna AS A');
        $this->db->where('A.id', $id);
        return $this->db->get()->row();
    }


    function sys_users($username, $password)
    {
        return $this->db->query("SELECT username,password FROM user WHERE (username = '$username' OR kodesatker='$username' OR email='$username') and password = '$password' AND status = '1' ")->row();
    }

    function cek_user($username = "", $password = "")
    {
        return $this->db->query("SELECT * FROM user  WHERE (username = '$username' OR kodesatker='$username' OR email='$username') AND password = '$password' ")->row();
    }

    function user($id)
    {
        $this->db->select('*');
        $this->db->from('user AS A');
        $this->db->where('A.id', $id);
        return $this->db->get()->row();
    }

    function arr2md5($arrinput)
    {
        $hasil = '';
        foreach ($arrinput as $val) {
            if ($hasil == '') {
                $hasil = md5($val);
            } else {
                $code = md5($val);
                for ($hit = 0; $hit < min(array(strlen($code), strlen($hasil))); $hit++) {
                    $hasil[$hit] = chr(ord($hasil[$hit]) ^ ord($code[$hit]));
                }
            }
        }
        return (md5($hasil));
    }
	
	
	
}
