<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class User_online_m extends CI_Model {
	function parseOrderby($col){
		if($col==1){
			return "fullname"; 
		}else if($col==2){
			return "username"; 
		}else if($col==3){
			return "host_address"; 
		}else{
			return "fullname";
		}
	}

	function get_user_online_list($col=1,$asc_desc='ASC',$begin=0,$key=''){
		$orderby = $this->parseOrderby($col);
		$where = '';
		if(!empty($key)){
			$where .= ' AND (fullname LIKE "%'.$key.'%" OR host_address LIKE "%'.$key.'%") ';
		}
		try {		
		
			return $this->db->query("SELECT su.username,su.fullname, suo.host_address, convert_tanggal_indonesia(suo.login_time) AS tanggal_login,TIME(suo.login_time) AS waktu_login FROM sys_user_online AS suo
				LEFT JOIN sys_users AS su ON suo.userid=su.userid
				WHERE DATE(login_time)=CURDATE() ".$where." ORDER BY ".$orderby." LIMIT ".$begin.",50;");
		} catch (Exception $e) {
			
		}
	}

	function fecth_data_num(){
		$query = $this->db->query("SELECT FOUND_ROWS() as cnt;");
		if($query->num_rows>0){
			foreach ($query->result() as $row) {
				return $row->cnt;
			}
    		return $query->num_rows;
    	}else{
    		return 0;
    	}
	}

	
}
?>