<?php 
class User extends Admin_Controller{
	
	function __construct()
		{
			parent::__construct();
			
		$this->load->model("mod_user");
		$this->load->library("form_validation");
		$this->load->helper(array('form','file'));
		
		
		}
		
	public function profile(){
		$tab['activeTab'] = "";
		//FORM validation rules
		$this->form_validation->set_rules('username', 'Username', 'required|min_length[5]|max_length[60]');
		$this->form_validation->set_rules('nusername', 'New Name', 'required|min_length[5]|max_length[60]');
		$this->form_validation->set_rules('opassword', 'Old Password', 'required|min_length[5]|max_length[20]');
		$this->form_validation->set_rules('npassword', 'New Password', 'required|min_length[5]|max_length[20]');
		$this->form_validation->set_rules('cpassword', 'Confirm Password', 'required|min_length[5]|max_length[20]|matches[npassword]');
		//End Rules
		
		if($this->form_validation->run() == TRUE){
		
		//Altering Database
		$username = $this->input->post('username');
        $password = sha1($this->input->post('opassword'));
		if($this->mod_user->compPassword($username, $password)){
			$id = $this->session->userdata('userId');
			$postdata['username'] = $_POST['nusername'];
			$postdata['password'] = sha1($_POST['npassword']);
			$this->mod_user->changeProfile($postdata,$id);
			$this->session->set_flashdata('message',"Profile Update successfully");
			redirect('admin/home');
        	exit();
		
		}else{
		$this->session->set_flashdata('message',"Profile Upadate failure");
			redirect('admin/user/profile');
        	exit();	
			
		}
			
		//End Altering Database
			
		}

		$this->load->view("admin/header",$tab);
		$this->load->view("admin/profile");
		$this->load->view("admin/footer");		
		
		}
	
	
	}