Index: pro-violet-viettel/sourcecode/application/modules/frontend/controllers/home.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/controllers/home.php	(revision 555)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/controllers/home.php	(revision 556)
@@ -1,143 +1,151 @@
 ﻿<?php
-if (!defined('BASEPATH'))
-    exit('No direct script access allowed');
+if (! defined ( 'BASEPATH' ))
+	exit ( 'No direct script access allowed' );
 
 /**
  * Home Class
- * 
+ *
  * @author dzungnv02
- *
+ *        
  */
 class Home extends MX_Controller {
-
-    const TOKENPW = 'violet';
-
-    public function __construct() {
-        parent::__construct();
-        $this->load->helper('cookie');
-    }
-
-    public function index() {
-        $user_info = $this->session->userdata('userInfo');
-        if ($user_info) {
-            redirect('/frontend/lecture');
-        } else {
-            $cookie_name = "siteCookie";
-            if (isset($_COOKIE[$cookie_name])) {
-                $arr_user = parse_str($_COOKIE[$cookie_name]);
-                $user_info = array('username' => $arr_user['username'], 'user' => $arr_user['user'], 'us_id' => $arr_user['us_id'], 'logined_in' => TRUE);
-                $this->session->set_userdata('userInfo', $user_info);
-                redirect('/frontend/lecture');
-            } else {
-                $this->load->view('home');
-            }
-        }
-    }
-
-    public function signin() {
-        $username = $this->input->post('username', TRUE);
-        $password = $this->input->post('password', TRUE);
-        $autologin = ($this->input->post('remember_me') == 'on') ? 1 : 0;
+	const TOKENPW = 'violet';
+	public function __construct() {
+		parent::__construct ();
+		$this->load->helper ( 'cookie' );
+	}
+	
+	public function index() {
+		$user_info = $this->session->userdata ( 'userInfo' );
+		if ($user_info) {
+			redirect ( '/frontend/lecture' );
+		} else {
+			$cookie_name = "siteCookie";
+			if (isset ( $_COOKIE [$cookie_name] )) {
+				$arr_user = parse_str ( $_COOKIE [$cookie_name] );
+				$user_info = array (
+						'username' => $arr_user ['username'],
+						'user' => $arr_user ['user'],
+						'us_id' => $arr_user ['us_id'],
+						'logined_in' => TRUE 
+				);
+				$this->session->set_userdata ( 'userInfo', $user_info );
+				redirect ( '/frontend/lecture' );
+			} else {
+				$this->load->view ( 'home' );
+			}
+		}
+	}
+	
+	public function signin() {
+		$username = $this->input->post ( 'username', TRUE );
+		$password = $this->input->post ( 'password', TRUE );
+		$autologin = ($this->input->post ( 'remember_me' ) == 'on') ? 1 : 0;
 		$src = 'SBG';
-        $token = md5($username . self::TOKENPW);
-        $this->load->model(array('user_model'));
-        $data = $this->user_model->checkLogin($src, $token, $username, $password);
-        
-        
-        if ($data == null) {
-            $this->session->set_flashdata('login_error', TRUE);
-            redirect('/frontend/home');
-        } else {
-            parse_str($data);
-            $is_viettel=$this->is_viettel($phone);
-            switch ($status) {
-                case 0:
-                case 4:
-
-                    if ($autologin == 1) {
-                        $cookie_name = 'siteCookie';
-                        //$cookie_time = 7200;
-                        $cookie_time = 3600 * 24 * 30;
-                        setcookie($cookie_name, 'username=' . $username . '&user=' . $data . '&us_id=' . $id, time() + $cookie_time);
-                    }
-                    $userdata = array('username' => $username, 'user' => $data, 'us_id' => $id, 'logined_in' => TRUE,'is_viettel'=>$is_viettel);
-                    $this->session->set_userdata('userInfo', $userdata);
-                    redirect('/frontend/lecture');
-                    break;
-                case 1:
-                    $this->session->set_flashdata('login_error', TRUE);
-                    redirect('/frontend/home');
-                    break;
-                case 2:
-                case 3:
-                    $this->session->set_flashdata('login_error', TRUE);
-                    redirect('/frontend/home');
-                    break;
-                //case 4:
-                //redirect('/frontend/home');
-                case 10:
-                    $this->session->set_flashdata('login_error_token', TRUE);
-                    redirect('/frontend/home');
-                    break;
-                default:
-                    break;
-            }
-        }
-    }
-
-    public function signout() {
-        $this->session->sess_destroy();
-        //unset($this->session->userdata); 
-        $cookie_name = "siteCookie";
-        setcookie($cookie_name, 'username=' . "", time() - 3600);
-        redirect('/frontend/home');
-    }
-    
-    public function register() {
-        $this->load->model('user_model');
-        $sentNumber = '0979947802';
-        $serviceID = 1;
-        $receiveID = '0985685735';
-        $commandcode = 'commandcode1';
-        $info = 'ABCD';
-        //$receiveTime = time();
-        $receiveTime = date("Y-m-d H:i:s");
-        $data = $this->user_model->register($sentNumber, $receiveID, $serviceID, $commandcode, $info, $receiveTime);
-        echo $data;
-    }
-
-    public function change_profile() {
-        $this->load->model('user_model');
-        $sentNumber = '0979947802';
-        $serviceID = 1;
-        $password = '123456';
-        $commandcode = "SBG";
-        $receiveID = '01662860000';
-        $info = "SBG TD";
-        $receiveTime = date("Y-m-d H:i:s");
-        $status = 0;
-        $data = $this->user_model->changeProfile($sentNumber, $receiveID, $password, $status);
-        echo $data;
-    }
-
-    public function change_password() {
-        $this->load->model('user_model');
-        $sentNumber = '01662860000';
-        $serviceID = 1;
-        $password = '123456';
-        //$oldpass = '123456';
-        $commandcode = "SBG";
-        //$receiveID = '0979947802';
-        $info = "SBG MK";
-        $receiveTime = date("Y-m-d H:i:s");
-        $status = 0;
-        $data = $this->user_model->changePassword($sentNumber, $password, $serviceID, $commandcode, $info, $receiveTime, $status);
-        echo $data;
-    }
-
-	
-	public function register_vip()
-	{
-		$this->load->model('user_model');
+		$token = md5 ( $username . self::TOKENPW );
+		$this->load->model ( array (
+				'user_model' 
+		) );
+		$data = $this->user_model->checkLogin ( $src, $token, $username, $password );
+		
+		if ($data == null) {
+			$this->session->set_flashdata ( 'login_error', TRUE );
+			redirect ( '/frontend/home' );
+		} else {
+			parse_str ( $data );
+			$is_viettel = $this->is_viettel ( $phone );
+			switch ($status) {
+				case 0 :
+				case 4 :
+					
+					if ($autologin == 1) {
+						$cookie_name = 'siteCookie';
+						// $cookie_time = 7200;
+						$cookie_time = 3600 * 24 * 30;
+						setcookie ( $cookie_name, 'username=' . $username . '&user=' . $data . '&us_id=' . $id, time () + $cookie_time );
+					}
+					$userdata = array (
+							'username' => $username,
+							'user' => $data,
+							'us_id' => $id,
+							'logined_in' => TRUE,
+							'is_viettel' => $is_viettel 
+					);
+					$this->session->set_userdata ( 'userInfo', $userdata );
+					redirect ( '/frontend/lecture' );
+					break;
+				case 1 :
+					$this->session->set_flashdata ( 'login_error', TRUE );
+					redirect ( '/frontend/home' );
+					break;
+				case 2 :
+				case 3 :
+					$this->session->set_flashdata ( 'login_error', TRUE );
+					redirect ( '/frontend/home' );
+					break;
+				// case 4:
+				// redirect('/frontend/home');
+				case 10 :
+					$this->session->set_flashdata ( 'login_error_token', TRUE );
+					redirect ( '/frontend/home' );
+					break;
+				default :
+					break;
+			}
+		}
+	}
+	
+	public function signout() {
+		$this->session->sess_destroy ();
+		// unset($this->session->userdata);
+		$cookie_name = "siteCookie";
+		setcookie ( $cookie_name, 'username=' . "", time () - 3600 );
+		redirect ( '/frontend/home' );
+	}
+	
+	public function register() {
+		$this->load->model ( 'user_model' );
+		$sentNumber = '0979947802';
+		$serviceID = 1;
+		$receiveID = '0985685735';
+		$commandcode = 'commandcode1';
+		$info = 'ABCD';
+		// $receiveTime = time();
+		$receiveTime = date ( "Y-m-d H:i:s" );
+		$data = $this->user_model->register ( $sentNumber, $receiveID, $serviceID, $commandcode, $info, $receiveTime );
+		echo $data;
+	}
+	
+	public function change_profile() {
+		$this->load->model ( 'user_model' );
+		$sentNumber = '0979947802';
+		$serviceID = 1;
+		$password = '123456';
+		$commandcode = "SBG";
+		$receiveID = '01662860000';
+		$info = "SBG TD";
+		$receiveTime = date ( "Y-m-d H:i:s" );
+		$status = 0;
+		$data = $this->user_model->changeProfile ( $sentNumber, $receiveID, $password, $status );
+		echo $data;
+	}
+	
+	public function change_password() {
+		$this->load->model ( 'user_model' );
+		$sentNumber = '01662860000';
+		$serviceID = 1;
+		$password = '123456';
+		// $oldpass = '123456';
+		$commandcode = "SBG";
+		// $receiveID = '0979947802';
+		$info = "SBG MK";
+		$receiveTime = date ( "Y-m-d H:i:s" );
+		$status = 0;
+		$data = $this->user_model->changePassword ( $sentNumber, $password, $serviceID, $commandcode, $info, $receiveTime, $status );
+		echo $data;
+	}
+	
+	public function register_vip() {
+		$this->load->model ( 'user_model' );
 		$sentNumber = '01662860000';
 		$serviceID = 1;
@@ -146,13 +154,12 @@
 		$mainAccBalanced = 15000;
 		$info = "SBG DK VIP1";
-		$receiveTime = date("Y-m-d H:i:s");
-		$status = 0;
-		$data = $this->user_model->registerVip($sentNumber, $vipNum, $serviceID, $commandcode, $info, $status);
-		echo $data;
-	}
-	
-	public function recharge_account()
-	{
-		$this->load->model('user_model');
+		$receiveTime = date ( "Y-m-d H:i:s" );
+		$status = 0;
+		$data = $this->user_model->registerVip ( $sentNumber, $vipNum, $serviceID, $commandcode, $info, $status );
+		echo $data;
+	}
+	
+	public function recharge_account() {
+		$this->load->model ( 'user_model' );
 		$sentNumber = '0979947802';
 		$receiveID = '01662860000';
@@ -164,19 +171,28 @@
 		$info = "SBG NAP 01662860000 10000";
 		$status = 0;
-		$data = $this->user_model->rechargeAccount($sentNumber, $receiveID, $mainAccBalanced, $amount, $serviceID, $commandcode, $info, $status);
-		echo $data;
-	}
-        public function is_viettel($number)
-        {
-            $viettel=array('096','097','098','0163','0164','0165','0166','0167','0168','0169');
-            foreach ($viettel as $num)
-            {
-                if (strpos($number, $num)===0)
-                {
-                  return true;                
-                }
-            }
-            return false; 
-        }
+		$data = $this->user_model->rechargeAccount ( $sentNumber, $receiveID, $mainAccBalanced, $amount, $serviceID, $commandcode, $info, $status );
+		echo $data;
+	}
+	
+	public function is_viettel($number) {
+		$viettel = array (
+				'096',
+				'097',
+				'098',
+				'0163',
+				'0164',
+				'0165',
+				'0166',
+				'0167',
+				'0168',
+				'0169' 
+		);
+		foreach ( $viettel as $num ) {
+			if (strpos ( $number, $num ) === 0) {
+				return true;
+			}
+		}
+		return false;
+	}
 }
 
Index: pro-violet-viettel/sourcecode/application/modules/frontend/controllers/user.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/controllers/user.php	(revision 555)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/controllers/user.php	(revision 556)
@@ -115,6 +115,9 @@
         $package = $this->servicepackage_model->getPackage($input['p_id']);
         $user['acc_balanced'] = $user['acc_balanced'] - $package['p_price'];
-        $user['expire_date'] = date('Y-m-d 00:00:00', strtotime("+" . $package['p_period'] . " " . $package['p_unit'], strtotime($user['expire_date'])));
-        $user['expire_date'] = date("Y-m-d 00:00:00", (strtotime($user['expire_date']) - 1));
+        
+        $currentExpireDate = $user['expire_date'] == NULL || trim($user['expire_date']) == '' ? date('Y-m-d 00:00:00') : $user['expire_date'];
+        $user['expire_date'] = date('Y-m-d', strtotime("+" . $package['p_period'] . " ".$package['p_unit'], strtotime($currentExpireDate))); 
+        $user['expire_date'] = date("Y-m-d", strtotime("-1 day", strtotime($user['expire_date'])));
+
         $user['p_id'] = $package['p_id'];
         $this->user_model->updateUser($us_id, $user);
Index: pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 555)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/models/user_model.php	(revision 556)
@@ -80,5 +80,5 @@
 		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!";
+				$sms = "Khong tim thay cong tac vien nao co so dien thoai [" . $collaborator . "] tren soanbaigiang.smas.vn";
 				$status = 0;
 				return $status . '|' . $sms;
@@ -94,4 +94,5 @@
 				'token' => $token 
 		), 'user' );
+		
 		if(!($data) || is_null($data))
 		{
@@ -100,4 +101,5 @@
 			return $status . '|' . $sms;
 		}
+		
 		parse_str ( $data );
 		
@@ -118,5 +120,5 @@
 			case 2 :
 			case 4 :
-				$sms = "So dien thoai cua Qui vi da duoc dang ky!";
+				$sms = "So dien thoai cua Qui vi da duoc dang ky";
 				$status = 0;
 				break;
@@ -341,5 +343,5 @@
 				
 				$this->updateUser ( $us_id, $user );
-				$sms = "Chuc mung Qui vi da dang ky su dung Soan Bai giang truc tuyen tren soanbaigiang.smas.vn. Qui vi co the su dung dich vu den 24h00 ngay " . date ( 'd/m/Y', strtotime ( $user ['expire_date'] ) );
+				$sms = "Chuc mung Qui vi da dang ky su dung Soan Bai giang truc tuyen tren soanbaigiang.smas.vn. Qui vi co the su dung dich vu den ngay " . date ( 'd/m/Y', strtotime ( $user ['expire_date'] ) );
 				$status = 1;
 			} else {
@@ -363,5 +365,5 @@
 			$user ['updated_time'] = date ( 'Y-m-d H:i:s' );
 			$this->updateUser ( $us_id, $user );
-			$sms = "Qui vi da nap thanh cong " . $amount . "VND 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/frontend/views/servicemodals.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/views/servicemodals.php	(revision 555)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/views/servicemodals.php	(revision 556)
@@ -17,5 +17,30 @@
 		      <div class="modal-footer">
 		      	<button type="button" class="btn btn-info" data-dismiss="modal">DÃ¹ng thá»­</button>
-		      	<button type="button" class="btn btn-success" id="services-reg">ÄÄng kÃœ</button>
+		      	<button type="button" class="btn btn-success" id="services-reg" data-dismiss="modal">ÄÄng kÃœ</button>
+		      </div>
+		    </div>
+		  </div>
+		</div>
+		<!-- END: alert-services -->
+		
+		<!-- alert-services-package -->
+		<div class="modal fade" id="alert-services-package" tabindex="-1" role="dialog"aria-hidden="true">
+		  <div class="modal-dialog">
+		    <div class="modal-content">
+		      <div class="modal-header">
+		        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
+		        <h4 class="modal-title">ThÃŽng bÃ¡o dá»ch vá»¥</h4>
+		      </div>
+		      <div class="modal-body">
+		      	<div class="alert alert-block alert-success">						
+							<p>
+								QuÃ­ vá» chÆ°a ÄÄng kÃ­ sá»­ dá»¥ng dá»ch vá»¥ Soáº¡n BÃ i giáº£ng online. QuÃ­ vá» cÃ³ thá» dÃ¹ng thá»­ dá»ch vá»¥ Soáº¡n BÃ i giáº£ng online trÆ°á»c khi ÄÄng kÃ­.
+							</p>
+						</div>
+		      </div>
+
+		      <div class="modal-footer">
+		      	<button type="button" class="btn btn-info" data-dismiss="modal">DÃ¹ng thá»­</button>
+		      	<button type="button" class="btn btn-success" id="save-package" data-dismiss="modal">LÆ°u bÃ i giáº£ng</button>
 		      </div>
 		    </div>
Index: pro-violet-viettel/sourcecode/application/modules/frontend/views/user_profile.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/views/user_profile.php	(revision 555)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/views/user_profile.php	(revision 556)
@@ -249,5 +249,5 @@
                                         <h4 class="header blue bolder smaller">ThÃŽng tin dá»ch vá»¥</h4>
 										<div class="col-sm-6">
-                                            <h4><b>Thá»i háº¡n sá»­ dá»¥ng</b></h4> <h3><b><span class="blue"><?php if(strtotime($expire_date)>0) { echo date('d/m/Y', strtotime($expire_date));}else { echo '';} ?> </span></b></h3>
+                                            <h4><b>Thá»i háº¡n sá»­ dá»¥ng</b></h4> <h3><b><span class="blue"><?php echo isset($expire_date) && strtotime($expire_date)>0 ? date('d/m/Y', strtotime($expire_date)) : '';?> </span></b></h3>
                                         </div> 
 										<div class="col-sm-6">
Index: pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 555)
+++ pro-violet-viettel/sourcecode/application/modules/services/models/services_model.php	(revision 556)
@@ -133,9 +133,14 @@
 				else {
 					$smsReturn = $this->objUserModel->rechargeAccount($userName, $amount);
-				}
+					if (_SBG_MO_PAY_TO_ACCOUNT_FOR) {
+						$smsMT = $smsReturn .' tu thue bao '. $sentNumber;
+						$sendMT = $this->sendMT($userName, $smsMT);
+					}
+				}
+				
 				//write to paid log
+				//$this->objUserModel->insertPaidlog();
 				break;
 			case _SBG_MO_UNSUBSCRIBE_SERVICE:
-				break;
 			case _SBG_MO_SYNTAX_ERR:
 			default:
