Index: pro-violet-viettel/sourcecode/application/helpers/lockfile_helper.php
===================================================================
--- pro-violet-viettel/sourcecode/application/helpers/lockfile_helper.php	(revision 619)
+++ pro-violet-viettel/sourcecode/application/helpers/lockfile_helper.php	(revision 620)
@@ -3,5 +3,5 @@
 if ( ! function_exists('createLockFile'))
 {
-	function createLockFile ($lockFilePrefix, $maxReach, $timeToUnlock, $colSep = '|', $lockFilePath = '')
+	function createLockFile ($lockFilePrefix, $maxReach, $timeToUnlock, $lockFilePath = '', $checkLockOnly = 0, $colSep = '|')
 	{
 		$currentTimeStamp = time();
@@ -24,5 +24,5 @@
 		$timeDiffMin = $lastTimeLock != '' ? dateDifference(date('Y-m-d H:i:s',$currentTimeStamp), date('Y-m-d H:i:s',$lastTimeLock), '%i') : 0;
 	
-		if ($lockCount < $maxReach && $timeDiffMin < $timeToUnlock) {
+		if ($lockCount < $maxReach && $timeDiffMin < $timeToUnlock && $checkLockOnly == 0) {
 			$lockCount ++;
 			$isLocked = $lockCount < $maxReach ? 0:1;
@@ -37,5 +37,6 @@
 		$lockTime = ($isLocked == 1) ? $lastTimeLock : $currentTimeStamp;
 		$content = $lockCount . $colSep . $lockTime . $colSep . $isLocked;
-		if($ready == 1) {
+		
+		if($ready == 1 && $checkLockOnly == 0) {
 			$fh = fopen ($filePath,'w');
 			fwrite ($fh, $content);
@@ -43,5 +44,5 @@
 		}
 	
-		return $lockCount;
+		return $isLocked;
 	}
 }
Index: pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 619)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 620)
@@ -192,5 +192,5 @@
 		
 		if ($checkSentNumber) {
-			$sms = "So Dien thoai " . $sentNumber . " da dang ky tren he thong SBG Online. Tran trong.";
+			$sms = "So dien thoai " . $sentNumber . " da dang ky tai khoan tren he thong SBG Online. Tran trong.";
 			$status = 0;
 			return $status . '|' . $sms;
@@ -234,5 +234,5 @@
 					break;
 				case 2:
-					$sms = "So Dien thoai " . $sentNumber . " da dang ky tren he thong SBG Online. Tran trong";
+					$sms = "So dien thoai " . $sentNumber . " da dang ky tai khoan tren he thong SBG Online. Tran trong";
 					$status = 0;
 					break;
@@ -247,5 +247,5 @@
 			}
 		} else {
-			$sms = "Tai khoan ".$username." chua dang ky tai khoan tren he thong SBG Online. Tran trong.";
+			$sms = "So dien thoai ".$username." chua dang ky tai khoan tren he thong SBG Online. Tran trong.";
 			$status = 0;
 		}
Index: pro-violet-viettel/sourcecode/application/modules/frontend/views/user_profile.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/views/user_profile.php	(revision 619)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/views/user_profile.php	(revision 620)
@@ -476,5 +476,5 @@
 			</div>
 			<div class="modal-body">
-				<div id="no_success_charge_info" class="alert alert-block alert-success"><center>MÃ£ tháº» hoáº·c Serial khÃŽng ÄÃºng hoáº·c ÄÃ£ ÄÆ°á»£c sá»­ dá»¥ng. QuÃ­ vá» vui lÃ²ng kiá»m tra láº¡i!</center></div>
+				<div id="no_success_charge_info" class="alert alert-block alert-success"><center></center></div>
 				<center><button id="package_register_finish_button" data-dismiss="modal" class="btn btn-primary" >ÄÃ³ng</button></center>
 			</div>
Index: pro-violet-viettel/sourcecode/application/modules/services/controllers/recharge.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/controllers/recharge.php	(revision 619)
+++ pro-violet-viettel/sourcecode/application/modules/services/controllers/recharge.php	(revision 620)
@@ -6,4 +6,7 @@
 	{
 		parent::__construct();
+		$this->load->model('frontend/user_model', 'objUserModel');
+		$this->load->helper('lockfile');
+		$this->load->model('services_model');
 	}
 	
@@ -14,36 +17,62 @@
 		$cardSerial = $input['card_serial'];
 		$pinCard = $input['pin_card'];
-		$aryParams = array(
-			'EWalletID' => $this->config->item('EWalletID'),
-			'CardSerial' => $cardSerial,
-			'PinCard' => $pinCard,
-		);
-		
-		$this->load->model('services_model');
-		$aryResult = array();
-		$data = $this->services_model->cardPaidProcess($aryParams,  $aryResult);
-		$this->load->model('frontend/user_model', 'objUserModel');
-		$paidType = 2;
-		$amount = $aryResult['TransactionAmount'];
-		$paidTime = date('Y-m-d H:i:s');
+		$isLocked = 0;
 		
 		$user = $this->objUserModel->get_user_by_id($userID);
-		$user['acc_balanced'] = $user['acc_balanced'] + $amount;
-		$user['updated_time'] = date('Y-m-d H:i:s');
-		if ($amount>0){
-			$this->objUserModel->updateUser($userID, $user);
+		$lockFilePreFix = $user['cellphone'];
+		$lockFilePath = $this->config->item('topup_lock_path');
+		$maxReach = $this->config->item('topup_lock_max_reach');
+		$timeToUnlock = $this->config->item('topup_unlock_minute');
+
+		$isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath, 1);
+		$chargCard = _SBG_CARD_PAY_SUCCESS;
+		$result = array();
+		$result['maxReach'] = $maxReach;
+		$result['timeToUnlock'] = $timeToUnlock;
+		$result['isLocked'] = $isLocked;
+		$result['tmp'] = $maxReach;
+		
+		$lockedMsg = 'QuÃœ vá» ÄÃ£ nháº­p sai thÃŽng tin tháº» cÃ o '. $maxReach .' láº§n liÃªn tiáº¿p.<br />Xin chá» '. $timeToUnlock .' phÃºt sau Äá» thao tÃ¡c láº¡i!';
+		$chargErrMsg = 'MÃ£ tháº» hoáº·c Serial khÃŽng ÄÃºng hoáº·c ÄÃ£ ÄÆ°á»£c sá»­ dá»¥ng. QuÃ­ vá» vui lÃ²ng kiá»m tra láº¡i!';
+		$errMsg = '';
+		
+		if ($isLocked == 0) {
+			$aryParams = array(
+					'EWalletID' => $this->config->item('EWalletID'),
+					'CardSerial' => $cardSerial,
+					'PinCard' => $pinCard,
+			);
+			
+			$aryResult = array();
+			$chargCard = $this->services_model->cardPaidProcess($aryParams,  $aryResult);
+			
+			$paidType = 2;
+			$amount = $aryResult['TransactionAmount'];
+			$paidTime = date('Y-m-d H:i:s');
+			$user['acc_balanced'] = $user['acc_balanced'] + $amount;
+			$user['updated_time'] = date('Y-m-d H:i:s');
+			if ($amount>0){
+				$this->objUserModel->updateUser($userID, $user);
+			}
+			
+			$result['success'] = $chargCard;
+			
+			if ($chargCard == _SBG_CARD_PAY_SUCCESS){
+				$result['username'] = $user['cellphone'];
+				$result['acc_balanced'] = $user['acc_balanced'];
+				$result['amount'] = $amount;
+				$this->objUserModel->insertPaidlog($user['cellphone'], $user['cellphone'], $paidType, $amount, $paidTime);
+				releaseLockFile($lockFilePreFix, $lockFilePath);
+			}
+			else {
+				$isLocked = createLockFile($lockFilePreFix, $maxReach, $timeToUnlock, $lockFilePath);
+				$errMsg = $isLocked == 1 ? $chargErrMsg .'<br />'.$lockedMsg : $chargErrMsg; 
+			}
+		}else if ($isLocked == 1) {
+			$errMsg = $lockedMsg; 
+			$result['success'] = _SBG_CARD_PAY_FAIL;
 		}
 		
-		$result = array();
-		if ($data == 1){
-			$result['success'] = 1;
-			$result['username'] = $user['cellphone'];
-			$result['acc_balanced'] = $user['acc_balanced'];
-			$result['amount'] = $amount;
-			$this->objUserModel->insertPaidlog($user['cellphone'], $user['cellphone'], $paidType, $amount, $paidTime);
-		}else
-		{
-			$result['success'] = 0;
-		}
+		$result['errMsg'] = $errMsg;
 		echo json_encode($result);
 	}
Index: pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 619)
+++ pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 620)
@@ -12,5 +12,5 @@
 
 if ( ! defined('_SBG_MO_SYNTAX_ERR')) define('_SBG_MO_SYNTAX_ERR', -1);
-if ( ! defined('_SBG_MO_SYNTAX_ERR_MSG')) define('_SBG_MO_SYNTAX_ERR_MSG', 'SBG Online khong co dich vu nÃ y, ban vui long kiem tra lai. Tran trong.');
+if ( ! defined('_SBG_MO_SYNTAX_ERR_MSG')) define('_SBG_MO_SYNTAX_ERR_MSG', 'SBG Online khong co dich vu nay, ban vui long kiem tra lai. Tran trong.');
 
 if ( ! defined('_SBG_CARD_PAY_FAIL')) define('_SBG_CARD_PAY_FAIL', -1);
