<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
error_reporting(E_ALL & E_STRICT);
/**
 * Viettel Class
 * 
 * @author dzungnv02
 *
 */

class Viettel extends MX_Controller 
{
	public function __construct() 
	{
		parent::__construct();
	}

	public function index() 
	{
		$this->forward('frontend/home');
	}
	
	public function mo() 
	{
		$aryParams = array();
		$aryParamsName = array(	'username',
								'password',
								'requestID',
								'userID',
								'receiverID',
								'serviceID',
								'commandCode',
								'info',
								'receiveTime');
		
		foreach ($aryParamsName as $key => $value) {
			$aryParams[$value] =  $this->input->post($value,TRUE);
		}

		try {
			$this->load->model('Sms_model', 'objSMS');
			$separator = '|';
			$errCode = 1;
			$messageType = 0;
			$message = $this->objSMS->getSMSByServiceId();
			
			header('Content-type:text/plain; charset=utf-8');
			echo $errCode,$separator,$messageType,$separator,$message;
		} catch (Exception $e) {
			var_dump($e);
		}
	}
	
	public function mt() 
	{
		$url = $this->config->item('mt_service_url');
		$username = 'sbg';
		$password = 'sbg56ab77cdsgb';
		$operator = 'InsertMT';
		$operation = 'http://tempuri.org/InsertMT';
		$xmlHeader = '<?xml version="1.0" encoding="utf-8" ?>'."\n";
		
		$aryParams = array(
				'User' => $username,
				'Pass' => $password,
				'CPCode' => '601',
				'UserID' => '841662860000',
				'RequestID' => '4',
				'ReceiverID' => '84988568786',
				'ServiceID' => '8062',
				'CommandCode' => 'SBG',
				'ContentType' => '0',
				'Info' => 'SMS test! - Host: '.$_SERVER['HTTP_HOST'].' - '. date('Y-m-d H:i:s')//'Test MT '. date('Y-m-d H:i:s'),
		);
		
		$xml = $this->load->view('mt', $aryParams, true);
		$client = new nusoap_client($url);
		$client->useHTTPPersistentConnection();
		$client->soap_defencoding = 'UTF-8';
		$client->operation = $operation;

		$result = $client->send($xmlHeader.$xml, $operation);
		$err = $client->getError();
		 
		if ($err) {
			echo '<p><b>Error: ' . $err . '</b></p>';
		}
		
		echo "<br/>";
		echo "<h2>Request</h2>";
		echo "<pre>" . htmlspecialchars($client->request, ENT_QUOTES) . "</pre>";
		echo "<h2>Response</h2>";
		echo "<pre>" . htmlspecialchars($client->response, ENT_QUOTES) . "</pre>";
		
	}
}

/* End of file viettel.php */
/* Location: ./application/modules/service/controllers/viettel.php */