Index: pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 575)
+++ pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 579)
@@ -39,5 +39,5 @@
 		_SBG_MO_PHONENUM_CHANGE 	=> array('pattern' => '/^(SBG[[:blank:]])(DDT)([[:blank:]][0-9]{10,11})([[:blank:]][a-zA-Z0-9]{4,16})$/'),
 		_SBG_MO_PASSWORD_RECOVERY 	=> array('pattern' => '/^(SBG[[:blank:]])(MK)$/'),
-		_SBG_MO_PASSWORD_CHANGE 	=> array('pattern' => '/^(SBG[[:blank:]])(MK)([[:blank:]][a-zA-Z0-9]{4,16})$/'),
+		_SBG_MO_PASSWORD_CHANGE 	=> array('pattern' => '/^(SBG[[:blank:]])(MK)([[:blank:]][a-zA-Z0-9~!@#$%^&*]{4,16})$/'),
 		_SBG_MO_VIP_REGISTER 		=> array('pattern' => '/^(SBG[[:blank:]])(VIP)([[:blank:]][0-9]{1,2})$/'),
 		_SBG_MO_PAY_TO_ACCOUNT 		=> array('pattern' => '/^(SBG[[:blank:]])(NAP)([[:blank:]][0-9]{3,})$/'),
@@ -50,16 +50,32 @@
 	}
 	
-	private function messageAnalys ($message) 
-	{
-		$aryMatched = array();
+	public function messageAnalys ($message)
+	{
+		$aryMatched = array();	
+		$aryContent = array();
 		$result = false;
-		foreach ($this->_arySmsMO as $key => $pattern) 
+		
+		foreach ($this->_arySmsMO as $key => $pattern)
 		{
-			$result = preg_match($pattern['pattern'], $message, $aryMatched);
+			$result = preg_match_all ($pattern['pattern'], strtoupper($message), $aryMatched);
 			if ((bool)$result) break;
 		}
 		
+		if (count ($aryMatched) > 0) {
+			foreach ($aryMatched as $k => $val) {
+				if ($k == 0) continue;
+				$aryContent[] = trim($val[0]);			
+			} 
+		}
+	
 		$key = (bool)$result ? $key:_SBG_MO_SYNTAX_ERR;
-		$aryResult = (bool)$result ? array('case' => $key, 'content' => $aryMatched):array('case' => $key);
+		if ($key == _SBG_MO_PASSWORD_CHANGE || $key == _SBG_MO_PHONENUM_CHANGE) {
+			$index = $key == _SBG_MO_PASSWORD_CHANGE ? 2 : 3;
+			$upcasePass = $aryContent[$index];
+			$password = substr($message, -strlen($upcasePass));
+			$aryContent[$index] = $password;
+		}
+			
+		$aryResult = (bool)$result ? array('case' => $key, 'content' => $aryContent):array('case' => $key);
 		return $aryResult;
 	}
@@ -75,14 +91,5 @@
 		$case = $aryMOAnalys['case'];
 		$aryContents = isset($aryMOAnalys['content']) ? $aryMOAnalys['content']: null;
-		if ($aryContents != null){
-			unset($aryContents[0]);
-			$aryTmp = array();			
-			foreach ($aryContents as $key => $val)
-			{
-				$aryTmp[] = trim($val);
-			}
-			$aryContents = $aryTmp;
-		}
-		
+		$debugMsg .= var_export($aryMOAnalys);
 		$this->load->model('frontend/user_model', 'objUserModel');
 		$debugMsg .= $case;
@@ -93,9 +100,11 @@
 				$userName = isset($aryContents[2]) ? $this->formatPhoneNumber($aryContents[2]) : $sentNumber;  
 				$collaborator = isset($aryContents[2]) ? $sentNumber:null;
-				$sms = $this->objUserModel->register($userName, $collaborator);
+				$collaboratorMsg = '';
+				$sms = $this->objUserModel->register($userName, $collaborator, $collaboratorMsg);
 				if ($case == _SBG_MO_REGISTER_FOR) {
-					$smsReturn = '1|Ban da dang ky thanh cong dich vu Soan bai giang Online cho '. $userName;
+					$smsReturn = $collaboratorMsg;
 					$arySMS = explode ('|', $sms);
-					$sendMT = $this->sendMT($userName, $arySMS[1]);
+					if ((int)$arySMS[0] == 1 )
+						$sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $arySMS[1]);
 				}
 				else {
@@ -131,6 +140,7 @@
 					$smsReturn = $this->objUserModel->rechargeAccount($userName, $amount);
 					if (_SBG_MO_PAY_TO_ACCOUNT_FOR) {
-						$smsMT = $smsReturn .' tu thue bao '. $sentNumber;
-						$sendMT = $this->sendMT($userName, $smsMT);
+						$arySmsReturn = explode ('|', $smsReturn);
+						$smsMT = $arySmsReturn[1] .' tu thue bao '. $sentNumber;
+						$sendMT = $this->sendMT($this->formatPhoneNumber($userName, -1), $smsMT);
 					}
 				}
@@ -147,5 +157,5 @@
 		}
 		
-		return $smsReturn;
+		return $smsReturn.'|'.$case;
 	}
 	
@@ -272,12 +282,18 @@
 	}
 	
-	public function formatPhoneNumber ($phoneNumber) {
+	public function formatPhoneNumber ($phoneNumber, $direction = 1) {
 		$aryMatch = array();
-		if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1) {
+		if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == 1) {
 			$result = '0'. $aryMatch[2];
 		}
-		else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber)) {
+		else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == 1) {
 			$result = $phoneNumber;
 		}
+		else if (preg_match('/^(84)([0-9]{9,10})$/', $phoneNumber) == 1 && $direction == -1) {
+			$result = $phoneNumber;
+		}
+		else if (preg_match('/^(0)([0-9]{9,10})$/', $phoneNumber, $aryMatch) == 1 && $direction == -1) {
+			$result = '84'. $aryMatch[2];
+		}
 		
 		return $result;
