<?php

class Admin extends CI_Controller {

public function index(){

 if ($this->session->userdata('user_id')) 
  return redirect('https://wwdemosite.com/Empire_Ranch/adminpanel/dashboard');
$this->load->helper('form');	
$this->load->view('public/admin_login');
}


public function login()
{

$this->load->library('form_validation');
$this->form_validation->set_rules('name11', 'Name', 'required|alpha|trim');
$this->form_validation->set_rules('phone11', 'Password', 'required');
$this->form_validation->set_error_delimiters('<div class="text-danger">', '</div>');
$this->load->helper('url');
      if( $this->form_validation->run() )
      {
        //Success
        $username = $this->input->post('name11');
        $password = $this->input->post('phone11');
        $this->load->model('loginmodel');    

        $login_id = $this->loginmodel->login_valid($username, $password);
        
        if ($login_id) {          
         
          $this->session->set_userdata('user_id',$login_id);
         return redirect('https://wwdemosite.com/Empire_Ranch/adminpanel/dashboard');
         //return redirect('../index.php/adminpanel/dashboard');
         // $this->load->controller('adminpanel/dashboard');  
          //$this->load->view('admin/dashboard');         
          //echo "password match";
          //valid user
        }
        else
        {

          $this->session->set_flashdata('login_failed',"Invalid Username and Password");
          return redirect('https://wwdemosite.com/Empire_Ranch/admin');
           echo "password not match";
          // invalid user
        }


      } 
      else
      {

       //failed
	     $this->load->view('public/admin_login');	     

       }



   }


   public function logout()

    {
      $this->session->unset_userdata('user_id');
      return redirect('https://wwdemosite.com/Empire_Ranch/admin');
    }

}
?>