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

class Change extends MY_Controller
{
    
     public $data = array(
        'breadcrumb'    => 'Change Password',
        'modul'         => 'Change Password',
        'pesan'         => '',
        'pagination'    => '',
        'datatable'    => '',
        'main_view'     => 'changepassword/changepassword', ///This View Form or Table is want to the load
        'form_action'   => '',
        'form_value'    => '',
        );
	
    public function __construct()
    {	
        parent::__construct();		
        $this->load->model('User_model', 'user', TRUE);
        $this->load->model('Login_model', 'userSession', TRUE);
        $this->load->library('session');
        $this->load->helper('encryption');
    }
	
    public function index()
    {
        $session_username = $this->session->userdata('username');
        $session_data = $this->session->userdata('full_name');
        $session_role = $this->session->userdata('role_id');
        $this->data['username'] = $session_username;   
        $this->data['full_name'] = $session_data;   
        $this->data['role_id'] = $session_role;     
        $this->data['role'] = $this->user->getRole();
        $this->load->view('template', $this->data);
    }

    public function CheckPassword()
    {
        $username = $this->input->post('username');   
        $datauser = $this->user->GetUserRowById($username);
        $oldpasstyping  = $this->input->post('oldpassword');

        $decriptCurrentPass = decrypt($datauser->password);
        if($decriptCurrentPass !=  $oldpasstyping)
        { 
            echo "<span class='password_status'> Password Yang Anda Ketikan Sekarang Tidak Sesuai Denga Username Anda</span>";
        } else{
            echo "";
        }
    }

    public function UpdatePassword()
    {
        $id =  $this->input->post('username');  
        $password = encrypt($this->input->post('txtNewPassword'));  
        $data = array(
                           
                        'password'  => $password, 
                    );
     
      $simpan = $this->user->UpdateUser($id,$data);
      echo 'ok';
    }
}

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