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

class Welcome extends CI_Controller {
public function __construct(){

        parent::__construct();
           $this->load->model('page_model');
  			$this->load->helper('url');
  	 		$this->load->model('user_model');
            $this->load->library('session');
    
           $this->load->helper(array('form', 'url'));
            $this->load->library('table');
       
       

 

}
	
	public function login()
	{
		$this->load->view('login.php');
	}
    public function dashboard(){
       
    $user_login=array(

  'user_email'=>$this->input->post('user_email'),
  'user_password'=>md5($this->input->post('user_password'))

    );
 $superemail=$this->input->post('user_email');
    $superpass=$this->input->post('user_password');
    $superadmin=$this->user_model->superlogin_user($superemail, $superpass);
    $data=$this->user_model->login_user($user_login['user_email'],$user_login['user_password']);
    
   
   
      if($data)
      {
         
        $this->session->set_userdata('user_id',$data['user_id']);
        $this->session->set_userdata('user_email',$data['user_email']);
        $this->session->set_userdata('first_name',$data['first_name']);
       
      redirect('user/dash', 'refresh');
        //$this->load->view('dashboard.php');

      }
    if($superadmin){
       foreach ($superadmin as $key=> $admin)
      
        $this->session->set_userdata('user_id',$admin->user_id);
        $this->session->set_userdata('user_email',$admin->user_email);
        //$this->session->set_userdata('first_name',$admin->user_first_name);
       
      redirect('user/dash', 'refresh');
    }
      else{
        $this->session->set_flashdata('error_msg', 'Error occured,Try again.');
        $this->load->view("login.php");

      }

  
}
}
