<?php

Class Lwds extends CI_Model
{
	private $mysql;
	public $lwd_id;
	public $login_name;
	public $fname;
	public $password;
	public $imei;
	public $email_address;
	public $costcenter;
	public $address;
	public $operator_table;
	public $signal_kill;
	

	function __construct()
	{
		parent::__construct();
		$this->mysql = $this->load->database('mysql',true);
		$this->operator_table = 'operators';
	}

	function login_name()
	{
		return $this->mysql->select('ref, loginname, createdate')->from('operators')->where(['loginname' => $this->login_name, 'logintype' => 'LWD'])->get()->first_row('array');
		 $this->mysql->last_query();
	}

	function email_address()
	{
		return$this->mysql->select('ref, emailaddress, createdate')->from('operators')->where(['emailaddress' => $this->email_address, 'logintype' => 'LWD'])->get()->first_row('array');
	}

	function add_lwd_db()
	{
		$data['fullname'] = $this->fname;
		$data['loginname'] = $this->login_name;
		$data['password'] = $this->password;
		$data['number'] = $this->number;
		$data['imei_no'] = $this->imei;
		$data['costcentre'] = $this->costcenter;
		$data['contractarea'] = $this->contractarea;
		$data['office'] = $this->office;
		$data['emailaddress'] = $this->email_address;
		$data['address'] = $this->address;
		$data['logintype'] = 'LWD';
		$data['createdate'] = date('Y-m-d H:i:s');
		//debug($data,1);
		$this->mysql->insert('operators', $data);
		return $insert_id = $this->mysql->insert_id();
	}
	
	function office_list($contractareaid)
	{
		return $this->mysql->select('*')->from('offices')->where(['contractarea_id'=>$contractareaid])->get()->result_array();
	}
	
	//fetch blogs
    function get_lwd_list($limit, $offset) {

    	return $this->mysql->select('*')->from('operators')->where('logintype','LWD')->limit( $limit , $offset )->order_by('
    		createdate', 'desc')->get()->result_array();
    	//echo $this->mysql->last_query();
    	/*return $this->mysql->where('logintype','LWD')->get($this->operator_table, $limit, $offset)->result_array();*/
    }

    function get_count_lwd()
    {
    	return $this->mysql->count_all('operators');
    }
	
    function map_location_lwd()
    {
    	$this->lwd_id;
    	//$this->mysql->select('*')->from('location')->where(['ref_id' => $this->lwd_id ])->like('create_date', date('Y-m-d'), 'after')->get()->result();
    	return $this->mysql->select('*')->from('location')->where(['ref_id' => $this->lwd_id ])->like('create_date', '2017-08-10', 'after')->get()->result();
    	//echo $this->mysql->last_query(;
    }

    function signal_status()
    {
    	$data['signal_kill'] = $this->signal_kill;
    	return $this->mysql->where([ 'ref' => $this->lwd_id ])->update('operators', $data);
    }

	/*function get_filter_lwd_list($limit, $offset, $officeid) {
		
		 if ($offset > 0) {
            $offset = ($offset - 1) * $limit;
        }
		$array = array('logintype' => 'LWD', 'office' => $officeid);
        $result['rows'] = $this->mysql->where('logintype','LWD')->where($array)->get($this->operator_table, $limit, $offset);
        $result['num_rows'] = $this->mysql->where($array)->count_all_results($this->operator_table);
        return $result;
	}*/

	/*function lwd_list()
	{
		
		
		return $this->mysql->select('*')->from('operators')->where([ 'logintype' => 'LWD' ])->get()->result_array();
	}*/
}