<?php
Class Exported extends CI_Model
{
	private $mysql;
	private $table;
	public $cost_center_name;
	public $costcenterid;
	public $status;
	public $number;

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

	function get_update()
	{
		return $query = $this->mysql->select('*')->from('export')->get()->result_array();

		/*foreach($query as $row)
		{
			$data['number'] = $row['PHONENUMBER'];
			$data['fullname'] = $row['FORENAME'];
			$data['loginname'] = $row['FORENAME'];

			$this->mysql->insert('operators',$data);

		}*/
	}

	function get_number()
	{
		return $this->mysql->select("*")->from('operators')->where([ 'number' => $this->number  ])->get()->result_array();
	}

	function check_duplicate()
	{
		//$this->mysqli = $this->load->database('mysql',true);
		$query = $this->mysql->query(' select * from export where PHONENUMBER not in ( select number from operators ) ');
		//debug($query->result_array(),1);
		foreach( $query->result_array() as $row )
		{
			//$data['ref'] = $row['REF'];
			$data['loginname'] = $row['FORENAME'];
			$data['fullname'] = $row['FORENAME'];
			$data['accesslevel'] = "10";
			$data['password'] = "password";
			$data['number'] = $row['PHONENUMBER'];
			$data['lastin'] = date('Y-m-d H:i:s');
			$data['lastout'] = date('Y-m-d H:i:s');
			$data['custref'] = "1";
			$data['depot'] = "WORKSHOP";
			$data['type'] = "5";
			$data['logintype'] = "LWD";
			$data['costcentre'] = '0';
			$data['contractarea'] = "0";
			$data['office'] = "0";
			$data['emailaddress'] = "email@gmail.com";
			$data['createdate'] = date('Y-m-d H:i:s');
			$data['termsagree'] = "1";

			$this->mysql->insert('operators', $data);
		}
		//debug($row,1);
	}

	function getting()
	{
		$data = [];
		$this->odbc = $this->load->database('odbc',true);
		$query =  $this->odbc->query('select * from operators');
		debug($query);
		/*$this->mysqli = $this->load->database('mysqli',true);
		
		//debug($query->result_array(),1);
		foreach($query->result_array() as $row)
		{
			$data['ref'] = $row['REF'];
			$data['loginname'] = $row['LOGINNAME'];
			$data['fullname'] = $row['FULLNAME'];
			$data['accesslevel'] = $row['ACCESSLEVEL'];
			$data['password'] = $row['PASSWORD_'];
			$data['lastin'] = $row['LASTIN'];
			$data['lastout'] = $row['LASTOUT'];
			$data['custref'] = $row['CUSTREF'];
			$data['depot'] = $row['DEPOT'];
			$data['type'] = $row['TYPE_'];
			$data['logintype'] = $row['LOGINTYPE'];
			$data['costcentre'] = $row['COSTCENTRE'];
			$data['contractarea'] = $row['CONTRACTAREA'];
			$data['office'] = $row['OFFICE'];
			$data['emailaddress'] = $row['EMAILADDRESS'];
			$data['createdate'] = $row['CREATEDATE'];
			$data['termsagree'] = $row['TERMSAGREED'];
			
			/*INERT INTO MYSQL DATABASE*/
			//$this->mysqli->insert('operators', $data);
		//}
	}

}