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

class Register 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() . 'register/');
		
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			if($this->session->userdata('member_active') AND $this->session->userdata('member_active') == 1) {
				$data = $this->member_model->get_member_account_details();
				$data['setting'] = $this->member_model->get_setting_details();
				$data['package'] = $this->member_model->get_package_list();
				
				$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_registration');
				
				$this->load->view('register', $data);
			}
			else {
				redirect('', 'refresh');
			}	
		}
		else {
			redirect('', 'refresh');
		}
	}
	
	public function submit()
	{
		if($this->session->userdata('user_type') && $this->session->userdata('user_type') == MEMBER) {
			if($this->session->userdata('member_active') AND $this->session->userdata('member_active') == 1) {
				if($_POST) {
					$rs = $this->member_model->register_member();
					
					echo $rs;
				}
				else {
					echo $this->lang->line('permission_denied');
				}
			}
			else {
				echo $this->lang->line('permission_denied');
			}	
		}
		else {
			echo $this->lang->line('permission_denied');
		}
	}
	
	public function referrer($username = NULL)
	{
		save_current_url(base_url() . 'register/referrer/' . $username);
		
		if( ! $this->session->userdata('user_type')) {
			$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_registration');
			
			$this->load->view('register_referrer', $data);
		}
		else {
			redirect('home', 'refresh');
		}	
	}
	
	public function referrer_submit()
	{
		if( ! $this->session->userdata('user_type')) {
			if($_POST) {
				$rs = $this->member_model->register_member();
				
				echo $rs;
			}
			else {
				echo $this->lang->line('permission_denied');
			}
		}
		else {
			redirect('home', 'refresh');
		}
	}
}

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