<?php

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

class Usermaster extends CI_Model {

    public function usermaster_all() {
		$date = date("Y-m-d");
		
       	$this->db->select('a.*');
		$this->db->select('b.create_dt as dateRegister, b.fldid, b.email');
		$this->db->select('c.ID as companyID, c.companyName');
		$this->db->from('payment_receive a');
		$this->db->where('a.nextexpiracy = (select max(nextExpiracy) FROM payment_receive where userID = a.userID) AND a.dateReceive = "'.$date.'"');
		$this->db->where('a.is_delete', 0);
		$this->db->join('tbl_usermaster b', 'b.fldid = a.userID', 'LEFT');
		$this->db->join('company c', 'b.fldid = c.userID', 'LEFT');
		$this->db->order_by('b.create_dt', 'DESC');
		$query = $this->db->get();
		//echo $this->db->last_query();
        if($query->num_rows() >= 1){
            return $query->result();
        } else {
            return FALSE;
        }
    }



	public function usermaster_getIpAndAccessComp($ID) {
        $this->db->select('last_seen_ip, access_comp');
		$this->db->where('fldid', $ID);
        $this->db->from('tbl_usermaster a');
		$query = $this->db->get();
        if($query->num_rows() >= 1){
            return $query->result();
        } else {
            return FALSE;
        }
    }

	public function insertUsermaster($tname, $data){
		$sql = $this->db->insert_string($tname, $data);
		$query = $this->db->query($sql);
		if($query === TRUE){
			return TRUE;
		} else {
			return FALSE;
		}
	}

	

	public function getServerAndDatabase() {
		$this->db->from('view_next_server_allocation');
		$query = $this->db->get();
        if($query->num_rows() >= 1){
            return $query->result();
        } else {
            return FALSE;
        }
    }
	

	public function getLogin($userid, $password) {
		$query = $this->db->get_where('tbl_usermaster', array('userid' => $userid, 'password' => md5($password), 'is_delete' => 0), 1);
        if ($query->num_rows() == 1) {
            return $query->result();
        } else {
            return false;
        }
    }

	
	public function usermaster_edit($updateuser, $fldid) {
        $this->db->where('fldid', $fldid);
        $query = $this->db->update('tbl_usermaster', $updateuser);
        if ($query === TRUE) {
            return TRUE;
        } else {
            return FALSE;
        }
    }

	
	
	public function getForgetPassword_byIDDesc(){
		$this->db->from('forget_password');
		$this->db->order_by('ID', 'DESC');
        $query = $this->db->get();
        if($query->num_rows() >= 1) {
            return $query->result();
        } else {
            return FALSE;
        }
    }
	
	
	public function changePassword($tname, $data, $ID) {
        $this->db->where('ID', $ID);
        $query = $this->db->update($tname, $data);
        if ($query === TRUE) {
            return TRUE;
        } else {
            return FALSE;
        }
    }
	
//***********************************
	

}
