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

class Setting extends MY_Controller {

	public function index()
	{
		if($this->session->userdata('user_type') && ($this->session->userdata('user_type') == SUPERADMIN || $this->session->userdata('user_type') == ADMIN)) {
			redirect('setting/service_setting', 'refresh');
		}
		else {
			redirect('login', 'refresh');
		}
	}
	
	public function service_setting()
	{
		save_current_url(base_url() . 'setting/service_setting/');
		
		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 = $this->user_model->get_service_setting();
			
			$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_setting') . ' - ' .$this->lang->line('hf_service_setting');
			
			$this->load->view('service_setting', $data);
		}
		else {
			redirect('login', 'refresh');
		}
	}
	
	public function service_setting_submit()
	{
		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());
			
				$_POST['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_setting') . ' - ' .$this->lang->line('hf_service_setting');
			
				$this->load->model('user_model');
				
				$rs = $this->user_model->set_service_setting();
					
				if($rs) {
					redirect('setting/service_setting/', 'refresh');
				}
				else {
					$this->load->view('service_setting', $_POST);
				}
			}
			else {
				redirect('setting/service_setting/', 'refresh');
			}	
		}
		else {
			redirect('login', 'refresh');
		}
	}
	
	public function currency_rate()
	{
		save_current_url(base_url() . 'setting/currency_rate/');
		
		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['currencies'] = $this->user_model->get_curency_rates();
			
			$data['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_setting') . ' - ' .$this->lang->line('hf_currency_rate');
			
			$this->load->view('currency_rate', $data);
		}
		else {
			redirect('login', 'refresh');
		}
	}
	
	public function currency_rate_submit()
	{
		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());
			
				$_POST['page_title'] = $this->lang->line('website_name') . ' | ' . $this->lang->line('hf_setting') . ' - ' .$this->lang->line('hf_currency_rate');
			
				$this->load->model('user_model');
				
				$rs = $this->user_model->set_currency_rate();
					
				if($rs) {
					redirect('setting/currency_rate/', 'refresh');
				}
				else {
					$this->load->view('currency_rate', $_POST);
				}
			}
			else {
				redirect('setting/currency_rate/', 'refresh');
			}	
		}
		else {
			redirect('login', 'refresh');
		}
	}
}

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