Index: pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 613)
+++ pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 615)
@@ -49,5 +49,5 @@
 		_SBG_MO_REGISTER 			=> array('pattern' => '/^(SBG[[:blank:]])(DK)$/'),
 		_SBG_MO_REGISTER_FOR 		=> array('pattern' => '/^(SBG[[:blank:]])(DK)([[:blank:]][0-9]{10,11})$/'),
-		_SBG_MO_PHONENUM_CHANGE 	=> array('pattern' => '/^(SBG[[:blank:]])(DDT)([[:blank:]][0-9]{10,11})([[:blank:]][a-zA-Z0-9~!@#$%^&*]{4,16})$/'),
+		_SBG_MO_PHONENUM_CHANGE 	=> array('pattern' => '/^(SBG[[:blank:]])(DDT)([[:blank:]][0-9]{10,11})([[:blank:]][a-zA-Z0-9]{1,})$/'),
 		_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})$/'), */
@@ -58,9 +58,5 @@
 	);
 	
-	private $_arySmsService = array(
-			'DK' => _SBG_MO_REGISTER_FOR,
-			'DDT' => _SBG_MO_PHONENUM_CHANGE,
-			'NAP' => _SBG_MO_PAY_TO_ACCOUNT_FOR,
-	);	
+	private $_aryServiceName = array('DK','DDT','VIP','NAP');	
 	
 	public function __construct(){
@@ -76,5 +72,5 @@
 		foreach ($this->_arySmsMO as $key => $pattern)
 		{
-			$result = preg_match_all ($pattern['pattern'], strtoupper($message), $aryMatched);
+			$result = preg_match_all ($pattern['pattern'], strtoupper(trim($message)), $aryMatched);
 			if ((bool)$result) break;
 		}
@@ -85,4 +81,8 @@
 			foreach ($aryMatched as $k => $val) {
 				if ($k == 0) continue;
+				if (count($val) == 0) {
+					$key = _SBG_MO_SYNTAX_ERR;
+					break;
+				}
 				$aryContent[] = trim($val[0]);			
 			} 
@@ -91,16 +91,41 @@
 		if ((bool)$result == FALSE) {
 			$aryContent = array();
-			foreach(explode(' ',strtoupper($message)) as $k => $val) {
+			foreach(explode(' ',strtoupper(trim($message))) as $k => $val) {
 				$aryContent[] = $val;
 			}
-			$key = $this->_arySmsService[$aryContent[1]];
-			$result = 1;
-		}
-		
-		if ($key == _SBG_MO_PASSWORD_CHANGE || $key == _SBG_MO_PHONENUM_CHANGE) {
-			$index = $key == _SBG_MO_PASSWORD_CHANGE ? 2 : 3;
-			$upcasePass = $aryContent[$index];
+			
+			$serviceName = $aryContent[1];
+			if (in_array($serviceName, $this->_aryServiceName)) {
+				if ($serviceName == 'DK' && count($aryContent) == 3) {
+					$key = _SBG_MO_REGISTER_FOR;
+				}
+				else if ($serviceName == 'DDT' && count($aryContent) == 4){
+					$key = _SBG_MO_PHONENUM_CHANGE;
+				}
+				else if ($serviceName == 'VIP' && count($aryContent) == 3){
+					$key = _SBG_MO_VIP_REGISTER;
+				}else if ($serviceName == 'NAP' && count($aryContent) == 3){
+					$key = _SBG_MO_PAY_TO_ACCOUNT;
+				}else if ($serviceName == 'NAP' && count($aryContent) == 4){
+					$key = _SBG_MO_PAY_TO_ACCOUNT_FOR;
+				}
+				
+				foreach ($aryContent as $k => $val) {
+					$aryContent[$k] = trim($val);
+				}
+				
+				$result = TRUE;
+			}
+		}
+		
+		if ($key == _SBG_MO_PHONENUM_CHANGE) {
+			$upcasePass = $aryContent[3];
 			$password = substr($message, -strlen($upcasePass));
 			$aryContent[$index] = $password;
+		}
+		
+		if ($key == _SBG_MO_REGISTER || $key == _SBG_MO_PASSWORD_RECOVERY) {
+			$debugMsg = var_export($aryContent, TRUE);
+			write_file('regis_log', $debugMsg);
 		}
 			
@@ -122,5 +147,5 @@
 		$this->load->model('frontend/user_model', 'objUserModel');
 		$debugMsg .= $case;
-		write_file('mt_log', $debugMsg);
+		
 		switch ($case) {
 			case _SBG_MO_REGISTER:
@@ -136,5 +161,7 @@
 				$collaborator = isset($aryContents[2]) ? $sentNumber:null;
 				$collaboratorMsg = '';
+				
 				$sms = $this->objUserModel->register($userName, $collaborator, $collaboratorMsg);
+				write_file('mt_log', $collaborator);
 				if ($case == _SBG_MO_REGISTER_FOR) {
 					$smsReturn = $collaboratorMsg;
@@ -152,14 +179,19 @@
 					break;
 				}
+				
 				$oldPhoneNumber = $this->formatPhoneNumber($aryContents[2]);
 				$password = $aryContents[3];
 				$smsReturn = $this->objUserModel->changeProfile($sentNumber, $oldPhoneNumber, $password);
+				
+				$arySMS = explode('|', $smsReturn);
+				$changeResult = (int)$arySMS[0];
+				
 				$sms = 'Ban da doi thanh cong so dien thoai tren SBG Online sang so dien thoai ' .$sentNumber. '. Tran trong.';
-				$sendMT = $this->sendMT($this->formatPhoneNumber($oldPhoneNumber, -1), $sms);
+				$sendMT = $changeResult == 1 ? $this->sendMT($this->formatPhoneNumber($oldPhoneNumber, -1), $sms) : '';
 				break;
 			case _SBG_MO_PASSWORD_RECOVERY:
-			case _SBG_MO_PASSWORD_CHANGE:
-				$password = isset($aryContents[2]) ? $aryContents[2] : null;
-				$smsReturn = $this->objUserModel->changePassword($sentNumber, $password);
+			/* case _SBG_MO_PASSWORD_CHANGE: */
+				/* $password = isset($aryContents[2]) ? $aryContents[2] : null; */
+				$smsReturn = $this->objUserModel->changePassword($sentNumber/* , $password */);
 				break;						
 			case _SBG_MO_VIP_REGISTER:
@@ -177,4 +209,9 @@
 				
 				$amount = $aryContents[2];
+				if (!preg_match('/^[0-9]{3,}$/', $amount)) {
+					$smsReturn = '0|So tien nap khong hop le.';
+					break;
+				}
+				
 				$result =$this->chargeRootAccountProcess($sentNumber, $amount, $sentNumber.' paid for SBG');
 				
