1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
2 |
|
---|
3 | class User extends MX_Controller
|
---|
4 | {
|
---|
5 | public function __construct()
|
---|
6 | {
|
---|
7 | parent::__construct();
|
---|
8 | $this->load->helper('cookie');
|
---|
9 | }
|
---|
10 |
|
---|
11 | public function profile()
|
---|
12 | {
|
---|
13 | $user_info = $this->session->userdata('userInfo');
|
---|
14 | if ($user_info)
|
---|
15 | {
|
---|
16 | $user = $user_info['user'];
|
---|
17 | $data = $this->get_data($user);
|
---|
18 | $this->load->view('/frontend/user_profile', $data);
|
---|
19 |
|
---|
20 | }else
|
---|
21 | {
|
---|
22 | redirect('/frontend/home');
|
---|
23 | }
|
---|
24 | }
|
---|
25 |
|
---|
26 | private function get_data($user)
|
---|
27 | {
|
---|
28 | $this->load->model('user_model');
|
---|
29 | $arr_users = explode("&", $user);
|
---|
30 | $str_id = $arr_users[0];
|
---|
31 | $str_username = $arr_users[1];
|
---|
32 | $str_fullname = $arr_users[2];
|
---|
33 | $str_gender = $arr_users[3];
|
---|
34 | $str_email = $arr_users[4];
|
---|
35 | $str_phone = $arr_users[5];
|
---|
36 | $str_school = $arr_users[6];
|
---|
37 | $str_province = $arr_users[7];
|
---|
38 | $str_money = $arr_users[8];
|
---|
39 | $str_level = $arr_users[9];
|
---|
40 | $arr_id = explode("=", $str_id);
|
---|
41 | $arr_username = explode("=", $str_username);
|
---|
42 | $arr_fullname = explode("=", $str_fullname);
|
---|
43 | $arr_gender = explode("=", $str_gender);
|
---|
44 | $arr_email = explode("=", $str_email);
|
---|
45 | $arr_phone = explode("=", $str_phone);
|
---|
46 | $arr_school = explode("=", $str_school);
|
---|
47 | $arr_province = explode("=", $str_province);
|
---|
48 | $arr_money = explode("=", $str_money);
|
---|
49 | $arr_level = explode("=", $str_level);
|
---|
50 | $us = $this->user_model->get_user_by_id($arr_id[1]);
|
---|
51 | $data = array('us_id'=>$arr_id[1], 'username'=>$arr_username[1], 'full_name'=>$arr_fullname[1],
|
---|
52 | 'gender'=>$arr_gender[1], 'email'=>$arr_email[1], 'phone'=>$arr_phone[1], 'school'=>$arr_school[1],
|
---|
53 | 'acc_balanced'=>$us['acc_balanced'], 'expire_date'=>$us['expire_date'], 'date_diff'=>$this->dateDiff($us['expire_date'])
|
---|
54 | );
|
---|
55 | return $data;
|
---|
56 | }
|
---|
57 |
|
---|
58 | private function dateDiff($expire_date)
|
---|
59 | {
|
---|
60 | $date1 = date("Y-m-d");
|
---|
61 | $diff = abs(strtotime($expire_date) - strtotime($date1));
|
---|
62 | $years = floor($diff / (365*60*60*24));
|
---|
63 | $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
|
---|
64 | $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
|
---|
65 | if ($years>0){
|
---|
66 | return $years." nÄm, ".$months." tháng, ".$days." ngà y còn lại";
|
---|
67 | }
|
---|
68 | else{
|
---|
69 | if ($months>0)
|
---|
70 | {
|
---|
71 | return $months." tháng, ".$days." ngà y còn lại";
|
---|
72 | }
|
---|
73 | else
|
---|
74 | {
|
---|
75 | return $days." ngà y còn lại";
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | }
|
---|
80 | } |
---|