Index: pro-violet-viettel/sourcecode/application/config/routes.php
===================================================================
--- pro-violet-viettel/sourcecode/application/config/routes.php	(revision 576)
+++ pro-violet-viettel/sourcecode/application/config/routes.php	(revision 579)
@@ -83,6 +83,4 @@
 $route['admin/doanh_thu_tong_hop/cap_nhat'] = 'admin/report/updateSms';
 
-
-
 $route['admin/thong_ke_cong_tac_vien'] = 'admin/reportAsistant';
 $route['admin/thong_ke_cong_tac_vien/trang'] = 'admin/reportAsistant/getCollaborators/1';
@@ -92,8 +90,4 @@
 $route['admin/thong_ke_cong_tac_vien/them'] = 'admin/reportAsistant/addSmstemplate';
 $route['admin/thong_ke_cong_tac_vien/:any'] = 'admin/reportAsistant/viewAsistant';
-
-
-
-
 
 $route['admin/quan_tri_vien'] = 'admin/admin_acc';
Index: pro-violet-viettel/sourcecode/application/modules/admin/controllers/user.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/admin/controllers/user.php	(revision 576)
+++ pro-violet-viettel/sourcecode/application/modules/admin/controllers/user.php	(revision 579)
@@ -59,10 +59,11 @@
 		$us = $this->user_model->get_list_users($data);
 		$users = array();
-		foreach($us as $u):
+		
+		foreach($us as $u) {
 			$id = $u['us_id'];
 			$username = $this->get_username($id);
 			$u['username'] = $username;
 			array_push($users, $u);
-		endforeach;
+		}
 		
 		$data['users'] = $users;
Index: pro-violet-viettel/sourcecode/application/modules/admin/models/cardlog_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/admin/models/cardlog_model.php	(revision 576)
+++ pro-violet-viettel/sourcecode/application/modules/admin/models/cardlog_model.php	(revision 579)
@@ -26,5 +26,6 @@
 			$order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
 		}
-		return $this->db->query($sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage']." ")->result_array();
+		$query = $this->db->query($sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage']." ");
+		return $query->result_array();
 	}
 	
@@ -37,5 +38,7 @@
 				$sql.=" WHERE (sender LIKE '%".$data['keyword']."%'";
 		}
-		return $this->db->query($sql)->row_array()['total'];
+		$query = $this->db->query($sql);
+		$row = $query->row_array();
+		return $row['total'];
 	}
 }
Index: pro-violet-viettel/sourcecode/application/modules/admin/models/smslog_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/admin/models/smslog_model.php	(revision 576)
+++ pro-violet-viettel/sourcecode/application/modules/admin/models/smslog_model.php	(revision 579)
@@ -26,5 +26,8 @@
 			$order = "ORDER BY " . $data['sorting_field'] . " " . $sort;
 		}
-		return $this->db->query($sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage']." ")->result_array();
+		
+		$query = $this->db->query($sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage']." ");
+		
+		return $query->result_array();
 	}
 	
@@ -37,5 +40,8 @@
 				$sql.=" WHERE (sender LIKE '%".$data['keyword']."%' OR mobody LIKE '%".$data['keyword']."%' OR mtbody LIKE '%".$data['keyword']."%') ";
 		}
-		return $this->db->query($sql)->row_array()['total'];
+		
+		$query =  $this->db->query($sql);
+		$row = $query->row_array();
+		return $row['total'];
 	}
 }
Index: pro-violet-viettel/sourcecode/application/modules/admin/models/user_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/admin/models/user_model.php	(revision 576)
+++ pro-violet-viettel/sourcecode/application/modules/admin/models/user_model.php	(revision 579)
@@ -1,5 +1,5 @@
 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
-class User_model extends MY_Model
+class User_model extends CI_Model
 {
 	
@@ -62,5 +62,9 @@
 				$sql.=" WHERE (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%') ";
 		}
-		return $this->db->query($sql)->row_array()['total'];
+		
+		$query = $this->db->query($sql);
+		$row = $query->row_array();
+		
+		return $row['total'];
 	}
 	
Index: pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 576)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 579)
@@ -71,5 +71,5 @@
 	}
 	
-	public function register($username, $collaborator, &$status = '') {
+	public function register($username, $collaborator, &$collaboratorMsg = '') {
 		$user = array ();
 		$password = $this->create_random_password ();
@@ -80,9 +80,10 @@
 		$token = md5 ( $username . self::TOKENPW );
 		$phone = $username;
+		$status = 0;
 		
 		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;
+				$collaboratorMsg = $status . '|'.$sms;
 				return $status . '|' . $sms;
 			}
@@ -101,5 +102,5 @@
 		{
 			$sms = "Tam thoi Qui vi khong the dang ky duoc. Xin thu lai sau. Cam on!";
-			$status = 0;
+			$collaboratorMsg = $status . '|'.$sms;
 			return $status . '|' . $sms;
 		}
@@ -120,4 +121,5 @@
 				$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;
+				$collaboratorMsg = $status . '|'. 'Ban da dang ky thanh cong dich vu Soan bai giang Online cho '.$username;
 				break;
 			case 2 :
@@ -125,8 +127,10 @@
 				$sms = "So dien thoai cua Qui vi da duoc dang ky";
 				$status = 0;
+				$collaboratorMsg = $status . '|'. 'So dien thoai '.$username.' da duoc dang ky';
 				break;
 			default :
 				$status = 0;
 				$sms = $errMsg;
+				$collaboratorMsg = $status . '|'. $sms;
 				break;
 		}
@@ -258,4 +262,5 @@
 		
 		$result = $this->get_user_by_cellphone ( $username );
+		
 		if ($result) {
 			$us_id = $result ['us_id'];
@@ -368,5 +373,5 @@
 			$user ['updated_time'] = date ( 'Y-m-d H:i:s' );
 			$this->updateUser ( $us_id, $user );
-			$sms = "Qui vi da nap thanh cong " . $amount . " VNÄ vao tai khoan " . $username . " tren soanbaigiang.smas.vn";
+			$sms = "Qui vi da nap thanh cong " . $amount . " VND vao tai khoan " . $username . " tren soanbaigiang.smas.vn";
 			$status = 1;
 		} else {
Index: pro-violet-viettel/sourcecode/application/modules/services/controllers/viettel.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/controllers/viettel.php	(revision 576)
+++ pro-violet-viettel/sourcecode/application/modules/services/controllers/viettel.php	(revision 579)
@@ -55,5 +55,5 @@
 			$CI->load->model('Services_model');
 			$CI->load->model('frontend/User_model', 'objUserModel');
-			$result = $CI->Services_model->processMORequest($userID, strtoupper($info));
+			$result = $CI->Services_model->processMORequest($userID, $info);
 			$CI->objUserModel->insertSmslog($receiverID, $serviceID, $commandCode, $info, $receiveTime);
 					
Index: pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 576)
+++ 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;
