<?php  
defined('BASEPATH') OR exit('No direct script access allowed');  
  
class Login extends CI_Controller {  
      
     public function index()
	{
		$data['title'] = 'Login';  
		$this->load->view('login',$data);
	}
	  
	  
	  //functions  
      function login()  
      {  
           //http://localhost/tutorial/codeigniter/main/login  
           $data['title'] = 'Login';  
           $this->load->view("login", $data);  
      }  
      function login_validation()  
      {  
           $this->load->library('form_validation');  
           $this->form_validation->set_rules('username', 'Username', 'required');  
           $this->form_validation->set_rules('password', 'Password', 'required');  
           if($this->form_validation->run())  
           {  
                //true  
                $username = $this->input->post('username');  
                $password = $this->input->post('password');  
                //model function  
                $this->load->model('main_model');  
                if($this->main_model->can_login($username, $password))  
                {  
                     $session_data = array(  
                          'username'     =>     $username  
                     );
					 $this->load->library('session');
					 $this->session->set_userdata($session_data);  
                     redirect(base_url() . 'main/enter');  
                }  
                else  
                {  
                     $this->session->set_flashdata('error', 'Invalid Username and Password');  
                     redirect(base_url() . 'main/login');  
                }  
           }  
           else  
           {  
                //false  
                $this->login();  
           }  
      }  
      function enter(){  
           if($this->session->userdata('username') != '')  
           {  
                redirect(base_url() . 'main/manage_cms');  
                echo '<label><a href="'.base_url

().'main/logout">Logout</a></label>';  
           }  
           else  
           {  
                redirect(base_url() . 'main/login');  
           }  
      }  
      function logout()  
      {  
           $this->session->unset_userdata('username');  
           redirect(base_url() . 'main/login');  
      } 
	  
	  
	  function manage_cms()  
      {  	
			$this->load->model('main_model');
			$data['data']=$this->main_model->get_pages();
			$data['title'] = 'Manage Cms';  
            $this->load->view("manage-cms", $data); 
           //redirect(base_url() . 'main/login');  
      } 


	function manage_users()  
      {  	
			//$this->load->model('main_model');
			//$data['data']=$this->main_model->get_pages();
			$data['title'] = 'Manage Users';  
            $this->load->view("manage-users", $data); 
           //redirect(base_url() . 'main/login');  
      }  

	function manage_forum()  
      {  	
			//$this->load->model('main_model');
			//$data['data']=$this->main_model->get_pages();
			$data['title'] = 'Manage Forum';  
            $this->load->view("manage-forum", $data); 
           //redirect(base_url() . 'main/login');  
      } 

	function forgot_pass()  
      {  	
			//$this->load->model('main_model');
			//$data['data']=$this->main_model->get_pages();
			$data['title'] = 'Forgot Password';  
            $this->load->view("forgot_pass", $data); 
           //redirect(base_url() . 'main/login');  
      }  	  
}  


?>  