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

class Security extends CI_Controller {

	public function __construct() 
	{
		parent::__construct();
		
		$this->lang->load('account_general', get_language());
		$this->load->model('member_model');
    }

	public function index()
	{
		save_current_url(base_url() . 'security/');
		
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_security_center');
			
			$this->load->view('security', $data);
		}
		else {
			redirect('', 'refresh');
		}
	}
	
	public function login_password()
	{
		save_current_url(base_url() . 'security/login_password/');
		
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_security_center') . ' | ' . $this->lang->line('hf_login_password');
			
			$this->load->view('login_password', $data);
		}
		else {
			redirect('', 'refresh');
		}
	}
	
	public function security_password()
	{
		save_current_url(base_url() . 'security/security_password/');
		
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_security_center') . ' | ' . $this->lang->line('hf_security_password');
			
			$this->load->view('security_password', $data);
		}
		else {
			redirect('', 'refresh');
		}
	}
	
	public function profile()
	{
		save_current_url(base_url() . 'security/profile/');
		
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			$data = $this->member_model->get_member_account_details();
			
			$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_security_center') . ' | ' . $this->lang->line('hf_profile');
			
			$this->load->view('profile', $data);
		}
		else {
			redirect('', 'refresh');
		}
	}
	
	public function account_binding()
	{
		save_current_url(base_url() . 'security/account_binding/');
		
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			$data = $this->member_model->get_member_account_details();
			
			$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_account_binding');
			
			$this->load->view('account_binding', $data);
		}
		else {
			redirect('', 'refresh');
		}
	}
	
	public function share()
	{
		save_current_url(base_url() . 'security/share/');
		
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			$data = $this->member_model->get_member_account_details();
			
			$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_share_invitation_link');
			
			$this->load->view('share', $data);
		}
		else {
			redirect('', 'refresh');
		}
	}
	
	public function login_password_submit()
	{
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			if($_POST) {
				$rs = $this->member_model->change_login_password();
					
				echo $rs;
			}
			else {
				echo $this->lang->line('permission_denied');
			}	
		}
		else {
			echo $this->lang->line('permission_denied');
		}
	}
	
	public function security_password_submit()
	{
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			if($_POST) {
				$rs = $this->member_model->change_security_password();
					
				echo $rs;
			}
			else {
				echo $this->lang->line('permission_denied');
			}	
		}
		else {
			echo $this->lang->line('permission_denied');
		}
	}
		
	public function profile_submit()
	{
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			if($_POST) {
				$rs = $this->member_model->update_profile();
				
				echo $rs;
			}
			else {
				echo $this->lang->line('permission_denied');
			}
		}
		else {
			echo $this->lang->line('permission_denied');
		}
	}
	
	public function get_bank($country = NULL)
	{
		$html = '';
		$bank_list = get_china_bank();
		
		if($country == 'HK') {
			$bank_list = get_hong_kong_bank();
		}
		else if($country == 'MY') {
			$bank_list = get_malaysia_bank();
		}
		
		foreach($bank_list as $k => $v) {
			$html .= '<option value="' . $k. '">' . $this->lang->line($v) . '</option>';
		}
		
		echo $html;
	}
	
	public function disclaimer()
	{
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_security_center') . ' | ' . $this->lang->line('hf_disclaimer');
			
			$this->load->view('disclaimer', $data);
		}
		else {
			redirect('', 'refresh');
		}
	}
	
	public function account_binding_submit()
	{
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			if($_POST) {
				$rs = $this->member_model->account_binding();
					
				echo $rs;
			}
			else {
				echo $this->lang->line('permission_denied');
			}	
		}
		else {
			echo $this->lang->line('permission_denied');
		}
	}
}

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