[521] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | if (!defined('BASEPATH'))
|
---|
| 4 | exit('No direct script access allowed');
|
---|
| 5 |
|
---|
[503] | 6 | class User extends MX_Controller {
|
---|
[466] | 7 |
|
---|
[521] | 8 | const TOKENPW = 'violet';
|
---|
[503] | 9 |
|
---|
[521] | 10 | public function __construct() {
|
---|
| 11 | parent::__construct();
|
---|
[554] | 12 | $this->load->helper('cookie');
|
---|
[521] | 13 | }
|
---|
| 14 |
|
---|
| 15 | public function profile() {
|
---|
| 16 | $user_info = $this->session->userdata('userInfo');
|
---|
[503] | 17 | if ($user_info) {
|
---|
[538] | 18 | $this->load->model('user_model');
|
---|
[503] | 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);
|
---|
[538] | 25 | $u = $this->user_model->get_user_by_id($us_id);
|
---|
[508] | 26 | $data['current_tab'] = $this->uri->segment(4, 'edit-basic');
|
---|
[503] | 27 | $data['packages'] = $this->servicepackage_model->getAllPackages();
|
---|
[554] | 28 | $data['is_viettel'] = $user_info['is_viettel'];
|
---|
[580] | 29 |
|
---|
[554] | 30 | $data = array_merge($data, $u);
|
---|
| 31 | $data = array_merge($data, $user_info);
|
---|
[559] | 32 |
|
---|
[503] | 33 | $this->load->view('frontend/user_profile', $data);
|
---|
[508] | 34 | } else {
|
---|
[503] | 35 | redirect('frontend/home');
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public function packageRegister() {
|
---|
| 40 | $result = array();
|
---|
| 41 | $input = $this->input->post();
|
---|
| 42 | $this->load->model('user_model');
|
---|
| 43 | $user_info = $this->session->userdata('userInfo');
|
---|
| 44 | if ($user_info) {
|
---|
| 45 | parse_str($user_info['user'], $info);
|
---|
| 46 | $this->load->model('servicepackage_model');
|
---|
[508] | 47 |
|
---|
[503] | 48 | $package = $this->servicepackage_model->getPackage($input['p_id']);
|
---|
| 49 | $user = $user_info['user'];
|
---|
| 50 | $us_id = $user_info['us_id'];
|
---|
| 51 | $user = $this->user_model->get_user_by_id($us_id);
|
---|
| 52 | $result['can_buy'] = 1;
|
---|
| 53 | $result['can_edit'] = 0;
|
---|
| 54 | if ($user['acc_balanced'] < $package['p_price']) {
|
---|
| 55 | $result['can_buy'] = 0;
|
---|
| 56 | }
|
---|
[580] | 57 |
|
---|
[503] | 58 | if ($user['p_id'] < 1) {
|
---|
| 59 | $result['can_edit'] = 1;
|
---|
| 60 | }
|
---|
[580] | 61 | if ($info['fullname']=="")
|
---|
| 62 | {
|
---|
| 63 | $result['can_edit'] = 1;
|
---|
| 64 | }
|
---|
[503] | 65 | $result['info'] = $info;
|
---|
| 66 | $result['user'] = $user;
|
---|
| 67 | $result['package'] = $package;
|
---|
| 68 | $result['modal'] = $this->load->view('frontend/package_register_modal', $result, true);
|
---|
| 69 | } else {
|
---|
| 70 |
|
---|
| 71 | }
|
---|
| 72 | echo json_encode($result);
|
---|
| 73 | }
|
---|
[554] | 74 |
|
---|
[503] | 75 | public function finishRegisterPackage() {
|
---|
| 76 | $result = array();
|
---|
| 77 | $result['success'] = 0;
|
---|
| 78 | $this->load->model('user_model');
|
---|
| 79 | $input = $this->input->post();
|
---|
| 80 | $user_info = $this->session->userdata('userInfo');
|
---|
[508] | 81 | parse_str($user_info['user'], $info);
|
---|
[503] | 82 | if (isset($input['fullname'])) {
|
---|
[548] | 83 | if (strlen($input['fullname']) < 1) {
|
---|
| 84 | $result['errors'][] = "Vui lòng nháºp há» tên Äầy Äá»§ tiếng Viá»t";
|
---|
[503] | 85 | }
|
---|
[548] | 86 | if (strlen($input['school']) < 1) {
|
---|
[554] | 87 | $result['errors'][] = "Vui lòng nháºp ÄÆ¡n vá» cÃŽng tác";
|
---|
[503] | 88 | }
|
---|
| 89 | if (!isset($result['errors'])) {
|
---|
[490] | 90 | $user_info = $this->session->userdata('userInfo');
|
---|
[503] | 91 | if ($user_info) {
|
---|
[508] | 92 |
|
---|
[503] | 93 | $src = "SBG";
|
---|
[508] | 94 | $us_id = $user_info['us_id'];
|
---|
[503] | 95 | $input['password'] = '';
|
---|
| 96 | $input['oldpass'] = '';
|
---|
| 97 | $input['gender'] = '';
|
---|
[508] | 98 | $input['email'] = '';
|
---|
[503] | 99 | $input['province'] = '';
|
---|
[508] | 100 | $info['fullname'] = $input['fullname'];
|
---|
| 101 | $info['school'] = $input['school'];
|
---|
[503] | 102 | $token = md5($us_id . self::TOKENPW);
|
---|
| 103 | $user = $this->get_data($src, $token, $us_id);
|
---|
| 104 | if ($input) {
|
---|
[490] | 105 | $this->load->model('user_model');
|
---|
[503] | 106 | $update = $this->user_model->update_user($src, $token, $input, $us_id);
|
---|
[508] | 107 | $info = urldecode(http_build_query($info));
|
---|
[554] | 108 | $userdata = array('username' => $user_info['username'], 'user' => $info, 'us_id' => $user_info['us_id'], 'logined_in' => TRUE, 'is_viettel' => $user_info['is_viettel']);
|
---|
[503] | 109 | $this->session->set_userdata('userInfo', $userdata);
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 | if (isset($result['errors'])) {
|
---|
[554] | 115 | echo json_encode($result);
|
---|
[503] | 116 | die();
|
---|
| 117 | }
|
---|
| 118 | $this->load->model('servicepackage_model');
|
---|
| 119 | $us_id = $user_info['us_id'];
|
---|
| 120 | $user = $this->user_model->get_user_by_id($us_id);
|
---|
| 121 | $package = $this->servicepackage_model->getPackage($input['p_id']);
|
---|
[508] | 122 | $user['acc_balanced'] = $user['acc_balanced'] - $package['p_price'];
|
---|
[556] | 123 |
|
---|
| 124 | $currentExpireDate = $user['expire_date'] == NULL || trim($user['expire_date']) == '' ? date('Y-m-d 00:00:00') : $user['expire_date'];
|
---|
| 125 | $user['expire_date'] = date('Y-m-d', strtotime("+" . $package['p_period'] . " ".$package['p_unit'], strtotime($currentExpireDate)));
|
---|
[508] | 126 | $user['p_id'] = $package['p_id'];
|
---|
| 127 | $this->user_model->updateUser($us_id, $user);
|
---|
| 128 | $user['expire_date'] = date("d-m-Y", (strtotime($user['expire_date'])));
|
---|
| 129 | $result['expire_date'] = $user['expire_date'];
|
---|
[503] | 130 | $result['success'] = 1;
|
---|
| 131 | echo json_encode($result);
|
---|
| 132 | }
|
---|
[554] | 133 |
|
---|
| 134 | public function regpackage() {
|
---|
| 135 | $user_info = $this->session->userdata('userInfo');
|
---|
| 136 | parse_str($user_info['user'], $info);
|
---|
| 137 | $p_id = $this->input->post('p_id', TRUE);
|
---|
| 138 |
|
---|
| 139 | $us_id = (int) $info['id'];
|
---|
| 140 | $this->load->model('servicepackage_model');
|
---|
| 141 | $this->load->model('user_model');
|
---|
| 142 |
|
---|
| 143 | $user = $this->user_model->get_user_by_id($us_id);
|
---|
| 144 | $package = $this->servicepackage_model->getPackage($p_id);
|
---|
| 145 |
|
---|
| 146 | if ($user['acc_balanced'] < $package['p_price']) {
|
---|
| 147 | $message = 'Sá» tiá»n trong Tà i khoản SBG Online hiá»n tại cá»§a Quà vá» là ' . $user['acc_balanced'] . ' Äá»ng.<br /> Äá» ÄÄng kà Sá» dụng dá»ch vụ Soạn Bà i giảng trá»±c tuyến, Quà vá» cần nạp thêm tiá»n và o tà i khoản.';
|
---|
| 148 | } else {
|
---|
| 149 | $user['acc_balanced'] = $user['acc_balanced'] - $package['p_price'];
|
---|
| 150 | $currentExpireDate = $user['expire_date'] == NULL || trim($user['expire_date']) == '' ? date('Y-m-d 00:00:00') : $user['expire_date'];
|
---|
| 151 |
|
---|
| 152 | $user['expire_date'] = date('Y-m-d', strtotime("+" . $package['p_period'] . " " . $package['p_unit'], strtotime($currentExpireDate)));
|
---|
| 153 | //$user['expire_date'] = date("Y-m-d", (strtotime($user['expire_date']) - 1));
|
---|
| 154 |
|
---|
| 155 | $user['p_id'] = $package['p_id'];
|
---|
| 156 |
|
---|
| 157 | $this->user_model->updateUser($us_id, $user);
|
---|
| 158 | $message = 'QuÜ vá» Äã ÄÄng kà sá» dụng CÃŽng cụ Soạn Bà i giảng trức tuyến. Quà vá» ÄÆ°á»£c sá» dụng dá»ch vụ Äến hết ngà y ' . date('d-m-Y', strtotime($user['expire_date']));
|
---|
| 159 | }
|
---|
| 160 |
|
---|
| 161 | $this->session->set_flashdata('message', $message);
|
---|
| 162 | redirect('frontend/user/profile#services-register');
|
---|
[521] | 163 | }
|
---|
[503] | 164 |
|
---|
| 165 | private function get_data($src, $token, $us_id) {
|
---|
| 166 | $this->load->model('user_model');
|
---|
| 167 | $user = $this->user_model->get_user_info($src, $token, $us_id);
|
---|
| 168 |
|
---|
| 169 | if (strpos($user, '&')) {
|
---|
| 170 | parse_str($user);
|
---|
| 171 | $us = $this->user_model->get_user_by_id($us_id);
|
---|
| 172 | $data = array('us_id' => $us_id, 'username' => $username, 'fullname' => $fullname,
|
---|
| 173 | 'gender' => $gender, 'email' => $email, 'phone' => $phone, 'school' => $school, 'province' => $province,
|
---|
| 174 | 'acc_balanced' => $us['acc_balanced'], 'expire_date' => $us['expire_date'], 'date_diff' => $this->dateDiff($us['expire_date'])
|
---|
| 175 | );
|
---|
| 176 | return $data;
|
---|
| 177 | } else {
|
---|
| 178 | return "";
|
---|
| 179 | }
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | private function dateDiff($expire_date) {
|
---|
| 183 | $date1 = date("Y-m-d");
|
---|
| 184 | if ((strtotime($expire_date) - strtotime($date1)) < 0)
|
---|
| 185 | return "0 ngà y còn lại";
|
---|
| 186 | $diff = strtotime($expire_date) - strtotime($date1);
|
---|
| 187 | $years = floor($diff / (365 * 60 * 60 * 24));
|
---|
| 188 | $months = floor(($diff - $years * 365 * 60 * 60 * 24) / (30 * 60 * 60 * 24));
|
---|
| 189 | $days = floor(($diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24) / (60 * 60 * 24));
|
---|
| 190 | if ($years > 0) {
|
---|
| 191 | return $years . " nÄm, " . $months . " tháng, " . $days . " ngà y còn lại";
|
---|
| 192 | } else {
|
---|
| 193 | if ($months > 0) {
|
---|
| 194 | return $months . " tháng, " . $days . " ngà y còn lại";
|
---|
| 195 | } else {
|
---|
| 196 | return $days . " ngà y còn lại";
|
---|
| 197 | }
|
---|
| 198 | }
|
---|
| 199 | }
|
---|
[604] | 200 |
|
---|
| 201 | public function update_info() {
|
---|
[580] | 202 | $result['success']=0;
|
---|
| 203 | $user_info = $this->session->userdata('userInfo');
|
---|
| 204 | if ($user_info) {
|
---|
| 205 | $us_id = $user_info['us_id'];
|
---|
| 206 | $result = array();
|
---|
| 207 | $result['success'] = 0;
|
---|
| 208 | $src = "SBG";
|
---|
| 209 | $token = md5($us_id . self::TOKENPW);
|
---|
| 210 | $user = $this->get_data($src, $token, $us_id);
|
---|
| 211 | $input = $this->input->post();
|
---|
| 212 | parse_str($user_info['user'], $info);
|
---|
| 213 | if ($input) {
|
---|
| 214 | if (strlen($input['fullname']) == 0) {
|
---|
| 215 | $result['errors'][] = array("content"=>"Há» tên khÃŽng ÄÆ°á»£c Äá» trá»ng!","field"=>"fullname");
|
---|
| 216 | }
|
---|
| 217 | if (strlen($input['school']) == 0) {
|
---|
| 218 | $result['errors'][] = array("content"=>"Tên ÄÆ¡n vá» khÃŽng ÄÆ°á»£c Äá» trá»ng!","field"=>"school");
|
---|
| 219 | }
|
---|
[508] | 220 |
|
---|
[580] | 221 | $input['password'] = '';
|
---|
| 222 | $input['oldpass'] = '';
|
---|
| 223 | $input['province'] = '';
|
---|
| 224 | $this->load->model('user_model');
|
---|
| 225 | if (!isset($result['errors'])) {
|
---|
| 226 | $result['data'] = $this->user_model->update_user($src, $token, $input, $us_id);
|
---|
| 227 | $result['success'] = 1;
|
---|
| 228 | $info['fullname']=$input['fullname'];
|
---|
| 229 | $info['school']=$input['school'];
|
---|
| 230 | $info = urldecode(http_build_query($info));
|
---|
| 231 | $userdata = array('username' => $user_info['username'], 'user' => $info, 'us_id' => $user_info['us_id'], 'logined_in' => TRUE, 'is_viettel' => $user_info['is_viettel']);
|
---|
| 232 | $this->session->set_userdata('userInfo', $userdata);
|
---|
| 233 | }
|
---|
| 234 | echo json_encode($result);
|
---|
| 235 | }
|
---|
| 236 | } else {
|
---|
| 237 | redirect('frontend/home');
|
---|
| 238 | }
|
---|
| 239 | }
|
---|
[604] | 240 |
|
---|
[503] | 241 | public function update_user() {
|
---|
| 242 | $us_id = $this->uri->segment(4);
|
---|
| 243 | $user_info = $this->session->userdata('userInfo');
|
---|
| 244 | if ($user_info) {
|
---|
| 245 | $result = array();
|
---|
| 246 | $result['success'] = 0;
|
---|
| 247 | $src = "SBG";
|
---|
| 248 | $token = md5($us_id . self::TOKENPW);
|
---|
| 249 | $user = $this->get_data($src, $token, $us_id);
|
---|
| 250 | $input = $this->input->post();
|
---|
| 251 | if ($input) {
|
---|
| 252 | $input['username'] = $user['username'];
|
---|
[508] | 253 | if (array_key_exists('fullname', $input)) {
|
---|
| 254 | if (strlen($input['fullname']) == 0) {
|
---|
[521] | 255 | $result['errors']['fullname_err'] = "Há» tên khÃŽng ÄÆ°á»£c Äá» trá»ng!";
|
---|
[508] | 256 | }
|
---|
| 257 | } else {
|
---|
| 258 | $input['fullname'] = $user['fullname'];
|
---|
| 259 | }
|
---|
[604] | 260 |
|
---|
[503] | 261 | $input['password'] = '';
|
---|
| 262 | $input['oldpass'] = '';
|
---|
| 263 | $this->load->model('user_model');
|
---|
| 264 | if (!isset($result['errors'])) {
|
---|
| 265 | $result['data'] = $this->user_model->update_user($src, $token, $input, $us_id);
|
---|
| 266 | $result['success'] = 1;
|
---|
| 267 | }
|
---|
[490] | 268 | echo json_encode($result);
|
---|
[503] | 269 | }
|
---|
| 270 | } else {
|
---|
| 271 | redirect('frontend/home');
|
---|
[490] | 272 | }
|
---|
[508] | 273 | }
|
---|
| 274 |
|
---|
| 275 | public function change_password() {
|
---|
| 276 | $us_id = $this->uri->segment(4);
|
---|
| 277 | $user_info = $this->session->userdata('userInfo');
|
---|
| 278 | if ($user_info) {
|
---|
| 279 | $this->load->model('user_model');
|
---|
| 280 | $us_id = $user_info['us_id'];
|
---|
| 281 | $src = "SBG";
|
---|
| 282 | $token = md5($us_id . self::TOKENPW);
|
---|
| 283 | $input = $this->input->post();
|
---|
[554] | 284 |
|
---|
[508] | 285 | if (strlen($input['passwd']) == 0) {
|
---|
[521] | 286 | $result['errors']['passwd_old_err'] = "Máºt khẩu khÃŽng ÄÆ°á»£c Äá» trá»ng!";
|
---|
[508] | 287 | }
|
---|
[602] | 288 |
|
---|
[508] | 289 | if (strlen($input['passwd_new']) == 0) {
|
---|
[521] | 290 | $result['errors']['passwd_new_err'] = "Máºt khẩu khÃŽng ÄÆ°á»£c Äá» trá»ng!";
|
---|
[614] | 291 | } else if (strcmp($input['passwd'], $input['passwd_new']) == 0) {
|
---|
[521] | 292 | $result['errors']['passwd_new_err'] = "Máºt khẩu trùng vá»i máºt khẩu hiá»n tại!";
|
---|
[602] | 293 | }else
|
---|
| 294 | {
|
---|
| 295 | if (!preg_match('/^([0-9a-zA-Z]{6,65})*$/', $input['passwd_new']))
|
---|
| 296 | {
|
---|
| 297 | $result['errors']['passwd_new_err'] = "Máºt khẩu Ãt nhất là 6 kà tá»±, và chá» chứa các kà tá»± sá» hoặc chữ, <br> khÃŽng chứa khoảng trắng và khÃŽng chứa kÜ tá»± Äặc biá»t!";
|
---|
| 298 | }
|
---|
| 299 | }
|
---|
| 300 |
|
---|
[554] | 301 | if ($input['passwd_new'] != $input['confirm_passwd_new']) {
|
---|
[521] | 302 | $result['errors']['confirm_passwd_new_err'] = "Máºt khẩu khÃŽng trùng nhau!";
|
---|
[508] | 303 | }
|
---|
[554] | 304 |
|
---|
[508] | 305 | if (!isset($result['errors'])) {
|
---|
| 306 | $user = array('username' => $user_info['username'], 'fullname' => null, 'gender' => null, 'email' => null, 'school' => null, 'province' => null, 'password' => $input['passwd_new'], 'oldpass' => $input['passwd']);
|
---|
| 307 | $data = $this->user_model->update_user($src, $token, $user, $us_id);
|
---|
| 308 | parse_str($data);
|
---|
| 309 | switch ($status) {
|
---|
| 310 | case 0:
|
---|
| 311 | $result['success'] = 1;
|
---|
| 312 | break;
|
---|
| 313 | case 6:
|
---|
[521] | 314 | $result['errors']['passwd_old_err'] = "Máºt khẩu cung cấp khÃŽng Äúng!";
|
---|
[508] | 315 | break;
|
---|
| 316 | default:
|
---|
| 317 | break;
|
---|
| 318 | }
|
---|
| 319 | }
|
---|
| 320 |
|
---|
| 321 | echo json_encode($result);
|
---|
| 322 | } else {
|
---|
| 323 | redirect('frontend/home');
|
---|
| 324 | }
|
---|
| 325 | }
|
---|
[574] | 326 |
|
---|
| 327 | public function trade_history()
|
---|
| 328 | {
|
---|
| 329 | $this->load->helper('pagging');
|
---|
| 330 | $us_id = $this->uri->segment(4);
|
---|
| 331 | $user_info = $this->session->userdata('userInfo');
|
---|
| 332 | if ($user_info)
|
---|
| 333 | {
|
---|
| 334 |
|
---|
| 335 | $data['us_id'] = $us_id;
|
---|
| 336 | $data['perpage'] = 10;
|
---|
| 337 | $data['current_page'] = $this->uri->segment(6, 1);
|
---|
| 338 | $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
|
---|
| 339 | $this->load->model('user_model');
|
---|
| 340 | $result = $this->user_model->getPaidlog($data);
|
---|
| 341 | $data['total'] = $this->user_model->countPaiglogs($us_id);
|
---|
| 342 | $data['num_links'] = 2;
|
---|
| 343 | $data['paging_url'] = base_url() . "frontend/user/trade_history/".$us_id."/page/";
|
---|
| 344 | $data['paging'] = pagging($data);
|
---|
| 345 | $paidlogs = array();
|
---|
| 346 | foreach ($result as $paidlog):
|
---|
| 347 | $paidlog['amount'] = number_format($paidlog['amount'], 0);
|
---|
| 348 | $paidlog['paid_time'] = date('d-m-Y H:i:s', strtotime($paidlog['paid_time']));
|
---|
| 349 | array_push($paidlogs, $paidlog);
|
---|
| 350 | endforeach;
|
---|
| 351 | $data['paidlogs'] = $paidlogs;
|
---|
| 352 | echo json_encode($data);
|
---|
| 353 | }else {
|
---|
| 354 | redirect('frontend/home');
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
[508] | 357 |
|
---|
[554] | 358 | }
|
---|