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

        class beranda  extends CI_Controller {

            public function __construct()
            {
                parent::__construct();
                $this->load->library(array('form_validation', 'pagination')); 
                $this->load->helper('url');
                
                $this->load->model('karyawan_model');
                
            }

           
        function index(){
        $this->load->view('login2');
        }
          public function loginact(){
        $this->_validate();
        $this->karyawan_model->ceklogin();
        
        }

     
      
        function logout(){
        $this->session->sess_destroy();
        redirect('beranda');     
    }
         private function _validate()
    {
        $data = array();
        $data['error_string'] = array();
        $data['inputerror'] = array();
        $data['status'] = TRUE;
        $username = $this->input->post('username');
        $resultuser = $this->karyawan_model->checkusername($username);
        $password = md5($this->input->post('password'));
        $resultpass = $this->karyawan_model->checkpassword($password);
        if($this->input->post('username') == '')
        {
            $data['inputerror'][] = 'username';
            $data['error_string'][] = 'username harap diisi';
            $data['status'] = FALSE;
        }
        if ($resultuser == '0') 
        {
            $data['inputerror'][] = 'password';
            $data['error_string'][] = 'username atau password salah';
            $data['status'] = FALSE;
        }
        if($this->input->post('username') == '')
        {
            $data['inputerror'][] = 'username';
            $data['error_string'][] = 'username harap diisi';
            $data['status'] = FALSE;
        }

        if ($resultpass == '0') 
        {
            $data['inputerror'][] = 'password';
            $data['error_string'][] = 'username atau password salah';
            $data['status'] = FALSE;
        }

        if($this->input->post('password') == '')
        {
            $data['inputerror'][] = 'password';
            $data['error_string'][] = 'password harap diisi';
            $data['status'] = FALSE;
        }
        if($data['status'] === FALSE)
        {
            echo json_encode($data);
            exit();
        }
    }
     
    }
