1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
2 |
|
---|
3 | class User extends MX_Controller
|
---|
4 | {
|
---|
5 |
|
---|
6 | const TOKENPW = 'violet';
|
---|
7 |
|
---|
8 | public function __construct()
|
---|
9 | {
|
---|
10 | parent::__construct();
|
---|
11 | $this->load->helper('cookie');
|
---|
12 | }
|
---|
13 |
|
---|
14 | public function profile()
|
---|
15 | {
|
---|
16 | $user_info = $this->session->userdata('userInfo');
|
---|
17 | if ($user_info)
|
---|
18 | {
|
---|
19 | $this->load->model('servicepackage_model');
|
---|
20 | $user = $user_info['user'];
|
---|
21 | $us_id = $user_info['us_id'];
|
---|
22 | $src = "SBG";
|
---|
23 | $token = md5($us_id.self::TOKENPW);
|
---|
24 | $data = $this->get_data($src, $token, $us_id);
|
---|
25 | $data['packages'] =$this->servicepackage_model->getAllPackages();
|
---|
26 | $this->load->view('frontend/user_profile', $data);
|
---|
27 |
|
---|
28 | }else
|
---|
29 | {
|
---|
30 | redirect('frontend/home');
|
---|
31 | }
|
---|
32 | }
|
---|
33 | public function packageRegister()
|
---|
34 | {
|
---|
35 | $result=array();
|
---|
36 | $input=$this->input->post();
|
---|
37 | $user_info = $this->session->userdata('userInfo');
|
---|
38 | if ($user_info)
|
---|
39 | {
|
---|
40 | $this->load->model('servicepackage_model');
|
---|
41 | $this->load->model('user_model');
|
---|
42 | $package=$this->servicepackage_model->getPackage($input['p_id']);
|
---|
43 | $user = $user_info['user'];
|
---|
44 | $us_id = $user_info['us_id'];
|
---|
45 | $user = $this->user_model->get_user_by_id($us_id);
|
---|
46 | $result['user']=$user;
|
---|
47 | $result['package']=$package;
|
---|
48 | $result['modal']=$this->load->view('frontend/package_register_modal', $result,true);
|
---|
49 | }else
|
---|
50 | {
|
---|
51 |
|
---|
52 | }
|
---|
53 | echo json_encode($result);
|
---|
54 | }
|
---|
55 | private function get_data($src, $token, $us_id)
|
---|
56 | {
|
---|
57 | $this->load->model('user_model');
|
---|
58 | $user = $this->user_model->get_user_info($src, $token, $us_id);
|
---|
59 |
|
---|
60 | if (strpos($user, '&')){
|
---|
61 | parse_str($user);
|
---|
62 | $us = $this->user_model->get_user_by_id($us_id);
|
---|
63 | $data = array('us_id'=>$us_id, 'username'=>$username, 'fullname'=>$fullname,
|
---|
64 | 'gender'=>$gender, 'email'=>$email, 'phone'=>$phone, 'school'=>$school, 'province'=>$province,
|
---|
65 | 'acc_balanced'=>$us['acc_balanced'], 'expire_date'=>$us['expire_date'], 'date_diff'=>$this->dateDiff($us['expire_date'])
|
---|
66 | );
|
---|
67 | return $data;
|
---|
68 | }else
|
---|
69 | {
|
---|
70 | return "";
|
---|
71 | }
|
---|
72 | }
|
---|
73 |
|
---|
74 | private function dateDiff($expire_date)
|
---|
75 | {
|
---|
76 | $date1 = date("Y-m-d");
|
---|
77 | if ((strtotime($expire_date) - strtotime($date1))<0) return "0 ngà y còn lại";
|
---|
78 | $diff = strtotime($expire_date) - strtotime($date1);
|
---|
79 | $years = floor($diff / (365*60*60*24));
|
---|
80 | $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
|
---|
81 | $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
|
---|
82 | if ($years>0){
|
---|
83 | return $years." nÄm, ".$months." tháng, ".$days." ngà y còn lại";
|
---|
84 | }
|
---|
85 | else{
|
---|
86 | if ($months>0)
|
---|
87 | {
|
---|
88 | return $months." tháng, ".$days." ngà y còn lại";
|
---|
89 | }
|
---|
90 | else
|
---|
91 | {
|
---|
92 | return $days." ngà y còn lại";
|
---|
93 | }
|
---|
94 | }
|
---|
95 |
|
---|
96 | }
|
---|
97 |
|
---|
98 | public function update_user()
|
---|
99 | {
|
---|
100 | $this->load->helper('email');
|
---|
101 | $us_id=$this->uri->segment(4);
|
---|
102 | $user_info = $this->session->userdata('userInfo');
|
---|
103 | if ($user_info)
|
---|
104 | {
|
---|
105 | $result = array();
|
---|
106 | $result['success'] = 0;
|
---|
107 | $src = "SBG";
|
---|
108 | $token = md5($us_id.self::TOKENPW);
|
---|
109 | $user = $this->get_data($src, $token, $us_id);
|
---|
110 | $input = $this->input->post();
|
---|
111 | if ($input){
|
---|
112 | $input['username'] = $user['username'];
|
---|
113 | $input['fullname'] = $user['fullname'];
|
---|
114 | $input['password'] = '';
|
---|
115 | $input['oldpass'] = '';
|
---|
116 | $this->load->model('user_model');
|
---|
117 | $result['fullname'] = $input['fullname'];
|
---|
118 | if (strlen($input['email'])>0){
|
---|
119 | if(!valid_email($input['email']))
|
---|
120 | {
|
---|
121 | $result['errors']['email_err'] = "Email khÃŽng Äúng Äá»nh dạng";
|
---|
122 | }
|
---|
123 | }
|
---|
124 | if (!isset($result['errors'])){
|
---|
125 | $result['data'] = $this->user_model->update_user($src, $token, $input, $us_id);
|
---|
126 | $result['success'] = 1;
|
---|
127 | }
|
---|
128 | echo json_encode($result);
|
---|
129 | }
|
---|
130 |
|
---|
131 | }else
|
---|
132 | {
|
---|
133 | redirect('frontend/home');
|
---|
134 | }
|
---|
135 | }
|
---|
136 |
|
---|
137 | public function change_password()
|
---|
138 | {
|
---|
139 | $us_id=$this->uri->segment(4);
|
---|
140 | $user_info = $this->session->userdata('userInfo');
|
---|
141 | if ($user_info)
|
---|
142 | {
|
---|
143 | $this->load->model('user_model');
|
---|
144 | $us_id = $user_info['us_id'];
|
---|
145 | $src = "SBG";
|
---|
146 | $token = md5($us_id.self::TOKENPW);
|
---|
147 | if (strlen($input['passwd']) == 0)
|
---|
148 | {
|
---|
149 | $result['errors']['passwd_old_err'] = "Máºt khẩu khÃŽng ÄÆ°á»£c Äá» trá»ng !";
|
---|
150 | }
|
---|
151 | if (strlen($input['passwd_new']) == 0)
|
---|
152 | {
|
---|
153 | $result['errors']['passwd_new_err'] = "Máºt khẩu khÃŽng ÄÆ°á»£c Äá» trá»ng !";
|
---|
154 | }else if($input['passwd'] == $input['passwd_new'])
|
---|
155 | {
|
---|
156 | $result['errors']['passwd_new_err'] = "Máºt khẩu trùng vá»i máºt khẩu hiá»n tại !";
|
---|
157 | }
|
---|
158 | if ($input['passwd_new'] != $input['confirm_passwd_new'])
|
---|
159 | {
|
---|
160 | $result['errors']['confirm_passwd_new_err'] = "Máºt khẩu khÃŽng trùng nhau !";
|
---|
161 | }
|
---|
162 | if (!isset($result['errors']))
|
---|
163 | {
|
---|
164 | $user = array('username'=>$username, 'fullname'=>null, );
|
---|
165 | $data = $this->user_model->update_user($src, $token, $user, $us_id);
|
---|
166 | parse_str($data);
|
---|
167 | switch($status)
|
---|
168 | {
|
---|
169 | case 0:
|
---|
170 | $result['success'] = 1;
|
---|
171 | break;
|
---|
172 | case 6:
|
---|
173 | $result['errors']['passwd_old_err'] = "Máºt khẩu cung cấp khÃŽng Äúng !";
|
---|
174 | break;
|
---|
175 | default:
|
---|
176 | break;
|
---|
177 | }
|
---|
178 | }
|
---|
179 |
|
---|
180 | echo json_encode($result);
|
---|
181 | }else
|
---|
182 | {
|
---|
183 | redirect('frontend/home');
|
---|
184 | }
|
---|
185 | }
|
---|
186 | } |
---|