<?php
class Auth_model extends CI_Model {
    
    // Admin login function
	public function login ( $data ) {
		$query = $this->db->get_where ( 'admins', array ( 'email' => $data['email'] ) );

		if ( $query->num_rows () == 0 ) {
			return false;
		} else {
			$result = $query->row_array ();
			if ( md5 ( $data['password'] ) == $result['password'] ) {
				return $result = $query->row_array ();
			}
		}
	}
	
	// Admin email exists
	public function admin_email_exists ( $email ) {
	    
		$query = $this->db->get_where ( 'admins', array ( 'email' => $email ) );
		
		if ( $query->num_rows () == 0 ) {
			return false;
		} else {
			return $query->row_array ();
		}
	}
	
	// Update admin details
	public function update_admin ( $data ) {
		$id = $data['id'];
		unset($data['id']);
		$this->db->where( 'id', $id );
		$this->db->update( 'admins', $data );
		return true;
	}
	
	// Get admin details
	public function get_admin_detail ( $id ) {
		$query = $this->db->get_where( 'admins', array( 'id' => $id ) );
		return $result = $query->row_array();
	}
}
?>