Index: /pro-violet-viettel/sourcecode/application/modules/frontend/controllers/user.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/frontend/controllers/user.php	(revision 516)
+++ /pro-violet-viettel/sourcecode/application/modules/frontend/controllers/user.php	(revision 517)
@@ -1,18 +1,56 @@
-<?php
-
-if (!defined('BASEPATH'))
-    exit('No direct script access allowed');
-
+<?php 
+if (! defined ( 'BASEPATH' ))
+	exit ( 'No direct script access allowed' );
 class User extends MX_Controller {
-
-    const TOKENPW = 'violet';
-
-    public function __construct() {
-        parent::__construct();
-        $this->load->helper('cookie');
-    }
-
-    public function profile() {
-        $user_info = $this->session->userdata('userInfo');
+	
+	const TOKENPW = 'violet';
+
+	public function __construct() {
+		parent::__construct ();
+		$this->load->helper ( 'cookie' );
+	}
+	
+	public function profile() {
+		$user_info = $this->session->userdata ( 'userInfo' );
+		if ($user_info) {
+			$this->load->model ( 'servicepackage_model' );
+			$user = $user_info ['user'];
+			$us_id = $user_info ['us_id'];
+			$src = "SBG";
+			$token = md5 ( $us_id . self::TOKENPW );
+			$data = $this->get_data ( $src, $token, $us_id );
+			$data ['packages'] = $this->servicepackage_model->getAllPackages ();
+			$this->load->view ( 'frontend/user_profile', $data );
+		} else {
+			redirect ( 'frontend/home' );
+		}
+	}
+	
+	public function packageRegister() {
+		$result = array ();
+		$input = $this->input->post ();
+		$user_info = $this->session->userdata ( 'userInfo' );
+		if ($user_info) {
+			$this->load->model ( 'servicepackage_model' );
+			$this->load->model ( 'user_model' );
+			$package = $this->servicepackage_model->getPackage ( $input ['p_id'] );
+			$user = $user_info ['user'];
+			$us_id = $user_info ['us_id'];
+			$user = $this->user_model->get_user_by_id ( $us_id );
+			$result ['can_buy'] = 1;
+			$result ['can_edit'] = 0;
+			if ($user ['acc_balanced'] < $package ['p_price']) {
+				$result ['can_buy'] = 0;
+			}
+			
+			if ($user ['p_id'] < 1) {
+				$result ['can_edit'] = 1;
+			}
+			$result ['user'] = $user;
+			$result ['package'] = $package;
+			$result ['modal'] = $this->load->view ( 'frontend/package_register_modal', $result, true );
+		} else {
+		}
+=======
 
         if ($user_info) {
@@ -199,4 +237,132 @@
                     $result['success'] = 1;
                 }
+>>>>>>> .r514
+<<<<<<< .mine
+		echo json_encode ( $result );
+	}
+	
+	private function get_data($src, $token, $us_id) {
+		$this->load->model ( 'user_model' );
+		$user = $this->user_model->get_user_info ( $src, $token, $us_id );
+		
+		if (strpos ( $user, '&' )) {
+			parse_str ( $user );
+			$us = $this->user_model->get_user_by_id ( $us_id );
+			$data = array (
+					'us_id' => $us_id,
+					'username' => $username,
+					'fullname' => $fullname,
+					'gender' => $gender,
+					'email' => $email,
+					'phone' => $phone,
+					'school' => $school,
+					'province' => $province,
+					'acc_balanced' => $us ['acc_balanced'],
+					'expire_date' => $us ['expire_date'],
+					'date_diff' => $this->dateDiff ( $us ['expire_date'] ) 
+			);
+			return $data;
+		} else {
+			return "";
+		}
+	}
+	
+	private function dateDiff($expire_date) {
+		$date1 = date ( "Y-m-d" );
+		if ((strtotime ( $expire_date ) - strtotime ( $date1 )) < 0)
+			return "0 ngÃ y cÃ²n láº¡i";
+		$diff = strtotime ( $expire_date ) - strtotime ( $date1 );
+		$years = floor ( $diff / (365 * 60 * 60 * 24) );
+		$months = floor ( ($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24) );
+		$days = floor ( ($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24) );
+		if ($years > 0) {
+			return $years . " nÄm, " . $months . " thÃ¡ng, " . $days . " ngÃ y cÃ²n láº¡i";
+		} else {
+			if ($months > 0) {
+				return $months . " thÃ¡ng, " . $days . " ngÃ y cÃ²n láº¡i";
+			} else {
+				return $days . " ngÃ y cÃ²n láº¡i";
+			}
+		}
+	}
+	
+	public function update_user() {
+		$this->load->helper ( 'email' );
+		$us_id = $this->uri->segment ( 4 );
+		$user_info = $this->session->userdata ( 'userInfo' );
+		if ($user_info) {
+			$result = array ();
+			$result ['success'] = 0;
+			$src = "SBG";
+			$token = md5 ( $us_id . self::TOKENPW );
+			$user = $this->get_data ( $src, $token, $us_id );
+			$input = $this->input->post ();
+			if ($input) {
+				$input ['username'] = $user ['username'];
+				$input ['fullname'] = $user ['fullname'];
+				$input ['password'] = '';
+				$input ['oldpass'] = '';
+				$this->load->model ( 'user_model' );
+				$result ['fullname'] = $input ['fullname'];
+				if (strlen ( $input ['email'] ) > 0) {
+					if (! valid_email ( $input ['email'] )) {
+						$result ['errors'] ['email_err'] = "Email khÃŽng ÄÃºng Äá»nh dáº¡ng";
+					}
+				}
+				if (! isset ( $result ['errors'] )) {
+					$result ['data'] = $this->user_model->update_user ( $src, $token, $input, $us_id );
+					$result ['success'] = 1;
+				}
+				echo json_encode ( $result );
+			}
+		} else {
+			redirect ( 'frontend/home' );
+		}
+	}
+	
+	public function change_password() {
+		$us_id = $this->uri->segment ( 4 );
+		$user_info = $this->session->userdata ( 'userInfo' );
+		if ($user_info) {
+			$this->load->model ( 'user_model' );
+			$us_id = $user_info ['us_id'];
+			$src = "SBG";
+			$token = md5 ( $us_id . self::TOKENPW );
+			if (strlen ( $input ['passwd'] ) == 0) {
+				$result ['errors'] ['passwd_old_err'] = "Máº­t kháº©u khÃŽng ÄÆ°á»£c Äá» trá»ng !";
+			}
+			if (strlen ( $input ['passwd_new'] ) == 0) {
+				$result ['errors'] ['passwd_new_err'] = "Máº­t kháº©u khÃŽng ÄÆ°á»£c Äá» trá»ng !";
+			} else if ($input ['passwd'] == $input ['passwd_new']) {
+				$result ['errors'] ['passwd_new_err'] = "Máº­t kháº©u trÃ¹ng vá»i máº­t kháº©u hiá»n táº¡i !";
+			}
+			if ($input ['passwd_new'] != $input ['confirm_passwd_new']) {
+				$result ['errors'] ['confirm_passwd_new_err'] = "Máº­t kháº©u khÃŽng trÃ¹ng nhau !";
+			}
+			if (! isset ( $result ['errors'] )) {
+				$user = array (
+						'username' => $username,
+						'fullname' => null 
+				);
+				$data = $this->user_model->update_user ( $src, $token, $user, $us_id );
+				parse_str ( $data );
+				switch ($status) {
+					case 0 :
+						$result ['success'] = 1;
+						break;
+					case 6 :
+						$result ['errors'] ['passwd_old_err'] = "Máº­t kháº©u cung cáº¥p khÃŽng ÄÃºng !";
+						break;
+					default :
+						break;
+				}
+			}
+			
+			echo json_encode ( $result );
+		} else {
+			redirect ( 'frontend/home' );
+		}
+	}
+}=======
                 echo json_encode($result);
             }
@@ -249,2 +415,3 @@
 
 }
+>>>>>>> .r514
Index: /pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 516)
+++ /pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 517)
@@ -1,20 +1,25 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
 
-class User_model extends CI_Model
-{
-	
+if (! defined ( 'BASEPATH' ))
+	exit ( 'No direct script access allowed' );
+
+class User_model extends CI_Model {
 	const TOKENPW = 'violet';
 	
-	public function __construct(){
-        parent::__construct();
-		$this->vservices->setApiUrl($this->config->item('api_url'));
-		$this->vservices->setConnection($this->curl);
-    } 
-	
-	public function checkLogin ($src, $token, $username, $password) 
-	{
-		$data = $this->vservices->actionExecute('login', array('src' => $src, 'token' => $token, 'username' => $username, 'password' => $password), 'user');
-		
-		$arr_users = explode("&", $data);
+	public function __construct() {
+		parent::__construct ();
+		$this->vservices->setApiUrl ( $this->config->item ( 'api_url' ) );
+		$this->vservices->setConnection ( $this->curl );
+	}
+	
+	public function checkLogin($src, $token, $username, $password) {
+		$data = $this->vservices->actionExecute ( 'login', array (
+				'src' => $src,
+				'token' => $token,
+				'username' => $username,
+				'password' => $password 
+		), 'user' );
+		
+		$arr_users = explode ( "&", $data );
 		$str_status = '';
 		$str_fullname = '';
@@ -23,92 +28,93 @@
 		$fullname = '';
 		
-		for ($i=0; $i < count($arr_users); $i++)
-		{
-			if (strpos($arr_users[$i], 'status=') !== false)
-			{
-				$str_status = $arr_users[$i];
+		for($i = 0; $i < count ( $arr_users ); $i ++) {
+			if (strpos ( $arr_users [$i], 'status=' ) !== false) {
+				$str_status = $arr_users [$i];
 			}
 			
-			if (strpos($arr_users[$i], 'fullname=') !== false)
-			{
-				$str_fullname = $arr_users[$i];
+			if (strpos ( $arr_users [$i], 'fullname=' ) !== false) {
+				$str_fullname = $arr_users [$i];
 			}
 			
-			if (strpos($arr_users[$i], 'id=') !== false)
-			{
-				$str_usid = $arr_users[$i];
-			}
-		}
-		$arr_status = explode("=", $str_status);
-		if ($str_fullname != '')
-		{
-			$arr_fullname = explode("=", $str_fullname);
-			$fullname = $arr_fullname[1];
-		}
-		if ($str_usid !== '')
-		{
-			$arr_usid = explode("=", $str_usid);
-			$usid = $arr_usid[1];
-		}
-		$status = (int)$arr_status[1];
-		
-		if ($status == 0 || $status == 4){
-			$us_id = (int)$usid;
+			if (strpos ( $arr_users [$i], 'id=' ) !== false) {
+				$str_usid = $arr_users [$i];
+			}
+		}
+		$arr_status = explode ( "=", $str_status );
+		if ($str_fullname != '') {
+			$arr_fullname = explode ( "=", $str_fullname );
+			$fullname = $arr_fullname [1];
+		}
+		if ($str_usid !== '') {
+			$arr_usid = explode ( "=", $str_usid );
+			$usid = $arr_usid [1];
+		}
+		$status = ( int ) $arr_status [1];
+		
+		if ($status == 0 || $status == 4) {
+			$us_id = ( int ) $usid;
 			$query = "SELECT * FROM tbluser WHERE us_id = ?";
-			$result = $this->db->query($query, array($us_id));
-			if($result->num_rows() == 1){
+			$result = $this->db->query ( $query, array (
+					$us_id 
+			) );
+			if ($result->num_rows () == 1) {
 				return $data;
-			}else
-			{
+			} else {
 				return null;
 			}
-		}else
-		{
+		} else {
 			return $data;
 		}
 	}
-
-	public function register ($username, $collaborator, &$status='')
-	{
-		$user = array();
-		$password = $this->create_random_password();
+	
+	public function register($username, $collaborator, &$status = '') {
+		$user = array ();
+		$password = $this->create_random_password ();
 		$src = 'SBG';
 		$sms = '';
 		$id = 0;
 		$errMsg = '';
-		$token = md5($username.self::TOKENPW);		
+		$token = md5 ( $username . self::TOKENPW );
 		$phone = $username;
 		
-		if (!is_null($collaborator) || $collaborator != ''){
-			if(!$this->isExistcollaborator($collaborator)){
-				$sms = "Khong tim thay cong tac vien nao co so dien thoai [".$collaborator."] tren soanbaigiang.smas.vn!";
+		if (! is_null ( $collaborator ) || $collaborator != '') {
+			if (! $this->isExistcollaborator ( $collaborator )) {
+				$sms = "Khong tim thay cong tac vien nao co so dien thoai [" . $collaborator . "] tren soanbaigiang.smas.vn!";
 				$status = 0;
-				return $status.'|'.$sms;
-			}
-		}
-		
-		$data = $this->vservices->actionExecute('update', array('src'=>$src, 'username'=>$username, 'password'=>$password, 'fullname'=>null, 'phone'=>$username, 'token'=>$token), 'user');
-		parse_str($data);
-		switch((int)$status)
-		{
-			case 0:
+				return $status . '|' . $sms;
+			}
+		}
+		
+		$data = $this->vservices->actionExecute ( 'update', array (
+				'src' => $src,
+				'username' => $username,
+				'password' => $password,
+				'fullname' => null,
+				'phone' => $username,
+				'token' => $token 
+		), 'user' );
+		
+		parse_str ( $data );
+		
+		switch (( int ) $status) {
+			case 0 :
 				$us_id = $id;
-				$user['created_time'] = date('Y-m-d H:i:s');
-				$user['us_id'] = $us_id;
-				$user['cellphone'] = $username;
-				if (!is_null($collaborator) || $collaborator != ''){
-					$user['collaborator'] = $collaborator;
+				$user ['created_time'] = date ( 'Y-m-d H:i:s' );
+				$user ['us_id'] = $us_id;
+				$user ['cellphone'] = $username;
+				if (! is_null ( $collaborator ) || $collaborator != '') {
+					$user ['collaborator'] = $collaborator;
 				}
-				$this->db->query('UNLOCK TABLES');
-				$this->db->insert('tbluser', $user);
-				$sms = "Chuc mung Qui vi da dang ky thanh cong tai khoan Soan Bai giang Online. Hay dang nhap vao soanbaigiang.smas.vn voi ten truy nhap ".$username.", mat khau ".$password." de su dung.";
+				$this->db->query ( 'UNLOCK TABLES' );
+				$this->db->insert ( 'tbluser', $user );
+				$sms = "Chuc mung Qui vi da dang ky thanh cong tai khoan Soan Bai giang Online. Hay dang nhap vao soanbaigiang.smas.vn voi ten truy nhap " . $username . ", mat khau " . $password . " de su dung.";
 				$status = 1;
 				break;
-			case 2:
-			case 4:
+			case 2 :
+			case 4 :
 				$sms = "So dien thoai cua Qui vi da duoc dang ky!";
 				$status = 0;
 				break;
-			default:
+			default :
 				$status = 0;
 				$sms = $errMsg;
@@ -116,103 +122,112 @@
 		}
 		
-		return $status.'|'.$sms;
-	}
-	
-	public function create_random_password()
-	{
-		//$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
+		return $status . '|' . $sms;
+	}
+	
+	public function create_random_password() {
+		// $alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
 		$alphabet = "0123456789";
-		$pass = array();
-		$alphaLength = strlen($alphabet) - 1;
-		for ($i = 0; $i < 6; $i++) {
-			$n = rand(0, $alphaLength);
-			$pass[] = $alphabet[$n];
-		}
-		return implode($pass);
-	}
-	
-	public function get_user_by_id($us_id)
-	{
-		$this->db->query('UNLOCK TABLES');
-		$this->db->select('*')->from('tbluser')->where('us_id', $us_id);
-		$query = $this->db->get();
-		if($query->num_rows() > 0)
-		{
-			$row = $query->row_array();
+		$pass = array ();
+		$alphaLength = strlen ( $alphabet ) - 1;
+		for($i = 0; $i < 6; $i ++) {
+			$n = rand ( 0, $alphaLength );
+			$pass [] = $alphabet [$n];
+		}
+		return implode ( $pass );
+	}
+	
+	public function get_user_by_id($us_id) {
+		$this->db->query ( 'UNLOCK TABLES' );
+		$this->db->select ( '*' )->from ( 'tbluser' )->where ( 'us_id', $us_id );
+		$query = $this->db->get ();
+		if ($query->num_rows () > 0) {
+			$row = $query->row_array ();
 			return $row;
 		}
 	}
 	
-	public function get_user_info($src, $token, $us_id)
-	{
-		$data = $this->vservices->actionExecute('getinfo', array('src' => $src, 'us_id' => $us_id, 'token'=>$token), 'user');
-        return $data;
-	}
-	
-	public function update_user($src, $token, $user, $us_id)
-	{
-		$data = $this->vservices->actionExecute('update', array('src'=>$src, 'token'=>$token, 'us_id'=>$us_id, 
-																'password'=>$user['password'], 'fullname'=>$user['fullname'],
-																'school'=>$user['school'], 'province'=>$user['province'], 'oldpass'=>$user['oldpass']),
-												'user');
+	public function get_user_info($src, $token, $us_id) {
+		$data = $this->vservices->actionExecute ( 'getinfo', array (
+				'src' => $src,
+				'us_id' => $us_id,
+				'token' => $token 
+		), 'user' );
 		return $data;
-								
-	}
-	
-	public function changeProfile($sentNumber, $username, $password, &$status='')
-	{
-		$user = array();
+	}
+	
+	public function update_user($src, $token, $user, $us_id) {
+		$data = $this->vservices->actionExecute ( 'update', array (
+				'src' => $src,
+				'token' => $token,
+				'us_id' => $us_id,
+				'password' => $user ['password'],
+				'fullname' => $user ['fullname'],
+				'school' => $user ['school'],
+				'province' => $user ['province'],
+				'oldpass' => $user ['oldpass'] 
+		), 'user' );
+		return $data;
+	}
+	
+	public function changeProfile($sentNumber, $username, $password, &$status = '') {
+		$user = array ();
 		$src = 'SBG';
 		$errMsg = '';
 		$sms = '';
-		$checkSentNumber = $this->get_user_by_cellphone($sentNumber);
-		if($checkSentNumber)
-		{
-			$sms = "So Dien thoai ".$sentNumber." da dang ky tren he thong SBG Online soanbaigiang.smas.vn nen Qui vi khong the doi sang so dien thoai nay duoc.";
+		$checkSentNumber = $this->get_user_by_cellphone ( $sentNumber );
+		
+		if ($checkSentNumber) {
+			$sms = "So Dien thoai " . $sentNumber . " da dang ky tren he thong SBG Online soanbaigiang.smas.vn nen Qui vi khong the doi sang so dien thoai nay duoc.";
 			$status = 0;
-			return $status.'|'.$sms;
-		}
-		$result = $this->get_user_by_cellphone($username);
-		if($result)
-		{
-			$us_id = $result['us_id'];
-			$token = md5($us_id.self::TOKENPW);
-			$data = $this->vservices->actionExecute('update', array('src'=>$src, 'token'=>$token, 'us_id'=>$us_id, 'username'=>$sentNumber, "password"=>$password, 'oldpass'=>$password, 'phone'=>$sentNumber), 'user');
-			parse_str($data);
-			switch((int)$status)
-			{
-				case 0:
+			return $status . '|' . $sms;
+		}
+		
+		$result = $this->get_user_by_cellphone ( $username );
+		
+		if ($result) {
+			$us_id = $result ['us_id'];
+			$token = md5 ( $us_id . self::TOKENPW );
+			$data = $this->vservices->actionExecute ( 'update', array (
+					'src' => $src,
+					'token' => $token,
+					'us_id' => $us_id,
+					'username' => $sentNumber,
+					"password" => $password,
+					'oldpass' => $password,
+					'phone' => $sentNumber 
+			), 'user' );
+			parse_str ( $data );
+			switch (( int ) $status) {
+				case 0 :
 					$us_id = $id;
-					$user['updated_time'] = date('Y-m-d H:i:s');
-					$user['us_id'] = $us_id;
-					$user['cellphone'] = $sentNumber;
-					$this->updateUser($us_id, $user);
-					$sms = "Qui vi da doi so dien thoai tren soanbaigiang.smas.vn sang so dien thoai [".$sentNumber."]";
+					$user ['updated_time'] = date ( 'Y-m-d H:i:s' );
+					$user ['us_id'] = $us_id;
+					$user ['cellphone'] = $sentNumber;
+					$this->updateUser ( $us_id, $user );
+					$sms = "Qui vi da doi so dien thoai tren soanbaigiang.smas.vn sang so dien thoai " . $sentNumber;
 					$status = 1;
 					break;
-				case 5:
+				case 5 :
 					$sms = "So dien thoai cá»§a Qui vi chua duoc dang ky!";
 					$status = 0;
 					break;
-				case 6:
+				case 6 :
 					$sms = "Mat khau cua qui vi khong dung !";
 					$status = 0;
 					break;
-				default:
+				default :
 					$status = 0;
 					$sms = $errMsg;
-					break;				
-			}
-		}else
-		{
+					break;
+			}
+		} else {
 			$sms = "So dien thoai cá»§a Qui vi chua duoc dang ky!";
 			$status = 0;
 		}
-		return $status.'|'.$sms;
-	}
-	
-	public function changePassword($username, $password, &$status = '')
-	{
-		$user = array();
+		return $status . '|' . $sms;
+	}
+	
+	public function changePassword($username, $password, &$status = '') {
+		$user = array ();
 		$src = 'SBG';
 		$errMsg = '';
@@ -220,204 +235,192 @@
 		$isForgotPassword = false;
 		$pass = $password;
-		if (is_null($password) || $password == '')
-		{
-			$pass = $this->create_random_password();
+		
+		if (is_null ( $password ) || $password == '') {
+			$pass = $this->create_random_password ();
 			$isForgotPassword = true;
 		}
-		$result = $this->get_user_by_cellphone($username);
-		if($result)
-		{
-			$us_id = $result['us_id'];
-			$token = md5($us_id.self::TOKENPW);
-			$data = $this->vservices->actionExecute('update', array('src'=>$src, 'token'=>$token, 'us_id'=>$us_id, "password"=>$pass), 'user');
-			parse_str($data);
-			switch((int)$status)
-			{
-				case 0:
+		
+		$result = $this->get_user_by_cellphone ( $username );
+		if ($result) {
+			$us_id = $result ['us_id'];
+			$token = md5 ( $us_id . self::TOKENPW );
+			$data = $this->vservices->actionExecute ( 'update', array (
+					'src' => $src,
+					'token' => $token,
+					'us_id' => $us_id,
+					"password" => $pass 
+			), 'user' );
+			parse_str ( $data );
+			switch (( int ) $status) {
+				case 0 :
 					$us_id = $id;
-					$user['updated_time'] = date('Y-m-d H:i:s');
-					$this->updateUser($us_id, $user);
-					if ($isForgotPassword)
-					{
-						$sms = "Mat khau moi cua quy vi tren soanbaigiang.smas.vn la [".$pass."]";
-					}else{
+					$user ['updated_time'] = date ( 'Y-m-d H:i:s' );
+					$this->updateUser ( $us_id, $user );
+					if ($isForgotPassword) {
+						$sms = "Mat khau moi cua quy vi tren soanbaigiang.smas.vn la " . $pass;
+					} else {
 						$sms = "Qui vi da doi thanh cong mat khau tren soanbaigiang.smas.vn.";
 					}
 					$status = 1;
 					break;
-				case 5:
+				case 5 :
 					$sms = "So dien thoai cá»§a Qui vi chua duoc dang ky!";
 					$status = 0;
 					break;
-				default:
+				default :
 					$status = 0;
 					$sms = $errMsg;
-					break;	
-			}
-		}
-		else
-		{
+					break;
+			}
+		} else {
 			$sms = "So dien thoai cá»§a Qui vi da duoc dang ky!";
 			$status = 0;
 		}
-		return $status.'|'.$sms;
-	}
-	
-	
-	public function checkLicense ($userId) 
-	{
+		return $status . '|' . $sms;
+	}
+	
+	public function checkLicense($userId) {
 		$isNotExpired = false;
-		$userInfo = array();
-		$userInfo = $this->get_user_by_id($userId);	
-
-		$expireDate = $userInfo['expire_date'];
-		
-		if ((trim($expireDate) == '')) return $isNotExpired;
-		
-		$today = mktime();
-		$expireTime = strtotime($expireDate.' 23:59:59');
+		$userInfo = array ();
+		$userInfo = $this->get_user_by_id ( $userId );
+		
+		$expireDate = $userInfo ['expire_date'];
+		
+		if ((trim ( $expireDate ) == ''))
+			return $isNotExpired;
+		
+		$today = mktime ();
+		$expireTime = strtotime ( $expireDate . ' 23:59:59' );
 		$isNotExpired = ($today < $expireTime);
 		return $isNotExpired;
 	}
 	
-	public function registerVip($username, $p_code)
-	{
-		$user = array();
+	public function registerVip($username, $p_code) {
+		$user = array ();
 		$sms = '';
 		
-		$result = $this->get_user_by_cellphone($username);
-		$package = $this->get_package((int)$p_code);
-		if($result){
+		$result = $this->get_user_by_cellphone ( $username );
+		$package = $this->get_package ( ( int ) $p_code );
+		if ($result) {
 			
-			if ($result['acc_balanced'] >= $package['p_price'])
-			{
-				$us_id = $result['us_id'];
-				$user['acc_balanced'] = $result['acc_balanced'] - $package['p_price'];
-				if ($this->checkLicense($us_id)){
-					$user['expire_date'] = date('Y-m-d', strtotime($result['expire_date'].' + '.$package['p_period'].' month'));
-				}else
-				{
-					$user['expire_date'] = date('Y-m-d', strtotime('now + '.$package['p_period'].' month'));
+			if ($result ['acc_balanced'] >= $package ['p_price']) {
+				$us_id = $result ['us_id'];
+				$user ['acc_balanced'] = $result ['acc_balanced'] - $package ['p_price'];
+				if ($this->checkLicense ( $us_id )) {
+					$user ['expire_date'] = date ( 'Y-m-d', strtotime ( $result ['expire_date'] . ' + ' . $package ['p_period'] . ' month' ) );
+				} else {
+					$user ['expire_date'] = date ( 'Y-m-d', strtotime ( 'now + ' . $package ['p_period'] . ' month' ) );
 				}
 				
-				$user['p_id'] = $package['p_id'];
-				$user['updated_time'] = date('Y-m-d H:i:s');
+				$user ['p_id'] = $package ['p_id'];
+				$user ['updated_time'] = date ( 'Y-m-d H:i:s' );
 				
-				$this->updateUser($us_id, $user);
-				$sms = "Chuc mung Qui vi da dang ky su dung Soan Bai giang truc tuyen tren soanbaigiang.smas.vn. Qui vi co the su dung dich vu den 24h00 ngay ".date('d/m/Y', strtotime($user['expire_date']));
+				$this->updateUser ( $us_id, $user );
+				$sms = "Chuc mung Qui vi da dang ky su dung Soan Bai giang truc tuyen tren soanbaigiang.smas.vn. Qui vi co the su dung dich vu den 24h00 ngay " . date ( 'd/m/Y', strtotime ( $user ['expire_date'] ) );
 				$status = 1;
-			}else
-			{
+			} else {
 				$sms = "Tai khoan cua qui vi khong du de dang ky su dung dich vu Soan Bai giang truc tuyen tren soanbaigiang.smas.vn. Hay nap tien va dang ky lai. Cam on!";
 				$status = 0;
 			}
-			
-		}else{
-			$sms = "Tai khoan [".$username."] chua dang ki tai khoan tren he thong SBG Online soanbaigiang.smas.vn.";
+		} else {
+			$sms = "Tai khoan [" . $username . "] chua dang ki tai khoan tren he thong SBG Online soanbaigiang.smas.vn.";
 			$status = 0;
 		}
-		return $status.'|'.$sms;
-	}
-	
-	public function rechargeAccount($username, $amount)
-	{
-		$user = array();
+		return $status . '|' . $sms;
+	}
+	
+	public function rechargeAccount($username, $amount) {
+		$user = array ();
 		$sms = '';
-		$result = $this->get_user_by_cellphone($username);
-		if($result)
-		{
-			$us_id = $result['us_id'];
-			$user['acc_balanced'] = $result['acc_balanced'] + $amount;
-			$user['updated_time'] = date('Y-m-d H:i:s');
-			$this->updateUser($us_id, $user);
-			$sms = "Qui vi da nap thanh cong ".$amount."VND vao tai khoan ".$username." tren soanbaigiang.smas.vn";
+		$result = $this->get_user_by_cellphone ( $username );
+		if ($result) {
+			$us_id = $result ['us_id'];
+			$user ['acc_balanced'] = $result ['acc_balanced'] + $amount;
+			$user ['updated_time'] = date ( 'Y-m-d H:i:s' );
+			$this->updateUser ( $us_id, $user );
+			$sms = "Qui vi da nap thanh cong " . $amount . "VND vao tai khoan " . $username . " tren soanbaigiang.smas.vn";
 			$status = 1;
-		}else
-		{
-			$sms = "Tai khoan ".$username." chua dang ki tai khoan tren he thong SBG Online soanbaigiang.smas.vn.";
+		} else {
+			$sms = "Tai khoan " . $username . " chua dang ki tai khoan tren he thong SBG Online soanbaigiang.smas.vn.";
 			$status = 0;
 		}
-		return $status.'|'.$sms;		
-	}
-	
-	public function get_user_by_cellphone($cellphone)
-	{
-		$this->db->query('UNLOCK TABLES');
+		return $status . '|' . $sms;
+	}
+	
+	public function get_user_by_cellphone($cellphone) {
+		$this->db->query ( 'UNLOCK TABLES' );
 		$sql = 'SELECT * FROM tbluser where cellphone = ? LIMIT 0,1';
-		$query = $this->db->query($sql, array($cellphone));
-		$row = $query->row_array();
+		$query = $this->db->query ( $sql, array (
+				$cellphone 
+		) );
+		$row = $query->row_array ();
 		return $row;
 	}
 	
-	public function isExistcollaborator($collaborator)
-	{
-		$this->db->query('UNLOCK TABLES');
-		$this->db->select('*')->from('tblcollaborator')->where('login_name', $collaborator)->limit(1);
-		$result = $this->db->get()->row_array();
-		if ($result) return true; else return false;
-	}
-	
-	public function updateUser($us_id, $data)
-	{
-		$this->db->query('UNLOCK TABLES');
-		$this->db->where('us_id', $us_id);
-		$this->db->update('tbluser', $data);
-	}
-	
-	public function get_package($p_code)
-	{
-		$this->db->query('UNLOCK TABLES');
+	public function isExistcollaborator($collaborator) {
+		$this->db->query ( 'UNLOCK TABLES' );
+		$this->db->select ( '*' )->from ( 'tblcollaborator' )->where ( 'login_name', $collaborator )->limit ( 1 );
+		$result = $this->db->get ()->row_array ();
+		if ($result)
+			return true;
+		else
+			return false;
+	}
+	
+	public function updateUser($us_id, $data) {
+		$this->db->query ( 'UNLOCK TABLES' );
+		$this->db->where ( 'us_id', $us_id );
+		$this->db->update ( 'tbluser', $data );
+	}
+	
+	public function get_package($p_code) {
+		$this->db->query ( 'UNLOCK TABLES' );
 		$sql = 'SELECT * FROM tblservicepackage where p_code = ? LIMIT 0,1';
-		$query = $this->db->query($sql, array($p_code));
-		$row = $query->row_array();
+		$query = $this->db->query ( $sql, array (
+				$p_code 
+		) );
+		$row = $query->row_array ();
 		return $row;
 	}
 	
-	public function insertSmslog($sentNumber, $serviceID, $commandcode, $info, $receiveTime)
-	{
-		if (preg_match('/^(84)([0-9]{9,10})$/', $sentNumber, $aryMatch) == 1) {
-			$sentNumber = '0'. $aryMatch[2];
+	public function insertSmslog($sentNumber, $serviceID, $commandcode, $info, $receiveTime) {
+		if (preg_match ( '/^(84)([0-9]{9,10})$/', $sentNumber, $aryMatch ) == 1) {
+			$sentNumber = '0' . $aryMatch [2];
 		}
 		
 		try {
-			$user = $this->get_user_by_cellphone($sentNumber);
-		}
-		catch(Exception $e) {
-			
-		}
-		
-		$smslog = array();
-		$smslog['sender'] = $sentNumber;
-		$smslog['us_id'] = isset($user['us_id']) ? $user['us_id']:NULL;
-		$smslog['service_id'] = $serviceID;
-		$smslog['commandcode'] = $commandcode;
-		$smslog['info'] = $info;
-		$smslog['created_time'] = $receiveTime;
-		$this->db->query('UNLOCK TABLES');
+			$user = $this->get_user_by_cellphone ( $sentNumber );
+		} catch ( Exception $e ) {
+		}
+		
+		$smslog = array ();
+		$smslog ['sender'] = $sentNumber;
+		$smslog ['us_id'] = isset ( $user ['us_id'] ) ? $user ['us_id'] : NULL;
+		$smslog ['service_id'] = $serviceID;
+		$smslog ['commandcode'] = $commandcode;
+		$smslog ['info'] = $info;
+		$smslog ['created_time'] = $receiveTime;
+		$this->db->query ( 'UNLOCK TABLES' );
 		$sql = 'INSERT INTO tblsmslog(sender, us_id, service_id, commandcode, info, created_time) VALUES(?,?,?,?,?,?)';
 		$query = $this->db->query($sql, $smslog);
-		//$this->db->insert('tblsmslog', $smslog);
-	}
-	
-	public function insertPaidlog($sentNumber, $receiveID, $paidType, $amount, $paidTime)
-	{
-		if (preg_match('/^(84)([0-9]{9,10})$/', $sentNumber, $aryMatch) == 1) {
-			$sentNumber = '0'. $aryMatch[2];
+	}
+	
+	public function insertPaidlog($sentNumber, $receiveID, $paidType, $amount, $paidTime) {
+		if (preg_match ( '/^(84)([0-9]{9,10})$/', $sentNumber, $aryMatch ) == 1) {
+			$sentNumber = '0' . $aryMatch [2];
 		}
 		
 		try {
-			$user = $this->get_user_by_cellphone($sentNumber);
-		}
-		catch(Exception $e) {
-			
-		}
-		$paidlog = array();
-		$paidlog['us_id'] = isset($user['us_id']) ? $user['us_id']:NULL;
-		$paidlog['paidType'] = $paidType;
-		$paidlog['amount'] = $amount;
-		$paidlog['paidTime'] = $paidTime;
-		$this->db->query('UNLOCK TABLES');
+			$user = $this->get_user_by_cellphone ( $sentNumber );
+		} catch ( Exception $e ) {
+		}
+		$paidlog = array ();
+		$paidlog ['us_id'] = isset ( $user ['us_id'] ) ? $user ['us_id'] : NULL;
+		$paidlog ['paidType'] = $paidType;
+		$paidlog ['amount'] = $amount;
+		$paidlog ['paidTime'] = $paidTime;
+		$this->db->query ( 'UNLOCK TABLES' );
 		$sql = 'INSERT INTO tblpaidlog(us_id, paidType, amount, paidTime) VALUES (?,?,?,?)';
-		$query = $this->db->query($sql, $paidog);
+		$query = $this->db->query ( $sql, $paidog );
 	}
 }
Index: /pro-violet-viettel/sourcecode/application/modules/services/controllers/sendmessage.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/services/controllers/sendmessage.php	(revision 516)
+++ /pro-violet-viettel/sourcecode/application/modules/services/controllers/sendmessage.php	(revision 517)
@@ -120,5 +120,9 @@
 	{
 		$url = $this->config->item('topup_service_url');
-		$operation = 'http://tempuri.org/ITopupService/TopUp';;
+		
+		//echo file_get_contents($url);
+		//exit();
+		
+		$operation = 'http://tempuri.org/ITopupService/TopUp';
 		
 		$username = 'sbg';
Index: /pro-violet-viettel/sourcecode/application/modules/services/controllers/viettel.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/services/controllers/viettel.php	(revision 516)
+++ /pro-violet-viettel/sourcecode/application/modules/services/controllers/viettel.php	(revision 517)
@@ -56,5 +56,5 @@
 			$CI->load->model('frontend/User_model', 'objUserModel');
 			$result = $CI->Services_model->processMORequest($userID, strtoupper($info));
-			$CI->objUserModel->insertSmslog($receiverID, $serviceID, $commandCode, $info, $receiveTime);
+			//$CI->objUserModel->insertSmslog($receiverID, $serviceID, $commandCode, $info, $receiveTime);
 					
 			$aryResult = explode ('|', $result);
Index: /pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 516)
+++ /pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 517)
@@ -167,5 +167,5 @@
 		$client->operation = $action;
 		
-		$result = $client->send($this->_xmlHeader.$xml, $operation);
+		$result = $client->send($xml, $operation);
 		
 		if ($client->fault) {
