[375] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
| 2 |
|
---|
| 3 | class User extends MX_Controller
|
---|
| 4 | {
|
---|
| 5 | public function __construct()
|
---|
| 6 | {
|
---|
| 7 | parent::__construct();
|
---|
| 8 | $this->load->helper('cookie');
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | public function index()
|
---|
| 12 | {
|
---|
| 13 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 14 | if ($admin_info)
|
---|
| 15 | {
|
---|
| 16 | $data['content'] = $this->get_users();
|
---|
| 17 | $this->load->view('user/index', $data);
|
---|
| 18 | }else
|
---|
| 19 | {
|
---|
| 20 | $this->load->view('login');
|
---|
| 21 | }
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | public function get_users()
|
---|
| 25 | {
|
---|
| 26 | $this->load->helper('pagging');
|
---|
| 27 | $this->load->model('user_model');
|
---|
| 28 | $data['current_page'] = $this->uri->segment(4, 1);
|
---|
[396] | 29 | $data['itemsoptions'] = array(10, 25, 50, 100);
|
---|
| 30 | $data['perpage'] = 10;
|
---|
[375] | 31 | $data['keyword'] = "";
|
---|
[396] | 32 | $data['sorting_order']="sorting_desc";
|
---|
| 33 | $data['sorting_field']="created_time";
|
---|
| 34 | if ($this->input->post('sorting_order')) {
|
---|
| 35 | if ($this->input->post('sorting_order') != "sorting")
|
---|
| 36 | {
|
---|
| 37 | $data['sorting_order'] = $this->input->post('sorting_order');
|
---|
| 38 | $data['sorting_field'] = $this->input->post('sorting_field');
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
[375] | 41 | if ($this->input->post('items'))
|
---|
| 42 | {
|
---|
| 43 | $data['perpage'] = $this->input->post('items');
|
---|
| 44 | }
|
---|
| 45 | if ($this->input->post('keyword')) {
|
---|
| 46 | $data['keyword'] = $this->input->post('keyword');
|
---|
| 47 | }
|
---|
| 48 | $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
|
---|
| 49 | $data['total'] = $this->user_model->get_total_users($data);
|
---|
| 50 | $data['users'] = $this->user_model->get_list_users($data);
|
---|
| 51 | $data['paging_url'] = base_url() . "admin/nguoi_dung/trang/";
|
---|
| 52 | $data['num_links'] = 2;
|
---|
| 53 | $data['paging'] = pagging($data);
|
---|
| 54 | if ($this->input->is_ajax_request())
|
---|
| 55 | {
|
---|
| 56 | return $this->load->view('user/listview', $data);
|
---|
| 57 | }
|
---|
| 58 | return $this->load->view('user/listview', $data, true);
|
---|
| 59 | }
|
---|
| 60 |
|
---|
[396] | 61 | public function edit_user()
|
---|
| 62 | {
|
---|
| 63 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 64 | if ($admin_info)
|
---|
| 65 | {
|
---|
| 66 | $input = $this->input->post();
|
---|
| 67 | $result = array();
|
---|
| 68 | $result['success'] = 0;
|
---|
| 69 | $us_id = (int)$this->uri->segment(4, 0);
|
---|
| 70 | if ($us_id==0){
|
---|
| 71 | $result['success'] = 0;
|
---|
| 72 | }else
|
---|
| 73 | {
|
---|
| 74 | $this->load->model('user_model');
|
---|
| 75 | $input['updated_time'] = date("Y-m-d H:i:s");
|
---|
| 76 | $this->user_model->update($us_id, $input);
|
---|
| 77 | $result['success'] = 1;
|
---|
| 78 | }
|
---|
| 79 | echo json_encode($result);
|
---|
| 80 | }else
|
---|
| 81 | {
|
---|
| 82 | $this->load->view('login');
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | public function delete_user()
|
---|
| 87 | {
|
---|
| 88 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 89 | if ($admin_info)
|
---|
| 90 | {
|
---|
| 91 | $result = array();
|
---|
| 92 | $result['success'] = 0;
|
---|
| 93 | $us_id = (int)$this->uri->segment(4, 0);
|
---|
| 94 | if ($us_id == 0){
|
---|
| 95 | $result['success'] = 0;
|
---|
| 96 | }else
|
---|
| 97 | {
|
---|
| 98 | $this->load->model('user_model');
|
---|
| 99 | $this->user_model->delete($us_id);
|
---|
| 100 | $result['success'] = 1;
|
---|
| 101 | }
|
---|
| 102 | echo json_encode($result);
|
---|
| 103 | }else
|
---|
| 104 | {
|
---|
| 105 | $this->load->view('login');
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | public function get_user_by_id()
|
---|
| 110 | {
|
---|
| 111 | $admin_info = $this->session->userdata('adminInfo');
|
---|
| 112 | if ($admin_info)
|
---|
| 113 | {
|
---|
| 114 | $result = array();
|
---|
| 115 | $result['success'] = 0;
|
---|
| 116 | $us_id = (int)$this->uri->segment(4, 0);
|
---|
| 117 | if ($us_id == 0)
|
---|
| 118 | {
|
---|
| 119 | $result['success'] = 0;
|
---|
| 120 | }else
|
---|
| 121 | {
|
---|
| 122 | $this->load->model('user_model');
|
---|
| 123 | $data = $this->user_model->search_by_id($us_id);
|
---|
| 124 | $result['item'] = $data;
|
---|
| 125 | $result['success'] = 1;
|
---|
| 126 | }
|
---|
| 127 | echo json_encode($result);
|
---|
| 128 | }else
|
---|
| 129 | {
|
---|
| 130 | $this->load->view('login');
|
---|
| 131 | }
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[375] | 134 | } |
---|