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

class Welcome extends CI_Controller {

	public function notfound()
	{
		$this->load->view('v_notfound');
	}

	public function index()
	{
		if($this->session->userdata('status')=="telah_login"){
			redirect(base_url().'Perolehan');
		}else {
			$this->load->view('v_login');
		}
	}

	public function aksi()
	{

		$this->form_validation->set_rules('username', 'Username', 'required');
		$this->form_validation->set_rules('password', 'Password', 'required');		

		if($this->form_validation->run() != false){			
			$username = $this->input->post('username');
			$password = $this->input->post('password');			


			$where = array(
				'user_username' => $username,
				'user_password' => md5($password)
			);

			$this->load->model('m_data');
			$cek = $this->m_data->cek_login('user',$where)->num_rows();
			if($cek > 0){				
				$data = $this->m_data->cek_login('user',$where)->row();
				$data_session = array(
					'id' => $data->user_id,
					'nama' => $data->user_nama,						
					'status' => 'telah_login'
				);
				$this->session->set_userdata($data_session);	
				$level = $data->user_level;
				if($level=="Admin"){
					redirect(base_url().'Perolehan');
				}elseif ($level=="Kepala") {
					redirect(base_url().'Perolehan');
				}					
				
			}else{
				redirect(base_url().'?alert=gagal');
			}

		}else{
			$this->load->view('v_login');
			
		}
	}
}
