Index: pro-violet-viettel/sourcecode/application/modules/admin/controllers/user.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/admin/controllers/user.php	(revision 770)
+++ pro-violet-viettel/sourcecode/application/modules/admin/controllers/user.php	(revision 883)
@@ -27,4 +27,5 @@
 		$this->load->helper ( 'pagging' );
 		$this->load->model ( 'user_model' );
+		
 		$provinces = lang('_PROVINCES_');
 		error_log(var_export($provinces, TRUE), 3, '/srv/www/sbg/log/provinces.log');
@@ -50,7 +51,12 @@
 		}
 		$data['provinces'] = $provinces;
-		$data['province_code'] = '';
-		if ($this->input->post ( 'province-code' )) {
-			$data ['province_code'] = $this->input->post ( 'province-code' );
+		$data['province'] = '';
+		if ($this->input->post ( 'province' )) {
+			$data ['province'] = $this->input->post ( 'province' );
+		}
+		if ($data['province'])
+			$data['districts'] = $this->user_model->getDistrictByProvince($data ['province']);
+		if ($this->input->post ( 'district' )) {
+			$data['district'] = $this->input->post ( 'district' );
 		}
 		$data ['keyword'] = "";
@@ -58,5 +64,5 @@
 		$data ['sorting_field'] = "created_time";
 		if ($this->input->post ( 'sorting_order' )) {
-			if ($this->input->post ( 'sorting_order' ) != "sorting") {
+			if ($this->input->post ( 'sorting_ord	er' ) != "sorting") {
 				$data ['sorting_order'] = $this->input->post ( 'sorting_order' );
 				$data ['sorting_field'] = $this->input->post ( 'sorting_field' );
@@ -84,5 +90,8 @@
 		
 		foreach ( $us as $u ) {
+			$dist = $this->user_model->getDistrictByIdAndProvince($u['district'], $u['province']);
+			$u['district_name'] = $dist['type']." ".$dist['district_name'];
 			$u ['province'] = isset($provinces[$u ['province']]) ? $provinces[$u ['province']] : $u ['province'];
+			
 			$userinfo = $this->get_userinfo ( $u ['us_id'] );
 			if ($userinfo) {
@@ -171,11 +180,249 @@
 		$this->load->model ( 'user_model' );
 		$data = $this->user_model->get_user_info ( $src, $us_id, $token );
-		// var_dump($data);
 		$result = array ();
 		parse_str ( $data, $result );
 		return $result;
+	}
+	
+	public function export(){
+		
+		$this->load->helper ( 'pagging' );
+		$this->load->model ( 'user_model' );
+		$provinces = lang('_PROVINCES_');
+	
+		$data ['current_page'] = $this->uri->segment ( 4, 1 );
+		$data ['itemsoptions'] = array (
+				10,
+				25,
+				50,
+				100 
+		);
+
+		$data ['perpage'] = $this->uri->segment (5, 10);
+		$data ['statusoptions'] = array (
+				0 => "Táº¥t cáº£",
+				1 => "ÄÃ£ ÄÄng kÃœ VIP",
+				2 => "DÃ¹ng thá»­ 7 ngÃ y",
+				3=> "DÃ¹ng thá»­ háº¡n cháº¿",
+				4=> "Háº¿t háº¡n"
+		);
+		$data ['status'] = $this->uri->segment (7, 0);
 		/*
-		 * if (strpos($data, '&')){ $arr_users = explode("&", $data); $str_username = $arr_users[1]; $arr_username = explode("=", $str_username); return $arr_username[1]; }else { return ""; }
-		 */
-	}
+		if ($this->input->post ( 'status' )) {
+			$data ['status'] = ( int ) $this->input->post ( 'status' );
+		}
+		*/
+		$data['provinces'] = $provinces;
+		$data['province'] = $this->uri->segment (8);
+		if ($data['province'] == 'default') $data['province'] = null;
+		if ($this->input->post ( 'province' )) {
+			$data ['province'] = $this->input->post ( 'province' );
+		}
+		if ($data['province'])
+			$data['districts'] = $this->user_model->getDistrictByProvince($data ['province']);
+		if ($this->input->post ( 'district' )) {
+			$data['district'] = $this->input->post ( 'district' );
+		}
+		
+		$data['district'] = $this->uri->segment (9);
+		if ($data['district'] == 'default') $data['district'] = null;
+		$data ['keyword'] = $this->uri->segment (6);
+		if ($data['keyword'] == 'default') $data['keyword'] = null;
+		$data ['sorting_order'] = "sorting_desc";
+		$data ['sorting_field'] = "created_time";
+		$data ['sorting_order'] = $this->uri->segment (11);
+		$data ['sorting_field'] = $this->uri->segment (12);
+		
+		if ($this->input->post ( 'sorting_order' )) {
+			if ($this->input->post ( 'sorting_order' ) != "sorting") {
+				$data ['sorting_order'] = $this->input->post ( 'sorting_order' );
+				$data ['sorting_field'] = $this->input->post ( 'sorting_field' );
+			}
+		}
+		
+		if ($this->input->post ( 'items' )) {
+			$data ['perpage'] = $this->input->post ( 'items' );
+		}
+		
+		if ($this->input->post ( 'keyword' )) {
+			$data ['keyword'] = $this->input->post ( 'keyword' );
+		}
+		
+		$data ['daterange_start'] = "";
+		$data ['daterange_end'] = "";
+		$daterange = $this->uri->segment (10);
+		if ($daterange == 'default') $daterange = null;
+		if($daterange){
+			$daterange = explode ( " - ", $daterange );
+			$daterange [0] = str_replace ( '/', '-', $daterange [0] );
+			$daterange [1] = str_replace ( '/', '-', $daterange [1] );
+			$data ['daterange_start'] = date ( 'Y-m-d H:i:s', strtotime ( $daterange [0] ) );
+			$data ['daterange_end'] = date ( 'Y-m-d H:is:s', strtotime ( $daterange [1] . ' + 1 day' ) );
+		}
+		if ($this->input->post ( 'daterange' )) {
+			$daterange = explode ( " - ", $this->input->post ( 'daterange' ) );
+			$daterange [0] = str_replace ( '/', '-', $daterange [0] );
+			$daterange [1] = str_replace ( '/', '-', $daterange [1] );
+			$data ['daterange_start'] = date ( 'Y-m-d H:i:s', strtotime ( $daterange [0] ) );
+			$data ['daterange_end'] = date ( 'Y-m-d H:is:s', strtotime ( $daterange [1] . ' + 1 day' ) );
+		}
+		$data ['start'] = ($data ['current_page'] - 1) * $data ['perpage'];
+		$data ['total'] = $this->user_model->get_total_users ( $data );
+		$us = $this->user_model->get_list_users ( $data );
+		$users = array ();
+		
+		foreach ( $us as $u ) {
+			$dist = $this->user_model->getDistrictByIdAndProvince($u['district'], $u['province']);
+			$u['district_name'] = $dist['type']." ".$dist['district_name'];
+			$u ['province'] = isset($provinces[$u ['province']]) ? $provinces[$u ['province']] : $u ['province'];
+			
+			$userinfo = $this->get_userinfo ( $u ['us_id'] );
+			if ($userinfo) {
+				$u ['username'] = $userinfo ['username'];
+				$u['fullname'] = $userinfo['fullname'];
+			}
+			
+			if (strtotime($u['expire_date']) > time() && $u['p_id'] != 5 ){
+				$u['status'] = 'ÄÃ£ ÄÄng kÃœ VIP';
+			}elseif(strtotime($u['expire_date']) > time() && $u['p_id'] == 5){
+				$u['status'] = 'DÃ¹ng thá»­ 7 ngÃ y';
+			}elseif(strtotime($u['expire_date']) < time() && $u['p_id'] == 5){
+				$u['status'] = 'DÃ¹ng thá»­ háº¡n cháº¿';
+			}else{
+				$u['status'] = 'Háº¿t háº¡n';
+			}
+			
+			array_push ( $users, $u );
+		}
+	
+		$data ['users'] = $users;
+		$data ['paging_url'] = base_url () . "admin/nguoi_dung/trang/";
+		$data ['num_links'] = 2;
+		$data ['paging'] = pagging ( $data );
+		
+		$this->load->library("PHPExcel");
+        $sheet = $this->phpexcel->getActiveSheet();
+		
+        $sheet->setTitle("bao cao thue bao " . $data['month'] . " - " . $data['year']);
+        $sheet->getColumnDimension('A')->setWidth(10);
+        $sheet->getColumnDimension('B')->setWidth(25);
+        $sheet->getColumnDimension('C')->setWidth(25);
+        $sheet->getColumnDimension('D')->setWidth(15);
+        $sheet->getColumnDimension('E')->setWidth(15);
+        $sheet->getColumnDimension('F')->setWidth(15);
+        $sheet->getColumnDimension('G')->setWidth(15);
+        $sheet->getColumnDimension('H')->setWidth(25); 
+        $sheet->getColumnDimension('I')->setWidth(25);
+		
+		
+		$sheet->setCellValue('B1', "Táº¬P ÄOÃN VIá»N THÃNG QUÃN Äá»I");
+		$style = array(
+			'font' => array('bold' => true, 'size' => 12, 'name' =>'Cambria', 'color' => array('rgb' => '0070bf')),
+			'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
+								'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
+								'wrap' => true )
+		);
+		$sheet->mergeCells('B1:I1');
+		$sheet->getStyle('B1')->applyFromArray($style);
+		
+		$sheet->setCellValue('B2', "Tá»NG CÃNG TY VIá»N THÃNG VIETTEL");
+		$style = array(
+			'font' => array('size' => 12, 'name' =>'Cambria', 'color' => array('rgb' => '0070bf')),
+			'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
+								'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
+								'wrap' => true )
+		);
+		$sheet->mergeCells('B2:I2');
+		$sheet->getStyle('B2')->applyFromArray($style);
+		
+		
+		$sheet->setCellValue('A4', "DANH SÃCH NGÆ¯á»I DÃNG");
+		$style = array(
+			'font' => array('bold' => true, 'size' => 14, 'name' =>'Cambria'),
+			'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
+								'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
+								'wrap' => true )
+		);
+		$sheet->mergeCells('A4:I4');
+		$sheet->getStyle('A4')->applyFromArray($style);
+		
+		$sheet->setCellValue('A6', 'STT');
+		$style = array(
+			'font' => array('bold' => true, 'size' => 11, 'name' =>'Cambria'),
+			'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
+								'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
+								'wrap' => true),
+			'borders' =>	array(
+				'allborders' => array(
+					'style' => \PHPExcel_Style_Border::BORDER_THIN
+					)
+			)
+		);
+		$sheet->getStyle('A6')->applyFromArray($style);
+		$style = array(
+			'font' => array('bold' => true, 'size' => 11, 'name' =>'Cambria'),
+			'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
+								'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
+								'wrap' => true),
+			'borders' =>	array(
+				'allborders' => array(
+					'style' => \PHPExcel_Style_Border::BORDER_THIN
+					)
+			)
+		);
+		
+		$sheet->setCellValue('B6', 'Sá» Äiá»n thoáº¡i');
+		$sheet->setCellValue('C6', "Há» tÃªn)");
+		$sheet->setCellValue('D6', "TÃ i khoáº£n SBG");
+		$sheet->setCellValue('E6', "NgÃ y ÄÄng kÃœ");
+		$sheet->setCellValue('F6', "NgÃ y háº¿t háº¡n");
+		$sheet->setCellValue('G6', "Tá»nh/ThÃ nh phá»");
+		$sheet->setCellValue('H6', "Quáº­n/Huyá»n");
+		$sheet->setCellValue('I6', "TÃ¬nh tráº¡ng");
+		$sheet->getStyle('A6:I6')->applyFromArray($style);
+		
+		$styleSTT = array(
+			'font' => array('size' => 11, 'name' =>'Cambria'),
+			'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
+								'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER),
+			'borders' =>	array(
+				'allborders' => array(
+					'style' => \PHPExcel_Style_Border::BORDER_THIN
+					)
+			)
+		);
+		$style = array(
+			'font' => array('size' => 11, 'name' =>'Cambria'),
+			'alignment' => array('vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER),
+			'borders' =>	array(
+				'allborders' => array(
+					'style' => \PHPExcel_Style_Border::BORDER_THIN
+					)
+			)
+		);
+		$dem = 0;
+		foreach ($users as $index => $user):
+			$sheet->setCellValue('A' . ($dem + 7), $index + 1);
+			$sheet->setCellValueExplicit('B' . ($dem + 7), $user['username'], PHPExcel_Cell_DataType::TYPE_STRING);
+            $sheet->setCellValue('C' . ($dem + 7), $user['fullname']);
+            $sheet->setCellValue('D' . ($dem + 7), $user['acc_balanced']);
+            $sheet->setCellValue('E' . ($dem + 7), date('d/m/Y', strtotime($user['created_time'])));
+            $sheet->setCellValue('F' . ($dem + 7), isset($user['expire_date']) && strtotime($user['expire_date']) > 0 ? date('d/m/Y', strtotime($user['expire_date'])) : '');
+            $sheet->setCellValue('G' . ($dem + 7), $user['province']);
+            $sheet->setCellValue('H' . ($dem + 7), $user['district_name']);
+			$sheet->setCellValue('I' . ($dem + 7), $user['status']);
+			$sheet->getStyle('A' . ($dem + 7))->applyFromArray($styleSTT);
+			$sheet->getStyle('B' . ($dem + 7).':I'.($dem + 7))->applyFromArray($style);
+			
+			
+			$dem++;
+		endforeach;
+		
+		$writer = new PHPExcel_Writer_Excel5($this->phpexcel);
+		header('Content-Type: application/vnd.ms-excel');
+        header('Content-Disposition: attachment; filename="danhsachnguoidung_trang_'.$data['current_page'].'.xls"');
+        $writer->save('php://output');
+		
+	}
+	
 }
