Index: pro-violet-viettel/sourcecode/application/modules/frontend/controllers/user.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/frontend/controllers/user.php	(revision 508)
+++ pro-violet-viettel/sourcecode/application/modules/frontend/controllers/user.php	(revision 517)
@@ -1,18 +1,56 @@
-<?php
-
-if (!defined('BASEPATH'))
-    exit('No direct script access allowed');
-
+<?php 
+if (! defined ( 'BASEPATH' ))
+	exit ( 'No direct script access allowed' );
 class User extends MX_Controller {
-
-    const TOKENPW = 'violet';
-
-    public function __construct() {
-        parent::__construct();
-        $this->load->helper('cookie');
-    }
-
-    public function profile() {
-        $user_info = $this->session->userdata('userInfo');
+	
+	const TOKENPW = 'violet';
+
+	public function __construct() {
+		parent::__construct ();
+		$this->load->helper ( 'cookie' );
+	}
+	
+	public function profile() {
+		$user_info = $this->session->userdata ( 'userInfo' );
+		if ($user_info) {
+			$this->load->model ( 'servicepackage_model' );
+			$user = $user_info ['user'];
+			$us_id = $user_info ['us_id'];
+			$src = "SBG";
+			$token = md5 ( $us_id . self::TOKENPW );
+			$data = $this->get_data ( $src, $token, $us_id );
+			$data ['packages'] = $this->servicepackage_model->getAllPackages ();
+			$this->load->view ( 'frontend/user_profile', $data );
+		} else {
+			redirect ( 'frontend/home' );
+		}
+	}
+	
+	public function packageRegister() {
+		$result = array ();
+		$input = $this->input->post ();
+		$user_info = $this->session->userdata ( 'userInfo' );
+		if ($user_info) {
+			$this->load->model ( 'servicepackage_model' );
+			$this->load->model ( 'user_model' );
+			$package = $this->servicepackage_model->getPackage ( $input ['p_id'] );
+			$user = $user_info ['user'];
+			$us_id = $user_info ['us_id'];
+			$user = $this->user_model->get_user_by_id ( $us_id );
+			$result ['can_buy'] = 1;
+			$result ['can_edit'] = 0;
+			if ($user ['acc_balanced'] < $package ['p_price']) {
+				$result ['can_buy'] = 0;
+			}
+			
+			if ($user ['p_id'] < 1) {
+				$result ['can_edit'] = 1;
+			}
+			$result ['user'] = $user;
+			$result ['package'] = $package;
+			$result ['modal'] = $this->load->view ( 'frontend/package_register_modal', $result, true );
+		} else {
+		}
+=======
 
         if ($user_info) {
@@ -199,4 +237,132 @@
                     $result['success'] = 1;
                 }
+>>>>>>> .r514
+<<<<<<< .mine
+		echo json_encode ( $result );
+	}
+	
+	private function get_data($src, $token, $us_id) {
+		$this->load->model ( 'user_model' );
+		$user = $this->user_model->get_user_info ( $src, $token, $us_id );
+		
+		if (strpos ( $user, '&' )) {
+			parse_str ( $user );
+			$us = $this->user_model->get_user_by_id ( $us_id );
+			$data = array (
+					'us_id' => $us_id,
+					'username' => $username,
+					'fullname' => $fullname,
+					'gender' => $gender,
+					'email' => $email,
+					'phone' => $phone,
+					'school' => $school,
+					'province' => $province,
+					'acc_balanced' => $us ['acc_balanced'],
+					'expire_date' => $us ['expire_date'],
+					'date_diff' => $this->dateDiff ( $us ['expire_date'] ) 
+			);
+			return $data;
+		} else {
+			return "";
+		}
+	}
+	
+	private function dateDiff($expire_date) {
+		$date1 = date ( "Y-m-d" );
+		if ((strtotime ( $expire_date ) - strtotime ( $date1 )) < 0)
+			return "0 ngÃ y cÃ²n láº¡i";
+		$diff = strtotime ( $expire_date ) - strtotime ( $date1 );
+		$years = floor ( $diff / (365 * 60 * 60 * 24) );
+		$months = floor ( ($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24) );
+		$days = floor ( ($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24) );
+		if ($years > 0) {
+			return $years . " nÄm, " . $months . " thÃ¡ng, " . $days . " ngÃ y cÃ²n láº¡i";
+		} else {
+			if ($months > 0) {
+				return $months . " thÃ¡ng, " . $days . " ngÃ y cÃ²n láº¡i";
+			} else {
+				return $days . " ngÃ y cÃ²n láº¡i";
+			}
+		}
+	}
+	
+	public function update_user() {
+		$this->load->helper ( 'email' );
+		$us_id = $this->uri->segment ( 4 );
+		$user_info = $this->session->userdata ( 'userInfo' );
+		if ($user_info) {
+			$result = array ();
+			$result ['success'] = 0;
+			$src = "SBG";
+			$token = md5 ( $us_id . self::TOKENPW );
+			$user = $this->get_data ( $src, $token, $us_id );
+			$input = $this->input->post ();
+			if ($input) {
+				$input ['username'] = $user ['username'];
+				$input ['fullname'] = $user ['fullname'];
+				$input ['password'] = '';
+				$input ['oldpass'] = '';
+				$this->load->model ( 'user_model' );
+				$result ['fullname'] = $input ['fullname'];
+				if (strlen ( $input ['email'] ) > 0) {
+					if (! valid_email ( $input ['email'] )) {
+						$result ['errors'] ['email_err'] = "Email khÃŽng ÄÃºng Äá»nh dáº¡ng";
+					}
+				}
+				if (! isset ( $result ['errors'] )) {
+					$result ['data'] = $this->user_model->update_user ( $src, $token, $input, $us_id );
+					$result ['success'] = 1;
+				}
+				echo json_encode ( $result );
+			}
+		} else {
+			redirect ( 'frontend/home' );
+		}
+	}
+	
+	public function change_password() {
+		$us_id = $this->uri->segment ( 4 );
+		$user_info = $this->session->userdata ( 'userInfo' );
+		if ($user_info) {
+			$this->load->model ( 'user_model' );
+			$us_id = $user_info ['us_id'];
+			$src = "SBG";
+			$token = md5 ( $us_id . self::TOKENPW );
+			if (strlen ( $input ['passwd'] ) == 0) {
+				$result ['errors'] ['passwd_old_err'] = "Máº­t kháº©u khÃŽng ÄÆ°á»£c Äá» trá»ng !";
+			}
+			if (strlen ( $input ['passwd_new'] ) == 0) {
+				$result ['errors'] ['passwd_new_err'] = "Máº­t kháº©u khÃŽng ÄÆ°á»£c Äá» trá»ng !";
+			} else if ($input ['passwd'] == $input ['passwd_new']) {
+				$result ['errors'] ['passwd_new_err'] = "Máº­t kháº©u trÃ¹ng vá»i máº­t kháº©u hiá»n táº¡i !";
+			}
+			if ($input ['passwd_new'] != $input ['confirm_passwd_new']) {
+				$result ['errors'] ['confirm_passwd_new_err'] = "Máº­t kháº©u khÃŽng trÃ¹ng nhau !";
+			}
+			if (! isset ( $result ['errors'] )) {
+				$user = array (
+						'username' => $username,
+						'fullname' => null 
+				);
+				$data = $this->user_model->update_user ( $src, $token, $user, $us_id );
+				parse_str ( $data );
+				switch ($status) {
+					case 0 :
+						$result ['success'] = 1;
+						break;
+					case 6 :
+						$result ['errors'] ['passwd_old_err'] = "Máº­t kháº©u cung cáº¥p khÃŽng ÄÃºng !";
+						break;
+					default :
+						break;
+				}
+			}
+			
+			echo json_encode ( $result );
+		} else {
+			redirect ( 'frontend/home' );
+		}
+	}
+}=======
                 echo json_encode($result);
             }
@@ -249,2 +415,3 @@
 
 }
+>>>>>>> .r514
