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

class Aqadmin_model extends CI_Model {
	function __construct()
	{
		parent::__construct();
		//$this->load->helper(array('form', 'url'));
	}
		function login($name, $password)

 	{

	   $this->db->select('*');

	   $this->db->from('exp_admin');

	   $this->db->where('email = ' . "'" . $name . "'");

	   $this->db->where('password = ' . "'" . $password . "'");
	   $this->db->where('ad_isactive = ' . "'" . 1 . "'");

	   $this->db->limit(1);

	   $query1 = $this->db->get();

	   if($query1 -> num_rows() == 1)

	   {

			 return $query1->result();

	   }

	   else

	   {

		 return FALSE;

	   }

 	}
 	function select_admin_email($name)

 	{

	   $this->db->select('*');

	   $this->db->from('exp_admin');

	   $this->db->where('email = ' . "'" . $name . "'");
	   $this->db->where('ad_isactive = ' . "'" . 1 . "'");

	   $query1 = $this->db->get();

	   if($query1 -> num_rows() == 1)

	   {

			 return $query1->result();

	   }

	   else

	   {

		 return FALSE;

	   }

 	}
 	
 	
	   function select($table,$field=NULL,$order=NULL)
 	{   
 		if($field!=NULL)
    	{
    		$this->db->order_by($field, $order); 
    	} 
        $reg=$this->db->get($table);
		return $reg->result();
	}

 	function select_condn($table,$cond,$field=NULL,$order=NULL)
	{
    	$this->db->where($cond);
    	if($field!=NULL)
    	{
    		$this->db->order_by($field, $order); 
    	} 
    	              
        $reg=$this->db->get($table);
        // echo $this->db->last_query();
		return $reg->result();
	}
	
	function select_single($table,$cond)
	{
		$this->db->where($cond);
		$result=$this->db->get($table);
		// echo $this->db->last_query();
		return $result->row();
	}

	function insert($table,$data)
	{

		$result=$this->db->insert($table,$data);
		if($result)
		{
			return 1;
		}
		else
		{
			$this->db->_error_number();
		}
	}
	
	function updatedata($table,$data,$cond)
	{         
		$this->db->where($cond);
		$result=$this->db->update($table,$data);
		if($result)
		{
			return 1;
		}
		else
		{
			return 0;
		}
	}
	function delete_single($table,$cond)
	{
		$this->db->where($cond);
		$this->db->delete($table);
	}
		function insert2($table,$data){

		$this->db->insert($table,$data);
		$affect=$this->db->affected_rows();
		return $affect;
		}
		
		function select1($table,$cond){
          $this->db->where($cond);           
         $reg=$this->db->get($table);
		return $reg;
		}
		
		function select2($table,$con,$field){
         $this->db->where($con);
          $this->db->order_by($field, "desc");                
         $reg=$this->db->get($table);
		return $reg;
		}
		function select3($table,$field){
        
          $this->db->order_by($field, "desc");                
         $reg=$this->db->get($table);
		return $reg;
		}
	
		
		function updatedata1($table,$con,$field,$points)
{
	$this->db->where($con);
    $this->db->set($field, $field.'+' . $points, FALSE);

    $this->db->update($table); 
}
function updatedata2($table,$con,$field,$points)
{
	$this->db->where($con);
    $this->db->set($field, $field.'-' . $points, FALSE);

    $this->db->update($table); 
}
			function count($table,$cond)
	{ 		
		 $this->db->where($cond); 	     
        return $this->db->count_all_results($table);
	}
		function count1($table)
	{ 		
		     
        return $this->db->count_all_results($table);
	}

	function insert1($table,$data){

		$this->db->insert($table,$data);
		$affect=$this->db->insert_id();
		return $affect;
		}
		function datadelete($table,$con){
		$this->db->where($con);
		$this->db->delete($table);

	}
	function updatedata3($table,$data,$cond){	  
       
          $this->db->where($cond);
		$affect=$this->db->update($table,$data);
		/*echo $affect=$this->db->affected_rows();
		$this->db->_error_message();
		echo "hii";*/
		return $affect;
		}
	
	
	}
