Index: pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 490)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 492)
@@ -68,43 +68,73 @@
 	}
 
-	function register ($sentNumber, $receiverID, $serviceID, $commandcode, $info, $receiveTime, &$status)
-	{
-		$username = '';
-		$collaborator = '';
-		$username = $receiverID;
+	function register ($username, $collaborator, &$status)
+	{
 		$user = array();
 		$password = $this->create_random_password();
 		$src = 'SBG';
+		$sms = '';
+		$id = 0;
+		$errMsg = '';
 		$username = '0'.substr($username, 2, strlen($username));
 		$token = md5($username.self::TOKENPW);		
 		$phone = $username;
-		$data = $this->vservices->actionExecute('update', array('src'=>$src, 'username'=>$username, 'password'=>$password, 'fullname'=>null, 'phone'=>$username, 'token'=>$token), 'user');
-		
-		$id = 0;
-		$errMsg = '';
-		parse_str($data);
-		$sms = '';
-		
-		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;
-				$user['collaborator'] = $collaborator;
-				$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:
-				$sms = "So dien thoai cua Qui vi da duoc dang ky !";
+		if (!is_null($collabolator) || $collabolator != ''){
+			if($this->isExistCollabolator($collabolator)){
+				$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;
+						$user['collaborator'] = $collaborator;
+						$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:
+						$sms = "So dien thoai cua Qui vi da duoc dang ky !";
+						$status = 0;
+						break;
+					default:
+						$status = 0;
+						$sms = $errMsg;
+						break;
+				}
+			}
+			else
+			{
+				$sms = "So dien thoai cua Qui vi chua la cong tac vien cua soanbaigiang.smas.vn!";
 				$status = 0;
-				break;
-			default:
-				$status = 0;
-				$sms = $errMsg;
-				break;
+			}
+		}else
+		{
+			$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;
+					$user['collaborator'] = $username;
+					$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:
+					$sms = "So dien thoai cua Qui vi da duoc dang ky !";
+					$status = 0;
+					break;
+				default:
+					$status = 0;
+					$sms = $errMsg;
+					break;
+			}
 		}
 		
@@ -151,9 +181,6 @@
 	}
 	
-	function changeProfile($sentNumber, $receiverID, $password, $serviceID, $commandcode, $info, &$status)
-	{
-		$username = '';
-		$username = $receiverID;
-		$username = '0'.substr($username, 2, strlen($username));
+	function changeProfile($sentNumber, $username, $password, &$status)
+	{
 		$user = array();
 		$src = 'SBG';
@@ -199,8 +226,6 @@
 	}
 	
-	function changePassword($sentNumber, $password, $serviceID, $commandcode, $info, &$status)
-	{
-		$username = $sentNumber;
-		$username = '0'.substr($username, 2, strlen($username));
+	function changePassword($username, $password, &$status)
+	{
 		$user = array();
 		$src = 'SBG';
@@ -269,23 +294,22 @@
 	}
 	
-	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);
+	function registerVip($username, $p_name, &$status)
+	{
+		$user = array();
+		$sms = '';
 		$result = $this->get_user_by_cellphone($username);
 		if($result){
-			if ($result['acc_balanced']>=$amount)
+			 $package = $this->get_package($p_name);
+			if ($result['acc_balanced']>=$package['p_price'])
 			{
 				$us_id = $result['us_id'];
-				$user['acc_balanced'] = $result['acc_balanced'] - $amount;
+				$user['acc_balanced'] = $result['acc_balanced'] - $p_price;
 				if ($this->checkLicense($us_id)){
-					$user['expire_date'] = date('Y-m-d', strtotime($result['expire_date'].' + '.$vipNum.' month'));
+					$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 + '.$vipNum.' month'));
+					$user['expire_date'] = date('Y-m-d', strtotime('now + '.$package['p_period'].' month'));
 				}
+				$user['user_package'] = $p_id;
 				$user['updated_time'] = date('Y-m-d H:i:s');
 				$this->updateUser($us_id, $user);
@@ -305,8 +329,6 @@
 	}
 	
-	function rechargeAccount($sentNumber, $receiverID, $amount, $serviceID, $commandcode, $info, &$status)
-	{
-		$username = $receiverID;
-		$username = '0'.substr($username, 2, strlen($username));
+	function rechargeAccount($username, $amount, &$status)
+	{
 		$user = array();
 		$sms = '';
@@ -325,11 +347,5 @@
 			$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;
-		
+		return $status.'|'.$sms;		
 	}
 	
@@ -341,8 +357,26 @@
 	}
 	
+	function isExistCollabolator($collabolator)
+	{
+		$this->db->select('*')->from('tbluser')->where('collabolator', $cellphone)->limit(1);
+		$result = $this->db->get()->row_array();
+		if ($result) return true; else return false;
+	}
+	
 	function updateUser($us_id, $data)
 	{
 		$this->db->where('us_id', $us_id);
 		$this->db->update('tbluser', $data);
+	}
+	
+	function get_package($p_name)
+	{
+		$this->db->select('*')->from('tblservicepackage')->where('p_name', $p_name);
+		$query = $this->db->get();
+		if($query->num_rows() > 0)
+		{
+			$row = $query->row_array();
+			return $row;
+		}
 	}
 	
