<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Profile extends MY_Controller{
	public function index(){
		$user = $this->fm->get_current_user();
		if($user != NULL){
			$data['user'] = $user;
			
			$this->load->view($this->router->fetch_class()."/index", $data);
		}
		else{
			redirect(base_url("logout"));
		}
	}
	
	public function update(){
		$this->load->model("user_model");
		$post = $this->input->post();
		
		//To prevent loss---
		$this->fm->keep_all_page_filter();
		//------------------
		
		$user_array = $this->user_model->get_data(array(
			'condition' => "<T>.<PK> = '".$this->session->userdata('user_id')."' AND <T>.PASSWORD = '".sha1($post['OLD_PASSWORD'])."'",
		));
		
		if(count($user_array) > 0){
			if($this->user_model->save($post)){
				$this->session->set_flashdata('success', "Update Successful!");
			}
			else{
				$this->session->set_flashdata('error', "Update Failed!");
			}
		}
		else{
			$this->session->set_flashdata('error', "Incorrect Password!");
		}
		
		redirect(base_url($this->router->fetch_class()));
	}
}