<?php
	class Masuk_model extends CI_Model {
		function __construct()
		{
			// Call the Model constructor
			parent::__construct();
			
			$this->dbhost=$this->load->database('khanza', TRUE);
					
			date_default_timezone_set('Asia/Jakarta');
		}
		
		/* public function getDataUser($user, $paswd)
		{
			$q=$this->db->get_where('karyawan1p', array('nik'=>$user, 'passwd'=> md5($paswd)));
			return $q->row();
		} */
		
		public function cek_loginPerujuk($email, $passwd)
		{
			$this->db->select("nik, nama");
			$this->db->where('nik', $email);
			$this->db->where('password', md5($passwd));
			$q = $this->db->get('perujuk');
			
			return $q->num_rows()>0?TRUE:FALSE;
		} 
		
		public function getDataUserPerujuk($email, $paswd)
		{
			$q=$this->db->get_where('perujuk', array('nik'=>$email, 'password'=> md5($paswd)));
			return $q->row();
		}
		
		public function getDataUser($user, $paswd)
		{
			//$q=$this->dbhost->get_where('users', array('nama'=>$user, 'password'=> $paswd));
			$q=$this->dbhost->query("SELECT AES_DECRYPT(a.`id_user`,'nur') AS id_user,AES_DECRYPT(a.`password`,'windi') AS passwd, b.* 
FROM `user` AS a 
LEFT JOIN `petugas` AS b ON AES_DECRYPT(a.`id_user`,'nur')=b.`nip`
WHERE a.`id_user`=AES_ENCRYPT('$user','nur') AND a.`password`=AES_ENCRYPT('$paswd','windi');");
			return $q->row();
		}
		
		public function cek_login($email, $passwd)
		{
			/* $this->dbhost->select("nama, DeptID");
			$this->dbhost->where('nama', $email);
			$this->dbhost->where('password', $passwd);
			$this->dbhost->where('status', 'A');
			$q = $this->dbhost->get('users'); */
			
			$q=$this->dbhost->query("SELECT AES_DECRYPT(a.`id_user`,'nur') AS id_user,AES_DECRYPT(a.`password`,'windi') AS passwd FROM `user` AS a WHERE a.`id_user`=AES_ENCRYPT('$email','nur') AND a.`password`=AES_ENCRYPT('$passwd','windi');");
						
			return $q->num_rows()>0?TRUE:FALSE;
		}
	}
