<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Clients Model FrontEnd
 *
 * @author Deepak saini
 */
if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Home_model extends CI_Model {    
   
	function get_login_details($email,$password){
		$this->db->where('EmailId', $email)->where('IsActive',1);  
		$validEmail = $this->db->get('tbladmin');		
		$dataEmail = $validEmail->num_rows();
		
		if($dataEmail){
			$this->db->where('EmailId', $email); 
			$this->db->where('Password', md5($password));
			$query = $this->db->get('tbladmin');
			$data = $query->row();
			if($data){
				 
				//var_dump($data);die;
				$admindata = array(
					'AdminId'    => $data->id,
					'FirstName'   => $data->FirstName,
					'TitleName'   => $data->TitleName,
					'RoleId'   	  => $data->RoleId,
					'EmailId'     => $data->EmailId,					 
					'Logged_In'   => TRUE
				);
				
				$this->session->set_userdata('mapmyadmin', $admindata);
				echo json_encode(array("success"=>true, "text"=>'<span style="color:green">Login Success!.</span>'));
				 
			}else{
				echo json_encode(array("success"=>false, "field_name"=>'a_password', "text"=>'<span style="color:red">Please enter valid Password.</span>'));
			}
		}else{
			echo json_encode(array("success"=>false, "field_name"=>'a_email', "text"=>'<span style="color:red">Account is deactivate.</span>'));
		}	
	}

	public function is_email_exists($email) {
        $query = $this->db->select('*')->from('tbladmin')->where('EmailId', $email)->get();
        if ($query->num_rows() == 0) {
            return false;
        }
        return $query->row();
    }
	

     
}
