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