<?php

Class Operator extends CI_Model
{
	function getting()
	{
		$data = [];
		$this->odbc = $this->load->database('odbc',true);
		$this->mysql = $this->load->database('mysql',true);
		//$query =  $this->odbc->query('select * from EXPORT_PORTAL_NUMBERS');
		$query =  $this->odbc->query('select * from EXPORT_PORTAL_NUMBERS2');
		$this->mysql->query('TRUNCATE operators');
		//debug($query->result_array());
		for( $i=0; $i<count($query->result_array()); $i++ )
		//foreach($query->result_array() as $row)
		{

			$data['number'] = $query->result_array()[$i]['PHONENUMBER'];
			$data['loginname'] = $query->result_array()[$i]['FORENAME'];
			$data['fullname'] = $query->result_array()[$i]['FORENAME'];
			$data['surname'] = $query->result_array()[$i]['SURNAME'];
			$data['lindex'] = $query->result_array()[$i]['PROPERTYREF'];

			/*INERT INTO MYSQL DATABASE*/
			$this->mysql->insert('operators', $data);
		}
		if( !empty($query->result_array()) )
		{
			return 'Total Rows: '.count($query->result_array());	
		}
		else{
			return 'Error no: '.$this->odbc->_error_number().' Error message: '.$this->odbc->_error_message();
		}

		
	}

	function getting_db()
	{
		$this->odbc = $this->load->database('odbc',true);
		$query =  $this->odbc->query("select * from CREATEAPPLOGIN('447900162308','1230')");
		debug($query->result_array(),1);
	}

	function operator_detail(){
		$this->odbc = $this->load->database('odbc',true);
		$query =  $this->odbc->query("select * from WEB_GETALARMCONTACTS(272470)");
		debug($query->result_array(),1);
	}

	function manual_entry()
	{
		$data['loginname'] = 'Shaun Willcock';
		$data['fullname'] = 'Shaun Willcock';
		$data['number'] = 	'447599804885';
		$this->mysql->insert('operators',$data);
	}
}
