1 | <?php
|
---|
2 |
|
---|
3 | if (!defined('BASEPATH'))
|
---|
4 | exit('No direct script access allowed');
|
---|
5 |
|
---|
6 | class User extends MX_Controller {
|
---|
7 |
|
---|
8 | const TOKENPW = 'violet';
|
---|
9 |
|
---|
10 | public function __construct() {
|
---|
11 | parent::__construct();
|
---|
12 | $this->load->helper('cookie');
|
---|
13 | $this->load->helper('language');
|
---|
14 | $this->lang->load('messages', 'message');
|
---|
15 | }
|
---|
16 |
|
---|
17 | public function profile() {
|
---|
18 | $user_info = $this->session->userdata('userInfo');
|
---|
19 | if ($user_info) {
|
---|
20 | $this->load->model('User_model');
|
---|
21 | $this->load->model('Servicepackage_model');
|
---|
22 | $user = $user_info['user'];
|
---|
23 | $us_id = $user_info['us_id'];
|
---|
24 | $src = "SBG";
|
---|
25 | $token = md5($us_id . self::TOKENPW);
|
---|
26 | $data = $this->get_data($src, $token, $us_id);
|
---|
27 | $data['can_edit'] = 0;
|
---|
28 | $u = $this->User_model->get_user_by_id($us_id);
|
---|
29 | if ($u['p_id'] < 1) {
|
---|
30 | $data['can_edit'] = 1;
|
---|
31 | }
|
---|
32 | if ($data['fullname']=="")
|
---|
33 | {
|
---|
34 | $data['can_edit'] = 1;
|
---|
35 | }
|
---|
36 | $data['current_tab'] = $this->uri->segment(4, 'edit-basic');
|
---|
37 | $data['packages'] = $this->Servicepackage_model->getAllPackages();
|
---|
38 | $data['is_viettel'] = isset($user_info['is_viettel']) ? $user_info['is_viettel']:FALSE;
|
---|
39 | $data['provinces'] = lang('_PROVINCES_');
|
---|
40 |
|
---|
41 | $data = (is_array($u)) ? array_merge($data, $u) : $data;
|
---|
42 | $data = (is_array($user_info)) ? array_merge($data, $user_info):$data;
|
---|
43 |
|
---|
44 | $this->load->view('frontend/user_profile', $data);
|
---|
45 | } else {
|
---|
46 | redirect('frontend/home');
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | public function packageRegister() {
|
---|
51 | $result = array();
|
---|
52 | $input = $this->input->post();
|
---|
53 | $this->load->model('user_model');
|
---|
54 | $user_info = $this->session->userdata('userInfo');
|
---|
55 | if ($user_info) {
|
---|
56 | parse_str($user_info['user'], $info);
|
---|
57 | $this->load->model('servicepackage_model');
|
---|
58 |
|
---|
59 | $package = $this->servicepackage_model->getPackage($input['p_id']);
|
---|
60 | $user = $user_info['user'];
|
---|
61 | $us_id = $user_info['us_id'];
|
---|
62 | $user = $this->user_model->get_user_by_id($us_id);
|
---|
63 | $result['can_buy'] = 1;
|
---|
64 | $result['can_edit'] = 0;
|
---|
65 | if ($user['acc_balanced'] < $package['p_price']) {
|
---|
66 | $result['can_buy'] = 0;
|
---|
67 | }
|
---|
68 |
|
---|
69 | if(strtotime($user['expire_date'])<strtotime(date('Y-m-d'))){
|
---|
70 | $result['can_edit'] = 1;
|
---|
71 | }
|
---|
72 | if ($user['p_id'] < 1) {
|
---|
73 | $result['can_edit'] = 1;
|
---|
74 | }
|
---|
75 | if ($info['fullname']=="")
|
---|
76 | {
|
---|
77 | $result['can_edit'] = 1;
|
---|
78 | }
|
---|
79 | $result['info'] = $info;
|
---|
80 | $result['user'] = $user;
|
---|
81 | $result['package'] = $package;
|
---|
82 | $result['modal'] = $this->load->view('frontend/package_register_modal', $result, true);
|
---|
83 | } else {
|
---|
84 |
|
---|
85 | }
|
---|
86 | echo json_encode($result);
|
---|
87 | }
|
---|
88 |
|
---|
89 | public function finishRegisterPackage() {
|
---|
90 | $result = array();
|
---|
91 | $result['success'] = 0;
|
---|
92 | $this->load->model('user_model');
|
---|
93 | $input = $this->input->post();
|
---|
94 | //print_r($input);
|
---|
95 | $user_info = $this->session->userdata('userInfo');
|
---|
96 | parse_str($user_info['user'], $info);
|
---|
97 | if (isset($input['fullname'])) {
|
---|
98 | if (strlen($input['fullname']) < 1) {
|
---|
99 | $result['errors'][] = lang('_SBG_REGISTER_VIP_FULLNAME_REQUIRED_MSG');
|
---|
100 | }
|
---|
101 | if (strlen($input['school']) < 1) {
|
---|
102 | $result['errors'][] = lang('_SBG_REGISTER_VIP_SCHOOL_REQUIRED_MSG');
|
---|
103 | }
|
---|
104 | if (!isset($result['errors'])) {
|
---|
105 | $user_info = $this->session->userdata('userInfo');
|
---|
106 | if ($user_info) {
|
---|
107 |
|
---|
108 | $src = "SBG";
|
---|
109 | $us_id = $user_info['us_id'];
|
---|
110 | $input['password'] = '';
|
---|
111 | $input['oldpass'] = '';
|
---|
112 | $input['gender'] = '';
|
---|
113 | $input['email'] = '';
|
---|
114 | //$input['province'] = '';
|
---|
115 | $info['fullname'] = $input['fullname'];
|
---|
116 | $info['school'] = $input['school'];
|
---|
117 | $token = md5($us_id . self::TOKENPW);
|
---|
118 | $user = $this->get_data($src, $token, $us_id);
|
---|
119 | //$input['district'] = '';
|
---|
120 | if ($input) {
|
---|
121 | $this->load->model('user_model');
|
---|
122 | $update = $this->user_model->update_user($src, $token, $input, $us_id);
|
---|
123 | $info = urldecode(http_build_query($info));
|
---|
124 | $userdata = array('username' => $user_info['username'], 'user' => $info, 'us_id' => $user_info['us_id'], 'logined_in' => TRUE, 'is_viettel' => $user_info['is_viettel']);
|
---|
125 | $this->session->set_userdata('userInfo', $userdata);
|
---|
126 | }
|
---|
127 | }
|
---|
128 | }
|
---|
129 | }
|
---|
130 |
|
---|
131 | if (isset($result['errors'])) {
|
---|
132 | echo json_encode($result);
|
---|
133 | exit();
|
---|
134 | }
|
---|
135 |
|
---|
136 | $this->load->model('servicepackage_model');
|
---|
137 | $us_id = $user_info['us_id'];
|
---|
138 | //$user = $this->user_model->get_user_by_id($us_id);
|
---|
139 | $user = $this->user_model->getUserById($us_id);
|
---|
140 | $package = $this->servicepackage_model->getPackage($input['p_id']);
|
---|
141 | $user['acc_balanced'] = $user['acc_balanced'] - $package['p_price'];
|
---|
142 |
|
---|
143 | $currentExpireDate = $user['expire_date'] == NULL || trim($user['expire_date']) == '' ? date('Y-m-d 00:00:00') : $user['expire_date'];
|
---|
144 | $user['expire_date'] = date('Y-m-d', strtotime("+" . $package['p_period'] . " ".$package['p_unit'], strtotime($currentExpireDate)));
|
---|
145 | $user['p_id'] = $package['p_id'];
|
---|
146 | //$user['district'] = $input['district'];
|
---|
147 | $user['province'] = $input['province'];
|
---|
148 | $this->user_model->updateUser($us_id, $user);
|
---|
149 | $user['expire_date'] = date("d-m-Y", (strtotime($user['expire_date'])));
|
---|
150 | $result['expire_date'] = $user['expire_date'];
|
---|
151 | $result['success'] = 1;
|
---|
152 | $message = str_replace(':period:', date("d/m/Y", (strtotime($user['expire_date']))), lang('_SBG_REGISTER_VIP_SUCCESS_MSG'));
|
---|
153 | $result['message'] = $message;
|
---|
154 |
|
---|
155 | $toDate = date("Y-m-d", (strtotime($result['expire_date'])));
|
---|
156 | $this->user_model->insertRegisterVipLog($user['cellphone'],$package['p_code'], false);
|
---|
157 | echo json_encode($result);
|
---|
158 | }
|
---|
159 |
|
---|
160 | public function regpackage() {
|
---|
161 | $user_info = $this->session->userdata('userInfo');
|
---|
162 | parse_str($user_info['user'], $info);
|
---|
163 | $p_id = $this->input->post('p_id', TRUE);
|
---|
164 |
|
---|
165 | $us_id = (int) $info['id'];
|
---|
166 | $this->load->model('servicepackage_model');
|
---|
167 | $this->load->model('user_model');
|
---|
168 |
|
---|
169 | $user = $this->user_model->get_user_by_id($us_id);
|
---|
170 | $package = $this->servicepackage_model->getPackage($p_id);
|
---|
171 |
|
---|
172 | if ($user['acc_balanced'] < $package['p_price']) {
|
---|
173 | $aryPatterns = array('/:acc_balanced:/');
|
---|
174 | $message = preg_replace($aryPatterns, array(number_format($user['acc_balanced'], 0)), lang('_SBG_ACC_BALANCE_LESS_PACKAGE_PRICE_MSG'));
|
---|
175 | } else {
|
---|
176 | $user['acc_balanced'] = $user['acc_balanced'] - $package['p_price'];
|
---|
177 | $currentExpireDate = $user['expire_date'] == NULL || trim($user['expire_date']) == '' ? date('Y-m-d 00:00:00') : $user['expire_date'];
|
---|
178 |
|
---|
179 | $user['expire_date'] = date('Y-m-d', strtotime("+" . $package['p_period'] . " " . $package['p_unit'], strtotime($currentExpireDate)));
|
---|
180 | //$user['expire_date'] = date("Y-m-d", (strtotime($user['expire_date']) - 1));
|
---|
181 |
|
---|
182 | $user['p_id'] = $package['p_id'];
|
---|
183 |
|
---|
184 | $this->user_model->updateUser($us_id, $user);
|
---|
185 | $aryPatterns = array('/:period:/');
|
---|
186 | $message = preg_replace($aryPatterns, array(date('d-m-Y', strtotime($user['expire_date']))), lang('_SBG_REGISTER_VIP_SUCCESS_MS'));
|
---|
187 | $this->user_model->insertRegisterVipLog($user['cellphone'], $package['p_code'], false);
|
---|
188 | }
|
---|
189 |
|
---|
190 | $this->session->set_flashdata('message', $message);
|
---|
191 | redirect('frontend/user/profile#services-register');
|
---|
192 | }
|
---|
193 |
|
---|
194 | private function get_data($src, $token, $us_id) {
|
---|
195 | $this->load->model('user_model');
|
---|
196 | $user = $this->user_model->get_user_info($src, $token, $us_id);
|
---|
197 |
|
---|
198 | if (strpos($user, '&')) {
|
---|
199 | parse_str($user);
|
---|
200 | $us = $this->user_model->get_user_by_id($us_id);
|
---|
201 | $data = array('us_id' => $us_id, 'username' => $username, 'fullname' => $fullname,
|
---|
202 | 'gender' => $gender, 'email' => $email, 'phone' => $phone, 'school' => $school, 'province' => $province,
|
---|
203 | 'acc_balanced' => $us['acc_balanced'], 'expire_date' => $us['expire_date'], 'date_diff' => $this->dateDiff($us['expire_date'])
|
---|
204 | );
|
---|
205 | return $data;
|
---|
206 | } else {
|
---|
207 | return "";
|
---|
208 | }
|
---|
209 | }
|
---|
210 |
|
---|
211 | private function dateDiff($expire_date) {
|
---|
212 | $date1 = date("Y-m-d");
|
---|
213 | if ((strtotime($expire_date) - strtotime($date1)) < 0)
|
---|
214 | return "0 ngà y còn lại";
|
---|
215 | $diff = strtotime($expire_date) - strtotime($date1);
|
---|
216 | $years = floor($diff / (365 * 60 * 60 * 24));
|
---|
217 | $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
|
---|
218 | $days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24));
|
---|
219 | if ($years > 0) {
|
---|
220 | return $years . " nÄm, " . $months . " tháng, " . $days . " ngà y còn lại";
|
---|
221 | } else {
|
---|
222 | if ($months > 0) {
|
---|
223 | return $months . " tháng, " . $days . " ngà y còn lại";
|
---|
224 | } else {
|
---|
225 | return $days . " ngà y còn lại";
|
---|
226 | }
|
---|
227 | }
|
---|
228 | }
|
---|
229 |
|
---|
230 | public function update_info() {
|
---|
231 | $result['success'] = 0;
|
---|
232 | $user_info = $this->session->userdata('userInfo');
|
---|
233 | if ($user_info) {
|
---|
234 | $us_id = $user_info['us_id'];
|
---|
235 | $result = array();
|
---|
236 | $result['success'] = 0;
|
---|
237 | $src = "SBG";
|
---|
238 | $token = md5($us_id . self::TOKENPW);
|
---|
239 | $user = $this->get_data($src, $token, $us_id);
|
---|
240 | $input = $this->input->post();
|
---|
241 | parse_str($user_info['user'], $info);
|
---|
242 | if ($input) {
|
---|
243 | if (strlen($input['fullname']) == 0) {
|
---|
244 | $result['errors'][] = array("content"=>lang('_SBG_FULLNAME_REQUIRED_MSG'),"field"=>"fullname");
|
---|
245 | }
|
---|
246 | if (strlen($input['school']) == 0) {
|
---|
247 | $result['errors'][] = array("content"=>lang('_SBG_REGISTER_VIP_SCHOOL_REQUIRED_MSG'),"field"=>"school");
|
---|
248 | }
|
---|
249 |
|
---|
250 | $input['password'] = '';
|
---|
251 | $input['oldpass'] = '';
|
---|
252 | $input['province'] = '';
|
---|
253 | $this->load->model('user_model');
|
---|
254 | if (!isset($result['errors'])) {
|
---|
255 | $result['data'] = $this->user_model->update_user($src, $token, $input, $us_id);
|
---|
256 | $result['success'] = 1;
|
---|
257 | $info['fullname'] = $input['fullname'];
|
---|
258 | $info['school'] = $input['school'];
|
---|
259 | $info = urldecode(http_build_query($info));
|
---|
260 | $userdata = array('username' => $user_info['username'], 'user' => $info, 'us_id' => $user_info['us_id'], 'logined_in' => TRUE, 'is_viettel' => $user_info['is_viettel']);
|
---|
261 | $this->session->set_userdata('userInfo', $userdata);
|
---|
262 | }
|
---|
263 | echo json_encode($result);
|
---|
264 | }
|
---|
265 | } else {
|
---|
266 | redirect('frontend/home');
|
---|
267 | }
|
---|
268 | }
|
---|
269 |
|
---|
270 | public function update_user() {
|
---|
271 | $us_id = $this->uri->segment(4);
|
---|
272 | $user_info = $this->session->userdata('userInfo');
|
---|
273 | if ($user_info) {
|
---|
274 | $result = array();
|
---|
275 | $result['success'] = 0;
|
---|
276 | $src = "SBG";
|
---|
277 | $token = md5($us_id . self::TOKENPW);
|
---|
278 | $user = $this->get_data($src, $token, $us_id);
|
---|
279 | $input = $this->input->post();
|
---|
280 | if ($input) {
|
---|
281 | $input['username'] = $user['username'];
|
---|
282 | if (array_key_exists('fullname', $input)) {
|
---|
283 | if (strlen($input['fullname']) == 0) {
|
---|
284 | $result['errors']['fullname_err'] = lang('_SBG_FULLNAME_REQUIRED_MSG');
|
---|
285 | }
|
---|
286 | } else {
|
---|
287 | $input['fullname'] = $user['fullname'];
|
---|
288 | }
|
---|
289 |
|
---|
290 | $input['password'] = '';
|
---|
291 | $input['oldpass'] = '';
|
---|
292 | $this->load->model('user_model');
|
---|
293 | if (!isset($result['errors'])) {
|
---|
294 | $result['data'] = $this->user_model->update_user($src, $token, $input, $us_id);
|
---|
295 | $result['success'] = 1;
|
---|
296 | }
|
---|
297 | echo json_encode($result);
|
---|
298 | }
|
---|
299 | } else {
|
---|
300 | redirect('frontend/home');
|
---|
301 | }
|
---|
302 | }
|
---|
303 |
|
---|
304 | public function change_password() {
|
---|
305 | $us_id = $this->uri->segment(4);
|
---|
306 | $user_info = $this->session->userdata('userInfo');
|
---|
307 | if ($user_info) {
|
---|
308 | $this->load->model('user_model');
|
---|
309 | $us_id = $user_info['us_id'];
|
---|
310 | $src = "SBG";
|
---|
311 | $token = md5($us_id . self::TOKENPW);
|
---|
312 | $input = $this->input->post();
|
---|
313 |
|
---|
314 | if (strlen($input['passwd']) == 0) {
|
---|
315 | $result['errors']['passwd_old_err'] = lang('_SBG_PASSWORD_REQUIRED_MSG');
|
---|
316 | }
|
---|
317 |
|
---|
318 | if (strlen($input['passwd_new']) == 0) {
|
---|
319 | $result['errors']['passwd_new_err'] = lang('_SBG_PASSWORD_REQUIRED_MSG');
|
---|
320 | } else if (strcmp($input['passwd'], $input['passwd_new']) == 0) {
|
---|
321 | $result['errors']['passwd_new_err'] = lang('_SBG_PASSWORD_DUPLICATE_MSG');
|
---|
322 | }else
|
---|
323 | {
|
---|
324 | if (!preg_match('/^([0-9a-zA-Z]{6,65})*$/', $input['passwd_new']))
|
---|
325 | {
|
---|
326 | $result['errors']['passwd_new_err'] = lang('_SBG_USER_PASSWORD_CHANGE_REQUIRED_MSG');
|
---|
327 | }
|
---|
328 | }
|
---|
329 |
|
---|
330 | if ($input['passwd_new'] != $input['confirm_passwd_new']) {
|
---|
331 | $result['errors']['confirm_passwd_new_err'] = lang('_SBG_PASSWORD_CONFIRM_MSG');
|
---|
332 | }
|
---|
333 |
|
---|
334 | if (!isset($result['errors'])) {
|
---|
335 | $user = array('username' => $user_info['username'], 'fullname' => null, 'gender' => null, 'email' => null, 'school' => null, 'province' => null, 'password' => $input['passwd_new'], 'oldpass' => $input['passwd']);
|
---|
336 | $data = $this->user_model->update_user($src, $token, $user, $us_id);
|
---|
337 | parse_str($data);
|
---|
338 | switch ($status) {
|
---|
339 | case 0:
|
---|
340 | $result['success'] = 1;
|
---|
341 | break;
|
---|
342 | case 6:
|
---|
343 | $result['errors']['passwd_old_err'] = lang('_SBG_OLD_PASSWORD_FAIL_MSG');
|
---|
344 | break;
|
---|
345 | default:
|
---|
346 | break;
|
---|
347 | }
|
---|
348 | }
|
---|
349 |
|
---|
350 | echo json_encode($result);
|
---|
351 | } else {
|
---|
352 | redirect('frontend/home');
|
---|
353 | }
|
---|
354 | }
|
---|
355 |
|
---|
356 | public function trade_history()
|
---|
357 | {
|
---|
358 | $this->load->helper('pagging');
|
---|
359 | $us_id = $this->uri->segment(4);
|
---|
360 |
|
---|
361 | $user_info = $this->session->userdata('userInfo');
|
---|
362 | $admin_info = $this->session->userdata('adminInfo');
|
---|
363 |
|
---|
364 | if ($user_info || $admin_info)
|
---|
365 | {
|
---|
366 | $data['us_id'] = $us_id;
|
---|
367 | $data['perpage'] = 10;
|
---|
368 | $data['current_page'] = $this->uri->segment(6, 1);
|
---|
369 | $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
|
---|
370 | $this->load->model('user_model');
|
---|
371 | $result = $this->user_model->getPaidlog($data);
|
---|
372 | $data['total'] = $this->user_model->countPaiglogs($us_id);
|
---|
373 | $data['num_links'] = 2;
|
---|
374 | $data['paging_url'] = base_url() . "frontend/user/trade_history/".$us_id."/page/";
|
---|
375 | $data['paging'] = pagging($data);
|
---|
376 | $paidlogs = array();
|
---|
377 | foreach ($result as $paidlog):
|
---|
378 | $paidlog['amount'] = number_format($paidlog['amount'], 0);
|
---|
379 | $paidlog['paid_time'] = date('d/m/Y H:i:s', strtotime($paidlog['paid_time']));
|
---|
380 | array_push($paidlogs, $paidlog);
|
---|
381 | endforeach;
|
---|
382 | $data['paidlogs'] = $paidlogs;
|
---|
383 | echo json_encode($data);
|
---|
384 | }else {
|
---|
385 | redirect('frontend/home');
|
---|
386 | }
|
---|
387 | }
|
---|
388 |
|
---|
389 | public function regis_history()
|
---|
390 | {
|
---|
391 | $this->load->helper('pagging');
|
---|
392 | $us_id = $this->uri->segment(4);
|
---|
393 | $this->load->model('user_model');
|
---|
394 | $user = $this->user_model->get_user_by_id($us_id);
|
---|
395 | $username = $user['cellphone'];
|
---|
396 | $user_info = $this->session->userdata('userInfo');
|
---|
397 | $admin_info = $this->session->userdata('adminInfo');
|
---|
398 | if ($user_info || $admin_info)
|
---|
399 | {
|
---|
400 | $data['username'] = $username;
|
---|
401 | $data['perpage'] = 10;
|
---|
402 | $data['current_page'] = $this->uri->segment(6, 1);
|
---|
403 | $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
|
---|
404 | $this->load->model('user_model');
|
---|
405 | $result = $this->user_model->getPackagelog($data);
|
---|
406 | $data['total'] = $this->user_model->countPackagelogs($username);
|
---|
407 | $data['num_links'] = 2;
|
---|
408 | $data['paging_url'] = base_url() . "frontend/user/regis_history/".$us_id."/page/";
|
---|
409 | $data['paging'] = pagging($data);
|
---|
410 | $packagelogs = array();
|
---|
411 | foreach ($result as $packagelog):
|
---|
412 | $packagelog['created_time'] = date('d/m/Y H:i:s', strtotime($packagelog['created_time']));
|
---|
413 | array_push($packagelogs, $packagelog);
|
---|
414 | endforeach;
|
---|
415 | $data['packagelogs'] = $packagelogs;
|
---|
416 | echo json_encode($data);
|
---|
417 | }else
|
---|
418 | {
|
---|
419 | redirect('frontend/home');
|
---|
420 | }
|
---|
421 |
|
---|
422 | }
|
---|
423 |
|
---|
424 | }
|
---|