Index: /pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 485)
+++ /pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 486)
@@ -74,5 +74,4 @@
 		$username = $receiverID;
 		$user = array();
-		$smslog = array();
 		$password = $this->create_random_password();
 		$src = 'SBG';
@@ -81,5 +80,5 @@
 		$phone = $username;
 		$data = $this->vservices->actionExecute('update', array('src'=>$src, 'username'=>$username, 'password'=>$password, 'fullname'=>null, 'phone'=>$username, 'token'=>$token), 'user');
-
+		
 		$id = 0;
 		$errMsg = '';
@@ -96,12 +95,4 @@
 				$user['collaborator'] = $collaborator;
 				$this->db->insert('tbluser', $user);
-				
-				$smslog['sender'] = $sentNumber;
-				$smslog['us_id'] = $us_id;
-				$smslog['service_id'] = $serviceID;
-				$smslog['commandcode'] = $commandcode;
-				$smslog['info'] = $info;
-				$smslog['created_time'] = $receiveTime;
-				$this->db->insert('tblsmslog', $smslog);
 				$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;
@@ -160,22 +151,19 @@
 	}
 	
-	function changeProfile($sentNumber, $receiverID, $password, $serviceID, $commandcode, $info, $receiveTime, &$status)
+	function changeProfile($sentNumber, $receiverID, $password, $serviceID, $commandcode, $info, &$status)
 	{
 		$username = '';
 		$username = $receiverID;
+		$username = '0'.substr($username, 2, strlen($username));
 		$user = array();
 		$src = 'SBG';
-		$us_id = 0;
 		$errMsg = '';
 		$sms = '';
-		$this->db->select('*')->from('tbluser')->where('cellphone', $receiverID);
-		$query = $this->db->get();
-		if($query->num_rows() > 0)
-		{
-			$row = $query->row_array();
-			$us_id = $row['us_id'];
+		$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');
-			var_dump($data);
 			parse_str($data);
 			switch((int)$status)
@@ -183,9 +171,8 @@
 				case 0:
 					$us_id = $id;
-					$user['updated_time'] = $receiveTime;
+					$user['updated_time'] = date('Y-m-d H:i:s');
 					$user['us_id'] = $us_id;
 					$user['cellphone'] = $sentNumber;
-					$this->db->where('us_id', $us_id);
-					$this->db->update('tbluser', $user);
+					$this->updateUser($us_id, $user);
 					$sms = "Qui vi da doi so dien thoai tren soanbaigiang.smas.vn sang so dien thoai [".$sentNumber."]";
 					$status = 1;
@@ -209,29 +196,26 @@
 			$status = 0;
 		}
-		$this->insert_smslog($sentNumber, $us_id, $serviceID, $commandcode, $info, $receiveTime);
-		return $status.'|'.$sms;
-	}
-	
-	function changePassword($sentNumber, $password, $serviceID, $commandcode, $info, $receiveTime, &$status)
+		return $status.'|'.$sms;
+	}
+	
+	function changePassword($sentNumber, $password, $serviceID, $commandcode, $info, &$status)
 	{
 		$username = $sentNumber;
+		$username = '0'.substr($username, 2, strlen($username));
 		$user = array();
 		$src = 'SBG';
-		$us_id = 0;
 		$errMsg = '';
 		$sms = '';
-		$flag = false;
+		$isForgotPassword = false;
 		$pass = $password;
 		if (is_null($password) || $password == '')
 		{
 			$pass = $this->create_random_password();
-			$flag = true;
-		}
-		$this->db->select('*')->from('tbluser')->where('cellphone', $username);
-		$query = $this->db->get();
-		if($query->num_rows() > 0)
-		{
-			$row = $query->row_array();
-			$us_id = $row['us_id'];
+			$$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');
@@ -241,10 +225,8 @@
 				case 0:
 					$us_id = $id;
-					$user['updated_time'] = $receiveTime;
-					$user['us_id'] = $us_id;
+					$user['updated_time'] = date('Y-m-d H:i:s');
 					$user['cellphone'] = $sentNumber;
-					$this->db->where('us_id', $us_id);
-					$this->db->update('tbluser', $user);
-					if ($flag)
+					$this->updateUser($us_id, $user);
+					if ($isForgotPassword)
 					{
 						$sms = "Mat khau moi cua quy vi tren soanbaigiang.smas.vn la [".$password."]";
@@ -255,5 +237,5 @@
 					break;
 				case 5:
-					$sms = "So dien thoai cá»§a Qui vi da duoc dang ky !";
+					$sms = "So dien thoai cá»§a Qui vi chua duoc dang ky !";
 					$status = 0;
 					break;
@@ -269,5 +251,4 @@
 			$status = 0;
 		}
-		$this->insert_smslog($sentNumber, $us_id, $serviceID, $commandcode, $info, $receiveTime);
 		return $status.'|'.$sms;
 	}
@@ -288,5 +269,83 @@
 	}
 	
-	function insert_smslog($sentNumber, $userID, $serviceID, $commandcode, $info, $receiveTime)
+	function registerVip($sentNumber, $receiverID, $vipNum, $serviceID, $commandcode, $info, &$status)
+	{
+		$username = $receiverID;
+		$username = '0'.substr($username, 2, strlen($username));
+		$user = array();
+		$sms = '';
+		$amount = $this->config->item($vipNum);
+		$result = $this->get_user_by_cellphone($username);
+		if($result){
+			if ($result['acc_balanced']>=$amount)
+			{
+				$us_id = $result['us_id'];
+				$user['acc_balanced'] = $result['acc_balanced'] - $amount;
+				if ($this->checkLicense($us_id)){
+					$user['expire_date'] = date('Y-m-d', strtotime($result['expire_date'].' + '.$vipNum.' month'));
+				}else
+				{
+					$user['expire_date'] = date('Y-m-d', strtotime('now + '.$vipNum.' month'));
+				}
+				$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']));
+				$status = 1;
+			}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.";
+			$status = 0;
+		}
+		return $status.'|'.$sms;
+	}
+	
+	function rechargeAccount($sentNumber, $receiverID, $amount, $serviceID, $commandcode, $info, &$status)
+	{
+		$username = $receiverID
+		$username = '0'.substr($username, 2, strlen($username));
+		$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."] 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.";
+			$status = 0;
+		}
+		/*}else
+		{
+			$sms = "Tai khoan cua Qui vi khong du de thuc hien lenh nap [".$amount."] vao tai khoan [".$username."] tren soanbaigiang.smas.vn ";
+			$status = 0;
+		}*/
+		return $status.'|'.$sms;
+		
+	}
+	
+	function get_user_by_cellphone($cellphone)
+	{
+		$this->db->select('*')->from('tbluser')->where('cellphone', $cellphone)->limit(1);
+		$result = $this->db->get()->row_array();
+		return $result;
+	}
+	
+	function updateUser($us_id, $data)
+	{
+		$this->db->where('us_id', $us_id);
+		$this->db->update('tbluser', $data);
+	}
+	
+	function insertSmslog($sentNumber, $userID, $serviceID, $commandcode, $info, $receiveTime)
 	{
 		$smslog = array();
