<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class login extends CI_Controller {

	function __contruct() //constructor
	{
		parent::__contruct();
			
		$this->load->helper('cookie');
		$this->load->model('m_login');
	}

	public function index()
	{
		$this->load->view('pages/login');
	}
	
	function dologin()
	{
		//validation
		$this->load->library('form_validation'); //default CI
		$valid = $this->form_validation;
		
		$valid->set_rules('username','Username','required|min_length[5]|xss_clean');
		$valid->set_rules('password','Password','required|min_length[5]|xss_clean');
	
		if($valid->run())
			{$this->load->model('m_login');
				$datauser = $this->input->post();
				
				$hasilcek = $this->m_login->check($datauser);
				
				if($hasilcek->num_rows() > 0)
				{
					$res = $hasilcek->result();
					foreach($res as $r){
						$uName = $r->username;
						$idAdmin = $r->adminId;
					}
					
					$this->session->set_userdata('sesAdmin',$uName);
					$this->session->set_userdata('sesID',$idAdmin);
					header( 'Location: '.base_url().'index.php/partners' ) ;
				}
				else
				{
					/*if($this->session->userdata('cbuff'))
					{
						$cc = $this->session->userdata('cbuff');
						$bb = 3 - $cc;
						$this->session->set_flashdata('msg',"Username atau Password tidak sesuai anda mempunyai ".$bb . "x kesempatan lagi");

					}
					else
					{
						$this->session->set_flashdata('msg',"Username atau Password tidak sesuai anda mempunyai 3x kesempatan lagi");
					}
					$this->buffer();
					*/
					redirect('index.php/login');
				}
				
			}
			else
			{
				$this->index();
			}	
		
	}
	
	function dologout()
			{
				$this->session->sess_destroy();
				redirect('index.php/login','refresh');
			}
	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */