source: pro-violet-viettel/sourcecode/application/modules/admin/controllers/user.php @ 584

Last change on this file since 584 was 584, checked in by namnd, 10 years ago
File size: 4.2 KB
RevLine 
[375]1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
2
3class 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');
[437]30                $this->load->model('user_model');
[375]31                $data['current_page'] = $this->uri->segment(4, 1);
[396]32                $data['itemsoptions'] = array(10, 25, 50, 100);
33                $data['perpage'] = 10;
[584]34                $data['statusoptions'] = array(0=>"Tất cả", 1=>"Đã đăng kÜ", 2=>"Dùng thá»­");
[408]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'];
[437]58                $data['total'] = $this->user_model->get_total_users($data);
59                $us = $this->user_model->get_list_users($data);
[408]60                $users = array();
[579]61               
62                foreach($us as $u) {
[408]63                        $id = $u['us_id'];
64                        $username = $this->get_username($id);
65                        $u['username'] = $username;
66                        array_push($users, $u);
[579]67                }
[408]68               
69                $data['users'] = $users;
[375]70                $data['paging_url'] = base_url() . "admin/nguoi_dung/trang/";
71                $data['num_links'] = 2;
72                $data['paging'] = pagging($data);
73                if ($this->input->is_ajax_request())
74                {
75                        return $this->load->view('user/listview', $data);
76                }
77                return $this->load->view('user/listview', $data, true);
78        }
79       
[396]80        public function edit_user()
81        {
82                $admin_info = $this->session->userdata('adminInfo');
83                if ($admin_info)
84                {
85                        $input = $this->input->post();
86                        $result = array();
87                        $result['success'] = 0;
88                        $us_id = (int)$this->uri->segment(4, 0);
89                        if ($us_id==0){
90                                $result['success'] = 0;
91                        }else
92                        {
[437]93                                $this->load->model('user_model');
[396]94                                $input['updated_time'] = date("Y-m-d H:i:s");
[437]95                                $this->user_model->update($us_id, $input);
[396]96                                $result['success'] = 1;
97                        }
98                        echo json_encode($result);
99                }else
100                {
101                        $this->load->view('login');
102                }
103        }
104       
105        public function delete_user()
106        {
107                $admin_info = $this->session->userdata('adminInfo');
108                if ($admin_info)
109                {
110                        $result = array();
111                        $result['success'] = 0;
112                        $us_id = (int)$this->uri->segment(4, 0);
113                        if ($us_id == 0){
114                                $result['success'] = 0;
115                        }else
116                        {
[437]117                                $this->load->model('user_model');
118                                $this->user_model->delete($us_id);
[396]119                                $result['success'] = 1;
120                        }
121                        echo json_encode($result);
122                }else
123                {
124                        $this->load->view('login');
125                }
126        }
127       
128        public function get_user_by_id()
129        {
130                $admin_info = $this->session->userdata('adminInfo');
131                if ($admin_info)
132                {
133                        $result = array();
134                        $result['success'] = 0;
135                        $us_id = (int)$this->uri->segment(4, 0);
136                        if ($us_id == 0)
137                        {
138                                $result['success'] = 0;
139                        }else
140                        {
[437]141                                $this->load->model('user_model');
142                                $data = $this->user_model->search_by_id($us_id);
[396]143                                $result['item'] = $data;
144                                $result['success'] = 1;
145                        }
146                        echo json_encode($result);
147                }else
148                {
149                        $this->load->view('login');
150                }
151        }
152       
[408]153        private function get_username($us_id)
154        {
155                $src = 'violet';
156                $token = md5($us_id.self::TOKENPW);
[437]157                $this->load->model('user_model');
158                $data = $this->user_model->get_user_info($src, $us_id, $token);
[459]159                //var_dump($data);
160                if (strpos($data, '&')){
[408]161                        $arr_users = explode("&", $data);
162                        $str_username = $arr_users[1];
163                        $arr_username = explode("=", $str_username);
164                        return $arr_username[1];
165                }else
166                {
167                        return "";
168                }
169
170        }
171       
[375]172}
Note: See TracBrowser for help on using the repository browser.