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

class Profile extends MY_Controller {

	public function index()
	{
		save_current_url(base_url() . 'profile/');
		
		if($this->session->userdata('user_type') && ($this->session->userdata('user_type') == SUPERADMIN || $this->session->userdata('user_type') == ADMIN)) {
			$this->lang->load('account_general', get_language());
			
			$this->load->model('user_model');
			
			$data['profile'] = $this->user_model->get_user_details();
			
			$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_profile') . ' - ' . $this->lang->line('hf_edit_profile');
			
			$this->load->view('profile', $data);
		}
		else {
			redirect('login', 'refresh');
		}
	}
	
	public function update()
	{
		if($this->session->userdata('user_type') && ($this->session->userdata('user_type') == SUPERADMIN || $this->session->userdata('user_type') == ADMIN)) {
			if($_POST) {
				$this->lang->load('account_general', get_language());
			
				$this->load->model('user_model');
				
				$rs = $this->user_model->update_user_details();
				
				if($rs) {
					redirect('profile/', 'refresh');
				}
				else {
					$_POST['profile'] = $this->user_model->get_user_details();
					$_POST['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_profile') . ' - ' . $this->lang->line('hf_edit_profile');
					
					$this->load->view('profile', $_POST);
				}
			}
			else {
				redirect('profile/', 'refresh');
			}
		}
		else {
			redirect('login', 'refresh');
		}
	}
	
	public function password()
	{
		save_current_url(base_url() . 'profile/password/');
		
		if($this->session->userdata('user_type') && ($this->session->userdata('user_type') == SUPERADMIN || $this->session->userdata('user_type') == ADMIN)) {
			$this->lang->load('account_general', get_language());
			
			$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_profile') . ' - ' . $this->lang->line('hf_change_password');
			
			$this->load->view('profile_password', $data);	
		}
		else {
			redirect('login', 'refresh');
		}
	}
	
	public function change_login_password()
	{
		if($this->session->userdata('user_type') && ($this->session->userdata('user_type') == SUPERADMIN || $this->session->userdata('user_type') == ADMIN)) {
			if($_POST) {
				$this->lang->load('account_general', get_language());
			
				$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_profile') . ' - ' . $this->lang->line('hf_change_password');
			
				$this->load->model('user_model');
				
				$rs = $this->user_model->change_login_password();
					
				if($rs) {
					redirect('profile/password/', 'refresh');
				}
				else {
					$this->load->view('profile_password', $data);
				}
			}
			else {
				redirect('profile/password/', 'refresh');
			}	
		}
		else {
			redirect('login', 'refresh');
		}
	}
}

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