[375] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
| 2 |
|
---|
| 3 | class User extends MX_Controller
|
---|
| 4 | {
|
---|
[408] | 5 |
|
---|
| 6 | const TOKENPW = 'violet';
|
---|
| 7 |
|
---|
[375] | 8 | public function __construct()
|
---|
| 9 | {
|
---|
| 10 | parent::__construct();
|
---|
| 11 | $this->load->helper('cookie');
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | public function index()
|
---|
| 15 | {
|
---|
| 16 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 17 | if ($admin_info)
|
---|
| 18 | {
|
---|
| 19 | $data['content'] = $this->get_users();
|
---|
| 20 | $this->load->view('user/index', $data);
|
---|
| 21 | }else
|
---|
| 22 | {
|
---|
| 23 | $this->load->view('login');
|
---|
| 24 | }
|
---|
| 25 | }
|
---|
| 26 |
|
---|
| 27 | public function get_users()
|
---|
| 28 | {
|
---|
| 29 | $this->load->helper('pagging');
|
---|
| 30 | $this->load->model('user_model');
|
---|
| 31 | $data['current_page'] = $this->uri->segment(4, 1);
|
---|
[396] | 32 | $data['itemsoptions'] = array(10, 25, 50, 100);
|
---|
| 33 | $data['perpage'] = 10;
|
---|
[408] | 34 | $data['statusoptions'] = array(0=>"Tất cả", 1=>"KÃch hoạt", 2=>"Tạm ngưng");
|
---|
| 35 | $data['status'] = 0;
|
---|
| 36 | if ($this->input->post('status'))
|
---|
| 37 | {
|
---|
| 38 | $data['status'] = (int)$this->input->post('status') ;
|
---|
| 39 | }
|
---|
[375] | 40 | $data['keyword'] = "";
|
---|
[396] | 41 | $data['sorting_order']="sorting_desc";
|
---|
| 42 | $data['sorting_field']="created_time";
|
---|
| 43 | if ($this->input->post('sorting_order')) {
|
---|
| 44 | if ($this->input->post('sorting_order') != "sorting")
|
---|
| 45 | {
|
---|
| 46 | $data['sorting_order'] = $this->input->post('sorting_order');
|
---|
| 47 | $data['sorting_field'] = $this->input->post('sorting_field');
|
---|
| 48 | }
|
---|
| 49 | }
|
---|
[375] | 50 | if ($this->input->post('items'))
|
---|
| 51 | {
|
---|
| 52 | $data['perpage'] = $this->input->post('items');
|
---|
| 53 | }
|
---|
| 54 | if ($this->input->post('keyword')) {
|
---|
| 55 | $data['keyword'] = $this->input->post('keyword');
|
---|
| 56 | }
|
---|
| 57 | $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
|
---|
| 58 | $data['total'] = $this->user_model->get_total_users($data);
|
---|
[408] | 59 | $us = $this->user_model->get_list_users($data);
|
---|
| 60 | $users = array();
|
---|
| 61 | foreach($us as $u):
|
---|
| 62 | $id = $u['us_id'];
|
---|
| 63 | $username = $this->get_username($id);
|
---|
| 64 | $u['username'] = $username;
|
---|
| 65 | array_push($users, $u);
|
---|
| 66 | endforeach;
|
---|
| 67 |
|
---|
| 68 | $data['users'] = $users;
|
---|
[375] | 69 | $data['paging_url'] = base_url() . "admin/nguoi_dung/trang/";
|
---|
| 70 | $data['num_links'] = 2;
|
---|
| 71 | $data['paging'] = pagging($data);
|
---|
| 72 | if ($this->input->is_ajax_request())
|
---|
| 73 | {
|
---|
| 74 | return $this->load->view('user/listview', $data);
|
---|
| 75 | }
|
---|
| 76 | return $this->load->view('user/listview', $data, true);
|
---|
| 77 | }
|
---|
| 78 |
|
---|
[396] | 79 | public function edit_user()
|
---|
| 80 | {
|
---|
| 81 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 82 | if ($admin_info)
|
---|
| 83 | {
|
---|
| 84 | $input = $this->input->post();
|
---|
| 85 | $result = array();
|
---|
| 86 | $result['success'] = 0;
|
---|
| 87 | $us_id = (int)$this->uri->segment(4, 0);
|
---|
| 88 | if ($us_id==0){
|
---|
| 89 | $result['success'] = 0;
|
---|
| 90 | }else
|
---|
| 91 | {
|
---|
| 92 | $this->load->model('user_model');
|
---|
| 93 | $input['updated_time'] = date("Y-m-d H:i:s");
|
---|
| 94 | $this->user_model->update($us_id, $input);
|
---|
| 95 | $result['success'] = 1;
|
---|
| 96 | }
|
---|
| 97 | echo json_encode($result);
|
---|
| 98 | }else
|
---|
| 99 | {
|
---|
| 100 | $this->load->view('login');
|
---|
| 101 | }
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | public function delete_user()
|
---|
| 105 | {
|
---|
| 106 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 107 | if ($admin_info)
|
---|
| 108 | {
|
---|
| 109 | $result = array();
|
---|
| 110 | $result['success'] = 0;
|
---|
| 111 | $us_id = (int)$this->uri->segment(4, 0);
|
---|
| 112 | if ($us_id == 0){
|
---|
| 113 | $result['success'] = 0;
|
---|
| 114 | }else
|
---|
| 115 | {
|
---|
| 116 | $this->load->model('user_model');
|
---|
| 117 | $this->user_model->delete($us_id);
|
---|
| 118 | $result['success'] = 1;
|
---|
| 119 | }
|
---|
| 120 | echo json_encode($result);
|
---|
| 121 | }else
|
---|
| 122 | {
|
---|
| 123 | $this->load->view('login');
|
---|
| 124 | }
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | public function get_user_by_id()
|
---|
| 128 | {
|
---|
| 129 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 130 | if ($admin_info)
|
---|
| 131 | {
|
---|
| 132 | $result = array();
|
---|
| 133 | $result['success'] = 0;
|
---|
| 134 | $us_id = (int)$this->uri->segment(4, 0);
|
---|
| 135 | if ($us_id == 0)
|
---|
| 136 | {
|
---|
| 137 | $result['success'] = 0;
|
---|
| 138 | }else
|
---|
| 139 | {
|
---|
| 140 | $this->load->model('user_model');
|
---|
| 141 | $data = $this->user_model->search_by_id($us_id);
|
---|
| 142 | $result['item'] = $data;
|
---|
| 143 | $result['success'] = 1;
|
---|
| 144 | }
|
---|
| 145 | echo json_encode($result);
|
---|
| 146 | }else
|
---|
| 147 | {
|
---|
| 148 | $this->load->view('login');
|
---|
| 149 | }
|
---|
| 150 | }
|
---|
| 151 |
|
---|
[408] | 152 | private function get_username($us_id)
|
---|
| 153 | {
|
---|
| 154 | $src = 'violet';
|
---|
| 155 | $token = md5($us_id.self::TOKENPW);
|
---|
| 156 | $this->load->model('user_model');
|
---|
| 157 | $data = $this->user_model->get_user_info($src, $us_id, $token);
|
---|
| 158 | if (strlen($data) > 0){
|
---|
| 159 | $arr_users = explode("&", $data);
|
---|
| 160 | $str_username = $arr_users[1];
|
---|
| 161 | $arr_username = explode("=", $str_username);
|
---|
| 162 | return $arr_username[1];
|
---|
| 163 | }else
|
---|
| 164 | {
|
---|
| 165 | return "";
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | }
|
---|
| 169 |
|
---|
[375] | 170 | } |
---|