[375] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
| 2 |
|
---|
| 3 | class Admin_Acc extends MX_Controller
|
---|
| 4 | {
|
---|
| 5 | public function __construct()
|
---|
| 6 | {
|
---|
| 7 | parent::__construct();
|
---|
| 8 | $this->load->helper('cookie');
|
---|
[636] | 9 | $this->load->helper('language');
|
---|
| 10 | $this->lang->load('messages', 'message');
|
---|
[375] | 11 | }
|
---|
| 12 |
|
---|
| 13 | public function index()
|
---|
| 14 | {
|
---|
| 15 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 16 | if ($admin_info)
|
---|
| 17 | {
|
---|
[590] | 18 | $role_id = $admin_info['role_id'];
|
---|
| 19 | if($role_id == 1){
|
---|
| 20 | $data['content'] = $this->get_admins();
|
---|
| 21 | $this->load->model('admin_model');
|
---|
| 22 | $data['roles'] = $this->admin_model->get_roles();
|
---|
| 23 | $this->load->view('admin_acc/index', $data);
|
---|
| 24 | }else
|
---|
| 25 | {
|
---|
| 26 | show_404();
|
---|
| 27 | }
|
---|
[375] | 28 | }else
|
---|
| 29 | {
|
---|
| 30 | $this->load->view('login');
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[392] | 34 | public function get_admins()
|
---|
[375] | 35 | {
|
---|
| 36 | $this->load->helper('pagging');
|
---|
| 37 | $this->load->model('admin_model');
|
---|
| 38 | $data['current_page'] = $this->uri->segment(4, 1);
|
---|
| 39 | $data['itemsoptions'] = array(10, 25, 50, 100);
|
---|
| 40 | $data['perpage'] = 10;
|
---|
| 41 | $data['keyword'] = "";
|
---|
[392] | 42 | $data['sorting_order']="sorting_desc";
|
---|
| 43 | $data['sorting_field']="created_time";
|
---|
| 44 | if ($this->input->post('sorting_order')) {
|
---|
| 45 | if ($this->input->post('sorting_order') != "sorting")
|
---|
| 46 | {
|
---|
| 47 | $data['sorting_order'] = $this->input->post('sorting_order');
|
---|
| 48 | $data['sorting_field'] = $this->input->post('sorting_field');
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
[375] | 51 | if ($this->input->post('items'))
|
---|
| 52 | {
|
---|
| 53 | $data['perpage'] = $this->input->post('items');
|
---|
| 54 | }
|
---|
| 55 | if ($this->input->post('keyword')) {
|
---|
| 56 | $data['keyword'] = $this->input->post('keyword');
|
---|
| 57 | }
|
---|
| 58 | $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
|
---|
| 59 | $data['total'] = $this->admin_model->get_total_admins($data);
|
---|
| 60 | $data['admins'] = $this->admin_model->get_list_admins($data);
|
---|
| 61 | $data['paging_url'] = base_url() . "admin/quan_tri_vien/trang/";
|
---|
| 62 | $data['num_links'] = 2;
|
---|
| 63 | $data['paging'] = pagging($data);
|
---|
| 64 | if ($this->input->is_ajax_request())
|
---|
| 65 | {
|
---|
| 66 | return $this->load->view('admin_acc/listview', $data);
|
---|
| 67 | }
|
---|
| 68 | return $this->load->view('admin_acc/listview', $data, true);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | public function add_admin()
|
---|
| 72 | {
|
---|
| 73 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 74 | if ($admin_info)
|
---|
| 75 | {
|
---|
| 76 | $this->load->helper('email');
|
---|
[424] | 77 | $result = array();
|
---|
[375] | 78 | $result['success'] = 0;
|
---|
| 79 | $input = $this->input->post();
|
---|
| 80 | $this->load->model('admin_model');
|
---|
| 81 | if (strlen($input['full_name'])==0)
|
---|
| 82 | {
|
---|
[636] | 83 | $result['errors']['full_name_err'] = lang('_SBG_FULLNAME_REQUIRED_MSG');
|
---|
[375] | 84 | }
|
---|
| 85 | if (strlen($input['login_name'])==0)
|
---|
| 86 | {
|
---|
[636] | 87 | $result['errors']['login_name_err'] = lang('_SBG_LOGIN_NAME_REQUIRED_MSG');
|
---|
[375] | 88 | }
|
---|
| 89 | else
|
---|
| 90 | {
|
---|
| 91 | if ($this->admin_model->check_exist(array('field'=>'login_name','value'=>$input['login_name'])))
|
---|
| 92 | {
|
---|
[636] | 93 | $result['errors']['login_name_err'] = lang('_SBG_LOGIN_NAME_DUPLICATE_MSG');
|
---|
[375] | 94 | }
|
---|
| 95 | }
|
---|
| 96 | if (strlen($input['phone'])==0)
|
---|
| 97 | {
|
---|
[636] | 98 | $result['errors']['phone_err'] = lang('_SBG_PHONE_REQUIRED_MSG');
|
---|
[375] | 99 | }
|
---|
| 100 | else
|
---|
| 101 | {
|
---|
[636] | 102 | if(!preg_match('/^([0-9]{10,11}$)$/', $input['phone'])){
|
---|
| 103 | $result['errors']['phone_err'] = lang('_SBG_PHONE_FORMAT_ERROR_MSG');
|
---|
[425] | 104 | }else if ($this->admin_model->check_exist(array('field'=>'phone','value'=>$input['phone'])))
|
---|
[375] | 105 | {
|
---|
[636] | 106 | $result['errors']['phone_err'] = lang('_SBG_PHONE_DUPLICATE_MSG');
|
---|
[375] | 107 | }
|
---|
[425] | 108 |
|
---|
[375] | 109 | }
|
---|
| 110 | if (strlen($input['passwd'])==0)
|
---|
| 111 | {
|
---|
[636] | 112 | $result['errors']['pwd1_err'] = lang('_SBG_PASSWORD_REQUIRED_MSG');
|
---|
[375] | 113 | }
|
---|
| 114 | if ($input['passwd'] != $input['pwd2'])
|
---|
| 115 | {
|
---|
[636] | 116 | $result['errors']['pwd2_err'] = lang('_SBG_PASSWORD_CONFIRM_MSG');
|
---|
[375] | 117 | }
|
---|
| 118 | if(strlen($input['email'])==0)
|
---|
| 119 | {
|
---|
[636] | 120 | $result['errors']['email_err'] = lang('_SBG_EMAIL_REQUIRED_MSG');
|
---|
[375] | 121 | }else{
|
---|
| 122 | if(!valid_email($input['email']))
|
---|
| 123 | {
|
---|
[636] | 124 | $result['errors']['email_err'] = lang('_SBG_EMAIL_FORMAT_ERROR_MSG');
|
---|
[375] | 125 | }
|
---|
| 126 | }
|
---|
| 127 | if (!isset($result['errors']))
|
---|
| 128 | {
|
---|
| 129 | unset($input['pwd2']);
|
---|
[424] | 130 | $input['passwd'] = md5($input['passwd']);
|
---|
[375] | 131 | $input['created_time']=date("Y-m-d H:i:s");
|
---|
| 132 | $input['updated_time']=date("Y-m-d H:i:s");
|
---|
| 133 | $this->admin_model->insert($input);
|
---|
| 134 | $result['success'] = 1;
|
---|
| 135 | }
|
---|
| 136 | echo json_encode($result);
|
---|
| 137 | }else{
|
---|
| 138 | $this->load->view('login');
|
---|
| 139 | }
|
---|
| 140 | }
|
---|
| 141 |
|
---|
| 142 | public function edit_admin()
|
---|
| 143 | {
|
---|
| 144 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 145 | if ($admin_info)
|
---|
| 146 | {
|
---|
[423] | 147 | $admin_id = $this->uri->segment(4);
|
---|
| 148 | $this->load->model('admin_model');
|
---|
| 149 | $data = $this->admin_model->search_by_id($admin_id);
|
---|
| 150 | $this->load->view('admin_acc/edit_admin', $data);
|
---|
| 151 | }else
|
---|
| 152 | {
|
---|
| 153 | $this->load->view('login');
|
---|
| 154 | }
|
---|
| 155 | }
|
---|
| 156 |
|
---|
| 157 | public function update_admin()
|
---|
| 158 | {
|
---|
| 159 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 160 | if ($admin_info)
|
---|
| 161 | {
|
---|
| 162 | $input = $this->input->post();
|
---|
| 163 | $result = array();
|
---|
| 164 | $result['success'] = 0;
|
---|
| 165 | $this->load->model('admin_model');
|
---|
| 166 | $input['updated_time']=date("Y-m-d H:i:s");
|
---|
| 167 | $this->admin_model->update($input['admin_id'], $input);
|
---|
| 168 | $result['success'] = 1;
|
---|
[375] | 169 | echo json_encode($result);
|
---|
| 170 | }else
|
---|
| 171 | {
|
---|
| 172 | $this->load->view('login');
|
---|
| 173 | }
|
---|
| 174 | }
|
---|
[423] | 175 |
|
---|
[375] | 176 | public function delete_admin()
|
---|
| 177 | {
|
---|
| 178 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 179 | if ($admin_info)
|
---|
| 180 | {
|
---|
| 181 | $result = array();
|
---|
| 182 | $result['success'] = 0;
|
---|
| 183 | $admin_id = (int)$this->uri->segment(4, 0);
|
---|
| 184 | if ($admin_id == 0){
|
---|
| 185 | $result['success'] = 0;
|
---|
| 186 | }else
|
---|
| 187 | {
|
---|
| 188 | $this->load->model('admin_model');
|
---|
| 189 | $this->admin_model->delete($admin_id);
|
---|
| 190 | $result['success'] = 1;
|
---|
| 191 | }
|
---|
| 192 | echo json_encode($result);
|
---|
| 193 | }else
|
---|
| 194 | {
|
---|
| 195 | $this->load->view('login');
|
---|
| 196 | }
|
---|
| 197 | }
|
---|
| 198 |
|
---|
| 199 | public function get_admin_by_id()
|
---|
| 200 | {
|
---|
| 201 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 202 | if ($admin_info)
|
---|
| 203 | {
|
---|
[423] | 204 | $admin_id = (int)$this->uri->segment(4);
|
---|
| 205 | $this->load->model('admin_model');
|
---|
| 206 | $data = $this->admin_model->search_by_id($admin_id);
|
---|
| 207 | $this->load->view('admin_acc/view_admin', $data);
|
---|
[375] | 208 | }else
|
---|
| 209 | {
|
---|
| 210 | $this->load->view('login');
|
---|
| 211 | }
|
---|
| 212 | }
|
---|
[424] | 213 |
|
---|
| 214 | public function admin_profile()
|
---|
| 215 | {
|
---|
| 216 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 217 | if($admin_info)
|
---|
| 218 | {
|
---|
| 219 | $admin_id = $admin_info['admin_id'];
|
---|
| 220 | $this->load->model(array('admin_model'));
|
---|
| 221 | $data = $this->admin_model->search_by_id($admin_id);
|
---|
| 222 | $this->load->view('admin_acc/admin_profile', $data);
|
---|
| 223 | }else
|
---|
| 224 | {
|
---|
| 225 | $this->load->view('login');
|
---|
| 226 | }
|
---|
| 227 | }
|
---|
| 228 |
|
---|
| 229 | public function update_info()
|
---|
| 230 | {
|
---|
| 231 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 232 | if ($admin_info)
|
---|
| 233 | {
|
---|
| 234 | $this->load->helper('email');
|
---|
| 235 | $input = $this->input->post();
|
---|
| 236 | $result = array();
|
---|
| 237 | $result['success'] = 0;
|
---|
| 238 | if(strlen($input['email'])>0){
|
---|
| 239 | if(!valid_email($input['email']))
|
---|
| 240 | {
|
---|
[636] | 241 | $result['errors']['email_err'] = lang('_SBG_EMAIL_FORMAT_ERROR_MSG');
|
---|
[424] | 242 | }
|
---|
| 243 | }
|
---|
| 244 | if(strlen($input['phone'])>0){
|
---|
| 245 | if (!preg_match('/[0-9]/', $input['phone']))
|
---|
| 246 | {
|
---|
[636] | 247 | $result['errors']['phone_err'] = lang('_SBG_PHONE_FORMAT_ERROR_MSG');
|
---|
[424] | 248 | }
|
---|
| 249 | }
|
---|
| 250 | if (!isset($result['errors']))
|
---|
| 251 | {
|
---|
| 252 | $input['admin_id'] = $admin_info['admin_id'];
|
---|
| 253 | $input['updated_time']=date("Y-m-d H:i:s");
|
---|
| 254 | $this->load->model('admin_model');
|
---|
| 255 | $this->admin_model->update($input['admin_id'], $input);
|
---|
| 256 | $result['success'] = 1;
|
---|
| 257 | }
|
---|
| 258 | echo json_encode($result);
|
---|
| 259 | }else
|
---|
| 260 | {
|
---|
| 261 | $this->load->view('login');
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | public function change_password()
|
---|
| 266 | {
|
---|
| 267 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 268 | if ($admin_info){
|
---|
| 269 | $result = array();
|
---|
| 270 | $result['success'] = 0;
|
---|
| 271 | $this->load->model('admin_model');
|
---|
| 272 | $input = $this->input->post();
|
---|
| 273 | $input['admin_id'] = $admin_info['admin_id'];
|
---|
| 274 | if (strlen($input['passwd']) == 0)
|
---|
| 275 | {
|
---|
[636] | 276 | $result['errors']['passwd_old_err'] = lang('_SBG_PASSWORD_REQUIRED_MSG');
|
---|
[424] | 277 | }else
|
---|
| 278 | {
|
---|
| 279 | $check_pass = $this->admin_model->check_password($input['admin_id'], $input['passwd']);
|
---|
| 280 | if (!$check_pass)
|
---|
| 281 | {
|
---|
[636] | 282 | $result['errors']['passwd_old_err'] = lang('_SBG_OLD_PASSWORD_FAIL_MSG');
|
---|
[424] | 283 | }
|
---|
| 284 | }
|
---|
| 285 | if (strlen($input['passwd_new']) == 0)
|
---|
| 286 | {
|
---|
[636] | 287 | $result['errors']['passwd_new_err'] = lang('_SBG_PASSWORD_REQUIRED_MSG');
|
---|
| 288 | }else if(strcmp($input['passwd'], $input['passwd_new']) == 0)
|
---|
[424] | 289 | {
|
---|
[636] | 290 | $result['errors']['passwd_new_err'] = lang('_SBG_PASSWORD_DUPLICATE_MSG');
|
---|
[424] | 291 | }
|
---|
| 292 | if ($input['passwd_new'] != $input['confirm_passwd_new'])
|
---|
| 293 | {
|
---|
[636] | 294 | $result['errors']['confirm_passwd_new_err'] = lang('_SBG_PASSWORD_CONFIRM_MSG');
|
---|
[424] | 295 | }
|
---|
| 296 | if (!isset($result['errors']))
|
---|
| 297 | {
|
---|
| 298 | $updated_time=date("Y-m-d H:i:s");
|
---|
| 299 | $data = array('passwd'=>md5($input['passwd_new']), 'updated_time'=>$updated_time);
|
---|
| 300 | $this->admin_model->update($input['admin_id'], $data);
|
---|
| 301 | $result['success'] = 1;
|
---|
| 302 | }
|
---|
| 303 |
|
---|
| 304 | echo json_encode($result);
|
---|
| 305 | }else
|
---|
| 306 | {
|
---|
| 307 | $this->load->view('login');
|
---|
| 308 | }
|
---|
| 309 |
|
---|
| 310 | }
|
---|
| 311 |
|
---|
[375] | 312 | } |
---|