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

class Admin extends CI_Controller {
	
	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */

	/*function __construct(){
		session_start();
		parent::__construct();
		
	}*/
	public function index()
	{
		//$this->output->enable_profiler(TRUE);
		if(isset($_SESSION['logged'])){
			redirect('admin/dashboard');
		}
		//echo md5('welcome1234');die();
		//$data['main_content']='admin/login';
		$this->load->library('form_validation');
		$this->form_validation->set_rules('user','Email Address','required|valid_email');
		$this->form_validation->set_rules('pwd','Password','required|min_length[6]');
		
		if($this->form_validation->run() !== false){
			//echo 'aaaa',
			$this->load->model('admin_model');
			
			$result=$this->admin_model->authenticate($this->input->post('user'),$this->input->post('pwd'));
			
			if($result !== false){
				$_SESSION['logged']=true;
				$_SESSION['user_id']=$result->id;
				$_SESSION['username']=$result->first_name.' '.$result->last_name;
				$_SESSION['useremail']=$result->email;
				redirect('admin/dashboard');
			}
		}
		$data['title']='Donah Website Control panel';
		$data['bodyid']='admin-login';
		$this->load->view('admin/login',$data);
	}
	public function logout(){
		session_destroy();
		redirect('admin');
	}
}

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