<?php

	defined('BASEPATH') or exit('No Direct Script is Allowed');

	/**
	 * 
	 */
    class LoginController extends CI_Controller
	    {
		    function __construct(){
                parent::__construct();
            }
            
            public function index(){
                $this->load->view('backend/login');
            }  
            
            public function login_action(){
            	$adm_email = $this->input->post('email');
            	$adm_password = $this->input->post('password');
            	$this->db->where('adm_email', $adm_email);
            	$this->db->where('adm_password', $adm_password);
            	$this->db->where('adm_status', '1');
            	$admin  = $this->db->get('tbl_admin');
		            if($admin->num_rows() > 0){
                	        $row = $admin->row();
                			$data = array(
                			    'id' => $row->adm_id,
                				'name' => $row->adm_name,
                				'mobile' => $row->adm_phone,
                				'email' => $row->adm_email,
                				);
                			$this->session->set_userdata($data);
                			echo json_encode(['msg' => 'done']);
                			exit;
                	}else{
                			echo json_encode(['msg' => 'error']);
                			exit;
                		}
		    }
		    
		    public function logout(){
			    $this->session->sess_destroy();
      		        redirect('/login');
		    }
	}